tests: add rb_dictionary1

This doesn't do much because replacing existing elements isn't allowed.
This commit is contained in:
Simon Arlott 2017-08-06 18:38:25 +01:00
parent 1272b289e6
commit 959dffde9b
No known key found for this signature in database
GPG Key ID: C8975F2043CA5D24
4 changed files with 66 additions and 0 deletions

1
.gitignore vendored
View File

@ -59,6 +59,7 @@ wsockd/wsockd
tests/core
tests/msgbuf_parse1
tests/msgbuf_unparse1
tests/rb_dictionary1
tests/rb_snprintf_append1
tests/rb_snprintf_try_append1
tests/send1

View File

@ -1,6 +1,7 @@
check_PROGRAMS = runtests \
msgbuf_parse1 \
msgbuf_unparse1 \
rb_dictionary1 \
rb_snprintf_append1 \
rb_snprintf_try_append1 \
send1 \
@ -21,6 +22,7 @@ tap_libtap_a_SOURCES = tap/basic.c tap/basic.h \
msgbuf_parse1_SOURCES = msgbuf_parse1.c
msgbuf_unparse1_SOURCES = msgbuf_unparse1.c
rb_dictionary1_SOURCES = rb_dictionary1.c
rb_snprintf_append1_SOURCES = rb_snprintf_append1.c
rb_snprintf_try_append1_SOURCES = rb_snprintf_try_append1.c
send1_SOURCES = send1.c ircd_util.c client_util.c

View File

@ -1,5 +1,6 @@
msgbuf_parse1
msgbuf_unparse1
rb_dictionary1
rb_snprintf_append1
rb_snprintf_try_append1
send1

62
tests/rb_dictionary1.c Normal file
View File

@ -0,0 +1,62 @@
/*
* rb_dictionary1.c: Test rb_dictionary
* Copyright 2017 Simon Arlott
*
* This program 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; either version 2 of the License, or
* (at your option) any later version.
*
* 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
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "tap/basic.h"
#include "stdinc.h"
#include "ircd_defs.h"
#include "client.h"
#define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
#define MKTEXT(n) &text[sizeof(text) - ((n) + 1)]
static void replace1(void)
{
rb_dictionary *dict = rb_dictionary_create("replace1", strcmp);
rb_dictionary_element *original = rb_dictionary_add(dict, "test", "data1");
ok(original != NULL, MSG);
is_string("data1", original->data, MSG);
#ifdef SOFT_ASSERT
rb_dictionary_element *replacement = rb_dictionary_add(dict, "test", "data2");
ok(replacement != NULL, MSG);
ok(original == replacement, MSG);
is_string("data2", original->data, MSG);
#endif
}
int main(int argc, char *argv[])
{
rb_lib_init(NULL, NULL, NULL, 0, 1024, DNODE_HEAP_SIZE, FD_HEAP_SIZE);
rb_linebuf_init(LINEBUF_HEAP_SIZE);
plan_lazy();
replace1();
return 0;
}