From 959dffde9b71493cd8e1a783d351442b51234ab8 Mon Sep 17 00:00:00 2001 From: Simon Arlott Date: Sun, 6 Aug 2017 18:38:25 +0100 Subject: [PATCH] tests: add rb_dictionary1 This doesn't do much because replacing existing elements isn't allowed. --- .gitignore | 1 + tests/Makefile.am | 2 ++ tests/TESTS | 1 + tests/rb_dictionary1.c | 62 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 tests/rb_dictionary1.c diff --git a/.gitignore b/.gitignore index dfc34683..34aafeb9 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/tests/Makefile.am b/tests/Makefile.am index dbd12360..500fca16 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 diff --git a/tests/TESTS b/tests/TESTS index fddef204..b6e1ded6 100644 --- a/tests/TESTS +++ b/tests/TESTS @@ -1,5 +1,6 @@ msgbuf_parse1 msgbuf_unparse1 +rb_dictionary1 rb_snprintf_append1 rb_snprintf_try_append1 send1 diff --git a/tests/rb_dictionary1.c b/tests/rb_dictionary1.c new file mode 100644 index 00000000..4328e448 --- /dev/null +++ b/tests/rb_dictionary1.c @@ -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 +#include +#include +#include +#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; +}