INN commit: trunk (6 files)
INN Commit
rra at isc.org
Thu Sep 4 19:34:06 UTC 2014
Date: Thursday, September 4, 2014 @ 12:34:06
Author: iulius
Revision: 9673
sync the vector test suite with upstream version
Add new string utilities for the TAP protocol. Update the vector
test suite with latest rra-c-util version.
Added:
trunk/tests/tap/string.c
trunk/tests/tap/string.h
Modified:
trunk/MANIFEST
trunk/include/inn/vector.h
trunk/tests/Makefile
trunk/tests/lib/vector-t.c
----------------------+
MANIFEST | 2
include/inn/vector.h | 2
tests/Makefile | 4 -
tests/lib/vector-t.c | 103 +++++++++++++++++++++++++++++++++++++++----------
tests/tap/string.c | 66 +++++++++++++++++++++++++++++++
tests/tap/string.h | 50 +++++++++++++++++++++++
6 files changed, 203 insertions(+), 24 deletions(-)
Modified: MANIFEST
===================================================================
--- MANIFEST 2014-09-03 17:54:25 UTC (rev 9672)
+++ MANIFEST 2014-09-04 19:34:06 UTC (rev 9673)
@@ -920,6 +920,8 @@
tests/tap/float.h Header file for floating point routines
tests/tap/libtap.sh Helper shell library for writing tests
tests/tap/macros.h Helpful macros for TAP header files
+tests/tap/string.c String utilities for the TAP protocol
+tests/tap/string.h Header file for string utilities
tests/util Test suite for utilities (Directory)
tests/util/convdate.t Tests for expire/convdate
tests/util/innbind-t.c Tests for backends/innbind
Modified: include/inn/vector.h
===================================================================
--- include/inn/vector.h 2014-09-03 17:54:25 UTC (rev 9672)
+++ include/inn/vector.h 2014-09-04 19:34:06 UTC (rev 9673)
@@ -26,7 +26,7 @@
#ifndef INN_VECTOR_H
#define INN_VECTOR_H 1
-#include <inn/defines.h>
+#include "config.h"
#include <stddef.h>
Modified: tests/Makefile
===================================================================
--- tests/Makefile 2014-09-03 17:54:25 UTC (rev 9672)
+++ tests/Makefile 2014-09-04 19:34:06 UTC (rev 9673)
@@ -223,8 +223,8 @@
lib/uwildmat.t: lib/uwildmat-t.o tap/basic.o $(LIBINN)
$(LINK) lib/uwildmat-t.o tap/basic.o $(LIBINN)
-lib/vector.t: lib/vector-t.o tap/basic.o $(LIBINN)
- $(LINK) lib/vector-t.o tap/basic.o $(LIBINN)
+lib/vector.t: lib/vector-t.o tap/basic.o tap/string.o $(LIBINN)
+ $(LINK) lib/vector-t.o tap/basic.o tap/string.o $(LIBINN)
lib/wire.t: lib/wire-t.o tap/basic.o $(LIBINN)
$(LINK) lib/wire-t.o tap/basic.o $(LIBINN)
Modified: tests/lib/vector-t.c
===================================================================
--- tests/lib/vector-t.c 2014-09-03 17:54:25 UTC (rev 9672)
+++ tests/lib/vector-t.c 2014-09-04 19:34:06 UTC (rev 9673)
@@ -1,12 +1,11 @@
-/*
+/* $Id$
+ *
* vector test suite.
*
- * $Id$
- *
* The canonical version of this file is maintained in the rra-c-util package,
* which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
*
- * Written by Russ Allbery <rra at stanford.edu>
+ * Written by Russ Allbery <eagle at eyrie.org>
*
* The authors hereby relinquish any claim to any copyright that they may have
* in this work, whether granted under contract or by operation of law or
@@ -21,32 +20,41 @@
#include "config.h"
#include "clibrary.h"
+
#include "portable/wait.h"
-#include "inn/messages.h"
+#include "tap/basic.h"
+#include "tap/string.h"
#include "inn/vector.h"
#include "inn/libinn.h"
-#include "tap/basic.h"
+
int
main(void)
{
struct vector *vector;
struct cvector *cvector;
- const char cstring[] = "This is a\ttest. ";
- const char tabs[] = "test\t\ting\t";
+ char *command, *string;
+ char *p;
+ pid_t child;
+ char empty[] = "";
+ static const char cstring[] = "This is a\ttest. ";
static const char nulls1[] = "This\0is\0a\0test.";
static const char nulls2[] = "This is a\t\0es\0. ";
- char empty[] = "";
- char buffer[256];
- char *string;
- char *p;
- pid_t child;
+ static const char tabs[] = "test\t\ting\t";
- plan(117);
+ /* Set up the plan. */
+ plan(119);
+ /* Be sure that freeing NULL doesn't cause a NULL pointer dereference. */
+ vector_free(NULL);
+ cvector_free(NULL);
+
+ /* Test basic add and resize functionality for vectors. */
vector = vector_new();
ok(vector != NULL, "vector_new returns non-NULL");
+ if (vector == NULL)
+ bail("vector_new returned NULL");
vector_add(vector, cstring);
is_int(1, vector->count, "vector_add increases count");
ok(vector->strings[0] != cstring, "...and allocated new memory");
@@ -61,13 +69,19 @@
is_string(cstring, vector->strings[1], "added the right string");
is_string(cstring, vector->strings[2], "added the right string");
is_string(cstring, vector->strings[3], "added the right string");
+
+ /* Verify that adding the same string creates new copies. */
ok(vector->strings[1] != vector->strings[2], "each pointer is different");
ok(vector->strings[2] != vector->strings[3], "each pointer is different");
ok(vector->strings[3] != vector->strings[0], "each pointer is different");
ok(vector->strings[0] != cstring, "each pointer is different");
+
+ /* Test vector_clear. */
vector_clear(vector);
is_int(0, vector->count, "vector_clear works");
is_int(4, vector->allocated, "...but doesn't free the allocation");
+
+ /* Test that resizing the vector shrinks it and frees the string. */
string = xstrdup(cstring);
vector_add(vector, cstring);
vector_add(vector, string);
@@ -76,14 +90,19 @@
vector_resize(vector, 1);
is_int(1, vector->count, "vector_resize shrinks the vector");
ok(vector->strings[0] != cstring, "...and the pointer is different");
+ free(string);
+
+ /* Test vector_addn. */
vector_addn(vector, cstring, 4);
is_int(2, vector->count, "vector_addn increments count");
is_string("This", vector->strings[1], "...and adds the right data");
vector_free(vector);
- free(string);
+ /* Test basic add and resize functionality for cvectors. */
cvector = cvector_new();
ok(cvector != NULL, "cvector_new returns non-NULL");
+ if (cvector == NULL)
+ bail("cvector_new returned NULL");
cvector_add(cvector, cstring);
is_int(1, cvector->count, "cvector_add adds a string");
ok(cvector->strings[0] == cstring, "...and keeps the same pointer");
@@ -98,9 +117,13 @@
ok(cvector->strings[2] == cvector->strings[3], "all pointers match");
ok(cvector->strings[3] == cvector->strings[0], "all pointers match");
ok(cvector->strings[0] == cstring, "all pointers match");
+
+ /* Test cvector_clear. */
cvector_clear(cvector);
is_int(0, cvector->count, "cvector_clear works");
is_int(4, cvector->allocated, "...but doesn't free the allocation");
+
+ /* Test that resizing the vector shrinks it. */
string = xstrdup(cstring);
cvector_add(cvector, cstring);
cvector_add(cvector, string);
@@ -112,6 +135,7 @@
cvector_free(cvector);
free(string);
+ /* Test vector_split_space. */
vector = vector_split_space("This is a\ttest. ", NULL);
is_int(4, vector->count, "vector_split_space returns right count");
is_int(4, vector->allocated, "...and allocation");
@@ -119,10 +143,14 @@
is_string("is", vector->strings[1], "...second string");
is_string("a", vector->strings[2], "...third string");
is_string("test.", vector->strings[3], "...fourth string");
+
+ /* Test that vector_add increases the size of the vector by one. */
vector_add(vector, cstring);
is_string(cstring, vector->strings[4], "...and can add another");
ok(vector->strings[4] != cstring, "allocates a new pointer");
is_int(5, vector->allocated, "allocation goes up by one");
+
+ /* Test vector_split with vector reuse. */
vector = vector_split(cstring, 't', vector);
is_int(3, vector->count, "resplitting returns the right count");
is_int(5, vector->allocated, "...but doesn't change allocation");
@@ -130,11 +158,14 @@
is_string("es", vector->strings[1], "...second string");
is_string(". ", vector->strings[2], "...third string");
ok(vector->strings[0] != cstring, "...and allocated new string");
+
+ /* Test vector_join. */
p = vector_join(vector, "fe");
is_string("This is a\tfeesfe. ", p, "vector_join works");
free(p);
vector_free(vector);
+ /* Test cvector_split_space. */
string = xstrdup(cstring);
cvector = cvector_split_space(string, NULL);
is_int(4, cvector->count, "cvector_split_space returns right count");
@@ -144,10 +175,14 @@
is_string("a", cvector->strings[2], "...third string");
is_string("test.", cvector->strings[3], "...fourth string");
ok(memcmp(string, nulls1, 16) == 0, "original string modified in place");
+
+ /* Test that cvector_add increases the size of the vector by one. */
cvector_add(cvector, cstring);
ok(cvector->strings[4] == cstring, "cvector_add then works");
is_int(5, cvector->allocated, "...and allocation increases by one");
free(string);
+
+ /* Test cvector_split with vector reuse. */
string = xstrdup(cstring);
cvector = cvector_split(string, 't', cvector);
is_int(3, cvector->count, "cvector_split into same cvector works");
@@ -157,12 +192,15 @@
is_string(". ", cvector->strings[2], "...third string");
ok(cvector->strings[0] == string, "no new memory is allocated");
ok(memcmp(string, nulls2, 18) == 0, "...and string is modified in place");
+
+ /* Test cvector_join. */
p = cvector_join(cvector, "oo");
is_string("This is a\tooesoo. ", p, "cvector_join works");
free(p);
cvector_free(cvector);
free(string);
+ /* Test vector_split and cvector_split on empty string. */
vector = vector_split("", ' ', NULL);
is_int(1, vector->count, "vector_split on empty string");
is_string("", vector->strings[0], "...returns only empty string");
@@ -172,13 +210,21 @@
is_string("", cvector->strings[0], "...returns only empty string");
cvector_free(cvector);
+ /* Test vector_split_space and cvector_split_space on empty string. */
vector = vector_split_space("", NULL);
is_int(0, vector->count, "vector_split_space on empty string");
+ p = vector_join(vector, "mumble");
+ is_string("", p, "vector_join with an empty vector works");
+ free(p);
vector_free(vector);
cvector = cvector_split_space(empty, NULL);
is_int(0, cvector->count, "cvector_split_space on empty string");
+ p = cvector_join(cvector, "mumble");
+ is_string("", p, "cvector_join with an empty vector works");
+ free(p);
cvector_free(cvector);
+ /* Test vector_split again and then join with an empty string. */
vector = vector_split(tabs, '\t', NULL);
is_int(4, vector->count, "vector_split on tab string");
is_string("test", vector->strings[0], "...first string");
@@ -190,6 +236,7 @@
free(p);
vector_free(vector);
+ /* Test cvector_split again and then join with an empty string. */
string = xstrdup(tabs);
cvector = cvector_split(string, '\t', NULL);
is_int(4, cvector->count, "cvector_split on tab string");
@@ -203,11 +250,11 @@
cvector_free(cvector);
free(string);
+ /* Test that newline is not space for (c)vector_split_space. */
vector = vector_split_space("foo\nbar", NULL);
is_int(1, vector->count, "newline is not space for vector_split_space");
is_string("foo\nbar", vector->strings[0], "...first string");
vector_free(vector);
-
string = xstrdup("foo\nbar");
cvector = cvector_split_space(string, NULL);
is_int(1, cvector->count, "newline is not space for cvector_split_space");
@@ -215,11 +262,11 @@
cvector_free(cvector);
free(string);
+ /* Test (c)vector_split_space with leading and trailing delimiters. */
vector = vector_split_space(" \t foo\t", NULL);
is_int(1, vector->count, "extra whitespace in vector_split_space");
is_string("foo", vector->strings[0], "...first string");
vector_free(vector);
-
string = xstrdup(" \t foo\t");
cvector = cvector_split_space(string, NULL);
is_int(1, cvector->count, "extra whitespace in cvector_split_space");
@@ -227,6 +274,7 @@
cvector_free(cvector);
free(string);
+ /* Test (c)vector_split_space on a string that's all delimiters. */
vector = vector_split_space(" \t ", NULL);
is_int(0, vector->count, "vector_split_space on all whitespace string");
vector_free(vector);
@@ -234,12 +282,15 @@
cvector = cvector_split_space(string, NULL);
is_int(0, cvector->count, "cvector_split_space on all whitespace string");
cvector_free(cvector);
+ free(string);
+ /* Test vector_split_multi. */
vector = vector_split_multi("foo, bar, baz", ", ", NULL);
is_int(3, vector->count, "vector_split_multi returns right count");
is_string("foo", vector->strings[0], "...first string");
is_string("bar", vector->strings[1], "...second string");
is_string("baz", vector->strings[2], "...third string");
+ vector_free(vector);
vector = vector_split_multi("", ", ", NULL);
is_int(0, vector->count, "vector_split_multi reuse with empty string");
vector = vector_split_multi(",,, foo, ", ", ", vector);
@@ -249,6 +300,7 @@
is_int(0, vector->count, "vector_split_multi with only separators");
vector_free(vector);
+ /* Test cvector_split_multi. */
string = xstrdup("foo, bar, baz");
cvector = cvector_split_multi(string, ", ", NULL);
is_int(3, cvector->count, "cvector_split_multi returns right count");
@@ -256,6 +308,7 @@
is_string("bar", cvector->strings[1], "...second string");
is_string("baz", cvector->strings[2], "...third string");
free(string);
+ cvector_free(cvector);
cvector = cvector_split_multi(empty, ", ", NULL);
is_int(0, cvector->count, "cvector_split_multi reuse with empty string");
string = xstrdup(",,, foo, ");
@@ -269,11 +322,15 @@
cvector_free(cvector);
free(string);
+ /*
+ * Test vector_exec. We mess with testnum here since the child outputs
+ * the okay message.
+ */
vector = vector_new();
vector_add(vector, "/bin/sh");
vector_add(vector, "-c");
- snprintf(buffer, sizeof(buffer), "echo ok %lu - vector_exec", testnum++);
- vector_add(vector, buffer);
+ basprintf(&command, "echo ok %lu - vector_exec", testnum++);
+ vector_add(vector, command);
child = fork();
if (child < 0)
sysbail("unable to fork");
@@ -282,12 +339,14 @@
sysdiag("unable to exec /bin/sh");
waitpid(child, NULL, 0);
vector_free(vector);
+ free(command);
+ /* Test cvector_exec the same way. */
cvector = cvector_new();
cvector_add(cvector, "/bin/sh");
cvector_add(cvector, "-c");
- snprintf(buffer, sizeof(buffer), "echo ok %lu - cvector_exec", testnum++);
- cvector_add(cvector, buffer);
+ basprintf(&command, "echo ok %lu - cvector_exec", testnum++);
+ cvector_add(cvector, command);
child = fork();
if (child < 0)
sysbail("unable to fork");
@@ -296,6 +355,8 @@
sysdiag("unable to exec /bin/sh");
waitpid(child, NULL, 0);
cvector_free(cvector);
+ free(command);
+ /* All done. */
return 0;
}
Added: tests/tap/string.c
===================================================================
--- tests/tap/string.c (rev 0)
+++ tests/tap/string.c 2014-09-04 19:34:06 UTC (rev 9673)
@@ -0,0 +1,66 @@
+/* $Id$
+ *
+ * String utilities for the TAP protocol.
+ *
+ * Additional string utilities that can't be included with C TAP Harness
+ * because they rely on additional portability code from rra-c-util.
+ *
+ * The canonical version of this file is maintained in the rra-c-util package,
+ * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ *
+ * Copyright 2011, 2012 Russ Allbery <eagle at eyrie.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+#include "clibrary.h"
+
+#include "tap/basic.h"
+#include "tap/string.h"
+
+
+/*
+ * vsprintf into a newly allocated string, reporting a fatal error with bail
+ * on failure.
+ */
+void
+bvasprintf(char **strp, const char *fmt, va_list args)
+{
+ int status;
+
+ status = vasprintf(strp, fmt, args);
+ if (status < 0)
+ sysbail("failed to allocate memory for vasprintf");
+}
+
+
+/*
+ * sprintf into a newly allocated string, reporting a fatal error with bail on
+ * failure.
+ */
+void
+basprintf(char **strp, const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ bvasprintf(strp, fmt, args);
+ va_end(args);
+}
Property changes on: trunk/tests/tap/string.c
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: tests/tap/string.h
===================================================================
--- tests/tap/string.h (rev 0)
+++ tests/tap/string.h 2014-09-04 19:34:06 UTC (rev 9673)
@@ -0,0 +1,50 @@
+/* $Id$
+ *
+ * String utilities for the TAP protocol.
+ *
+ * Additional string utilities that can't be included with C TAP Harness
+ * because they rely on additional portability code from rra-c-util.
+ *
+ * The canonical version of this file is maintained in the rra-c-util package,
+ * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ *
+ * Copyright 2011, 2012 Russ Allbery <eagle at eyrie.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef TAP_STRING_H
+#define TAP_STRING_H 1
+
+#include "config.h"
+#include "tap/macros.h"
+
+#include <stdarg.h> /* va_list */
+
+BEGIN_DECLS
+
+/* sprintf into an allocated string, calling bail on any failure. */
+void basprintf(char **, const char *, ...)
+ __attribute__((__nonnull__, __format__(printf, 2, 3)));
+void bvasprintf(char **, const char *, va_list)
+ __attribute__((__nonnull__));
+
+END_DECLS
+
+#endif /* !TAP_STRING_H */
Property changes on: trunk/tests/tap/string.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: svn:keywords
+ Author Date Id Revision
More information about the inn-committers
mailing list