From d5071267e71ea36068aaef3f3b11f07b13cbfc47 Mon Sep 17 00:00:00 2001 From: counterpoint Date: Wed, 8 Oct 2014 18:04:28 +0100 Subject: [PATCH] More tests; minor fixes. --- server/core/buffer.c | 2 + server/core/server.c | 2 +- server/core/test/CMakeLists.txt | 3 ++ server/core/test/testbuffer.c | 3 ++ server/core/test/testhint.c | 69 +++++++++++++++++++++++++++++++++ server/core/test/testservice.c | 6 +++ 6 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 server/core/test/testhint.c diff --git a/server/core/buffer.c b/server/core/buffer.c index bb40a8d40..46315cf69 100644 --- a/server/core/buffer.c +++ b/server/core/buffer.c @@ -42,6 +42,8 @@ #include #include #include +#include +#include static buffer_object_t* gwbuf_remove_buffer_object( GWBUF* buf, diff --git a/server/core/server.c b/server/core/server.c index 2afe3bd44..167ae4f23 100644 --- a/server/core/server.c +++ b/server/core/server.c @@ -136,7 +136,7 @@ SERVER *ptr; /** * Set a unique name for the server * - * @param server The server to ste the name on + * @param server The server to set the name on * @param name The unique name for the server */ void diff --git a/server/core/test/CMakeLists.txt b/server/core/test/CMakeLists.txt index ee3e46b32..14a80cd36 100644 --- a/server/core/test/CMakeLists.txt +++ b/server/core/test/CMakeLists.txt @@ -1,4 +1,5 @@ add_executable(test_hash testhash.c) +add_executable(test_hint testhint.c) add_executable(test_spinlock testspinlock.c) add_executable(test_filter testfilter.c) add_executable(test_buffer testbuffer.c) @@ -10,6 +11,7 @@ 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_hint fullcore) target_link_libraries(test_spinlock fullcore) target_link_libraries(test_filter fullcore) target_link_libraries(test_buffer fullcore) @@ -21,6 +23,7 @@ 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(TestHint test_hint) add_test(TestSpinlock test_spinlock) add_test(TestFilter test_filter) add_test(TestBuffer test_buffer) diff --git a/server/core/test/testbuffer.c b/server/core/test/testbuffer.c index baca6af3f..87ebf858b 100644 --- a/server/core/test/testbuffer.c +++ b/server/core/test/testbuffer.c @@ -58,6 +58,9 @@ int buflen; ss_info_dassert(size == buflen, "Incorrect buffer size"); ss_info_dassert(0 == GWBUF_EMPTY(buffer), "Buffer should not be empty"); ss_info_dassert(GWBUF_IS_TYPE_UNDEFINED(buffer), "Buffer type should be undefined"); + ss_dfprintf(stderr, "\t..done\nSet a property for the buffer"); + gwbuf_add_property(buffer, "name", "value"); + ss_info_dassert(0 == strcmp("value", gwbuf_get_property(buffer, "name")), "Should now have correct property"); strcpy(GWBUF_DATA(buffer), "The quick brown fox jumps over the lazy dog"); ss_dfprintf(stderr, "\t..done\nLoad some data into the buffer"); ss_info_dassert('q' == GWBUF_DATA_CHAR(buffer, 4), "Fourth character of buffer must be 'q'"); diff --git a/server/core/test/testhint.c b/server/core/test/testhint.c new file mode 100644 index 000000000..3d2241642 --- /dev/null +++ b/server/core/test/testhint.c @@ -0,0 +1,69 @@ +/* + * 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() +{ +HINT *hint; + + /* Hint tests */ + ss_dfprintf(stderr, + "testhint : Add a parameter hint to a null list"); + hint = hint_create_parameter(NULL, strdup("name"), "value"); + ss_info_dassert(NULL != hint, "New hint list should not be null"); + ss_info_dassert(0 == strcmp("value", hint->value), "Hint value should be correct"); + ss_info_dassert(0 != hint_exists(hint, HINT_PARAMETER), "Hint of parameter type should exist"); + ss_dfprintf(stderr, "\t..done\nFree hints."); + if (NULL != hint) hint_free(hint); + 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 e17a15e6e..2b12c8062 100644 --- a/server/core/test/testservice.c +++ b/server/core/test/testservice.c @@ -57,9 +57,15 @@ int result; ss_dfprintf(stderr, "\t..done\nAdding protocol HTTPD."); ss_info_dassert(0 != serviceAddProtocol(service, "HTTPD", "localhost", 9876), "Add Protocol should succeed"); ss_info_dassert(0 != serviceHasProtocol(service, "HTTPD", 9876), "Service should have new protocol as requested"); + serviceStartProtocol(service, "HTTPD", 9876); ss_dfprintf(stderr, "\t..done\nStarting Service."); result = serviceStart(service); ss_info_dassert(0 != result, "Start should succeed"); + result = serviceStop(service); + ss_info_dassert(0 != result, "Stop should succeed"); + result = serviceStartAll(); + ss_info_dassert(0 != result, "Start all should succeed"); + ss_dfprintf(stderr, "\t..done\nStopping Service."); ss_info_dassert(0 != serviceStop(service), "Stop should succeed"); ss_dfprintf(stderr, "\t..done\nFreeing Service.");