diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-11-13 13:12:04 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-11-13 13:12:04 +0000 |
commit | 841845233e6b31d017077ff70111c4049076bd27 (patch) | |
tree | 85dbc8ef97109ab1f1a19798d209cdbe4f10af12 | |
parent | 7c88233a645884a468625effd7d8a3e0a0622e94 (diff) | |
download | libmicrohttpd-841845233e6b31d017077ff70111c4049076bd27.tar.gz libmicrohttpd-841845233e6b31d017077ff70111c4049076bd27.zip |
testcase for 1901
-rw-r--r-- | src/testcurl/Makefile.am | 6 | ||||
-rw-r--r-- | src/testcurl/test_start_stop.c | 114 |
2 files changed, 120 insertions, 0 deletions
diff --git a/src/testcurl/Makefile.am b/src/testcurl/Makefile.am index 73c6840b..74732f07 100644 --- a/src/testcurl/Makefile.am +++ b/src/testcurl/Makefile.am | |||
@@ -27,6 +27,7 @@ endif | |||
27 | endif | 27 | endif |
28 | 28 | ||
29 | check_PROGRAMS = \ | 29 | check_PROGRAMS = \ |
30 | test_start_stop \ | ||
30 | daemontest_get \ | 31 | daemontest_get \ |
31 | daemontest_get_sendfile \ | 32 | daemontest_get_sendfile \ |
32 | daemontest_urlparse \ | 33 | daemontest_urlparse \ |
@@ -72,6 +73,11 @@ noinst_LIBRARIES = libcurl_version_check.a | |||
72 | libcurl_version_check_a_SOURCES = \ | 73 | libcurl_version_check_a_SOURCES = \ |
73 | curl_version_check.c | 74 | curl_version_check.c |
74 | 75 | ||
76 | test_start_stop_SOURCES = \ | ||
77 | test_start_stop.c | ||
78 | test_start_stop_LDADD = \ | ||
79 | $(top_builddir)/src/daemon/libmicrohttpd.la | ||
80 | |||
75 | daemon_options_test_SOURCES = \ | 81 | daemon_options_test_SOURCES = \ |
76 | daemon_options_test.c | 82 | daemon_options_test.c |
77 | daemon_options_test_LDADD = \ | 83 | daemon_options_test_LDADD = \ |
diff --git a/src/testcurl/test_start_stop.c b/src/testcurl/test_start_stop.c new file mode 100644 index 00000000..90046685 --- /dev/null +++ b/src/testcurl/test_start_stop.c | |||
@@ -0,0 +1,114 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | (C) 2011 Christian Grothoff | ||
4 | |||
5 | libmicrohttpd is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | libmicrohttpd is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with libmicrohttpd; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file test_start_stop.c | ||
23 | * @brief test for #1901 (start+stop) | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "MHD_config.h" | ||
27 | #include "platform.h" | ||
28 | #include <curl/curl.h> | ||
29 | #include <microhttpd.h> | ||
30 | |||
31 | |||
32 | static int | ||
33 | ahc_echo (void *cls, | ||
34 | struct MHD_Connection *connection, | ||
35 | const char *url, | ||
36 | const char *method, | ||
37 | const char *version, | ||
38 | const char *upload_data, size_t *upload_data_size, | ||
39 | void **unused) | ||
40 | { | ||
41 | return MHD_NO; | ||
42 | } | ||
43 | |||
44 | |||
45 | static int | ||
46 | testInternalGet (int poll_flag) | ||
47 | { | ||
48 | struct MHD_Daemon *d; | ||
49 | |||
50 | d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | poll_flag, | ||
51 | 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | ||
52 | if (d == NULL) | ||
53 | return 1; | ||
54 | MHD_stop_daemon (d); | ||
55 | return 0; | ||
56 | } | ||
57 | |||
58 | static int | ||
59 | testMultithreadedGet (int poll_flag) | ||
60 | { | ||
61 | struct MHD_Daemon *d; | ||
62 | |||
63 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG | poll_flag, | ||
64 | 1081, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | ||
65 | if (d == NULL) | ||
66 | return 2; | ||
67 | MHD_stop_daemon (d); | ||
68 | return 0; | ||
69 | } | ||
70 | |||
71 | static int | ||
72 | testMultithreadedPoolGet (int poll_flag) | ||
73 | { | ||
74 | struct MHD_Daemon *d; | ||
75 | |||
76 | d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | poll_flag, | ||
77 | 1081, NULL, NULL, &ahc_echo, "GET", | ||
78 | MHD_OPTION_THREAD_POOL_SIZE, 4, MHD_OPTION_END); | ||
79 | if (d == NULL) | ||
80 | return 4; | ||
81 | MHD_stop_daemon (d); | ||
82 | return 0; | ||
83 | } | ||
84 | |||
85 | static int | ||
86 | testExternalGet () | ||
87 | { | ||
88 | struct MHD_Daemon *d; | ||
89 | |||
90 | d = MHD_start_daemon (MHD_USE_DEBUG, | ||
91 | 1082, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | ||
92 | if (d == NULL) | ||
93 | return 8; | ||
94 | MHD_stop_daemon (d); | ||
95 | return 0; | ||
96 | } | ||
97 | |||
98 | |||
99 | int | ||
100 | main (int argc, char *const *argv) | ||
101 | { | ||
102 | unsigned int errorCount = 0; | ||
103 | |||
104 | errorCount += testInternalGet (0); | ||
105 | errorCount += testMultithreadedGet (0); | ||
106 | errorCount += testMultithreadedPoolGet (0); | ||
107 | errorCount += testExternalGet (); | ||
108 | errorCount += testInternalGet (MHD_USE_POLL); | ||
109 | errorCount += testMultithreadedGet (MHD_USE_POLL); | ||
110 | errorCount += testMultithreadedPoolGet (MHD_USE_POLL); | ||
111 | if (errorCount != 0) | ||
112 | fprintf (stderr, "Error (code: %u)\n", errorCount); | ||
113 | return errorCount != 0; /* 0 == pass */ | ||
114 | } | ||