main.c 2.9 KB

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