diff options
Diffstat (limited to 'src/microhttpd/test_options.c')
-rw-r--r-- | src/microhttpd/test_options.c | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/src/microhttpd/test_options.c b/src/microhttpd/test_options.c new file mode 100644 index 00000000..3198c731 --- /dev/null +++ b/src/microhttpd/test_options.c | |||
@@ -0,0 +1,135 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | Copyright (C) 2007 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., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file mhds_get_test.c | ||
23 | * @brief Testcase for libmicrohttpd HTTPS GET operations | ||
24 | * @author Sagie Amir | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "microhttpd.h" | ||
29 | #include "mhd_sockets.h" | ||
30 | |||
31 | #define MHD_E_MEM "Error: memory error\n" | ||
32 | #define MHD_E_SERVER_INIT "Error: failed to start server\n" | ||
33 | |||
34 | const int DEBUG_GNUTLS_LOG_LEVEL = 0; | ||
35 | const char *test_file_name = "https_test_file"; | ||
36 | const char test_file_data[] = "Hello World\n"; | ||
37 | |||
38 | static int | ||
39 | ahc_echo (void *cls, | ||
40 | struct MHD_Connection *connection, | ||
41 | const char *url, | ||
42 | const char *method, | ||
43 | const char *version, | ||
44 | const char *upload_data, size_t *upload_data_size, | ||
45 | void **unused) | ||
46 | { | ||
47 | (void)cls; | ||
48 | (void)connection; | ||
49 | (void)url; | ||
50 | (void)method; | ||
51 | (void)version; | ||
52 | (void)upload_data; | ||
53 | (void)upload_data_size; | ||
54 | (void)unused; | ||
55 | |||
56 | return 0; | ||
57 | } | ||
58 | |||
59 | static int | ||
60 | test_wrap_loc (char *test_name, int (*test) (void)) | ||
61 | { | ||
62 | int ret; | ||
63 | |||
64 | fprintf (stdout, "running test: %s ", test_name); | ||
65 | ret = test (); | ||
66 | if (ret == 0) | ||
67 | { | ||
68 | fprintf (stdout, "[pass]\n"); | ||
69 | } | ||
70 | else | ||
71 | { | ||
72 | fprintf (stdout, "[fail]\n"); | ||
73 | } | ||
74 | return ret; | ||
75 | } | ||
76 | |||
77 | |||
78 | /** | ||
79 | * Test daemon initialization with the MHD_OPTION_SOCK_ADDR option | ||
80 | */ | ||
81 | static int | ||
82 | test_ip_addr_option () | ||
83 | { | ||
84 | struct MHD_Daemon *d; | ||
85 | struct sockaddr_in daemon_ip_addr; | ||
86 | #if HAVE_INET6 | ||
87 | struct sockaddr_in6 daemon_ip_addr6; | ||
88 | #endif | ||
89 | |||
90 | memset (&daemon_ip_addr, 0, sizeof (struct sockaddr_in)); | ||
91 | daemon_ip_addr.sin_family = AF_INET; | ||
92 | daemon_ip_addr.sin_port = 0; | ||
93 | daemon_ip_addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); | ||
94 | |||
95 | #if HAVE_INET6 | ||
96 | memset (&daemon_ip_addr6, 0, sizeof (struct sockaddr_in6)); | ||
97 | daemon_ip_addr6.sin6_family = AF_INET6; | ||
98 | daemon_ip_addr6.sin6_port = 0; | ||
99 | daemon_ip_addr6.sin6_addr = in6addr_loopback; | ||
100 | #endif | ||
101 | |||
102 | d = MHD_start_daemon (MHD_USE_ERROR_LOG, 0, | ||
103 | NULL, NULL, &ahc_echo, NULL, MHD_OPTION_SOCK_ADDR, | ||
104 | &daemon_ip_addr, MHD_OPTION_END); | ||
105 | |||
106 | if (d == 0) | ||
107 | return -1; | ||
108 | |||
109 | MHD_stop_daemon (d); | ||
110 | |||
111 | #if HAVE_INET6 | ||
112 | d = MHD_start_daemon (MHD_USE_ERROR_LOG | MHD_USE_IPv6, 0, | ||
113 | NULL, NULL, &ahc_echo, NULL, MHD_OPTION_SOCK_ADDR, | ||
114 | &daemon_ip_addr6, MHD_OPTION_END); | ||
115 | |||
116 | if (d == 0) | ||
117 | return -1; | ||
118 | |||
119 | MHD_stop_daemon (d); | ||
120 | #endif | ||
121 | |||
122 | return 0; | ||
123 | } | ||
124 | |||
125 | /* setup a temporary transfer test file */ | ||
126 | int | ||
127 | main (int argc, char *const *argv) | ||
128 | { | ||
129 | unsigned int errorCount = 0; | ||
130 | (void)argc; (void)argv; /* Unused. Silent compiler warning. */ | ||
131 | |||
132 | errorCount += test_wrap_loc ("ip addr option", &test_ip_addr_option); | ||
133 | |||
134 | return errorCount != 0; | ||
135 | } | ||