summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mack <github@zonque.org>2016-03-22 10:23:12 +0100
committerDaniel Mack <github@zonque.org>2016-03-22 10:23:12 +0100
commit99d91109a6ed7f8bcdeef164fe9497112128944a (patch)
tree2138bd81e84ef5cd42f2d017cf622662d4b265d7
parentc4b3e434a7f08a904ac60d4285c668e40bcdb69a (diff)
parentb8c83cfc1a12456d0f0f30c5b4cb62f34ed4fa35 (diff)
Merge pull request #2880 from keszybz/more-tests
Add some simple tests for env_value_is_valid and env_assignment_is_valid
-rw-r--r--.gitignore2
-rw-r--r--Makefile.am8
-rw-r--r--src/test/test-env-util.c (renamed from src/test/test-env-replace.c)30
3 files changed, 35 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore
index dd887902ad..0e1d428ab0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -182,7 +182,7 @@
/test-efi-disk.img
/test-ellipsize
/test-engine
-/test-env-replace
+/test-env-util
/test-escape
/test-event
/test-execute
diff --git a/Makefile.am b/Makefile.am
index 9a7ae2c286..2b72a53ecd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1421,7 +1421,7 @@ tests += \
test-watchdog \
test-cgroup-mask \
test-job-type \
- test-env-replace \
+ test-env-util \
test-strbuf \
test-strv \
test-path \
@@ -2197,10 +2197,10 @@ test_cgroup_util_SOURCES = \
test_cgroup_util_LDADD = \
libshared.la
-test_env_replace_SOURCES = \
- src/test/test-env-replace.c
+test_env_util_SOURCES = \
+ src/test/test-env-util.c
-test_env_replace_LDADD = \
+test_env_util_LDADD = \
libshared.la
test_strbuf_SOURCES = \
diff --git a/src/test/test-env-replace.c b/src/test/test-env-util.c
index 264acc6ea6..35bb62906e 100644
--- a/src/test/test-env-replace.c
+++ b/src/test/test-env-util.c
@@ -2,6 +2,7 @@
This file is part of systemd.
Copyright 2010 Lennart Poettering
+ Copyright 2016 Zbigniew Jędrzejewski-Szmek
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
@@ -177,10 +178,37 @@ static void test_env_name_is_valid(void) {
assert_se(!env_name_is_valid(NULL));
assert_se(!env_name_is_valid(""));
+ assert_se(!env_name_is_valid("xxx\a"));
+ assert_se(!env_name_is_valid("xxx\007b"));
+ assert_se(!env_name_is_valid("\007\009"));
assert_se(!env_name_is_valid("5_starting_with_a_number_is_wrong"));
assert_se(!env_name_is_valid("#¤%&?_only_numbers_letters_and_underscore_allowed"));
}
+static void test_env_value_is_valid(void) {
+ assert_se(env_value_is_valid(""));
+ assert_se(env_value_is_valid("głąb kapuściany"));
+ assert_se(env_value_is_valid("printf \"\\x1b]0;<mock-chroot>\\x07<mock-chroot>\""));
+}
+
+static void test_env_assignment_is_valid(void) {
+ assert_se(env_assignment_is_valid("a="));
+ assert_se(env_assignment_is_valid("b=głąb kapuściany"));
+ assert_se(env_assignment_is_valid("c=\\007\\009\\011"));
+ assert_se(env_assignment_is_valid("e=printf \"\\x1b]0;<mock-chroot>\\x07<mock-chroot>\""));
+
+ assert_se(!env_assignment_is_valid("="));
+ assert_se(!env_assignment_is_valid("a b="));
+ assert_se(!env_assignment_is_valid("a ="));
+ assert_se(!env_assignment_is_valid(" b="));
+ /* no dots or dashes: http://tldp.org/LDP/abs/html/gotchas.html */
+ assert_se(!env_assignment_is_valid("a.b="));
+ assert_se(!env_assignment_is_valid("a-b="));
+ assert_se(!env_assignment_is_valid("\007=głąb kapuściany"));
+ assert_se(!env_assignment_is_valid("c\009=\007\009\011"));
+ assert_se(!env_assignment_is_valid("głąb=printf \"\x1b]0;<mock-chroot>\x07<mock-chroot>\""));
+}
+
int main(int argc, char *argv[]) {
test_strv_env_delete();
test_strv_env_unset();
@@ -189,6 +217,8 @@ int main(int argc, char *argv[]) {
test_replace_env_arg();
test_env_clean();
test_env_name_is_valid();
+ test_env_value_is_valid();
+ test_env_assignment_is_valid();
return 0;
}