Add tests
This commit is contained in:
@ -32,6 +32,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <buffer.h>
|
#include <buffer.h>
|
||||||
|
#include <hint.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test1 Allocate a buffer and do lots of things
|
* test1 Allocate a buffer and do lots of things
|
||||||
@ -41,6 +42,7 @@ static int
|
|||||||
test1()
|
test1()
|
||||||
{
|
{
|
||||||
GWBUF *buffer, *extra, *clone, *partclone, *transform;
|
GWBUF *buffer, *extra, *clone, *partclone, *transform;
|
||||||
|
HINT *hint;
|
||||||
int size = 100;
|
int size = 100;
|
||||||
int bite1 = 35;
|
int bite1 = 35;
|
||||||
int bite2 = 60;
|
int bite2 = 60;
|
||||||
@ -58,6 +60,10 @@ int buflen;
|
|||||||
ss_info_dassert(size == buflen, "Incorrect buffer size");
|
ss_info_dassert(size == buflen, "Incorrect buffer size");
|
||||||
ss_info_dassert(0 == GWBUF_EMPTY(buffer), "Buffer should not be empty");
|
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_info_dassert(GWBUF_IS_TYPE_UNDEFINED(buffer), "Buffer type should be undefined");
|
||||||
|
ss_dfprintf(stderr, "\t..done\nSet a hint for the buffer");
|
||||||
|
hint = hint_create_parameter(NULL, strdup("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");
|
ss_dfprintf(stderr, "\t..done\nSet a property for the buffer");
|
||||||
gwbuf_add_property(buffer, "name", "value");
|
gwbuf_add_property(buffer, "name", "value");
|
||||||
ss_info_dassert(0 == strcmp("value", gwbuf_get_property(buffer, "name")), "Should now have correct property");
|
ss_info_dassert(0 == strcmp("value", gwbuf_get_property(buffer, "name")), "Should now have correct property");
|
||||||
|
|||||||
@ -51,6 +51,7 @@ int buflen;
|
|||||||
ss_dfprintf(stderr,
|
ss_dfprintf(stderr,
|
||||||
"testdcb : creating buffer with type DCB_ROLE_SERVICE_LISTENER");
|
"testdcb : creating buffer with type DCB_ROLE_SERVICE_LISTENER");
|
||||||
dcb = dcb_alloc(DCB_ROLE_SERVICE_LISTENER);
|
dcb = dcb_alloc(DCB_ROLE_SERVICE_LISTENER);
|
||||||
|
printDCB(dcb);
|
||||||
ss_info_dassert(dcb_isvalid(dcb), "New DCB must be valid");
|
ss_info_dassert(dcb_isvalid(dcb), "New DCB must be valid");
|
||||||
ss_dfprintf(stderr, "\t..done\nAllocated dcb.");
|
ss_dfprintf(stderr, "\t..done\nAllocated dcb.");
|
||||||
clone = dcb_clone(dcb);
|
clone = dcb_clone(dcb);
|
||||||
|
|||||||
83
server/core/test/testgwbitmask.c
Normal file
83
server/core/test/testgwbitmask.c
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
* 13-10-2014 Martin Brampton Initial implementation
|
||||||
|
*
|
||||||
|
* @endverbatim
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <gwbitmask.h>
|
||||||
|
|
||||||
|
#include <skygw_debug.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test1 Allocate table of users and mess around with it
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int
|
||||||
|
test1()
|
||||||
|
{
|
||||||
|
static GWBITMASK bitmask, another;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* Hint tests */
|
||||||
|
ss_dfprintf(stderr,
|
||||||
|
"testgwbitmask : Initialise a bitmask");
|
||||||
|
bitmask_init(&bitmask);
|
||||||
|
ss_info_dassert(BIT_LENGTH_INITIAL == bitmask.length, "Length should be initial length.");
|
||||||
|
for (i = 0; i < BIT_LENGTH_INITIAL; i++) {
|
||||||
|
ss_info_dassert(0 == bitmask_isset(&bitmask, i), "All bits should initially be zero");
|
||||||
|
}
|
||||||
|
ss_info_dassert(0 != bitmask_isallclear(&bitmask), "Should be all clear");
|
||||||
|
ss_dfprintf(stderr, "\t..done\nSet an arbitrary bit.");
|
||||||
|
bitmask_set(&bitmask, 17);
|
||||||
|
bitmask_copy(&another, &bitmask);
|
||||||
|
ss_info_dassert(0 != bitmask_isset(&another, 17), "Test bit should be set");
|
||||||
|
ss_dfprintf(stderr, "\t..done\nClear the arbitrary bit.");
|
||||||
|
bitmask_clear(&bitmask, 17);
|
||||||
|
ss_info_dassert(0 == bitmask_isset(&bitmask, 17), "Test bit should be clear");
|
||||||
|
ss_info_dassert(0 != bitmask_isallclear(&bitmask), "Should be all clear");
|
||||||
|
ss_dfprintf(stderr, "\t..done\nFree the bitmask.");
|
||||||
|
bitmask_free(&bitmask);
|
||||||
|
ss_info_dassert(0 == bitmask.length, "Length should be zero after bit mask freed.");
|
||||||
|
ss_dfprintf(stderr, "\t..done\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
result += test1();
|
||||||
|
|
||||||
|
exit(result);
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user