summaryrefslogtreecommitdiff
path: root/glib/tests/guuid.c
blob: bfe27955b821c980fac732032be99f0614ea2fac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* guuid.c
 *
 * Copyright (C) 2013-2015, 2017 Red Hat, Inc.
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "config.h"

#undef G_DISABLE_ASSERT

#include <glib.h>
#include <string.h>

static void
test_guuid_string (void)
{
  g_assert_false (g_uuid_string_is_valid ("00010203-0405-0607-0809"));
  g_assert_false (g_uuid_string_is_valid ("zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz"));
  g_assert_false (g_uuid_string_is_valid ("000102030405060708090a0b0c0d0e0f"));
  g_assert_false (g_uuid_string_is_valid ("{urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6}"));
  g_assert_false (g_uuid_string_is_valid ("urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6"));

  g_assert_true (g_uuid_string_is_valid ("00010203-0405-0607-0809-0a0b0c0d0e0f"));
  g_assert_true (g_uuid_string_is_valid ("7d444840-9dc0-11d1-b245-5ffdce74fad2"));
  g_assert_true (g_uuid_string_is_valid ("e902893a-9d22-3c7e-a7b8-d6e313b71d9f"));
  g_assert_true (g_uuid_string_is_valid ("6ba7b810-9dad-11d1-80b4-00c04fd430c8"));
}

static void
test_guuid_random (void)
{
  gchar *str1, *str2;

  str1 = g_uuid_string_random ();
  g_assert_cmpuint (strlen (str1), ==, 36);
  g_assert_true (g_uuid_string_is_valid (str1));

  str2 = g_uuid_string_random ();
  g_assert_cmpuint (strlen (str2), ==, 36);
  g_assert_true (g_uuid_string_is_valid (str2));
  g_assert_cmpstr (str1, !=, str2);

  g_free (str1);
  g_free (str2);
}

int
main (int argc, char **argv)
{
  g_test_init (&argc, &argv, NULL);

  /* GUuid Tests */
  g_test_add_func ("/uuid/string", test_guuid_string);
  g_test_add_func ("/uuid/random", test_guuid_random);

  return g_test_run ();
}