main.c 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Copyright (c) 2015 the Civetweb developers
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. */
  21. #include "civetweb_check.h"
  22. #include "shared.h"
  23. #include "public_func.h"
  24. #include "public_server.h"
  25. #include "private.h"
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #include <string.h>
  29. /* This unit test file uses the excellent Check unit testing library.
  30. * The API documentation is available here:
  31. * http://check.sourceforge.net/doc/check_html/index.html
  32. */
  33. int main(const int argc, const char * const * const argv) {
  34. // Determine what tests to run
  35. const char * suite = NULL;
  36. const char * const suite_arg = "--suite=";
  37. const size_t suite_arg_size = strlen(suite_arg);
  38. const char * test_case = NULL;
  39. const char * const test_case_arg = "--test-case=";
  40. const size_t test_case_arg_size = strlen(test_case_arg);
  41. const char * const test_dir_arg = "--test-dir=";
  42. const size_t test_dir_arg_size = strlen(test_dir_arg);
  43. for (int i = 1; i < argc; ++i) {
  44. if (0 == strncmp(suite_arg, argv[i], suite_arg_size) && (strlen(argv[i]) > suite_arg_size)) {
  45. suite = &argv[i][suite_arg_size];
  46. } else if (0 == strncmp(test_case_arg, argv[i], test_case_arg_size) && (strlen(argv[i]) > test_case_arg_size)) {
  47. test_case = &argv[i][test_case_arg_size];
  48. } else if (0 == strncmp(test_dir_arg, argv[i], test_dir_arg_size) && (strlen(argv[i]) > test_dir_arg_size)) {
  49. set_test_directory(&argv[i][test_dir_arg_size]);
  50. } else if (0 == strcmp("--help", argv[i])) {
  51. printf("Usage: %s [options]\n"
  52. " --suite=Suite Determines the suite to run\n"
  53. " --test-case='Test Case' Determines the test case to run\n"
  54. " --test-dir='folder/path' The location of the test directory with the \n"
  55. " 'fixtures' and 'expected\n",
  56. argv[0]);
  57. exit(EXIT_SUCCESS);
  58. } else {
  59. fprintf(stderr, "Invalid argument: %s\n", argv[i]);
  60. exit(EXIT_FAILURE);
  61. }
  62. }
  63. // Run up the tests
  64. SRunner * const srunner = srunner_create(make_public_func_suite());
  65. srunner_add_suite(srunner, make_public_server_suite());
  66. srunner_add_suite(srunner, make_private_suite());
  67. srunner_run(srunner, suite, test_case, CK_NORMAL);
  68. const int number_run = srunner_ntests_run(srunner);
  69. const int number_failed = srunner_ntests_failed(srunner);
  70. srunner_free(srunner);
  71. return (number_failed == 0) && (number_run != 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  72. }