diff options
Diffstat (limited to 'src/daemon/daemontest.c')
-rw-r--r-- | src/daemon/daemontest.c | 153 |
1 files changed, 75 insertions, 78 deletions
diff --git a/src/daemon/daemontest.c b/src/daemon/daemontest.c index e7378cdd..7b4ad4de 100644 --- a/src/daemon/daemontest.c +++ b/src/daemon/daemontest.c | |||
@@ -31,131 +31,128 @@ | |||
31 | #include <string.h> | 31 | #include <string.h> |
32 | #include <stdio.h> | 32 | #include <stdio.h> |
33 | 33 | ||
34 | static int testStartError() { | 34 | static int |
35 | struct MHD_Daemon * d; | 35 | testStartError () |
36 | { | ||
37 | struct MHD_Daemon *d; | ||
36 | 38 | ||
37 | d = MHD_start_daemon(MHD_USE_DEBUG, 0, NULL, NULL, NULL, NULL); | 39 | d = MHD_start_daemon (MHD_USE_DEBUG, 0, NULL, NULL, NULL, NULL); |
38 | if (d != NULL) | 40 | if (d != NULL) |
39 | return 1; | 41 | return 1; |
40 | return 0; | 42 | return 0; |
41 | } | 43 | } |
42 | 44 | ||
43 | static int apc_nothing(void * cls, | 45 | static int |
44 | const struct sockaddr * addr, | 46 | apc_nothing (void *cls, const struct sockaddr *addr, socklen_t addrlen) |
45 | socklen_t addrlen) { | 47 | { |
46 | return MHD_NO; | 48 | return MHD_NO; |
47 | } | 49 | } |
48 | 50 | ||
49 | static int apc_all(void * cls, | 51 | static int |
50 | const struct sockaddr * addr, | 52 | apc_all (void *cls, const struct sockaddr *addr, socklen_t addrlen) |
51 | socklen_t addrlen) { | 53 | { |
52 | return MHD_YES; | 54 | return MHD_YES; |
53 | } | 55 | } |
54 | 56 | ||
55 | static int ahc_nothing(void * cls, | 57 | static int |
56 | struct MHD_Connection * connection, | 58 | ahc_nothing (void *cls, |
57 | const char * url, | 59 | struct MHD_Connection *connection, |
58 | const char * method, | 60 | const char *url, |
59 | const char * version, | 61 | const char *method, |
60 | const char * upload_data, | 62 | const char *version, |
61 | unsigned int * upload_data_size) { | 63 | const char *upload_data, unsigned int *upload_data_size) |
64 | { | ||
62 | return MHD_NO; | 65 | return MHD_NO; |
63 | } | 66 | } |
64 | 67 | ||
65 | static int testStartStop() { | 68 | static int |
66 | struct MHD_Daemon * d; | 69 | testStartStop () |
70 | { | ||
71 | struct MHD_Daemon *d; | ||
67 | 72 | ||
68 | d = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, | 73 | d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, |
69 | 1080, | 74 | 1080, |
70 | &apc_nothing, | 75 | &apc_nothing, |
71 | NULL, | 76 | NULL, &ahc_nothing, NULL, MHD_OPTION_END); |
72 | &ahc_nothing, | ||
73 | NULL, | ||
74 | MHD_OPTION_END); | ||
75 | if (d == NULL) | 77 | if (d == NULL) |
76 | return 2; | 78 | return 2; |
77 | MHD_stop_daemon(d); | 79 | MHD_stop_daemon (d); |
78 | return 0; | 80 | return 0; |
79 | } | 81 | } |
80 | 82 | ||
81 | static int testExternalRun() { | 83 | static int |
82 | struct MHD_Daemon * d; | 84 | testExternalRun () |
85 | { | ||
86 | struct MHD_Daemon *d; | ||
83 | fd_set rs; | 87 | fd_set rs; |
84 | int maxfd; | 88 | int maxfd; |
85 | int i; | 89 | int i; |
86 | 90 | ||
87 | d = MHD_start_daemon(MHD_USE_DEBUG, | 91 | d = MHD_start_daemon (MHD_USE_DEBUG, |
88 | 1081, | 92 | 1081, |
89 | &apc_all, | 93 | &apc_all, NULL, &ahc_nothing, NULL, MHD_OPTION_END); |
90 | NULL, | ||
91 | &ahc_nothing, | ||
92 | NULL, | ||
93 | MHD_OPTION_END); | ||
94 | 94 | ||
95 | if (d == NULL) | 95 | if (d == NULL) |
96 | return 4; | 96 | return 4; |
97 | i = 0; | 97 | i = 0; |
98 | while(i < 15) { | 98 | while (i < 15) |
99 | maxfd = 0; | 99 | { |
100 | FD_ZERO(&rs); | 100 | maxfd = 0; |
101 | MHD_get_fdset(d, &rs, &rs, &rs, &maxfd); | 101 | FD_ZERO (&rs); |
102 | if (MHD_run(d) == MHD_NO) { | 102 | MHD_get_fdset (d, &rs, &rs, &rs, &maxfd); |
103 | MHD_stop_daemon(d); | 103 | if (MHD_run (d) == MHD_NO) |
104 | return 8; | 104 | { |
105 | MHD_stop_daemon (d); | ||
106 | return 8; | ||
107 | } | ||
108 | i++; | ||
105 | } | 109 | } |
106 | i++; | 110 | MHD_stop_daemon (d); |
107 | } | ||
108 | MHD_stop_daemon(d); | ||
109 | return 0; | 111 | return 0; |
110 | } | 112 | } |
111 | 113 | ||
112 | static int testThread() { | 114 | static int |
113 | struct MHD_Daemon * d; | 115 | testThread () |
114 | d = MHD_start_daemon(MHD_USE_DEBUG | MHD_USE_SELECT_INTERNALLY, | 116 | { |
115 | 1082, | 117 | struct MHD_Daemon *d; |
116 | &apc_all, | 118 | d = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_SELECT_INTERNALLY, |
117 | NULL, | 119 | 1082, |
118 | &ahc_nothing, | 120 | &apc_all, NULL, &ahc_nothing, NULL, MHD_OPTION_END); |
119 | NULL, | ||
120 | MHD_OPTION_END); | ||
121 | 121 | ||
122 | if (d == NULL) | 122 | if (d == NULL) |
123 | return 16; | 123 | return 16; |
124 | if (MHD_run(d) != MHD_NO) | 124 | if (MHD_run (d) != MHD_NO) |
125 | return 32; | 125 | return 32; |
126 | MHD_stop_daemon(d); | 126 | MHD_stop_daemon (d); |
127 | return 0; | 127 | return 0; |
128 | } | 128 | } |
129 | 129 | ||
130 | static int testMultithread() { | 130 | static int |
131 | struct MHD_Daemon * d; | 131 | testMultithread () |
132 | d = MHD_start_daemon(MHD_USE_DEBUG | MHD_USE_THREAD_PER_CONNECTION, | 132 | { |
133 | 1083, | 133 | struct MHD_Daemon *d; |
134 | &apc_all, | 134 | d = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_THREAD_PER_CONNECTION, |
135 | NULL, | 135 | 1083, |
136 | &ahc_nothing, | 136 | &apc_all, NULL, &ahc_nothing, NULL, MHD_OPTION_END); |
137 | NULL, | ||
138 | MHD_OPTION_END); | ||
139 | 137 | ||
140 | if (d == NULL) | 138 | if (d == NULL) |
141 | return 64; | 139 | return 64; |
142 | if (MHD_run(d) != MHD_NO) | 140 | if (MHD_run (d) != MHD_NO) |
143 | return 128; | 141 | return 128; |
144 | MHD_stop_daemon(d); | 142 | MHD_stop_daemon (d); |
145 | return 0; | 143 | return 0; |
146 | } | 144 | } |
147 | 145 | ||
148 | int main(int argc, | 146 | int |
149 | char * const * argv) { | 147 | main (int argc, char *const *argv) |
148 | { | ||
150 | unsigned int errorCount = 0; | 149 | unsigned int errorCount = 0; |
151 | errorCount += testStartError(); | 150 | errorCount += testStartError (); |
152 | errorCount += testStartStop(); | 151 | errorCount += testStartStop (); |
153 | errorCount += testExternalRun(); | 152 | errorCount += testExternalRun (); |
154 | errorCount += testThread(); | 153 | errorCount += testThread (); |
155 | errorCount += testMultithread(); | 154 | errorCount += testMultithread (); |
156 | if (errorCount != 0) | 155 | if (errorCount != 0) |
157 | fprintf(stderr, | 156 | fprintf (stderr, "Error (code: %u)\n", errorCount); |
158 | "Error (code: %u)\n", | 157 | return errorCount != 0; /* 0 == pass */ |
159 | errorCount); | ||
160 | return errorCount != 0; /* 0 == pass */ | ||
161 | } | 158 | } |