summaryrefslogtreecommitdiff
path: root/src/test/test-parse-util.c
diff options
context:
space:
mode:
authorJan Janssen <medhefgo@web.de>2021-11-24 12:00:02 +0100
committerJan Janssen <medhefgo@web.de>2021-11-25 15:03:06 +0100
commit4f7452a8eb7a946efea927fae017d4d661097833 (patch)
tree413778cc0fb08fbbed0890130b5ba66c90581e61 /src/test/test-parse-util.c
parent4d5ad9d951299c905453ac8e3769dc82b0a09fb4 (diff)
downloadsystemd-4f7452a8eb7a946efea927fae017d4d661097833.tar.gz
test: Use TEST macro
This converts to TEST macro where it is trivial. Some additional notable changes: - simplify HAVE_LIBIDN #ifdef in test-dns-domain.c - use saved_argc/saved_argv in test-copy.c, test-path-util.c, test-tmpfiles.c and test-unit-file.c
Diffstat (limited to 'src/test/test-parse-util.c')
-rw-r--r--src/test/test-parse-util.c63
1 files changed, 20 insertions, 43 deletions
diff --git a/src/test/test-parse-util.c b/src/test/test-parse-util.c
index b6a593d0db..27f83f98ab 100644
--- a/src/test/test-parse-util.c
+++ b/src/test/test-parse-util.c
@@ -10,8 +10,9 @@
#include "log.h"
#include "parse-util.h"
#include "string-util.h"
+#include "tests.h"
-static void test_parse_boolean(void) {
+TEST(parse_boolean) {
assert_se(parse_boolean("1") == 1);
assert_se(parse_boolean("y") == 1);
assert_se(parse_boolean("Y") == 1);
@@ -37,7 +38,7 @@ static void test_parse_boolean(void) {
assert_se(parse_boolean("full") < 0);
}
-static void test_parse_pid(void) {
+TEST(parse_pid) {
int r;
pid_t pid;
@@ -71,7 +72,7 @@ static void test_parse_pid(void) {
assert_se(r == -EINVAL);
}
-static void test_parse_mode(void) {
+TEST(parse_mode) {
mode_t m;
assert_se(parse_mode("-1", &m) < 0);
@@ -93,7 +94,7 @@ static void test_parse_mode(void) {
assert_se(parse_mode(" 1", &m) >= 0 && m == 1);
}
-static void test_parse_size(void) {
+TEST(parse_size) {
uint64_t bytes;
assert_se(parse_size("", 1024, &bytes) == -EINVAL);
@@ -163,7 +164,7 @@ static void test_parse_size(void) {
assert_se(parse_size("-10B 20K", 1024, &bytes) == -ERANGE);
}
-static void test_parse_range(void) {
+TEST(parse_range) {
unsigned lower, upper;
/* Successful cases */
@@ -346,7 +347,7 @@ static void test_parse_range(void) {
assert_se(upper == 9999);
}
-static void test_safe_atolli(void) {
+TEST(safe_atolli) {
int r;
long long l;
@@ -397,7 +398,7 @@ static void test_safe_atolli(void) {
assert_se(r == -EINVAL);
}
-static void test_safe_atou16(void) {
+TEST(safe_atou16) {
int r;
uint16_t l;
@@ -431,7 +432,7 @@ static void test_safe_atou16(void) {
assert_se(r == -EINVAL);
}
-static void test_safe_atoi16(void) {
+TEST(safe_atoi16) {
int r;
int16_t l;
@@ -478,7 +479,7 @@ static void test_safe_atoi16(void) {
assert_se(r == -EINVAL);
}
-static void test_safe_atoux16(void) {
+TEST(safe_atoux16) {
int r;
uint16_t l;
@@ -523,7 +524,7 @@ static void test_safe_atoux16(void) {
assert_se(r == -EINVAL);
}
-static void test_safe_atou64(void) {
+TEST(safe_atou64) {
int r;
uint64_t l;
@@ -565,7 +566,7 @@ static void test_safe_atou64(void) {
assert_se(r == -EINVAL);
}
-static void test_safe_atoi64(void) {
+TEST(safe_atoi64) {
int r;
int64_t l;
@@ -612,7 +613,7 @@ static void test_safe_atoi64(void) {
assert_se(r == -EINVAL);
}
-static void test_safe_atoux64(void) {
+TEST(safe_atoux64) {
int r;
uint64_t l;
@@ -657,7 +658,7 @@ static void test_safe_atoux64(void) {
assert_se(r == -EINVAL);
}
-static void test_safe_atod(void) {
+TEST(safe_atod) {
int r;
double d;
char *e;
@@ -714,7 +715,7 @@ static void test_safe_atod(void) {
assert_se(r == -EINVAL);
}
-static void test_parse_nice(void) {
+TEST(parse_nice) {
int n;
assert_se(parse_nice("0", &n) >= 0 && n == 0);
@@ -741,7 +742,7 @@ static void test_parse_nice(void) {
assert_se(parse_nice("+20", &n) == -ERANGE);
}
-static void test_parse_dev(void) {
+TEST(parse_dev) {
dev_t dev;
assert_se(parse_dev("", &dev) == -EINVAL);
@@ -758,7 +759,7 @@ static void test_parse_dev(void) {
assert_se(parse_dev("0:0", &dev) >= 0 && major(dev) == 0 && minor(dev) == 0);
}
-static void test_parse_errno(void) {
+TEST(parse_errno) {
assert_se(parse_errno("EILSEQ") == EILSEQ);
assert_se(parse_errno("EINVAL") == EINVAL);
assert_se(parse_errno("0") == 0);
@@ -779,7 +780,7 @@ static void test_parse_errno(void) {
assert_se(parse_errno("EINVALaaa") == -EINVAL);
}
-static void test_parse_mtu(void) {
+TEST(parse_mtu) {
uint32_t mtu = 0;
assert_se(parse_mtu(AF_UNSPEC, "1500", &mtu) >= 0 && mtu == 1500);
@@ -800,7 +801,7 @@ static void test_parse_mtu(void) {
assert_se(parse_mtu(AF_UNSPEC, "", &mtu) == -EINVAL);
}
-static void test_parse_loadavg_fixed_point(void) {
+TEST(parse_loadavg_fixed_point) {
loadavg_t fp;
assert_se(parse_loadavg_fixed_point("1.23", &fp) == 0);
@@ -836,28 +837,4 @@ static void test_parse_loadavg_fixed_point(void) {
assert_se(parse_loadavg_fixed_point("", &fp) == -EINVAL);
}
-int main(int argc, char *argv[]) {
- log_parse_environment();
- log_open();
-
- test_parse_boolean();
- test_parse_pid();
- test_parse_mode();
- test_parse_size();
- test_parse_range();
- test_safe_atolli();
- test_safe_atou16();
- test_safe_atoi16();
- test_safe_atoux16();
- test_safe_atou64();
- test_safe_atoi64();
- test_safe_atoux64();
- test_safe_atod();
- test_parse_nice();
- test_parse_dev();
- test_parse_errno();
- test_parse_mtu();
- test_parse_loadavg_fixed_point();
-
- return 0;
-}
+DEFINE_TEST_MAIN(LOG_INFO);