test_helpers.h (2860B)
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 * @a prog_name ends with slash or @a marker is not found in 38 * program name, non-zero if @a maker is found in program 39 * name. 40 */ 41 static int 42 has_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 #if defined(_WIN32) || defined(__CYGWIN__) 57 else if ('\\' == prog_name[pos]) 58 name_pos = pos + 1; 59 #endif /* _WIN32 || __CYGWIN__ */ 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 /** 69 * Check whether one of strings in array is equal to @a param. 70 * String @a argv[0] is ignored. 71 * @param argc number of strings in @a argv, as passed to main function 72 * @param argv array of strings, as passed to main function 73 * @param param parameter to look for. 74 * @return zero if @a argv is NULL, @a param is NULL or empty string, 75 * @a argc is less then 2 or @a param is not found in @a argv, 76 * non-zero if one of strings in @a argv is equal to @a param. 77 */ 78 static int 79 has_param (int argc, char *const argv[], const char *param) 80 { 81 int i; 82 if (! argv || ! param || ! param[0]) 83 return 0; 84 85 for (i = 1; i < argc; i++) 86 { 87 if (argv[i] && (strcmp (argv[i], param) == 0) ) 88 return ! 0; 89 } 90 91 return 0; 92 }