diff options
author | Alistair Delva <adelva@google.com> | 2021-10-27 15:04:29 -0700 |
---|---|---|
committer | Alistair Delva <adelva@google.com> | 2021-10-27 15:06:42 -0700 |
commit | aa1e1baec4e1cdc49d0ee7aec83d07e30adaf19f (patch) | |
tree | 6a4709841e622abaad951691e859a4ef59044903 /regress/unittests/misc/test_strdelim.c | |
parent | 393ead3e4a22c473a4d316e47f9bbda36f638188 (diff) | |
parent | bf944e3794eff5413f2df1ef37cddf96918c6bde (diff) | |
download | openssh-aa1e1baec4e1cdc49d0ee7aec83d07e30adaf19f.tar.gz |
Merge commit 'bf944e3794eff5413f2df1ef37cddf96918c6bde' into HEAD
Corresponds to 8.8p1 release.
Bug: 195664829
Test: lunch aosp_cf_arm64_phone-userdebug && mmma external/openssh
Test: lunch aosp_cf_x86_64_phone-userdebug && mmma external/openssh
Link: https://github.com/openssh/openssh-portable/releases/tag/V_8_8_P1
Change-Id: I96cca0f86a2ea006a47d7f0595e1f958ec35dbe6
Diffstat (limited to 'regress/unittests/misc/test_strdelim.c')
-rw-r--r-- | regress/unittests/misc/test_strdelim.c | 202 |
1 files changed, 202 insertions, 0 deletions
diff --git a/regress/unittests/misc/test_strdelim.c b/regress/unittests/misc/test_strdelim.c new file mode 100644 index 000000000..1d9133d4b --- /dev/null +++ b/regress/unittests/misc/test_strdelim.c @@ -0,0 +1,202 @@ +/* $OpenBSD: test_strdelim.c,v 1.2 2021/05/21 03:59:01 djm Exp $ */ +/* + * Regress test for misc strdelim() and co + * + * Placed in the public domain. + */ + +#include "includes.h" + +#include <sys/types.h> +#include <sys/param.h> +#include <stdio.h> +#ifdef HAVE_STDINT_H +#include <stdint.h> +#endif +#include <stdlib.h> +#include <string.h> + +#include "../test_helper/test_helper.h" + +#include "log.h" +#include "misc.h" +#include "xmalloc.h" + +void test_strdelim(void); + +void +test_strdelim(void) +{ + char *orig, *str, *cp; + +#define START_STRING(x) orig = str = xstrdup(x) +#define DONE_STRING() free(orig) + + TEST_START("empty"); + START_STRING(""); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, ""); /* XXX arguable */ + cp = strdelim(&str); + ASSERT_PTR_EQ(cp, NULL); + DONE_STRING(); + TEST_DONE(); + + TEST_START("whitespace"); + START_STRING(" "); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, ""); /* XXX better as NULL */ + ASSERT_STRING_EQ(str, ""); + DONE_STRING(); + TEST_DONE(); + + TEST_START("trivial"); + START_STRING("blob"); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, "blob"); + cp = strdelim(&str); + ASSERT_PTR_EQ(cp, NULL); + ASSERT_PTR_EQ(str, NULL); + DONE_STRING(); + TEST_DONE(); + + TEST_START("trivial whitespace"); + START_STRING("blob "); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, "blob"); + ASSERT_STRING_EQ(str, ""); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, ""); /* XXX better as NULL */ + ASSERT_PTR_EQ(str, NULL); + DONE_STRING(); + TEST_DONE(); + + TEST_START("multi"); + START_STRING("blob1 blob2"); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, "blob1"); + ASSERT_STRING_EQ(str, "blob2"); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, "blob2"); + ASSERT_PTR_EQ(str, NULL); + cp = strdelim(&str); + ASSERT_PTR_EQ(cp, NULL); + DONE_STRING(); + TEST_DONE(); + + TEST_START("multi whitespace"); + START_STRING("blob1 blob2 "); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, "blob1"); + ASSERT_STRING_EQ(str, "blob2 "); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, "blob2"); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, ""); /* XXX better as NULL */ + ASSERT_PTR_EQ(str, NULL); + DONE_STRING(); + TEST_DONE(); + + TEST_START("multi equals"); + START_STRING("blob1=blob2"); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, "blob1"); + ASSERT_STRING_EQ(str, "blob2"); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, "blob2"); + ASSERT_PTR_EQ(str, NULL); + cp = strdelim(&str); + ASSERT_PTR_EQ(cp, NULL); + DONE_STRING(); + TEST_DONE(); + + TEST_START("multi too many equals"); + START_STRING("blob1==blob2"); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, "blob1"); /* XXX better returning NULL early */ + ASSERT_STRING_EQ(str, "=blob2"); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, ""); + ASSERT_STRING_EQ(str, "blob2"); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, "blob2"); /* XXX should (but can't) reject */ + ASSERT_PTR_EQ(str, NULL); + DONE_STRING(); + TEST_DONE(); + + TEST_START("multi equals strdelimw"); + START_STRING("blob1=blob2"); + cp = strdelimw(&str); + ASSERT_STRING_EQ(cp, "blob1=blob2"); + ASSERT_PTR_EQ(str, NULL); + cp = strdelimw(&str); + ASSERT_PTR_EQ(cp, NULL); + DONE_STRING(); + TEST_DONE(); + + TEST_START("quoted"); + START_STRING("\"blob\""); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, "blob"); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, ""); /* XXX better as NULL */ + ASSERT_PTR_EQ(str, NULL); + DONE_STRING(); + TEST_DONE(); + + TEST_START("quoted multi"); + START_STRING("\"blob1\" blob2"); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, "blob1"); + ASSERT_STRING_EQ(str, "blob2"); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, "blob2"); + ASSERT_PTR_EQ(str, NULL); + cp = strdelim(&str); + ASSERT_PTR_EQ(cp, NULL); + DONE_STRING(); + TEST_DONE(); + + TEST_START("quoted multi reverse"); + START_STRING("blob1 \"blob2\""); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, "blob1"); + ASSERT_STRING_EQ(str, "\"blob2\""); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, "blob2"); + ASSERT_STRING_EQ(str, ""); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, ""); /* XXX better as NULL */ + ASSERT_PTR_EQ(str, NULL); + DONE_STRING(); + TEST_DONE(); + + TEST_START("quoted multi middle"); + START_STRING("blob1 \"blob2\" blob3"); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, "blob1"); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, "blob2"); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, "blob3"); + cp = strdelim(&str); + ASSERT_PTR_EQ(cp, NULL); + DONE_STRING(); + TEST_DONE(); + + TEST_START("badquote"); + START_STRING("\"blob"); + cp = strdelim(&str); + ASSERT_PTR_EQ(cp, NULL); + DONE_STRING(); + TEST_DONE(); + + TEST_START("oops quote"); + START_STRING("\"blob\\\""); + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, "blob\\"); /* XXX wrong */ + cp = strdelim(&str); + ASSERT_STRING_EQ(cp, ""); + DONE_STRING(); + TEST_DONE(); + +} |