main.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 "public.h"
  23. #include "private.h"
  24. #include <stdlib.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. /* This unit test file uses the excellent Check unit testing library.
  28. * The API documentation is available here:
  29. * http://check.sourceforge.net/doc/check_html/index.html
  30. */
  31. int main(const int argc, const char * const * const argv) {
  32. // Determine what tests to run
  33. const char * suite = NULL;
  34. const char * const suite_arg = "--suite=";
  35. const size_t suite_arg_size = strlen(suite_arg);
  36. const char * test_case = NULL;
  37. const char * const test_case_arg = "--test-case=";
  38. const size_t test_case_arg_size = strlen(test_case_arg);
  39. for (int i = 1; i < argc; ++i) {
  40. if (0 == strncmp(suite_arg, argv[i], suite_arg_size) && (strlen(argv[i]) > suite_arg_size)) {
  41. suite = &argv[i][suite_arg_size];
  42. } else if (0 == strncmp(test_case_arg, argv[i], test_case_arg_size) && (strlen(argv[i]) > test_case_arg_size)) {
  43. test_case = &argv[i][test_case_arg_size];
  44. } else if (0 == strcmp("--help", argv[i])) {
  45. printf("Usage: %s [options]\n"
  46. " --suite=Suite Determines the suite to run\n"
  47. " --test-case='Test Case' Determines the test case to run\n",
  48. argv[0]);
  49. exit(EXIT_SUCCESS);
  50. } else {
  51. fprintf(stderr, "Invalid argument: %s\n", argv[i]);
  52. exit(EXIT_FAILURE);
  53. }
  54. }
  55. // Run up the tests
  56. SRunner * const srunner = srunner_create(make_public_suite());
  57. srunner_add_suite(srunner, make_private_suite());
  58. srunner_run(srunner, suite, test_case, CK_NORMAL);
  59. const int number_run = srunner_ntests_run(srunner);
  60. const int number_failed = srunner_ntests_failed(srunner);
  61. srunner_free(srunner);
  62. return (number_failed == 0) && (number_run != 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  63. }