1*592efe25SPierre Pronchery /*
2*592efe25SPierre Pronchery * test-fragment.c
3*592efe25SPierre Pronchery * Tests for the public libpkgconf fragment API.
4*592efe25SPierre Pronchery *
5*592efe25SPierre Pronchery * SPDX-License-Identifier: pkgconf
6*592efe25SPierre Pronchery *
7*592efe25SPierre Pronchery * Copyright (c) 2026 pkgconf authors (see AUTHORS).
8*592efe25SPierre Pronchery *
9*592efe25SPierre Pronchery * Permission to use, copy, modify, and/or distribute this software for any
10*592efe25SPierre Pronchery * purpose with or without fee is hereby granted, provided that the above
11*592efe25SPierre Pronchery * copyright notice and this permission notice appear in all copies.
12*592efe25SPierre Pronchery *
13*592efe25SPierre Pronchery * This software is provided 'as is' and without any warranty, express or
14*592efe25SPierre Pronchery * implied. In no event shall the authors be liable for any damages arising
15*592efe25SPierre Pronchery * from the use of this software.
16*592efe25SPierre Pronchery */
17*592efe25SPierre Pronchery
18*592efe25SPierre Pronchery #include "test-api.h"
19*592efe25SPierre Pronchery
20*592efe25SPierre Pronchery static size_t
fragment_count(const pkgconf_list_t * list)21*592efe25SPierre Pronchery fragment_count(const pkgconf_list_t *list)
22*592efe25SPierre Pronchery {
23*592efe25SPierre Pronchery size_t n = 0;
24*592efe25SPierre Pronchery const pkgconf_node_t *iter;
25*592efe25SPierre Pronchery
26*592efe25SPierre Pronchery PKGCONF_FOREACH_LIST_ENTRY(list->head, iter)
27*592efe25SPierre Pronchery {
28*592efe25SPierre Pronchery n++;
29*592efe25SPierre Pronchery }
30*592efe25SPierre Pronchery
31*592efe25SPierre Pronchery return n;
32*592efe25SPierre Pronchery }
33*592efe25SPierre Pronchery
34*592efe25SPierre Pronchery static const pkgconf_fragment_t *
fragment_at(const pkgconf_list_t * list,size_t index)35*592efe25SPierre Pronchery fragment_at(const pkgconf_list_t *list, size_t index)
36*592efe25SPierre Pronchery {
37*592efe25SPierre Pronchery const pkgconf_node_t *iter;
38*592efe25SPierre Pronchery size_t i = 0;
39*592efe25SPierre Pronchery
40*592efe25SPierre Pronchery PKGCONF_FOREACH_LIST_ENTRY(list->head, iter)
41*592efe25SPierre Pronchery {
42*592efe25SPierre Pronchery if (i++ == index)
43*592efe25SPierre Pronchery return iter->data;
44*592efe25SPierre Pronchery }
45*592efe25SPierre Pronchery
46*592efe25SPierre Pronchery return NULL;
47*592efe25SPierre Pronchery }
48*592efe25SPierre Pronchery
49*592efe25SPierre Pronchery /*
50*592efe25SPierre Pronchery * Render a fragment list to a newly-allocated C string for assertions.
51*592efe25SPierre Pronchery * Caller frees.
52*592efe25SPierre Pronchery */
53*592efe25SPierre Pronchery static char *
render_to_string(const pkgconf_list_t * list)54*592efe25SPierre Pronchery render_to_string(const pkgconf_list_t *list)
55*592efe25SPierre Pronchery {
56*592efe25SPierre Pronchery pkgconf_buffer_t buf = PKGCONF_BUFFER_INITIALIZER;
57*592efe25SPierre Pronchery pkgconf_fragment_render_buf(list, &buf, false, NULL, ' ');
58*592efe25SPierre Pronchery
59*592efe25SPierre Pronchery if (pkgconf_buffer_str(&buf) == NULL)
60*592efe25SPierre Pronchery return strdup("");
61*592efe25SPierre Pronchery
62*592efe25SPierre Pronchery char *out = strdup(pkgconf_buffer_str(&buf));
63*592efe25SPierre Pronchery pkgconf_buffer_finalize(&buf);
64*592efe25SPierre Pronchery return out;
65*592efe25SPierre Pronchery }
66*592efe25SPierre Pronchery
67*592efe25SPierre Pronchery static void
test_fragment_parse_cflags(void)68*592efe25SPierre Pronchery test_fragment_parse_cflags(void)
69*592efe25SPierre Pronchery {
70*592efe25SPierre Pronchery pkgconf_client_t *client = test_client_new();
71*592efe25SPierre Pronchery pkgconf_list_t frags = PKGCONF_LIST_INITIALIZER;
72*592efe25SPierre Pronchery pkgconf_list_t vars = PKGCONF_LIST_INITIALIZER;
73*592efe25SPierre Pronchery
74*592efe25SPierre Pronchery TEST_ASSERT_TRUE(pkgconf_fragment_parse(client, &frags, &vars, "-I/usr/include -DFOO=1", 0));
75*592efe25SPierre Pronchery TEST_ASSERT_EQ(fragment_count(&frags), 2);
76*592efe25SPierre Pronchery
77*592efe25SPierre Pronchery const pkgconf_fragment_t *first = fragment_at(&frags, 0);
78*592efe25SPierre Pronchery TEST_ASSERT_NONNULL(first);
79*592efe25SPierre Pronchery TEST_ASSERT_EQ(first->type, 'I');
80*592efe25SPierre Pronchery TEST_ASSERT_STRCMP_EQ(first->data, "/usr/include");
81*592efe25SPierre Pronchery
82*592efe25SPierre Pronchery pkgconf_fragment_free(&frags);
83*592efe25SPierre Pronchery pkgconf_variable_list_free(&vars);
84*592efe25SPierre Pronchery pkgconf_client_free(client);
85*592efe25SPierre Pronchery }
86*592efe25SPierre Pronchery
87*592efe25SPierre Pronchery static void
test_fragment_parse_libs(void)88*592efe25SPierre Pronchery test_fragment_parse_libs(void)
89*592efe25SPierre Pronchery {
90*592efe25SPierre Pronchery pkgconf_client_t *client = test_client_new();
91*592efe25SPierre Pronchery pkgconf_list_t frags = PKGCONF_LIST_INITIALIZER;
92*592efe25SPierre Pronchery pkgconf_list_t vars = PKGCONF_LIST_INITIALIZER;
93*592efe25SPierre Pronchery
94*592efe25SPierre Pronchery TEST_ASSERT_TRUE(pkgconf_fragment_parse(client, &frags, &vars, "-L/usr/lib -lfoo -lbar", 0));
95*592efe25SPierre Pronchery TEST_ASSERT_EQ(fragment_count(&frags), 3);
96*592efe25SPierre Pronchery
97*592efe25SPierre Pronchery const pkgconf_fragment_t *f0 = fragment_at(&frags, 0);
98*592efe25SPierre Pronchery const pkgconf_fragment_t *f1 = fragment_at(&frags, 1);
99*592efe25SPierre Pronchery const pkgconf_fragment_t *f2 = fragment_at(&frags, 2);
100*592efe25SPierre Pronchery
101*592efe25SPierre Pronchery TEST_ASSERT_NONNULL(f0);
102*592efe25SPierre Pronchery TEST_ASSERT_NONNULL(f1);
103*592efe25SPierre Pronchery TEST_ASSERT_NONNULL(f2);
104*592efe25SPierre Pronchery
105*592efe25SPierre Pronchery TEST_ASSERT_EQ(f0->type, 'L');
106*592efe25SPierre Pronchery TEST_ASSERT_STRCMP_EQ(f0->data, "/usr/lib");
107*592efe25SPierre Pronchery TEST_ASSERT_EQ(f1->type, 'l');
108*592efe25SPierre Pronchery TEST_ASSERT_STRCMP_EQ(f1->data, "foo");
109*592efe25SPierre Pronchery TEST_ASSERT_EQ(f2->type, 'l');
110*592efe25SPierre Pronchery TEST_ASSERT_STRCMP_EQ(f2->data, "bar");
111*592efe25SPierre Pronchery
112*592efe25SPierre Pronchery pkgconf_fragment_free(&frags);
113*592efe25SPierre Pronchery pkgconf_variable_list_free(&vars);
114*592efe25SPierre Pronchery pkgconf_client_free(client);
115*592efe25SPierre Pronchery }
116*592efe25SPierre Pronchery
117*592efe25SPierre Pronchery static void
test_fragment_parse_empty(void)118*592efe25SPierre Pronchery test_fragment_parse_empty(void)
119*592efe25SPierre Pronchery {
120*592efe25SPierre Pronchery pkgconf_client_t *client = test_client_new();
121*592efe25SPierre Pronchery pkgconf_list_t frags = PKGCONF_LIST_INITIALIZER;
122*592efe25SPierre Pronchery pkgconf_list_t vars = PKGCONF_LIST_INITIALIZER;
123*592efe25SPierre Pronchery
124*592efe25SPierre Pronchery TEST_ASSERT_TRUE(pkgconf_fragment_parse(client, &frags, &vars, "", 0));
125*592efe25SPierre Pronchery TEST_ASSERT_EQ(fragment_count(&frags), 0);
126*592efe25SPierre Pronchery
127*592efe25SPierre Pronchery pkgconf_fragment_free(&frags);
128*592efe25SPierre Pronchery pkgconf_variable_list_free(&vars);
129*592efe25SPierre Pronchery pkgconf_client_free(client);
130*592efe25SPierre Pronchery }
131*592efe25SPierre Pronchery
132*592efe25SPierre Pronchery static void
test_fragment_add_single(void)133*592efe25SPierre Pronchery test_fragment_add_single(void)
134*592efe25SPierre Pronchery {
135*592efe25SPierre Pronchery pkgconf_client_t *client = test_client_new();
136*592efe25SPierre Pronchery pkgconf_list_t frags = PKGCONF_LIST_INITIALIZER;
137*592efe25SPierre Pronchery pkgconf_list_t vars = PKGCONF_LIST_INITIALIZER;
138*592efe25SPierre Pronchery
139*592efe25SPierre Pronchery pkgconf_fragment_add(client, &frags, &vars, "-I/opt/include", 0);
140*592efe25SPierre Pronchery
141*592efe25SPierre Pronchery TEST_ASSERT_EQ(fragment_count(&frags), 1);
142*592efe25SPierre Pronchery
143*592efe25SPierre Pronchery const pkgconf_fragment_t *f = fragment_at(&frags, 0);
144*592efe25SPierre Pronchery TEST_ASSERT_NONNULL(f);
145*592efe25SPierre Pronchery TEST_ASSERT_EQ(f->type, 'I');
146*592efe25SPierre Pronchery TEST_ASSERT_STRCMP_EQ(f->data, "/opt/include");
147*592efe25SPierre Pronchery
148*592efe25SPierre Pronchery pkgconf_fragment_free(&frags);
149*592efe25SPierre Pronchery pkgconf_variable_list_free(&vars);
150*592efe25SPierre Pronchery pkgconf_client_free(client);
151*592efe25SPierre Pronchery }
152*592efe25SPierre Pronchery
153*592efe25SPierre Pronchery static void
test_fragment_render_cflags(void)154*592efe25SPierre Pronchery test_fragment_render_cflags(void)
155*592efe25SPierre Pronchery {
156*592efe25SPierre Pronchery pkgconf_client_t *client = test_client_new();
157*592efe25SPierre Pronchery pkgconf_list_t frags = PKGCONF_LIST_INITIALIZER;
158*592efe25SPierre Pronchery pkgconf_list_t vars = PKGCONF_LIST_INITIALIZER;
159*592efe25SPierre Pronchery
160*592efe25SPierre Pronchery pkgconf_fragment_parse(client, &frags, &vars, "-I/usr/include -I/opt/include", 0);
161*592efe25SPierre Pronchery
162*592efe25SPierre Pronchery char *rendered = render_to_string(&frags);
163*592efe25SPierre Pronchery TEST_ASSERT_NONNULL(rendered);
164*592efe25SPierre Pronchery TEST_ASSERT_STRCMP_EQ(rendered, "-I/usr/include -I/opt/include");
165*592efe25SPierre Pronchery
166*592efe25SPierre Pronchery free(rendered);
167*592efe25SPierre Pronchery pkgconf_fragment_free(&frags);
168*592efe25SPierre Pronchery pkgconf_variable_list_free(&vars);
169*592efe25SPierre Pronchery pkgconf_client_free(client);
170*592efe25SPierre Pronchery }
171*592efe25SPierre Pronchery
172*592efe25SPierre Pronchery static void
test_fragment_render_libs(void)173*592efe25SPierre Pronchery test_fragment_render_libs(void)
174*592efe25SPierre Pronchery {
175*592efe25SPierre Pronchery pkgconf_client_t *client = test_client_new();
176*592efe25SPierre Pronchery pkgconf_list_t frags = PKGCONF_LIST_INITIALIZER;
177*592efe25SPierre Pronchery pkgconf_list_t vars = PKGCONF_LIST_INITIALIZER;
178*592efe25SPierre Pronchery
179*592efe25SPierre Pronchery pkgconf_fragment_parse(client, &frags, &vars, "-L/usr/lib -lfoo", 0);
180*592efe25SPierre Pronchery
181*592efe25SPierre Pronchery char *rendered = render_to_string(&frags);
182*592efe25SPierre Pronchery TEST_ASSERT_NONNULL(rendered);
183*592efe25SPierre Pronchery TEST_ASSERT_STRCMP_EQ(rendered, "-L/usr/lib -lfoo");
184*592efe25SPierre Pronchery
185*592efe25SPierre Pronchery free(rendered);
186*592efe25SPierre Pronchery pkgconf_fragment_free(&frags);
187*592efe25SPierre Pronchery pkgconf_variable_list_free(&vars);
188*592efe25SPierre Pronchery pkgconf_client_free(client);
189*592efe25SPierre Pronchery }
190*592efe25SPierre Pronchery
191*592efe25SPierre Pronchery static void
test_fragment_render_empty(void)192*592efe25SPierre Pronchery test_fragment_render_empty(void)
193*592efe25SPierre Pronchery {
194*592efe25SPierre Pronchery pkgconf_list_t frags = PKGCONF_LIST_INITIALIZER;
195*592efe25SPierre Pronchery
196*592efe25SPierre Pronchery char *rendered = render_to_string(&frags);
197*592efe25SPierre Pronchery TEST_ASSERT_NONNULL(rendered);
198*592efe25SPierre Pronchery TEST_ASSERT_EMPTY_STRING(rendered);
199*592efe25SPierre Pronchery
200*592efe25SPierre Pronchery free(rendered);
201*592efe25SPierre Pronchery }
202*592efe25SPierre Pronchery
203*592efe25SPierre Pronchery // Filter predicate: keep only -I (include) fragments.
204*592efe25SPierre Pronchery static bool
filter_only_includes(const pkgconf_client_t * client,const pkgconf_fragment_t * frag,void * data)205*592efe25SPierre Pronchery filter_only_includes(const pkgconf_client_t *client, const pkgconf_fragment_t *frag, void *data)
206*592efe25SPierre Pronchery {
207*592efe25SPierre Pronchery (void) client;
208*592efe25SPierre Pronchery (void) data;
209*592efe25SPierre Pronchery return frag->type == 'I';
210*592efe25SPierre Pronchery }
211*592efe25SPierre Pronchery
212*592efe25SPierre Pronchery // Filter predicate: keep only -l (library name) fragments.
213*592efe25SPierre Pronchery static bool
filter_only_libnames(const pkgconf_client_t * client,const pkgconf_fragment_t * frag,void * data)214*592efe25SPierre Pronchery filter_only_libnames(const pkgconf_client_t *client, const pkgconf_fragment_t *frag, void *data)
215*592efe25SPierre Pronchery {
216*592efe25SPierre Pronchery (void) client;
217*592efe25SPierre Pronchery (void) data;
218*592efe25SPierre Pronchery return frag->type == 'l';
219*592efe25SPierre Pronchery }
220*592efe25SPierre Pronchery
221*592efe25SPierre Pronchery // Filter predicate: keep nothing.
222*592efe25SPierre Pronchery static bool
filter_nothing(const pkgconf_client_t * client,const pkgconf_fragment_t * frag,void * data)223*592efe25SPierre Pronchery filter_nothing(const pkgconf_client_t *client, const pkgconf_fragment_t *frag, void *data)
224*592efe25SPierre Pronchery {
225*592efe25SPierre Pronchery (void) client;
226*592efe25SPierre Pronchery (void) frag;
227*592efe25SPierre Pronchery (void) data;
228*592efe25SPierre Pronchery return false;
229*592efe25SPierre Pronchery }
230*592efe25SPierre Pronchery
231*592efe25SPierre Pronchery static void
test_fragment_filter_only_includes(void)232*592efe25SPierre Pronchery test_fragment_filter_only_includes(void)
233*592efe25SPierre Pronchery {
234*592efe25SPierre Pronchery pkgconf_client_t *client = test_client_new();
235*592efe25SPierre Pronchery pkgconf_list_t src = PKGCONF_LIST_INITIALIZER;
236*592efe25SPierre Pronchery pkgconf_list_t dst = PKGCONF_LIST_INITIALIZER;
237*592efe25SPierre Pronchery pkgconf_list_t vars = PKGCONF_LIST_INITIALIZER;
238*592efe25SPierre Pronchery
239*592efe25SPierre Pronchery pkgconf_fragment_parse(client, &src, &vars, "-I/usr/include -L/usr/lib -lfoo -I/opt/include", 0);
240*592efe25SPierre Pronchery
241*592efe25SPierre Pronchery pkgconf_fragment_filter(client, &dst, &src, filter_only_includes, NULL);
242*592efe25SPierre Pronchery TEST_ASSERT_EQ(fragment_count(&dst), 2);
243*592efe25SPierre Pronchery
244*592efe25SPierre Pronchery const pkgconf_fragment_t *f0 = fragment_at(&dst, 0);
245*592efe25SPierre Pronchery const pkgconf_fragment_t *f1 = fragment_at(&dst, 1);
246*592efe25SPierre Pronchery TEST_ASSERT_NONNULL(f0);
247*592efe25SPierre Pronchery TEST_ASSERT_NONNULL(f1);
248*592efe25SPierre Pronchery TEST_ASSERT_EQ(f0->type, 'I');
249*592efe25SPierre Pronchery TEST_ASSERT_STRCMP_EQ(f0->data, "/usr/include");
250*592efe25SPierre Pronchery TEST_ASSERT_EQ(f1->type, 'I');
251*592efe25SPierre Pronchery TEST_ASSERT_STRCMP_EQ(f1->data, "/opt/include");
252*592efe25SPierre Pronchery
253*592efe25SPierre Pronchery pkgconf_fragment_free(&dst);
254*592efe25SPierre Pronchery pkgconf_fragment_free(&src);
255*592efe25SPierre Pronchery pkgconf_variable_list_free(&vars);
256*592efe25SPierre Pronchery pkgconf_client_free(client);
257*592efe25SPierre Pronchery }
258*592efe25SPierre Pronchery
259*592efe25SPierre Pronchery static void
test_fragment_filter_only_libnames(void)260*592efe25SPierre Pronchery test_fragment_filter_only_libnames(void)
261*592efe25SPierre Pronchery {
262*592efe25SPierre Pronchery pkgconf_client_t *client = test_client_new();
263*592efe25SPierre Pronchery pkgconf_list_t src = PKGCONF_LIST_INITIALIZER;
264*592efe25SPierre Pronchery pkgconf_list_t dst = PKGCONF_LIST_INITIALIZER;
265*592efe25SPierre Pronchery pkgconf_list_t vars = PKGCONF_LIST_INITIALIZER;
266*592efe25SPierre Pronchery
267*592efe25SPierre Pronchery pkgconf_fragment_parse(client, &src, &vars, "-L/usr/lib -lfoo -lbar -I/usr/include", 0);
268*592efe25SPierre Pronchery
269*592efe25SPierre Pronchery pkgconf_fragment_filter(client, &dst, &src, filter_only_libnames, NULL);
270*592efe25SPierre Pronchery
271*592efe25SPierre Pronchery TEST_ASSERT_EQ(fragment_count(&dst), 2);
272*592efe25SPierre Pronchery
273*592efe25SPierre Pronchery const pkgconf_fragment_t *f0 = fragment_at(&dst, 0);
274*592efe25SPierre Pronchery const pkgconf_fragment_t *f1 = fragment_at(&dst, 1);
275*592efe25SPierre Pronchery TEST_ASSERT_NONNULL(f0);
276*592efe25SPierre Pronchery TEST_ASSERT_NONNULL(f1);
277*592efe25SPierre Pronchery TEST_ASSERT_EQ(f0->type, 'l');
278*592efe25SPierre Pronchery TEST_ASSERT_STRCMP_EQ(f0->data, "foo");
279*592efe25SPierre Pronchery TEST_ASSERT_EQ(f1->type, 'l');
280*592efe25SPierre Pronchery TEST_ASSERT_STRCMP_EQ(f1->data, "bar");
281*592efe25SPierre Pronchery
282*592efe25SPierre Pronchery pkgconf_fragment_free(&dst);
283*592efe25SPierre Pronchery pkgconf_fragment_free(&src);
284*592efe25SPierre Pronchery pkgconf_variable_list_free(&vars);
285*592efe25SPierre Pronchery pkgconf_client_free(client);
286*592efe25SPierre Pronchery }
287*592efe25SPierre Pronchery
288*592efe25SPierre Pronchery static void
test_fragment_filter_keeps_nothing(void)289*592efe25SPierre Pronchery test_fragment_filter_keeps_nothing(void)
290*592efe25SPierre Pronchery {
291*592efe25SPierre Pronchery pkgconf_client_t *client = test_client_new();
292*592efe25SPierre Pronchery pkgconf_list_t src = PKGCONF_LIST_INITIALIZER;
293*592efe25SPierre Pronchery pkgconf_list_t dst = PKGCONF_LIST_INITIALIZER;
294*592efe25SPierre Pronchery pkgconf_list_t vars = PKGCONF_LIST_INITIALIZER;
295*592efe25SPierre Pronchery
296*592efe25SPierre Pronchery pkgconf_fragment_parse(client, &src, &vars, "-I/usr/include -lfoo", 0);
297*592efe25SPierre Pronchery
298*592efe25SPierre Pronchery pkgconf_fragment_filter(client, &dst, &src, filter_nothing, NULL);
299*592efe25SPierre Pronchery
300*592efe25SPierre Pronchery TEST_ASSERT_EQ(fragment_count(&dst), 0);
301*592efe25SPierre Pronchery
302*592efe25SPierre Pronchery pkgconf_fragment_free(&dst);
303*592efe25SPierre Pronchery pkgconf_fragment_free(&src);
304*592efe25SPierre Pronchery pkgconf_variable_list_free(&vars);
305*592efe25SPierre Pronchery pkgconf_client_free(client);
306*592efe25SPierre Pronchery }
307*592efe25SPierre Pronchery
308*592efe25SPierre Pronchery static void
test_fragment_has_system_dir_matches(void)309*592efe25SPierre Pronchery test_fragment_has_system_dir_matches(void)
310*592efe25SPierre Pronchery {
311*592efe25SPierre Pronchery pkgconf_client_t *client = test_client_new();
312*592efe25SPierre Pronchery pkgconf_list_t frags = PKGCONF_LIST_INITIALIZER;
313*592efe25SPierre Pronchery pkgconf_list_t vars = PKGCONF_LIST_INITIALIZER;
314*592efe25SPierre Pronchery
315*592efe25SPierre Pronchery pkgconf_path_add("/usr/include", &client->filter_includedirs, false);
316*592efe25SPierre Pronchery
317*592efe25SPierre Pronchery pkgconf_fragment_parse(client, &frags, &vars, "-I/usr/include -I/opt/include", 0);
318*592efe25SPierre Pronchery
319*592efe25SPierre Pronchery const pkgconf_fragment_t *system = fragment_at(&frags, 0);
320*592efe25SPierre Pronchery const pkgconf_fragment_t *other = fragment_at(&frags, 1);
321*592efe25SPierre Pronchery TEST_ASSERT_NONNULL(system);
322*592efe25SPierre Pronchery TEST_ASSERT_NONNULL(other);
323*592efe25SPierre Pronchery
324*592efe25SPierre Pronchery TEST_ASSERT_TRUE(pkgconf_fragment_has_system_dir(client, system));
325*592efe25SPierre Pronchery TEST_ASSERT_FALSE(pkgconf_fragment_has_system_dir(client, other));
326*592efe25SPierre Pronchery
327*592efe25SPierre Pronchery pkgconf_fragment_free(&frags);
328*592efe25SPierre Pronchery pkgconf_variable_list_free(&vars);
329*592efe25SPierre Pronchery pkgconf_client_free(client);
330*592efe25SPierre Pronchery }
331*592efe25SPierre Pronchery
332*592efe25SPierre Pronchery static void
test_fragment_has_system_dir_libs(void)333*592efe25SPierre Pronchery test_fragment_has_system_dir_libs(void)
334*592efe25SPierre Pronchery {
335*592efe25SPierre Pronchery pkgconf_client_t *client = test_client_new();
336*592efe25SPierre Pronchery pkgconf_list_t frags = PKGCONF_LIST_INITIALIZER;
337*592efe25SPierre Pronchery pkgconf_list_t vars = PKGCONF_LIST_INITIALIZER;
338*592efe25SPierre Pronchery
339*592efe25SPierre Pronchery pkgconf_path_add("/usr/lib", &client->filter_libdirs, false);
340*592efe25SPierre Pronchery
341*592efe25SPierre Pronchery pkgconf_fragment_parse(client, &frags, &vars, "-L/usr/lib -L/opt/lib", 0);
342*592efe25SPierre Pronchery
343*592efe25SPierre Pronchery const pkgconf_fragment_t *system = fragment_at(&frags, 0);
344*592efe25SPierre Pronchery const pkgconf_fragment_t *other = fragment_at(&frags, 1);
345*592efe25SPierre Pronchery TEST_ASSERT_NONNULL(system);
346*592efe25SPierre Pronchery TEST_ASSERT_NONNULL(other);
347*592efe25SPierre Pronchery
348*592efe25SPierre Pronchery TEST_ASSERT_TRUE(pkgconf_fragment_has_system_dir(client, system));
349*592efe25SPierre Pronchery TEST_ASSERT_FALSE(pkgconf_fragment_has_system_dir(client, other));
350*592efe25SPierre Pronchery
351*592efe25SPierre Pronchery pkgconf_fragment_free(&frags);
352*592efe25SPierre Pronchery pkgconf_variable_list_free(&vars);
353*592efe25SPierre Pronchery pkgconf_client_free(client);
354*592efe25SPierre Pronchery }
355*592efe25SPierre Pronchery
356*592efe25SPierre Pronchery int
main(int argc,char * argv[])357*592efe25SPierre Pronchery main(int argc, char *argv[])
358*592efe25SPierre Pronchery {
359*592efe25SPierre Pronchery (void) argc;
360*592efe25SPierre Pronchery const char *basename = pkgconf_path_find_basename(argv[0]);
361*592efe25SPierre Pronchery
362*592efe25SPierre Pronchery TEST_RUN(basename, test_fragment_parse_empty);
363*592efe25SPierre Pronchery TEST_RUN(basename, test_fragment_parse_cflags);
364*592efe25SPierre Pronchery TEST_RUN(basename, test_fragment_parse_libs);
365*592efe25SPierre Pronchery TEST_RUN(basename, test_fragment_add_single);
366*592efe25SPierre Pronchery TEST_RUN(basename, test_fragment_render_empty);
367*592efe25SPierre Pronchery TEST_RUN(basename, test_fragment_render_cflags);
368*592efe25SPierre Pronchery TEST_RUN(basename, test_fragment_render_libs);
369*592efe25SPierre Pronchery TEST_RUN(basename, test_fragment_filter_only_includes);
370*592efe25SPierre Pronchery TEST_RUN(basename, test_fragment_filter_only_libnames);
371*592efe25SPierre Pronchery TEST_RUN(basename, test_fragment_filter_keeps_nothing);
372*592efe25SPierre Pronchery TEST_RUN(basename, test_fragment_has_system_dir_matches);
373*592efe25SPierre Pronchery TEST_RUN(basename, test_fragment_has_system_dir_libs);
374*592efe25SPierre Pronchery
375*592efe25SPierre Pronchery return EXIT_SUCCESS;
376*592efe25SPierre Pronchery }
377