1 | /* guuid.c |
2 | * |
3 | * Copyright (C) 2013-2015, 2017 Red Hat, Inc. |
4 | * |
5 | * This is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Lesser General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2.1 of the License, or (at your option) any later version. |
9 | * |
10 | * This is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Lesser General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Lesser General Public |
16 | * License along with this library; if not, write to the Free Software |
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
18 | */ |
19 | |
20 | #include "config.h" |
21 | |
22 | #undef G_DISABLE_ASSERT |
23 | |
24 | #include <glib.h> |
25 | #include <string.h> |
26 | |
27 | static void |
28 | test_guuid_string (void) |
29 | { |
30 | g_assert_false (g_uuid_string_is_valid ("00010203-0405-0607-0809" )); |
31 | g_assert_false (g_uuid_string_is_valid ("zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz" )); |
32 | g_assert_false (g_uuid_string_is_valid ("000102030405060708090a0b0c0d0e0f" )); |
33 | g_assert_false (g_uuid_string_is_valid ("{urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6}" )); |
34 | g_assert_false (g_uuid_string_is_valid ("urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6" )); |
35 | |
36 | g_assert_true (g_uuid_string_is_valid ("00010203-0405-0607-0809-0a0b0c0d0e0f" )); |
37 | g_assert_true (g_uuid_string_is_valid ("7d444840-9dc0-11d1-b245-5ffdce74fad2" )); |
38 | g_assert_true (g_uuid_string_is_valid ("e902893a-9d22-3c7e-a7b8-d6e313b71d9f" )); |
39 | g_assert_true (g_uuid_string_is_valid ("6ba7b810-9dad-11d1-80b4-00c04fd430c8" )); |
40 | } |
41 | |
42 | static void |
43 | test_guuid_random (void) |
44 | { |
45 | gchar *str1, *str2; |
46 | |
47 | str1 = g_uuid_string_random (); |
48 | g_assert_cmpuint (strlen (str1), ==, 36); |
49 | g_assert_true (g_uuid_string_is_valid (str1)); |
50 | |
51 | str2 = g_uuid_string_random (); |
52 | g_assert_cmpuint (strlen (str2), ==, 36); |
53 | g_assert_true (g_uuid_string_is_valid (str2)); |
54 | g_assert_cmpstr (str1, !=, str2); |
55 | |
56 | g_free (mem: str1); |
57 | g_free (mem: str2); |
58 | } |
59 | |
60 | int |
61 | main (int argc, char **argv) |
62 | { |
63 | g_test_init (argc: &argc, argv: &argv, NULL); |
64 | g_test_bug_base (uri_pattern: "http://bugzilla.gnome.org/" ); |
65 | |
66 | /* GUuid Tests */ |
67 | g_test_add_func (testpath: "/uuid/string" , test_func: test_guuid_string); |
68 | g_test_add_func (testpath: "/uuid/random" , test_func: test_guuid_random); |
69 | |
70 | return g_test_run (); |
71 | } |
72 | |