mirror of
https://github.com/civetweb/civetweb
synced 2025-03-28 21:13:27 +00:00
Added check unit tests
These use the excellent check unit testing framework to test the civetweb public API
This commit is contained in:
parent
e03cf46867
commit
548baf792c
25
test/README.md
Normal file
25
test/README.md
Normal file
@ -0,0 +1,25 @@
|
||||
Testing
|
||||
=======
|
||||
|
||||
C API
|
||||
-----
|
||||
|
||||
The unit tests leverage the CTest and Check frameworks to provide a easy
|
||||
environment to build up unit tests. They are split into Public and Private
|
||||
test suites reflecting the public and internal API functions of civetweb.
|
||||
|
||||
When adding new functionality to civetweb tests should be written so that the
|
||||
new functionality will be tested across the continuous build servers. There
|
||||
are various levels of the unit tests:
|
||||
|
||||
* Tests are included in
|
||||
* Test Cases which are there are multiple in
|
||||
* Test Suites which are ran by the check framework by
|
||||
* `civetweb-unit-tests` which is driven using the `--suite` and
|
||||
`--test-case` arguments by
|
||||
* CTest via `add_test` in `CMakeLists.txt`
|
||||
|
||||
Each test suite and test case is ran individually by CTest so that it provides
|
||||
good feedback to the continuous integration servers and also CMake. Adding a
|
||||
new test case or suite will require the corresponding `add_test` driver to be
|
||||
added to `CMakeLists.txt`
|
41
test/civetweb_check.h
Normal file
41
test/civetweb_check.h
Normal file
@ -0,0 +1,41 @@
|
||||
/* Copyright (c) 2013-2015 the Civetweb developers
|
||||
* Copyright (c) 2004-2013 Sergey Lyubka
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef TEST_CIVETWEB_CHECK_H_
|
||||
#define TEST_CIVETWEB_CHECK_H_
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
// FIXME: check uses GCC specific variadic macros that are non-standard
|
||||
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
#undef pid_t
|
||||
#define pid_t int
|
||||
/* Unreferenced formal parameter. START_TEST has _i */
|
||||
#pragma warning(disable: 4100)
|
||||
#endif
|
||||
#include <check.h>
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif /* TEST_CIVETWEB_CHECK_H_ */
|
69
test/main.c
Normal file
69
test/main.c
Normal file
@ -0,0 +1,69 @@
|
||||
/* Copyright (c) 2013-2015 the Civetweb developers
|
||||
* Copyright (c) 2004-2013 Sergey Lyubka
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "civetweb_check.h"
|
||||
#include "public.h"
|
||||
#include "private.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/* This unit test file uses the excellent Check unit testing library.
|
||||
* The API documentation is available here:
|
||||
* http://check.sourceforge.net/doc/check_html/index.html
|
||||
*/
|
||||
|
||||
int main(const int argc, const char * const * const argv) {
|
||||
// Determine what tests to run
|
||||
const char * suite = NULL;
|
||||
const char * const suite_arg = "--suite=";
|
||||
const size_t suite_arg_size = strlen(suite_arg);
|
||||
const char * test_case = NULL;
|
||||
const char * const test_case_arg = "--test-case=";
|
||||
const size_t test_case_arg_size = strlen(test_case_arg);
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (0 == strncmp(suite_arg, argv[i], suite_arg_size) && (strlen(argv[i]) > suite_arg_size)) {
|
||||
suite = &argv[i][suite_arg_size];
|
||||
} else if (0 == strncmp(test_case_arg, argv[i], test_case_arg_size) && (strlen(argv[i]) > test_case_arg_size)) {
|
||||
test_case = &argv[i][test_case_arg_size];
|
||||
} else if (0 == strcmp("--help", argv[i])) {
|
||||
printf("Usage: %s [options]\n"
|
||||
" --suite=Suite Determines the suite to run\n"
|
||||
" --test-case='Test Case' Determines the test case to run\n",
|
||||
argv[0]);
|
||||
exit(EXIT_SUCCESS);
|
||||
} else {
|
||||
fprintf(stderr, "Invalid argument: %s\n", argv[i]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
// Run up the tests
|
||||
SRunner * const srunner = srunner_create(make_public_suite());
|
||||
srunner_add_suite(srunner, make_private_suite());
|
||||
srunner_run(srunner, suite, test_case, CK_NORMAL);
|
||||
const int number_run = srunner_ntests_run(srunner);
|
||||
const int number_failed = srunner_ntests_failed(srunner);
|
||||
srunner_free(srunner);
|
||||
return (number_failed == 0) && (number_run != 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
52
test/private.c
Normal file
52
test/private.c
Normal file
@ -0,0 +1,52 @@
|
||||
/* Copyright (c) 2013-2015 the Civetweb developers
|
||||
* Copyright (c) 2004-2013 Sergey Lyubka
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* We include the source file so that we access to the internal private
|
||||
* static functions
|
||||
*/
|
||||
#include "../src/civetweb.c"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "private.h"
|
||||
|
||||
/* This unit test file uses the excellent Check unit testing library.
|
||||
* The API documentation is available here:
|
||||
* http://check.sourceforge.net/doc/check_html/index.html
|
||||
*/
|
||||
|
||||
START_TEST (test_parse_http_message)
|
||||
{
|
||||
fail_if(0, "s not null after free");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
Suite * make_private_suite (void) {
|
||||
Suite * const suite = suite_create("Private");
|
||||
|
||||
TCase * const http_message = tcase_create("HTTP Message");
|
||||
tcase_add_test(http_message, test_parse_http_message);
|
||||
suite_add_tcase(suite, http_message);
|
||||
|
||||
return suite;
|
||||
}
|
29
test/private.h
Normal file
29
test/private.h
Normal file
@ -0,0 +1,29 @@
|
||||
/* Copyright (c) 2013-2015 the Civetweb developers
|
||||
* Copyright (c) 2004-2013 Sergey Lyubka
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef TEST_PRIVATE_H_
|
||||
#define TEST_PRIVATE_H_
|
||||
|
||||
#include "civetweb_check.h"
|
||||
|
||||
Suite * make_private_suite (void);
|
||||
|
||||
#endif /* TEST_PRIVATE_H_ */
|
46
test/public.c
Normal file
46
test/public.c
Normal file
@ -0,0 +1,46 @@
|
||||
/* Copyright (c) 2013-2015 the Civetweb developers
|
||||
* Copyright (c) 2004-2013 Sergey Lyubka
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "public.h"
|
||||
|
||||
/* This unit test file uses the excellent Check unit testing library.
|
||||
* The API documentation is available here:
|
||||
* http://check.sourceforge.net/doc/check_html/index.html
|
||||
*/
|
||||
|
||||
START_TEST (test_mg_get_cookie)
|
||||
{
|
||||
fail_if(0, "s not null after free");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
Suite * make_public_suite (void) {
|
||||
Suite * const suite = suite_create("Public");
|
||||
|
||||
TCase * const cookies = tcase_create("Cookies");
|
||||
tcase_add_test(cookies, test_mg_get_cookie);
|
||||
suite_add_tcase(suite, cookies);
|
||||
|
||||
return suite;
|
||||
}
|
29
test/public.h
Normal file
29
test/public.h
Normal file
@ -0,0 +1,29 @@
|
||||
/* Copyright (c) 2013-2015 the Civetweb developers
|
||||
* Copyright (c) 2004-2013 Sergey Lyubka
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef TEST_PUBLIC_H_
|
||||
#define TEST_PUBLIC_H_
|
||||
|
||||
#include "civetweb_check.h"
|
||||
|
||||
Suite * make_public_suite (void);
|
||||
|
||||
#endif /* TEST_PUBLIC_H_ */
|
Loading…
x
Reference in New Issue
Block a user