Add forgotten ltmain.sh from libtool-2.4.6
[libisds.git] / test / simline / isds_ping.c
blobe12db57126b5869fe0568b8af7ea49888a8c63e8
1 #ifndef _POSIX_SOURCE
2 #define _POSIX_SOURCE /* For getaddrinfo(3) */
3 #endif
5 #ifndef _BSD_SOURCE
6 #define _BSD_SOURCE /* For NI_MAXHOST up to glibc-2.19 */
7 #endif
8 #ifndef _DEFAULT_SOURCE
9 #define _DEFAULT_SOURCE /* For NI_MAXHOST since glibc-2.20 */
10 #endif
12 #ifndef _XOPEN_SOURCE
13 #define _XOPEN_SOURCE 600 /* For unsetenv(3) */
14 #endif
16 #include "../test.h"
17 #include "server.h"
18 #include "isds.h"
20 static const char *username = "Doug1as$";
21 static const char *password = "42aA#bc8";
24 static int test_login(const isds_error error, struct isds_ctx *context,
25 const char *url, const char *username, const char *password,
26 const struct isds_pki_credentials *pki_credentials,
27 struct isds_otp *otp) {
28 isds_error err;
30 err = isds_login(context, url, username, password, pki_credentials, otp);
31 if (error != err)
32 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
33 isds_strerror(error), isds_strerror(err),
34 isds_long_message(context));
36 PASS_TEST;
39 static int test_isds_ping(const isds_error error, struct isds_ctx *context) {
40 isds_error err;
42 err = isds_ping(context);
44 if (error != err) {
45 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
46 isds_strerror(error), isds_strerror(err),
47 isds_long_message(context));
50 PASS_TEST;
54 int main(void) {
55 int error;
56 pid_t server_process;
57 struct isds_ctx *context = NULL;
58 char *url = NULL;
60 INIT_TEST("isds_ping");
62 if (unsetenv("http_proxy")) {
63 ABORT_UNIT("Could not remove http_proxy variable from environment\n");
65 if (isds_init()) {
66 isds_cleanup();
67 ABORT_UNIT("isds_init() failed\n");
69 context = isds_ctx_create();
70 if (!context) {
71 isds_cleanup();
72 ABORT_UNIT("isds_ctx_create() failed\n");
76 const struct service_configuration services[] = {
77 { SERVICE_DS_Dz_DummyOperation, NULL },
78 { SERVICE_END, NULL }
80 const struct arguments_basic_authentication server_arguments = {
81 .username = username,
82 .password = password,
83 .isds_deviations = 1,
84 .services = services
87 error = start_server(&server_process, &url,
88 server_basic_authentication, &server_arguments, NULL);
89 if (error == -1) {
90 isds_ctx_free(&context);
91 isds_cleanup();
92 ABORT_UNIT(server_error);
95 TEST("prior logging in", test_isds_ping,
96 IE_CONNECTION_CLOSED, context);
97 TEST("login", test_login, IE_SUCCESS,
98 context, url, username, password, NULL, NULL);
99 TEST("after logging in", test_isds_ping,
100 IE_SUCCESS, context);
102 /* Terminate server without loggin out, we will exhibit calls on the
103 * logged-in context later. */
104 if (stop_server(server_process)) {
105 isds_ctx_free(&context);
106 isds_cleanup();
107 ABORT_UNIT(server_error);
109 free(url);
110 url = NULL;
113 /* Shorten network timeout to make tests faster */
114 if (isds_set_timeout(context, 500) != IE_SUCCESS) {
115 isds_ctx_free(&context);
116 isds_cleanup();
117 ABORT_UNIT("isds_set_timeout() failed");
119 TEST("when server disappears", test_isds_ping,
120 IE_NETWORK, context);
122 isds_logout(context);
123 TEST("after logging out", test_isds_ping,
124 IE_CONNECTION_CLOSED, context);
126 isds_ctx_free(&context);
127 isds_cleanup();
128 SUM_TEST();