aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/test_helpers.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/test_helpers.h')
-rw-r--r--src/microhttpd/test_helpers.h91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/microhttpd/test_helpers.h b/src/microhttpd/test_helpers.h
new file mode 100644
index 00000000..c3f0f7be
--- /dev/null
+++ b/src/microhttpd/test_helpers.h
@@ -0,0 +1,91 @@
1/*
2 This file is part of libmicrohttpd
3 Copyright (C) 2016 Karlson2k (Evgeny Grin)
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
20/**
21 * @file microhttpd/test_helpers.h
22 * @brief Static functions and macros helpers for testsuite.
23 * @author Karlson2k (Evgeny Grin)
24 */
25
26#include <string.h>
27
28/**
29 * Check whether program name contains specific @a marker string.
30 * Only last component in pathname is checked for marker presence,
31 * all leading directories names (if any) are ignored. Directories
32 * separators are handled correctly on both non-W32 and W32
33 * platforms.
34 * @param prog_name program name, may include path
35 * @param marker marker to look for.
36 * @return zero if any parameter is NULL or empty string or
37 * @prog_name ends with slash or @marker is not found in
38 * program name, non-zero if @maker is found in program
39 * name.
40 */
41static int
42has_in_name(const char *prog_name, const char *marker)
43{
44 size_t name_pos;
45 size_t pos;
46
47 if (!prog_name || !marker || !prog_name[0] || !marker[0])
48 return 0;
49
50 pos = 0;
51 name_pos = 0;
52 while (prog_name[pos])
53 {
54 if ('/' == prog_name[pos])
55 name_pos = pos + 1;
56#ifdef _WIN32
57 else if ('\\' == prog_name[pos])
58 name_pos = pos + 1;
59#endif /* _WIN32 */
60 pos++;
61 }
62 if (name_pos == pos)
63 return 0;
64 return strstr(prog_name + name_pos, marker) != (char*)0;
65}
66
67/**
68 * Check whether one of strings in array is equal to @a param.
69 * String @a argv[0] is ignored.
70 * @param argc number of strings in @a argv, as passed to main function
71 * @param argv array of strings, as passed to main function
72 * @param param parameter to look for.
73 * @return zero if @a argv is NULL, @a param is NULL or empty string,
74 * @a argc is less then 2 or @a param is not found in @a argv,
75 * non-zero if one of strings in @a argv is equal to @a param.
76 */
77static int
78has_param(int argc, char * const argv[], const char * param)
79{
80 int i;
81 if (!argv || !param || !param[0])
82 return 0;
83
84 for(i = 1; i < argc; i++)
85 {
86 if(argv[i] && strcmp(argv[i], param) == 0)
87 return !0;
88 }
89
90 return 0;
91}