2 #define _POSIX_SOURCE /* For getaddrinfo(3) */
6 #define _BSD_SOURCE /* For NI_MAXHOST up to glibc-2.19 */
8 #ifndef _DEFAULT_SOURCE
9 #define _DEFAULT_SOURCE /* For NI_MAXHOST since glibc-2.20 */
13 #define _XOPEN_SOURCE 600 /* For unsetenv(3) */
17 #include "test_DbOwnerInfo.h"
21 static const char *username
= "Doug1as$";
22 static const char *password
= "42aA#bc8";
25 static int test_login(const isds_error error
, struct isds_ctx
*context
,
26 const char *url
, const char *username
, const char *password
,
27 const struct isds_pki_credentials
*pki_credentials
,
28 struct isds_otp
*otp
) {
31 err
= isds_login(context
, url
, username
, password
, pki_credentials
, otp
);
33 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
34 isds_strerror(error
), isds_strerror(err
),
35 isds_long_message(context
));
40 /* Compare isds_box_state_period.
41 * @return 0 if equaled, 1 otherwise. */
42 static int compare_isds_box_state_period(
43 const struct isds_box_state_period
*expected_result
,
44 const struct isds_box_state_period
*result
) {
46 TEST_POINTER_DUPLICITY(expected_result
, result
);
47 if (NULL
== expected_result
)
50 TEST_TIMEVALPTR_DUPLICITY(&expected_result
->from
, &result
->from
);
51 TEST_TIMEVALPTR_DUPLICITY(&expected_result
->to
, &result
->to
);
52 TEST_INT_DUPLICITY(expected_result
->dbState
, result
->dbState
);
57 /* Compare list of isds_box_state_period structures.
58 * @return 0 if equaled, 1 otherwise and set failure reason. */
59 static int compare_isds_box_state_period_lists(const struct isds_list
*expected_list
,
60 const struct isds_list
*list
) {
61 const struct isds_list
*expected_item
, *item
;
64 for (i
= 1, expected_item
= expected_list
, item
= list
;
65 NULL
!= expected_item
&& NULL
!= item
;
66 i
++, expected_item
= expected_item
->next
, item
= item
->next
) {
67 if (compare_isds_box_state_period(
68 (struct isds_box_state_period
*)expected_item
->data
,
69 (struct isds_box_state_period
*)item
->data
))
72 if (NULL
!= expected_item
&& NULL
== item
)
73 FAIL_TEST("Result list is missing %d. item", i
);
74 if (NULL
== expected_item
&& NULL
!= item
)
75 FAIL_TEST("Result list has superfluous %d. item", i
);
80 static int test_isds_get_box_state_history(const isds_error expected_error
,
81 struct isds_ctx
*context
,
82 const char *dbID
, const struct timeval
*from
, const struct timeval
*to
,
83 const struct isds_list
*expected_results
) {
85 struct isds_list
*results
;
88 error
= isds_get_box_state_history(context
, dbID
, from
, to
, &results
);
89 TEST_DESTRUCTOR((void(*)(void*))isds_list_free
, &results
);
91 if (expected_error
!= error
) {
92 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
93 isds_strerror(expected_error
), isds_strerror(error
),
94 isds_long_message(context
));
97 if (IE_SUCCESS
!= error
) {
98 TEST_POINTER_IS_NULL(results
);
102 if (compare_isds_box_state_period_lists(expected_results
, results
))
111 pid_t server_process
;
112 struct isds_ctx
*context
= NULL
;
114 INIT_TEST("isds_get_box_state_history");
116 if (unsetenv("http_proxy")) {
117 ABORT_UNIT("Could not remove http_proxy variable from environment\n");
121 ABORT_UNIT("isds_init() failed\n");
123 context
= isds_ctx_create();
126 ABORT_UNIT("isds_ctx_create() failed\n");
130 /* Full response with two results */
133 char *input_dbID
= "A123456";
134 struct timeval input_from
= {
138 struct timeval input_to
= {
143 struct isds_box_state_period period1
= {
155 struct isds_box_state_period period2
= {
166 struct isds_list results2
= {
171 struct isds_list results
= {
177 struct server_box_state_period server_period1
= {
178 .from
= &period1
.from
,
180 .dbState
= period1
.dbState
182 struct server_box_state_period server_period2
= {
183 .from
= &period2
.from
,
185 .dbState
= period2
.dbState
187 struct server_list server_results2
= {
189 .data
= &server_period2
,
192 struct server_list server_results
= {
193 .next
= &server_results2
,
194 .data
= &server_period1
,
198 const struct arguments_DS_df_GetDataBoxActivityStatus
199 service_arguments
= {
200 .status_code
= "0000",
201 .status_message
= "Ok.",
202 .box_id
= input_dbID
,
205 .result_box_id
= "B123456",
207 .results
= &server_results
209 const struct service_configuration services
[] = {
210 { SERVICE_DS_Dz_DummyOperation
, NULL
},
211 { SERVICE_DS_df_GetDataBoxActivityStatus
, &service_arguments
},
212 { SERVICE_END
, NULL
}
214 const struct arguments_basic_authentication server_arguments
= {
215 .username
= username
,
216 .password
= password
,
217 .isds_deviations
= 1,
220 error
= start_server(&server_process
, &url
,
221 server_basic_authentication
, &server_arguments
, NULL
);
223 isds_ctx_free(&context
);
225 ABORT_UNIT(server_error
);
227 TEST("login", test_login
, IE_SUCCESS
,
228 context
, url
, username
, password
, NULL
, NULL
);
231 TEST("All data", test_isds_get_box_state_history
, IE_SUCCESS
,
232 context
, input_dbID
, &input_from
, &input_to
, &results
);
234 isds_logout(context
);
235 if (stop_server(server_process
)) {
236 isds_ctx_free(&context
);
238 ABORT_UNIT(server_error
);
246 char *input_dbID
= "A123456";
247 struct timeval input_from
= {
251 struct timeval input_to
= {
256 const struct arguments_DS_df_GetDataBoxActivityStatus
257 service_arguments
= {
258 .status_code
= "0002",
259 .status_message
= "No such box",
260 .box_id
= input_dbID
,
263 .result_box_id
= NULL
,
267 const struct service_configuration services
[] = {
268 { SERVICE_DS_Dz_DummyOperation
, NULL
},
269 { SERVICE_DS_df_GetDataBoxActivityStatus
, &service_arguments
},
270 { SERVICE_END
, NULL
}
272 const struct arguments_basic_authentication server_arguments
= {
273 .username
= username
,
274 .password
= password
,
275 .isds_deviations
= 1,
278 error
= start_server(&server_process
, &url
,
279 server_basic_authentication
, &server_arguments
, NULL
);
281 isds_ctx_free(&context
);
283 ABORT_UNIT(server_error
);
285 TEST("login", test_login
, IE_SUCCESS
,
286 context
, url
, username
, password
, NULL
, NULL
);
289 TEST("An error", test_isds_get_box_state_history
, IE_ISDS
,
290 context
, input_dbID
, &input_from
, &input_to
, NULL
);
292 isds_logout(context
);
293 if (stop_server(server_process
)) {
294 isds_ctx_free(&context
);
296 ABORT_UNIT(server_error
);
301 isds_ctx_free(&context
);