1 /* GSequencer - Advanced GTK Sequencer
2  * Copyright (C) 2019 Joël Krähemann
3  *
4  * This file is part of GSequencer.
5  *
6  * GSequencer is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * GSequencer is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with GSequencer.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <glib.h>
21 #include <glib-object.h>
22 
23 #include <ags/libags.h>
24 
25 #include <CUnit/CUnit.h>
26 #include <CUnit/Automated.h>
27 #include <CUnit/Basic.h>
28 
29 int ags_xml_business_group_test_init_suite();
30 int ags_xml_business_group_test_clean_suite();
31 
32 void ags_xml_business_group_test_get_group_uuid();
33 void ags_xml_business_group_test_set_group_name();
34 void ags_xml_business_group_test_get_group_name();
35 void ags_xml_business_group_test_set_user();
36 void ags_xml_business_group_test_get_user();
37 void ags_xml_business_group_test_open_filename();
38 
39 #define AGS_XML_BUSINESS_GROUP_TEST_GET_GROUP_UUID_DEFAULT_USER_UUID "ags-test-uuid"
40 #define AGS_XML_BUSINESS_GROUP_TEST_GET_GROUP_UUID_DEFAULT_SECURITY_TOKEN "ags-test-security-token"
41 
42 #define AGS_XML_BUSINESS_GROUP_TEST_SET_GROUP_NAME_DEFAULT_USER_UUID "ags-test-uuid"
43 #define AGS_XML_BUSINESS_GROUP_TEST_SET_GROUP_NAME_DEFAULT_SECURITY_TOKEN "ags-test-security-token"
44 #define AGS_XML_BUSINESS_GROUP_TEST_SET_GROUP_NAME_DEFAULT_GROUP_UUID "ags-test-group-uuid"
45 #define AGS_XML_BUSINESS_GROUP_TEST_SET_GROUP_NAME_DEFAULT_GROUP_NAME "ags-test-group-name"
46 
47 #define AGS_XML_BUSINESS_GROUP_TEST_GET_GROUP_NAME_DEFAULT_USER_UUID "ags-test-uuid"
48 #define AGS_XML_BUSINESS_GROUP_TEST_GET_GROUP_NAME_DEFAULT_SECURITY_TOKEN "ags-test-security-token"
49 #define AGS_XML_BUSINESS_GROUP_TEST_GET_GROUP_NAME_DEFAULT_GROUP_UUID "ags-test-group-uuid"
50 
51 #define AGS_XML_BUSINESS_GROUP_TEST_SET_USER_DEFAULT_USER_UUID "ags-test-uuid"
52 #define AGS_XML_BUSINESS_GROUP_TEST_SET_USER_DEFAULT_SECURITY_TOKEN "ags-test-security-token"
53 #define AGS_XML_BUSINESS_GROUP_TEST_SET_USER_DEFAULT_GROUP_UUID "ags-test-group-uuid"
54 
55 #define AGS_XML_BUSINESS_GROUP_TEST_GET_USER_DEFAULT_USER_UUID "ags-test-uuid"
56 #define AGS_XML_BUSINESS_GROUP_TEST_GET_USER_DEFAULT_SECURITY_TOKEN "ags-test-security-token"
57 #define AGS_XML_BUSINESS_GROUP_TEST_GET_USER_DEFAULT_GROUP_UUID "ags-test-group-uuid"
58 
59 #define AGS_XML_BUSINESS_GROUP_TEST_OPEN_FILENAME SRCDIR "/" "ags_business_group_test.xml"
60 
61 AgsServerApplicationContext *server_application_context;
62 
63 /* The suite initialization time.
64  * Opens the temporary file used by the tests.
65  * Returns zero on success, non-zero otherwise.
66  */
67 int
ags_xml_business_group_test_init_suite()68 ags_xml_business_group_test_init_suite()
69 {
70   AgsConfig *config;
71 
72   ags_priority_load_defaults(ags_priority_get_instance());
73 
74   config = ags_config_get_instance();
75 
76   server_application_context = (AgsApplicationContext *) ags_server_application_context_new();
77   g_object_ref(server_application_context);
78 
79   ags_application_context_prepare(server_application_context);
80   ags_application_context_setup(server_application_context);
81 
82   return(0);
83 }
84 
85 /* The suite cleanup time.
86  * Closes the temporary file used by the tests.
87  * Returns zero on success, non-zero otherwise.
88  */
89 int
ags_xml_business_group_test_clean_suite()90 ags_xml_business_group_test_clean_suite()
91 {
92   return(0);
93 }
94 
95 void
ags_xml_business_group_test_get_group_uuid()96 ags_xml_business_group_test_get_group_uuid()
97 {
98   AgsXmlBusinessGroup *xml_business_group;
99   AgsSecurityContext *security_context;
100 
101   GError *error;
102 
103   xml_business_group = ags_xml_business_group_new();
104 
105   security_context = ags_auth_security_context_get_instance();
106 
107   error = NULL;
108   ags_business_group_get_group_uuid(AGS_BUSINESS_GROUP(xml_business_group),
109 				    security_context,
110 				    AGS_XML_BUSINESS_GROUP_TEST_GET_GROUP_UUID_DEFAULT_USER_UUID,
111 				    AGS_XML_BUSINESS_GROUP_TEST_GET_GROUP_UUID_DEFAULT_SECURITY_TOKEN,
112 				    &error);
113 
114   //TODO:JK: implement me
115 }
116 
117 void
ags_xml_business_group_test_set_group_name()118 ags_xml_business_group_test_set_group_name()
119 {
120   AgsXmlBusinessGroup *xml_business_group;
121   AgsSecurityContext *security_context;
122 
123   GError *error;
124 
125   xml_business_group = ags_xml_business_group_new();
126 
127   security_context = ags_auth_security_context_get_instance();
128 
129   error = NULL;
130   ags_business_group_set_group_name(AGS_BUSINESS_GROUP(xml_business_group),
131 				    security_context,
132 				    AGS_XML_BUSINESS_GROUP_TEST_SET_GROUP_NAME_DEFAULT_USER_UUID,
133 				    AGS_XML_BUSINESS_GROUP_TEST_SET_GROUP_NAME_DEFAULT_SECURITY_TOKEN,
134 				    AGS_XML_BUSINESS_GROUP_TEST_SET_GROUP_NAME_DEFAULT_GROUP_UUID,
135 				    AGS_XML_BUSINESS_GROUP_TEST_SET_GROUP_NAME_DEFAULT_GROUP_NAME,
136 				    &error);
137 
138   //TODO:JK: implement me
139 }
140 
141 void
ags_xml_business_group_test_get_group_name()142 ags_xml_business_group_test_get_group_name()
143 {
144   AgsXmlBusinessGroup *xml_business_group;
145   AgsSecurityContext *security_context;
146 
147   gchar *group_name;
148 
149   GError *error;
150 
151   xml_business_group = ags_xml_business_group_new();
152 
153   security_context = ags_auth_security_context_get_instance();
154 
155   error = NULL;
156   group_name = ags_business_group_get_group_name(AGS_BUSINESS_GROUP(xml_business_group),
157 						 security_context,
158 						 AGS_XML_BUSINESS_GROUP_TEST_GET_GROUP_NAME_DEFAULT_USER_UUID,
159 						 AGS_XML_BUSINESS_GROUP_TEST_GET_GROUP_NAME_DEFAULT_SECURITY_TOKEN,
160 						 AGS_XML_BUSINESS_GROUP_TEST_GET_GROUP_NAME_DEFAULT_GROUP_UUID,
161 						 &error);
162 
163   CU_ASSERT(group_name == NULL);
164 
165   //TODO:JK: implement me
166 }
167 
168 void
ags_xml_business_group_test_set_user()169 ags_xml_business_group_test_set_user()
170 {
171   AgsXmlBusinessGroup *xml_business_group;
172   AgsSecurityContext *security_context;
173 
174   GError *error;
175 
176   static const gchar **default_user = {
177     "ags-test-user-uuid-0",
178     "ags-test-user-uuid-1",
179     "ags-test-user-uuid-2",
180     NULL,
181   };
182 
183   xml_business_group = ags_xml_business_group_new();
184 
185   security_context = ags_auth_security_context_get_instance();
186 
187   error = NULL;
188   ags_business_group_set_user(AGS_BUSINESS_GROUP(xml_business_group),
189 			      security_context,
190 			      AGS_XML_BUSINESS_GROUP_TEST_SET_USER_DEFAULT_USER_UUID,
191 			      AGS_XML_BUSINESS_GROUP_TEST_SET_USER_DEFAULT_SECURITY_TOKEN,
192 			      AGS_XML_BUSINESS_GROUP_TEST_SET_USER_DEFAULT_GROUP_UUID,
193 			      default_user,
194 			      &error);
195 
196   //TODO:JK: implement me
197 }
198 
199 void
ags_xml_business_group_test_get_user()200 ags_xml_business_group_test_get_user()
201 {
202   AgsXmlBusinessGroup *xml_business_group;
203   AgsSecurityContext *security_context;
204 
205   gchar *user;
206 
207   GError *error;
208 
209   xml_business_group = ags_xml_business_group_new();
210 
211   security_context = ags_auth_security_context_get_instance();
212 
213   error = NULL;
214   user = ags_business_group_get_user(AGS_BUSINESS_GROUP(xml_business_group),
215 				     security_context,
216 				     AGS_XML_BUSINESS_GROUP_TEST_GET_USER_DEFAULT_USER_UUID,
217 				     AGS_XML_BUSINESS_GROUP_TEST_GET_USER_DEFAULT_SECURITY_TOKEN,
218 				     AGS_XML_BUSINESS_GROUP_TEST_GET_USER_DEFAULT_GROUP_UUID,
219 				     &error);
220 
221   CU_ASSERT(user == NULL);
222 
223   //TODO:JK: implement me
224 }
225 
226 void
ags_xml_business_group_test_open_filename()227 ags_xml_business_group_test_open_filename()
228 {
229   AgsXmlPasswordStore *xml_business_group;
230 
231   xml_business_group = ags_xml_business_group_new();
232 
233   ags_xml_business_group_open_filename(xml_business_group,
234 				       AGS_XML_BUSINESS_GROUP_TEST_OPEN_FILENAME);
235 
236   CU_ASSERT(xml_business_group->filename != NULL);
237   CU_ASSERT(xml_business_group->doc != NULL);
238   CU_ASSERT(xml_business_group->root_node != NULL);
239 }
240 
241 int
main(int argc,char ** argv)242 main(int argc, char **argv)
243 {
244   CU_pSuite pSuite = NULL;
245 
246   /* initialize the CUnit test registry */
247   if(CUE_SUCCESS != CU_initialize_registry()){
248     return CU_get_error();
249   }
250 
251   /* add a suite to the registry */
252   pSuite = CU_add_suite("AgsXmlBusinessGroupTest", ags_xml_business_group_test_init_suite, ags_xml_business_group_test_clean_suite);
253 
254   if(pSuite == NULL){
255     CU_cleanup_registry();
256 
257     return CU_get_error();
258   }
259 
260   /* add the tests to the suite */
261   if((CU_add_test(pSuite, "test of AgsXmlBusinessGroup get group UUID", ags_xml_business_group_test_get_group_uuid) == NULL) ||
262      (CU_add_test(pSuite, "test of AgsXmlBusinessGroup set group name", ags_xml_business_group_test_set_group_name) == NULL) ||
263      (CU_add_test(pSuite, "test of AgsXmlBusinessGroup get group name", ags_xml_business_group_test_get_group_name) == NULL) ||
264      (CU_add_test(pSuite, "test of AgsXmlBusinessGroup set user", ags_xml_business_group_test_set_user) == NULL) ||
265      (CU_add_test(pSuite, "test of AgsXmlBusinessGroup get user", ags_xml_business_group_test_get_user) == NULL) ||
266      (CU_add_test(pSuite, "test of AgsXmlBusinessGroup open filename", ags_xml_business_group_test_open_filename) == NULL)){
267     CU_cleanup_registry();
268 
269     return CU_get_error();
270   }
271 
272   /* Run all tests using the CUnit Basic interface */
273   CU_basic_set_mode(CU_BRM_VERBOSE);
274   CU_basic_run_tests();
275 
276   CU_cleanup_registry();
277 
278   return(CU_get_error());
279 }
280