aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/test_options.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/test_options.c')
-rw-r--r--src/testcurl/test_options.c127
1 files changed, 127 insertions, 0 deletions
diff --git a/src/testcurl/test_options.c b/src/testcurl/test_options.c
new file mode 100644
index 00000000..79042a46
--- /dev/null
+++ b/src/testcurl/test_options.c
@@ -0,0 +1,127 @@
1/*
2 This file is part of libmicrohttpd
3 (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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, 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
30#define MHD_E_MEM "Error: memory error\n"
31#define MHD_E_SERVER_INIT "Error: failed to start server\n"
32
33const int DEBUG_GNUTLS_LOG_LEVEL = 0;
34const char *test_file_name = "https_test_file";
35const char test_file_data[] = "Hello World\n";
36
37static int
38ahc_echo (void *cls,
39 struct MHD_Connection *connection,
40 const char *url,
41 const char *method,
42 const char *version,
43 const char *upload_data, size_t *upload_data_size,
44 void **unused)
45{
46 return 0;
47}
48
49int
50test_wrap (char *test_name, int (*test) (void))
51{
52 int ret;
53
54 fprintf (stdout, "running test: %s ", test_name);
55 ret = test ();
56 if (ret == 0)
57 {
58 fprintf (stdout, "[pass]\n");
59 }
60 else
61 {
62 fprintf (stdout, "[fail]\n");
63 }
64 return ret;
65}
66
67
68/**
69 * Test daemon initialization with the MHD_OPTION_SOCK_ADDR option
70 */
71static int
72test_ip_addr_option ()
73{
74 struct MHD_Daemon *d;
75 struct sockaddr_in daemon_ip_addr;
76#if HAVE_INET6
77 struct sockaddr_in6 daemon_ip_addr6;
78#endif
79
80 memset (&daemon_ip_addr, 0, sizeof (struct sockaddr_in));
81 daemon_ip_addr.sin_family = AF_INET;
82 daemon_ip_addr.sin_port = htons (4233);
83
84#if HAVE_INET6
85 memset (&daemon_ip_addr6, 0, sizeof (struct sockaddr_in6));
86 daemon_ip_addr6.sin6_family = AF_INET6;
87 daemon_ip_addr6.sin6_port = htons (4233);
88#endif
89
90 inet_pton (AF_INET, "127.0.0.1", &daemon_ip_addr.sin_addr);
91#if HAVE_INET6
92 inet_pton (AF_INET6, "::ffff:127.0.0.1", &daemon_ip_addr6.sin6_addr);
93#endif
94
95 d = MHD_start_daemon (MHD_USE_DEBUG, 4233,
96 NULL, NULL, &ahc_echo, NULL, MHD_OPTION_SOCK_ADDR,
97 &daemon_ip_addr, MHD_OPTION_END);
98
99 if (d == 0)
100 return -1;
101
102 MHD_stop_daemon (d);
103
104#if HAVE_INET6
105 d = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_IPv6, 4233,
106 NULL, NULL, &ahc_echo, NULL, MHD_OPTION_SOCK_ADDR,
107 &daemon_ip_addr6, MHD_OPTION_END);
108
109 if (d == 0)
110 return -1;
111
112 MHD_stop_daemon (d);
113#endif
114
115 return 0;
116}
117
118/* setup a temporary transfer test file */
119int
120main (int argc, char *const *argv)
121{
122 unsigned int errorCount = 0;
123
124 errorCount += test_wrap ("ip addr option", &test_ip_addr_option);
125
126 return errorCount != 0;
127}