[mpich2-commits] r8007 - in mpich2/trunk/src/mpl: . test
goodell at mcs.anl.gov
goodell at mcs.anl.gov
Tue Feb 22 08:24:11 CST 2011
Author: goodell
Date: 2011-02-22 08:24:11 -0600 (Tue, 22 Feb 2011)
New Revision: 8007
Added:
mpich2/trunk/src/mpl/test/
mpich2/trunk/src/mpl/test/strsep.c
Modified:
mpich2/trunk/src/mpl/Makefile.am
Log:
add strsep unit test to MPL
This also happens to be the first builtin test for MPL. It can be run by
"make check" in the src/mpl build directory.
Reviewed by balaji at .
Modified: mpich2/trunk/src/mpl/Makefile.am
===================================================================
--- mpich2/trunk/src/mpl/Makefile.am 2011-02-22 14:24:08 UTC (rev 8006)
+++ mpich2/trunk/src/mpl/Makefile.am 2011-02-22 14:24:11 UTC (rev 8007)
@@ -10,3 +10,10 @@
lib_LTLIBRARIES = libmpl.la
libmpl_la_SOURCES = src/mplstr.c src/mpltrmem.c src/mplenv.c
libmpl_la_LDFLAGS = -version-info ${libmpl_so_version}
+
+MPL_TESTS = strsep
+TESTS = $(MPL_TESTS)
+check_PROGRAMS = $(MPL_TESTS)
+strsep_SOURCES = test/strsep.c
+strsep_LDADD = libmpl.la
+
Added: mpich2/trunk/src/mpl/test/strsep.c
===================================================================
--- mpich2/trunk/src/mpl/test/strsep.c (rev 0)
+++ mpich2/trunk/src/mpl/test/strsep.c 2011-02-22 14:24:11 UTC (rev 8007)
@@ -0,0 +1,77 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ * (C) 2011 by Argonne National Laboratory.
+ * See COPYRIGHT in top-level directory.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include "mpl.h"
+
+int main(void)
+{
+ char *orig;
+ char *str;
+ char *next;
+
+ str = NULL;
+ next = MPL_strsep(&str, "|");
+ assert(next == NULL);
+ assert(str == NULL);
+
+ orig = strdup("");
+ str = orig;
+ next = MPL_strsep(&str, "|");
+ assert(str == NULL);
+ assert(next == orig);
+ free(orig);
+
+ orig = strdup("a|b|c");
+ str = orig;
+ next = MPL_strsep(&str, "|");
+ assert(next == orig);
+ assert(0 == strcmp(next, "a"));
+ next = MPL_strsep(&str, "|");
+ assert(0 == strcmp(next, "b"));
+ next = MPL_strsep(&str, "|");
+ assert(0 == strcmp(next, "c"));
+ next = MPL_strsep(&str, "|");
+ assert(next == NULL);
+ assert(str == NULL);
+ free(orig);
+
+ orig = strdup("a|b:c");
+ str = orig;
+ next = MPL_strsep(&str, ":|");
+ assert(next == orig);
+ assert(0 == strcmp(next, "a"));
+ next = MPL_strsep(&str, ":|");
+ assert(0 == strcmp(next, "b"));
+ next = MPL_strsep(&str, ":|");
+ assert(0 == strcmp(next, "c"));
+ next = MPL_strsep(&str, ":|");
+ assert(next == NULL);
+ assert(str == NULL);
+ free(orig);
+
+ orig = strdup("a|:b:c");
+ str = orig;
+ next = MPL_strsep(&str, ":|");
+ assert(next == orig);
+ assert(0 == strcmp(next, "a"));
+ next = MPL_strsep(&str, ":|");
+ assert(0 == strcmp(next, ""));
+ next = MPL_strsep(&str, ":|");
+ assert(0 == strcmp(next, "b"));
+ next = MPL_strsep(&str, ":|");
+ assert(0 == strcmp(next, "c"));
+ next = MPL_strsep(&str, ":|");
+ assert(next == NULL);
+ assert(str == NULL);
+ free(orig);
+
+ return 0;
+}
+
More information about the mpich2-commits
mailing list