1 /*
2  * Copyright (C) 2012 Vivien Malerba <malerba@gnome-db.org>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18 
19 #include <libgda/libgda.h>
20 #include <string.h>
21 
22 guint
test_quark(GdaQuarkList * ql,guint * out_ntests)23 test_quark (GdaQuarkList *ql, guint *out_ntests)
24 {
25 	const gchar *tmp;
26 	guint nfailed = 0;
27 	guint ntests = 0;
28 
29 	ntests ++;
30 	tmp = gda_quark_list_find (ql, "PARAM");
31 	if (!tmp || strcmp (tmp, "value"))
32 		nfailed++;
33 
34 	ntests ++;
35 	tmp = gda_quark_list_find (ql, "PASSWORD");
36 	if (!tmp || strcmp (tmp, "*mypass*"))
37 		nfailed++;
38 
39 	ntests ++;
40 	tmp = gda_quark_list_find (ql, "PASSWORD");
41 	if (!tmp || strcmp (tmp, "*mypass*"))
42 		nfailed++;
43 
44 	gda_quark_list_protect_values (ql);
45 
46 	ntests ++;
47 	tmp = gda_quark_list_find (ql, "PASSWORD");
48 	if (!tmp || strcmp (tmp, "*mypass*"))
49 		nfailed++;
50 
51 	ntests ++;
52 	tmp = gda_quark_list_find (ql, "USERNAME");
53 	if (!tmp || strcmp (tmp, "dirch"))
54 		nfailed++;
55 
56 	gda_quark_list_remove (ql, "PASSWORD");
57 
58 	ntests ++;
59 	tmp = gda_quark_list_find (ql, "PASSWORD");
60 	if (tmp)
61 		nfailed++;
62 
63 	gda_quark_list_protect_values (ql);
64 
65 	if (out_ntests)
66 		*out_ntests = ntests;
67 	return nfailed;
68 }
69 
70 int
main(int argc,char ** argv)71 main (int argc, char** argv)
72 {
73 	GdaQuarkList *ql, *ql2;
74 	guint nfailed = 0;
75 	guint ntests = 0;
76 	guint tmp;
77 
78 	ql = gda_quark_list_new_from_string ("PARAM=value;PASSWORD=*mypass*;USERNAME=dirch");
79 	ql2 = gda_quark_list_copy (ql);
80 	nfailed = test_quark (ql, &ntests);
81 	nfailed += test_quark (ql2, &tmp);
82 	ntests += tmp;
83 
84 	/* out */
85 	gda_quark_list_free (ql);
86 	gda_quark_list_free (ql2);
87 
88 	if (nfailed == 0) {
89 		g_print ("Ok (%d tests passed)\n", ntests);
90 		return EXIT_SUCCESS;
91 	}
92 	else {
93 		g_print ("Failed (%d tests failed out of %d)\n", nfailed, ntests);
94 		return EXIT_FAILURE;
95 	}
96 }
97