#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);
assert_se(parse_boolean("full") < 0);
}
-static void test_parse_pid(void) {
+TEST(parse_pid) {
int r;
pid_t pid;
assert_se(r == -EINVAL);
}
-static void test_parse_mode(void) {
+TEST(parse_mode) {
mode_t m;
assert_se(parse_mode("-1", &m) < 0);
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);
assert_se(parse_size("-10B 20K", 1024, &bytes) == -ERANGE);
}
-static void test_parse_range(void) {
+TEST(parse_range) {
unsigned lower, upper;
/* Successful cases */
assert_se(upper == 9999);
}
-static void test_safe_atolli(void) {
+TEST(safe_atolli) {
int r;
long long l;
assert_se(r == -EINVAL);
}
-static void test_safe_atou16(void) {
+TEST(safe_atou16) {
int r;
uint16_t l;
assert_se(r == -EINVAL);
}
-static void test_safe_atoi16(void) {
+TEST(safe_atoi16) {
int r;
int16_t l;
assert_se(r == -EINVAL);
}
-static void test_safe_atoux16(void) {
+TEST(safe_atoux16) {
int r;
uint16_t l;
assert_se(r == -EINVAL);
}
-static void test_safe_atou64(void) {
+TEST(safe_atou64) {
int r;
uint64_t l;
assert_se(r == -EINVAL);
}
-static void test_safe_atoi64(void) {
+TEST(safe_atoi64) {
int r;
int64_t l;
assert_se(r == -EINVAL);
}
-static void test_safe_atoux64(void) {
+TEST(safe_atoux64) {
int r;
uint64_t l;
assert_se(r == -EINVAL);
}
-static void test_safe_atod(void) {
+TEST(safe_atod) {
int r;
double d;
char *e;
assert_se(r == -EINVAL);
}
-static void test_parse_nice(void) {
+TEST(parse_nice) {
int n;
assert_se(parse_nice("0", &n) >= 0 && n == 0);
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);
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);
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);
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);
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);