Merge remote-tracking branch 'origin/develop' into MXS-329-develop-20151111
# Conflicts: # server/core/CMakeLists.txt # server/core/buffer.c # server/core/service.c # server/modules/filter/tee.c # server/modules/monitor/mysql_mon.c # server/modules/routing/binlog/blr.c # server/modules/routing/binlog/blr_slave.c # server/modules/routing/debugcmd.c # server/modules/routing/readwritesplit/readwritesplit.c # utils/skygw_utils.cc - resolved.
This commit is contained in:
@ -14,6 +14,7 @@ add_executable(test_users testusers.c)
|
||||
add_executable(test_adminusers testadminusers.c)
|
||||
add_executable(testmemlog testmemlog.c ../random_jkiss.c)
|
||||
add_executable(testfeedback testfeedback.c)
|
||||
add_executable(testmaxscalepcre2 testmaxscalepcre2.c)
|
||||
target_link_libraries(test_mysql_users MySQLClient fullcore)
|
||||
target_link_libraries(test_hash fullcore log_manager)
|
||||
target_link_libraries(test_hint fullcore log_manager)
|
||||
@ -29,6 +30,7 @@ target_link_libraries(test_users fullcore)
|
||||
target_link_libraries(test_adminusers fullcore)
|
||||
target_link_libraries(testmemlog fullcore log_manager)
|
||||
target_link_libraries(testfeedback fullcore)
|
||||
target_link_libraries(testmaxscalepcre2 fullcore log_manager)
|
||||
add_test(Internal-TestMySQLUsers test_mysql_users)
|
||||
add_test(Internal-TestHash test_hash)
|
||||
add_test(Internal-TestHint test_hint)
|
||||
@ -43,5 +45,6 @@ add_test(Internal-TestServer test_server)
|
||||
add_test(Internal-TestUsers test_users)
|
||||
add_test(Internal-TestAdminUsers test_adminusers)
|
||||
add_test(Internal-TestMemlog testmemlog)
|
||||
add_test(Internal-TestMaxScalePCRE2 testmaxscalepcre2)
|
||||
add_test(TestFeedback testfeedback)
|
||||
set_tests_properties(TestFeedback PROPERTIES TIMEOUT 30)
|
||||
|
||||
@ -68,9 +68,7 @@ int buflen;
|
||||
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 hint for the buffer");
|
||||
char* name = strdup("name");
|
||||
hint = hint_create_parameter(NULL, name, "value");
|
||||
free(name);
|
||||
hint = hint_create_parameter(NULL, "name", "value");
|
||||
gwbuf_add_hint(buffer, hint);
|
||||
ss_info_dassert(hint == buffer->hint, "Buffer should point to first and only hint");
|
||||
ss_dfprintf(stderr, "\t..done\nSet a property for the buffer");
|
||||
@ -157,7 +155,24 @@ int buflen;
|
||||
ss_info_dassert(100000 == buflen, "Incorrect buffer size");
|
||||
ss_info_dassert(buffer == extra, "The buffer pointer should now point to the extra buffer");
|
||||
ss_dfprintf(stderr, "\t..done\n");
|
||||
|
||||
|
||||
/** gwbuf_clone_all test */
|
||||
size_t headsize = 10;
|
||||
GWBUF* head = gwbuf_alloc(headsize);
|
||||
size_t tailsize = 20;
|
||||
GWBUF* tail = gwbuf_alloc(tailsize);
|
||||
|
||||
ss_info_dassert(head && tail, "Head and tail buffers should both be non-NULL");
|
||||
GWBUF* append = gwbuf_append(head, tail);
|
||||
ss_info_dassert(append == head, "gwbuf_append should return head");
|
||||
ss_info_dassert(append->next == tail, "After append tail should be in the next pointer of head");
|
||||
ss_info_dassert(append->tail == tail, "After append tail should be in the tail pointer of head");
|
||||
GWBUF* all_clones = gwbuf_clone_all(head);
|
||||
ss_info_dassert(all_clones && all_clones->next, "Cloning all should work");
|
||||
ss_info_dassert(GWBUF_LENGTH(all_clones) == headsize, "First buffer should be 10 bytes");
|
||||
ss_info_dassert(GWBUF_LENGTH(all_clones->next) == tailsize, "Second buffer should be 20 bytes");
|
||||
ss_info_dassert(gwbuf_length(all_clones) == headsize + tailsize, "Total buffer length should be 30 bytes");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
111
server/core/test/testmaxscalepcre2.c
Normal file
111
server/core/test/testmaxscalepcre2.c
Normal file
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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 MariaDB Corporation Ab 2015
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 05-11-2015 Markus Makela Initial implementation
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
|
||||
// To ensure that ss_info_assert asserts also when builing in non-debug mode.
|
||||
#ifndef SS_DEBUG
|
||||
#define SS_DEBUG
|
||||
#endif
|
||||
#ifdef NDEBUG
|
||||
#undef NDEBUG
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <maxscale_pcre2.h>
|
||||
#include <skygw_debug.h>
|
||||
|
||||
#define test_assert(a, b) if(!(a)){fprintf(stderr, b);return 1;}
|
||||
|
||||
/**
|
||||
* Test PCRE2 regular expression simple matching function test
|
||||
*/
|
||||
static int test1()
|
||||
{
|
||||
int error = 0;
|
||||
mxs_pcre2_result_t result = mxs_pcre2_simple_match("brown.*dog", "The quick brown fox jumps over the lazy dog", 0, &error);
|
||||
test_assert(result == MXS_PCRE2_MATCH, "Pattern should match");
|
||||
error = 0;
|
||||
result = mxs_pcre2_simple_match("BROWN.*DOG", "The quick brown fox jumps over the lazy dog", PCRE2_CASELESS, &error);
|
||||
test_assert(result == MXS_PCRE2_MATCH, "Pattern should match with PCRE2_CASELESS option");
|
||||
error = 0;
|
||||
result = mxs_pcre2_simple_match("black.*dog", "The quick brown fox jumps over the lazy dog", 0, &error);
|
||||
test_assert(result == MXS_PCRE2_NOMATCH && error == 0, "Pattern should not match");
|
||||
error = 0;
|
||||
result = mxs_pcre2_simple_match("black.*[dog", "The quick brown fox jumps over the lazy dog", 0, &error);
|
||||
test_assert(result == MXS_PCRE2_ERROR, "Pattern should not match and a failure should be retured");
|
||||
test_assert(error != 0, "Error number should be non-zero");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test PCRE2 string substitution
|
||||
*/
|
||||
static int test2()
|
||||
{
|
||||
int err;
|
||||
size_t erroff;
|
||||
const char* pattern = "(.*)dog";
|
||||
const char* pattern2 = "(.*)duck";
|
||||
const char* good_replace = "$1cat";
|
||||
const char* bad_replace = "$6cat";
|
||||
const char* subject = "The quick brown fox jumps over the lazy dog";
|
||||
const char* expected = "The quick brown fox jumps over the lazy cat";
|
||||
|
||||
/** We'll assume malloc and the PCRE2 library works */
|
||||
pcre2_code *re = pcre2_compile((PCRE2_SPTR) pattern, PCRE2_ZERO_TERMINATED,
|
||||
0, &err, &erroff, NULL);
|
||||
pcre2_code *re2 = pcre2_compile((PCRE2_SPTR) pattern2, PCRE2_ZERO_TERMINATED,
|
||||
0, &err, &erroff, NULL);
|
||||
size_t size = 1000;
|
||||
char* dest = malloc(size);
|
||||
mxs_pcre2_result_t result = mxs_pcre2_substitute(re, subject, good_replace, &dest, &size);
|
||||
|
||||
test_assert(result == MXS_PCRE2_MATCH, "Substitution should substitute");
|
||||
test_assert(strcmp(dest, expected) == 0, "Replaced text should match expected text");
|
||||
|
||||
result = mxs_pcre2_substitute(re2, subject, good_replace, &dest, &size);
|
||||
test_assert(result == MXS_PCRE2_NOMATCH, "Non-matching substitution should not substitute");
|
||||
|
||||
result = mxs_pcre2_substitute(re, subject, bad_replace, &dest, &size);
|
||||
test_assert(result == MXS_PCRE2_ERROR, "Bad substitution should return an error");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
result += test1();
|
||||
result += test2();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user