MXS-1450 Add test case for trim
This commit is contained in:
@ -16,6 +16,7 @@ add_executable(test_spinlock testspinlock.c)
|
|||||||
add_executable(test_trxcompare testtrxcompare.cc ../../../query_classifier/test/testreader.cc)
|
add_executable(test_trxcompare testtrxcompare.cc ../../../query_classifier/test/testreader.cc)
|
||||||
add_executable(test_trxtracking testtrxtracking.cc)
|
add_executable(test_trxtracking testtrxtracking.cc)
|
||||||
add_executable(test_users testusers.c)
|
add_executable(test_users testusers.c)
|
||||||
|
add_executable(test_utils testutils.cc)
|
||||||
add_executable(testfeedback testfeedback.c)
|
add_executable(testfeedback testfeedback.c)
|
||||||
add_executable(testmaxscalepcre2 testmaxscalepcre2.c)
|
add_executable(testmaxscalepcre2 testmaxscalepcre2.c)
|
||||||
add_executable(testmodulecmd testmodulecmd.c)
|
add_executable(testmodulecmd testmodulecmd.c)
|
||||||
@ -39,6 +40,7 @@ target_link_libraries(test_spinlock maxscale-common)
|
|||||||
target_link_libraries(test_trxcompare maxscale-common)
|
target_link_libraries(test_trxcompare maxscale-common)
|
||||||
target_link_libraries(test_trxtracking maxscale-common)
|
target_link_libraries(test_trxtracking maxscale-common)
|
||||||
target_link_libraries(test_users maxscale-common)
|
target_link_libraries(test_users maxscale-common)
|
||||||
|
target_link_libraries(test_utils maxscale-common)
|
||||||
target_link_libraries(testfeedback maxscale-common)
|
target_link_libraries(testfeedback maxscale-common)
|
||||||
target_link_libraries(testmaxscalepcre2 maxscale-common)
|
target_link_libraries(testmaxscalepcre2 maxscale-common)
|
||||||
target_link_libraries(testmodulecmd maxscale-common)
|
target_link_libraries(testmodulecmd maxscale-common)
|
||||||
@ -62,6 +64,7 @@ add_test(TestServer test_server)
|
|||||||
add_test(TestService test_service)
|
add_test(TestService test_service)
|
||||||
add_test(TestSpinlock test_spinlock)
|
add_test(TestSpinlock test_spinlock)
|
||||||
add_test(TestUsers test_users)
|
add_test(TestUsers test_users)
|
||||||
|
add_test(TestUtils test_utils)
|
||||||
add_test(TestModulecmd testmodulecmd)
|
add_test(TestModulecmd testmodulecmd)
|
||||||
add_test(TestConfig testconfig)
|
add_test(TestConfig testconfig)
|
||||||
add_test(TestTrxTracking test_trxtracking)
|
add_test(TestTrxTracking test_trxtracking)
|
||||||
|
80
server/core/test/testutils.cc
Normal file
80
server/core/test/testutils.cc
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||||
|
*
|
||||||
|
* Use of this software is governed by the Business Source License included
|
||||||
|
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||||
|
*
|
||||||
|
* Change Date: 2019-07-01
|
||||||
|
*
|
||||||
|
* On the date above, in accordance with the Business Source License, use
|
||||||
|
* of this software will be governed by version 2 or later of the General
|
||||||
|
* Public License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <maxscale/utils.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
#define TRIM_TEST_CASE_ENTRY(zFrom, zTo) { zFrom, zTo }
|
||||||
|
|
||||||
|
struct TRIM_TEST_CASE
|
||||||
|
{
|
||||||
|
const char* zFrom;
|
||||||
|
const char* zTo;
|
||||||
|
} trim_testcases[] =
|
||||||
|
{
|
||||||
|
TRIM_TEST_CASE_ENTRY("", ""),
|
||||||
|
TRIM_TEST_CASE_ENTRY("a", "a"),
|
||||||
|
TRIM_TEST_CASE_ENTRY(" a", "a"),
|
||||||
|
TRIM_TEST_CASE_ENTRY("a ", "a"),
|
||||||
|
TRIM_TEST_CASE_ENTRY("a ", "a"),
|
||||||
|
TRIM_TEST_CASE_ENTRY(" a ", "a"),
|
||||||
|
TRIM_TEST_CASE_ENTRY(" a", "a"),
|
||||||
|
TRIM_TEST_CASE_ENTRY("a ", "a"),
|
||||||
|
TRIM_TEST_CASE_ENTRY(" a ", "a"),
|
||||||
|
TRIM_TEST_CASE_ENTRY(" a b ", "a b"),
|
||||||
|
};
|
||||||
|
|
||||||
|
const int n_trim_testcases = sizeof(trim_testcases) / sizeof(trim_testcases[0]);
|
||||||
|
|
||||||
|
|
||||||
|
int test(TRIM_TEST_CASE* pTest_cases, int n_test_cases, char* (*p)(char*))
|
||||||
|
{
|
||||||
|
int rv = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < n_test_cases; ++i)
|
||||||
|
{
|
||||||
|
const char* zFrom = pTest_cases[i].zFrom;
|
||||||
|
const char* zTo = pTest_cases[i].zTo;
|
||||||
|
|
||||||
|
char copy[strlen(zFrom) + 1];
|
||||||
|
strcpy(copy, zFrom);
|
||||||
|
|
||||||
|
char* z = p(copy);
|
||||||
|
|
||||||
|
if (strcmp(z, zTo) != 0)
|
||||||
|
{
|
||||||
|
++rv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test1()
|
||||||
|
{
|
||||||
|
return test(trim_testcases, n_trim_testcases, trim);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
int rv = 0;
|
||||||
|
|
||||||
|
rv += test1();
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
Reference in New Issue
Block a user