aboutsummaryrefslogtreecommitdiffstats
path: root/jnlib/t-stringhelp.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2009-08-25 20:19:37 +0000
committerWerner Koch <[email protected]>2009-08-25 20:19:37 +0000
commit24e5a68f9e8e4bfdf10b4e5262b2a5fac2712291 (patch)
treee86141da64b2bb527414806acd0616f5d09d42e5 /jnlib/t-stringhelp.c
parent* gpg.text: Suggested new ordering for --edit-key. (diff)
downloadgnupg-24e5a68f9e8e4bfdf10b4e5262b2a5fac2712291.tar.gz
gnupg-24e5a68f9e8e4bfdf10b4e5262b2a5fac2712291.zip
New fucntions strconcat and xstrconcat.
Diffstat (limited to '')
-rw-r--r--jnlib/t-stringhelp.c145
1 files changed, 145 insertions, 0 deletions
diff --git a/jnlib/t-stringhelp.c b/jnlib/t-stringhelp.c
index f6590230e..317b02049 100644
--- a/jnlib/t-stringhelp.c
+++ b/jnlib/t-stringhelp.c
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include "stringhelp.h"
@@ -118,6 +119,148 @@ test_compare_filenames (void)
}
+static void
+test_strconcat (void)
+{
+ char *out;
+
+ out = strconcat ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
+ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
+ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
+ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
+ "1", "2", "3", "4", "5", "6", "7", NULL);
+ if (!out)
+ fail (0);
+ else
+ xfree (out);
+ out = strconcat ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
+ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
+ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
+ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
+ "1", "2", "3", "4", "5", "6", "7", "8", NULL);
+ if (out)
+ fail (0);
+ else if (errno != EINVAL)
+ fail (0);
+
+ out = strconcat ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
+ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
+ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
+ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
+ "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL);
+ if (out)
+ fail (0);
+ else if (errno != EINVAL)
+ fail (0);
+
+#if __GNUC__ < 4 /* gcc 4.0 has a sentinel attribute. */
+ out = strconcat (NULL);
+ if (!out || *out)
+ fail (1);
+#endif
+ out = strconcat (NULL, NULL);
+ if (!out || *out)
+ fail (1);
+ out = strconcat ("", NULL);
+ if (!out || *out)
+ fail (1);
+ xfree (out);
+
+ out = strconcat ("", "", NULL);
+ if (!out || *out)
+ fail (2);
+ xfree (out);
+
+ out = strconcat ("a", "b", NULL);
+ if (!out || strcmp (out, "ab"))
+ fail (3);
+ xfree (out);
+ out = strconcat ("a", "b", "c", NULL);
+ if (!out || strcmp (out, "abc"))
+ fail (3);
+ xfree (out);
+
+ out = strconcat ("a", "b", "cc", NULL);
+ if (!out || strcmp (out, "abcc"))
+ fail (4);
+ xfree (out);
+ out = strconcat ("a1", "b1", "c1", NULL);
+ if (!out || strcmp (out, "a1b1c1"))
+ fail (4);
+ xfree (out);
+
+ out = strconcat ("", " long b ", "", "--even-longer--", NULL);
+ if (!out || strcmp (out, " long b --even-longer--"))
+ fail (5);
+ xfree (out);
+
+ out = strconcat ("", " long b ", "", "--even-longer--", NULL);
+ if (!out || strcmp (out, " long b --even-longer--"))
+ fail (5);
+ xfree (out);
+}
+
+static void
+test_xstrconcat (void)
+{
+ char *out;
+
+ out = xstrconcat ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
+ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
+ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
+ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
+ "1", "2", "3", "4", "5", "6", "7", NULL);
+ if (!out)
+ fail (0);
+
+#if __GNUC__ < 4 /* gcc 4.0 has a sentinel attribute. */
+ out = xstrconcat (NULL);
+ if (!out)
+ fail (1);
+#endif
+ out = xstrconcat (NULL, NULL);
+ if (!out)
+ fail (1);
+ out = xstrconcat ("", NULL);
+ if (!out || *out)
+ fail (1);
+ xfree (out);
+
+ out = xstrconcat ("", "", NULL);
+ if (!out || *out)
+ fail (2);
+ xfree (out);
+
+ out = xstrconcat ("a", "b", NULL);
+ if (!out || strcmp (out, "ab"))
+ fail (3);
+ xfree (out);
+ out = xstrconcat ("a", "b", "c", NULL);
+ if (!out || strcmp (out, "abc"))
+ fail (3);
+ xfree (out);
+
+ out = xstrconcat ("a", "b", "cc", NULL);
+ if (!out || strcmp (out, "abcc"))
+ fail (4);
+ xfree (out);
+ out = xstrconcat ("a1", "b1", "c1", NULL);
+ if (!out || strcmp (out, "a1b1c1"))
+ fail (4);
+ xfree (out);
+
+ out = xstrconcat ("", " long b ", "", "--even-longer--", NULL);
+ if (!out || strcmp (out, " long b --even-longer--"))
+ fail (5);
+ xfree (out);
+
+ out = xstrconcat ("", " long b ", "", "--even-longer--", NULL);
+ if (!out || strcmp (out, " long b --even-longer--"))
+ fail (5);
+ xfree (out);
+}
+
+
int
main (int argc, char **argv)
{
@@ -126,6 +269,8 @@ main (int argc, char **argv)
test_percent_escape ();
test_compare_filenames ();
+ test_strconcat ();
+ test_xstrconcat ();
return 0;
}