1 | /* |
2 | * Copyright © 2020 Canonical Ltd. |
3 | * |
4 | * This work is provided "as is"; redistribution and modification |
5 | * in whole or in part, in any medium, physical or electronic is |
6 | * permitted without restriction. |
7 | * |
8 | * This work is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11 | * |
12 | * In no event shall the authors or contributors be liable for any |
13 | * direct, indirect, incidental, special, exemplary, or consequential |
14 | * damages (including, but not limited to, procurement of substitute |
15 | * goods or services; loss of use, data, or profits; or business |
16 | * interruption) however caused and on any theory of liability, whether |
17 | * in contract, strict liability, or tort (including negligence or |
18 | * otherwise) arising in any way out of the use of this software, even |
19 | * if advised of the possibility of such damage. |
20 | */ |
21 | |
22 | #include "glib.h" |
23 | |
24 | static void |
25 | test_strvbuilder_empty (void) |
26 | { |
27 | GStrvBuilder *builder; |
28 | GStrv result; |
29 | |
30 | builder = g_strv_builder_new (); |
31 | result = g_strv_builder_end (builder); |
32 | g_assert_nonnull (result); |
33 | g_assert_cmpint (g_strv_length (result), ==, 0); |
34 | |
35 | g_strfreev (str_array: result); |
36 | g_strv_builder_unref (builder); |
37 | } |
38 | |
39 | static void |
40 | test_strvbuilder_add (void) |
41 | { |
42 | GStrvBuilder *builder; |
43 | GStrv result; |
44 | const gchar *expected[] = { "one" , "two" , "three" , NULL }; |
45 | |
46 | builder = g_strv_builder_new (); |
47 | g_strv_builder_add (builder, value: "one" ); |
48 | g_strv_builder_add (builder, value: "two" ); |
49 | g_strv_builder_add (builder, value: "three" ); |
50 | result = g_strv_builder_end (builder); |
51 | g_assert_nonnull (result); |
52 | g_assert_true (g_strv_equal ((const gchar *const *) result, expected)); |
53 | |
54 | g_strfreev (str_array: result); |
55 | g_strv_builder_unref (builder); |
56 | } |
57 | |
58 | static void |
59 | test_strvbuilder_ref (void) |
60 | { |
61 | GStrvBuilder *builder; |
62 | |
63 | builder = g_strv_builder_new (); |
64 | g_strv_builder_ref (builder); |
65 | g_strv_builder_unref (builder); |
66 | g_strv_builder_unref (builder); |
67 | } |
68 | |
69 | int |
70 | main (int argc, |
71 | char *argv[]) |
72 | { |
73 | g_test_init (argc: &argc, argv: &argv, NULL); |
74 | |
75 | g_test_add_func (testpath: "/strvbuilder/empty" , test_func: test_strvbuilder_empty); |
76 | g_test_add_func (testpath: "/strvbuilder/add" , test_func: test_strvbuilder_add); |
77 | g_test_add_func (testpath: "/strvbuilder/ref" , test_func: test_strvbuilder_ref); |
78 | |
79 | return g_test_run (); |
80 | } |
81 | |