summaryrefslogtreecommitdiff
path: root/src/test/test-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-03-23 18:55:36 +0700
committerLennart Poettering <lennart@poettering.net>2015-03-26 11:56:22 +0100
commit4034a06ddb82ec9868cd52496fef2f5faa25575f (patch)
treea832cd56abb7830985f3e7e9dff7451b96478c24 /src/test/test-util.c
parentbe3ce3014eacd66fa292fc9e4e6b3d3b0ef7de23 (diff)
util: rework word parsing and c unescaping code
When parsing words from input files, optionally automatically unescape the passed strings, controllable via a new flags parameter. Make use of this in tmpfiles, and port everything else over, too. This improves parsing quite a bit, since we no longer have to process the same string multiple times with different calls, where an earlier call might corrupt the input for a later call.
Diffstat (limited to 'src/test/test-util.c')
-rw-r--r--src/test/test-util.c50
1 files changed, 31 insertions, 19 deletions
diff --git a/src/test/test-util.c b/src/test/test-util.c
index 9515a8cbf1..d32ddd3a68 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -1283,64 +1283,76 @@ static void test_unquote_first_word(void) {
char *t;
p = original = "foobar waldo";
- assert_se(unquote_first_word(&p, &t, false) > 0);
+ assert_se(unquote_first_word(&p, &t, 0) > 0);
assert_se(streq(t, "foobar"));
free(t);
assert_se(p == original + 7);
- assert_se(unquote_first_word(&p, &t, false) > 0);
+ assert_se(unquote_first_word(&p, &t, 0) > 0);
assert_se(streq(t, "waldo"));
free(t);
assert_se(p == original + 12);
- assert_se(unquote_first_word(&p, &t, false) == 0);
+ assert_se(unquote_first_word(&p, &t, 0) == 0);
assert_se(!t);
assert_se(p == original + 12);
p = original = "\"foobar\" \'waldo\'";
- assert_se(unquote_first_word(&p, &t, false) > 0);
+ assert_se(unquote_first_word(&p, &t, 0) > 0);
assert_se(streq(t, "foobar"));
free(t);
assert_se(p == original + 9);
- assert_se(unquote_first_word(&p, &t, false) > 0);
+ assert_se(unquote_first_word(&p, &t, 0) > 0);
assert_se(streq(t, "waldo"));
free(t);
assert_se(p == original + 16);
- assert_se(unquote_first_word(&p, &t, false) == 0);
+ assert_se(unquote_first_word(&p, &t, 0) == 0);
assert_se(!t);
assert_se(p == original + 16);
p = original = "\"";
- assert_se(unquote_first_word(&p, &t, false) == -EINVAL);
+ assert_se(unquote_first_word(&p, &t, 0) == -EINVAL);
assert_se(p == original + 1);
p = original = "\'";
- assert_se(unquote_first_word(&p, &t, false) == -EINVAL);
+ assert_se(unquote_first_word(&p, &t, 0) == -EINVAL);
assert_se(p == original + 1);
p = original = "\'fooo";
- assert_se(unquote_first_word(&p, &t, false) == -EINVAL);
+ assert_se(unquote_first_word(&p, &t, 0) == -EINVAL);
assert_se(p == original + 5);
p = original = "\'fooo";
- assert_se(unquote_first_word(&p, &t, true) > 0);
+ assert_se(unquote_first_word(&p, &t, UNQUOTE_RELAX) > 0);
assert_se(streq(t, "fooo"));
free(t);
assert_se(p == original + 5);
p = original = "yay\'foo\'bar";
- assert_se(unquote_first_word(&p, &t, false) > 0);
+ assert_se(unquote_first_word(&p, &t, 0) > 0);
assert_se(streq(t, "yayfoobar"));
free(t);
assert_se(p == original + 11);
p = original = " foobar ";
- assert_se(unquote_first_word(&p, &t, false) > 0);
+ assert_se(unquote_first_word(&p, &t, 0) > 0);
assert_se(streq(t, "foobar"));
free(t);
assert_se(p == original + 12);
+
+ p = original = " foo\\ba\\x6ar ";
+ assert_se(unquote_first_word(&p, &t, UNQUOTE_CUNESCAPE) > 0);
+ assert_se(streq(t, "foo\ba\x6ar"));
+ free(t);
+ assert_se(p == original + 13);
+
+ p = original = " foo\\ba\\x6ar ";
+ assert_se(unquote_first_word(&p, &t, 0) > 0);
+ assert_se(streq(t, "foobax6ar"));
+ free(t);
+ assert_se(p == original + 13);
}
static void test_unquote_many_words(void) {
@@ -1348,7 +1360,7 @@ static void test_unquote_many_words(void) {
char *a, *b, *c;
p = original = "foobar waldi piep";
- assert_se(unquote_many_words(&p, &a, &b, &c, NULL) == 3);
+ assert_se(unquote_many_words(&p, 0, &a, &b, &c, NULL) == 3);
assert_se(p == original + 17);
assert_se(streq_ptr(a, "foobar"));
assert_se(streq_ptr(b, "waldi"));
@@ -1358,7 +1370,7 @@ static void test_unquote_many_words(void) {
free(c);
p = original = "'foobar' wa\"ld\"i ";
- assert_se(unquote_many_words(&p, &a, &b, &c, NULL) == 2);
+ assert_se(unquote_many_words(&p, 0, &a, &b, &c, NULL) == 2);
assert_se(p == original + 19);
assert_se(streq_ptr(a, "foobar"));
assert_se(streq_ptr(b, "waldi"));
@@ -1367,31 +1379,31 @@ static void test_unquote_many_words(void) {
free(b);
p = original = "";
- assert_se(unquote_many_words(&p, &a, &b, &c, NULL) == 0);
+ assert_se(unquote_many_words(&p, 0, &a, &b, &c, NULL) == 0);
assert_se(p == original);
assert_se(streq_ptr(a, NULL));
assert_se(streq_ptr(b, NULL));
assert_se(streq_ptr(c, NULL));
p = original = " ";
- assert_se(unquote_many_words(&p, &a, &b, &c, NULL) == 0);
+ assert_se(unquote_many_words(&p, 0, &a, &b, &c, NULL) == 0);
assert_se(p == original+2);
assert_se(streq_ptr(a, NULL));
assert_se(streq_ptr(b, NULL));
assert_se(streq_ptr(c, NULL));
p = original = "foobar";
- assert_se(unquote_many_words(&p, NULL) == 0);
+ assert_se(unquote_many_words(&p, 0, NULL) == 0);
assert_se(p == original);
p = original = "foobar waldi";
- assert_se(unquote_many_words(&p, &a, NULL) == 1);
+ assert_se(unquote_many_words(&p, 0, &a, NULL) == 1);
assert_se(p == original+7);
assert_se(streq_ptr(a, "foobar"));
free(a);
p = original = " foobar ";
- assert_se(unquote_many_words(&p, &a, NULL) == 1);
+ assert_se(unquote_many_words(&p, 0, &a, NULL) == 1);
assert_se(p == original+15);
assert_se(streq_ptr(a, "foobar"));
free(a);