From 76e85dfb1137dfe068557faa4d89761802e15df3 Mon Sep 17 00:00:00 2001 From: counterpoint Date: Wed, 8 Oct 2014 13:33:08 +0100 Subject: [PATCH] Add more tests --- server/core/test/CMakeLists.txt | 21 ++++++++ server/core/test/testserver.c | 89 +++++++++++++++++++++++++++++++++ server/core/test/testservice.c | 2 +- server/core/test/testusers.c | 81 ++++++++++++++++++++++++++++++ 4 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 server/core/test/testserver.c create mode 100644 server/core/test/testusers.c diff --git a/server/core/test/CMakeLists.txt b/server/core/test/CMakeLists.txt index 914fe277e..ee3e46b32 100644 --- a/server/core/test/CMakeLists.txt +++ b/server/core/test/CMakeLists.txt @@ -1,13 +1,34 @@ add_executable(test_hash testhash.c) add_executable(test_spinlock testspinlock.c) add_executable(test_filter testfilter.c) +add_executable(test_buffer testbuffer.c) +add_executable(test_dcb testdcb.c) +add_executable(test_modutil testmodutil.c) +add_executable(test_poll testpoll.c) +add_executable(test_service testservice.c) +add_executable(test_server testserver.c) +add_executable(test_users testusers.c) add_executable(test_adminusers testadminusers.c) target_link_libraries(test_hash fullcore) target_link_libraries(test_spinlock fullcore) target_link_libraries(test_filter fullcore) +target_link_libraries(test_buffer fullcore) +target_link_libraries(test_dcb fullcore) +target_link_libraries(test_modutil fullcore) +target_link_libraries(test_poll fullcore) +target_link_libraries(test_service fullcore) +target_link_libraries(test_server fullcore) +target_link_libraries(test_users fullcore) target_link_libraries(test_adminusers fullcore) add_test(TestHash test_hash) add_test(TestSpinlock test_spinlock) add_test(TestFilter test_filter) +add_test(TestBuffer test_buffer) +add_test(TestDCB test_dcb) +add_test(TestModutil test_modutil) +add_test(TestPoll test_poll) +add_test(TestService test_service) +add_test(TestServer test_server) +add_test(TestUsers test_users) add_test(TestAdminUsers test_adminusers) diff --git a/server/core/test/testserver.c b/server/core/test/testserver.c new file mode 100644 index 000000000..b06e53269 --- /dev/null +++ b/server/core/test/testserver.c @@ -0,0 +1,89 @@ +/* + * This file is distributed as part of MaxScale. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2014 + */ + +/** + * + * @verbatim + * Revision History + * + * Date Who Description + * 08-10-2014 Martin Brampton Initial implementation + * + * @endverbatim + */ + +#include +#include +#include + +#include + +/** + * test1 Allocate a server and do lots of other things + * + */ +static int +test1() +{ +SERVER *server; +int result; +char *status; + + /* Server tests */ + ss_dfprintf(stderr, + "testserver : creating server called MyServer"); + server = server_alloc("MyServer", "HTTPD", 9876); + ss_info_dassert(NULL != service, "New server with valid protocol and port must not be null"); + ss_info_dassert(0 != service_isvalid(service), "Service must be valid after creation"); + ss_dfprintf(stderr, "\t..done\nTest Parameter for Server."); + ss_info_dassert(NULL == serverGetParameter(server, "name"), "Parameter should be null when not set"); + serverAddParameter(server, "name", "value"); + ss_info_dassert(0 == strcmp("value", serverGetParameter(server, "name")), "Parameter should be returned correctly"); + ss_dfprintf(stderr, "\t..done\nTesting Unique Name for Server."); + ss_info_dassert(NULL == server_find_by_unique_name("uniquename"), "Should not find non-existent unique name."); + server_set_unique_name(server, "uniquename"); + ss_info_dassert(server == server_find_by_unique_name("uniquename"), "Should find by unique name."); + ss_dfprintf(stderr, "\t..done\nTesting Status Setting for Server."); + status = server_status(server); + ss_info_dassert(0 == strcmp("Down", status), "Status of Server should be Down prior to being set."); + if (NULL != status) free(status); + server_set_status(server, SERVER_MASTER); + status = server_status(server); + ss_info_dassert(0 == strcmp("Master, Down", status), "Should find correct status."); + server_clear_status(server, SERVER_MASTER); + ss_info_dassert(0 == strcmp("Down", status), "Status of Server should be Down after status cleared."); + if (NULL != status) free(status); + ss_dfprintf(stderr, "\t..done\nRun Prints for Server and all Servers."); + printServer(server); + printAllServers(); + ss_dfprintf(stderr, "\t..done\nFreeing Server."); + ss_info_dassert(0 != server_free(server), "Free should succeed"); + ss_dfprintf(stderr, "\t..done\n"); + + return 0; + +} + +int main(int argc, char **argv) +{ +int result = 0; + + result += test1(); + + exit(result); +} diff --git a/server/core/test/testservice.c b/server/core/test/testservice.c index d8a7463ee..e17a15e6e 100644 --- a/server/core/test/testservice.c +++ b/server/core/test/testservice.c @@ -46,7 +46,7 @@ int result; /* Service tests */ ss_dfprintf(stderr, "testservice : creating service called MyService with router nonexistent"); - service = service_alloc("MyService", "nonexistent"); + service = service_alloc("MyService", "non-existent"); ss_info_dassert(NULL == service, "New service with invalid router should be null"); ss_info_dassert(0 == service_isvalid(service), "Service must not be valid after incorrect creation"); ss_dfprintf(stderr, "\t..done\nValid service creation, router testroute."); diff --git a/server/core/test/testusers.c b/server/core/test/testusers.c new file mode 100644 index 000000000..1f32c5d97 --- /dev/null +++ b/server/core/test/testusers.c @@ -0,0 +1,81 @@ +/* + * This file is distributed as part of MaxScale. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2014 + */ + +/** + * + * @verbatim + * Revision History + * + * Date Who Description + * 08-10-2014 Martin Brampton Initial implementation + * + * @endverbatim + */ + +#include +#include +#include + +#include + +/** + * test1 Allocate table of users and mess around with it + * + */ + +static int +test1() +{ +USERS *users; +int result, count; + + /* Poll tests */ + ss_dfprintf(stderr, + "testusers : Initialise the user table."); + users = users_alloc(); + ss_info_dassert(NULL != servers, "Allocating user table should not return NULL.") + ss_dfprintf(stderr, "\t..done\nAdd a user"); + count = users_add(users, "username", "authorisation"); + ss_info_dassert(1 == count, "Should add one user"); + ss_info_dassert(strcmp("authorisation", users_fetch(users, "username")), "User authorisation should be correct"); + ss_dfprintf(stderr, "\t..done\nPrint users"); + usersPrint(users); + ss_dfprintf(stderr, "\t..done\nUpdate a user"); + count = users_update(users, "username", "newauth"); + ss_info_dassert(1 == count, "Should update just one user"); + ss_info_dassert(strcmp("newauth", users_fetch(users, "username")), "User authorisation should be correctly updated"); + ss_dfprintf(stderr, "\t..done\nDelete a user."); + count = users_delete(users, "username"); + ss_info_dassert(1 == count, "Should delete just one user"); + ss_dfprintf(stderr, "\t..done\nFree user table."); + users_free(users); + ss_dfprintf(stderr, "\t..done\n"); + + return 0; + +} + +int main(int argc, char **argv) +{ +int result = 0; + + result += test1(); + + exit(result); +} +