6 char *exact_matches[] = {
14 GFileAttributeMatcher *matcher;
18 for (i = 0; i < G_N_ELEMENTS (exact_matches); i++)
20 matcher = g_file_attribute_matcher_new (exact_matches[i]);
21 s = g_file_attribute_matcher_to_string (matcher);
22 if (! g_str_equal (exact_matches[i], s))
25 g_test_message ("matcher should be %s, but is %s", exact_matches[i], s);
28 g_file_attribute_matcher_unref (matcher);
39 /* star makes everything else go away */
45 { "*", "a::b,*,a::*" },
46 /* a::* makes a::<anything> go away */
47 { "a::*", "a::*,a::*" },
48 { "a::*", "a::*,a::b" },
49 { "a::*", "a::b,a::*" },
50 { "a::*", "a::b,a::*,a::c" },
51 /* a::b does not allow duplicates */
52 { "a::b", "a::b,a::b" },
53 { "a::b,a::c", "a::b,a::c,a::b" },
54 /* stuff gets ordered in registration order */
55 { "a::b,a::c", "a::c,a::b" },
56 { "a::*,b::*", "b::*,a::*" },
59 GFileAttributeMatcher *matcher;
63 for (i = 0; i < G_N_ELEMENTS (equals); i++)
65 matcher = g_file_attribute_matcher_new (equals[i].actual);
66 s = g_file_attribute_matcher_to_string (matcher);
67 if (! g_str_equal (equals[i].expected, s))
70 g_test_message ("matcher for %s should be %s, but is %s", equals[i].actual, equals[i].expected, s);
73 g_file_attribute_matcher_unref (matcher);
85 /* * subtracts everything */
87 { "a::*", "*", NULL },
88 { "a::b", "*", NULL },
89 { "a::b,a::c", "*", NULL },
90 { "a::*,b::*", "*", NULL },
91 { "a::*,b::c", "*", NULL },
92 { "a::b,b::*", "*", NULL },
93 { "a::b,b::c", "*", NULL },
94 { "a::b,a::c,b::*", "*", NULL },
95 { "a::b,a::c,b::c", "*", NULL },
96 /* a::* subtracts all a's */
98 { "a::*", "a::*", NULL },
99 { "a::b", "a::*", NULL },
100 { "a::b,a::c", "a::*", NULL },
101 { "a::*,b::*", "a::*", "b::*" },
102 { "a::*,b::c", "a::*", "b::c" },
103 { "a::b,b::*", "a::*", "b::*" },
104 { "a::b,b::c", "a::*", "b::c" },
105 { "a::b,a::c,b::*", "a::*", "b::*" },
106 { "a::b,a::c,b::c", "a::*", "b::c" },
107 /* a::b subtracts exactly that */
108 { "*", "a::b", "*" },
109 { "a::*", "a::b", "a::*" },
110 { "a::b", "a::b", NULL },
111 { "a::b,a::c", "a::b", "a::c" },
112 { "a::*,b::*", "a::b", "a::*,b::*" },
113 { "a::*,b::c", "a::b", "a::*,b::c" },
114 { "a::b,b::*", "a::b", "b::*" },
115 { "a::b,b::c", "a::b", "b::c" },
116 { "a::b,a::c,b::*", "a::b", "a::c,b::*" },
117 { "a::b,a::c,b::c", "a::b", "a::c,b::c" },
118 /* a::b,b::* subtracts both of those */
119 { "*", "a::b,b::*", "*" },
120 { "a::*", "a::b,b::*", "a::*" },
121 { "a::b", "a::b,b::*", NULL },
122 { "a::b,a::c", "a::b,b::*", "a::c" },
123 { "a::*,b::*", "a::b,b::*", "a::*" },
124 { "a::*,b::c", "a::b,b::*", "a::*" },
125 { "a::b,b::*", "a::b,b::*", NULL },
126 { "a::b,b::c", "a::b,b::*", NULL },
127 { "a::b,a::c,b::*", "a::b,b::*", "a::c" },
128 { "a::b,a::c,b::c", "a::b,b::*", "a::c" },
129 /* a::b,b::c should work, too */
130 { "*", "a::b,b::c", "*" },
131 { "a::*", "a::b,b::c", "a::*" },
132 { "a::b", "a::b,b::c", NULL },
133 { "a::b,a::c", "a::b,b::c", "a::c" },
134 { "a::*,b::*", "a::b,b::c", "a::*,b::*" },
135 { "a::*,b::c", "a::b,b::c", "a::*" },
136 { "a::b,b::*", "a::b,b::c", "b::*" },
137 { "a::b,b::c", "a::b,b::c", NULL },
138 { "a::b,a::c,b::*", "a::b,b::c", "a::c,b::*" },
139 { "a::b,a::c,b::c", "a::b,b::c", "a::c" },
142 GFileAttributeMatcher *matcher, *subtract, *result;
146 for (i = 0; i < G_N_ELEMENTS (subtractions); i++)
148 matcher = g_file_attribute_matcher_new (subtractions[i].attributes);
149 subtract = g_file_attribute_matcher_new (subtractions[i].subtract);
150 result = g_file_attribute_matcher_subtract (matcher, subtract);
151 s = g_file_attribute_matcher_to_string (result);
152 if (g_strcmp0 (subtractions[i].result, s))
155 g_test_message ("matcher for %s - %s should be %s, but is %s",
156 subtractions[i].attributes, subtractions[i].subtract,
157 subtractions[i].result, s);
160 g_file_attribute_matcher_unref (matcher);
161 g_file_attribute_matcher_unref (subtract);
162 g_file_attribute_matcher_unref (result);
167 main (int argc, char *argv[])
169 g_test_init (&argc, &argv, NULL);
171 g_test_add_func ("/fileattributematcher/exact", test_exact);
172 g_test_add_func ("/fileattributematcher/equality", test_equality);
173 g_test_add_func ("/fileattributematcher/subtract", test_subtract);
175 return g_test_run ();