summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/tests/libntp/msyslog.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ntp/tests/libntp/msyslog.c')
-rw-r--r--contrib/ntp/tests/libntp/msyslog.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/contrib/ntp/tests/libntp/msyslog.c b/contrib/ntp/tests/libntp/msyslog.c
index 23ec401..dec8d85 100644
--- a/contrib/ntp/tests/libntp/msyslog.c
+++ b/contrib/ntp/tests/libntp/msyslog.c
@@ -6,12 +6,22 @@
#ifndef VSNPRINTF_PERCENT_M
// format_errmsg() is normally private to msyslog.c
-void format_errmsg (char *, size_t, const char *, int);
+void format_errmsg(char *, size_t, const char *, int);
#endif
+void test_msnprintf(void);
+void test_msnprintfLiteralPercentm(void);
+void test_msnprintfBackslashLiteralPercentm(void);
+void test_msnprintfBackslashPercent(void);
+void test_msnprintfHangingPercent(void);
+void test_format_errmsgHangingPercent(void);
+void test_msnprintfNullTarget(void);
+void test_msnprintfTruncate(void);
-void test_msnprintf(void) {
+
+void
+test_msnprintf(void) {
#define FMT_PREFIX "msyslog.cpp ENOENT: "
char exp_buf[512];
char act_buf[512];
@@ -22,6 +32,7 @@ void test_msnprintf(void) {
strerror(ENOENT));
errno = ENOENT;
act_cnt = msnprintf(act_buf, sizeof(act_buf), FMT_PREFIX "%m");
+
TEST_ASSERT_EQUAL(exp_cnt, act_cnt);
TEST_ASSERT_EQUAL_STRING(exp_buf, act_buf);
}
@@ -37,6 +48,7 @@ test_msnprintfLiteralPercentm(void)
exp_cnt = snprintf(exp_buf, sizeof(exp_buf), "%%m");
errno = ENOENT;
act_cnt = msnprintf(act_buf, sizeof(act_buf), "%%m");
+
TEST_ASSERT_EQUAL(exp_cnt, act_cnt);
TEST_ASSERT_EQUAL_STRING(exp_buf, act_buf);
}
@@ -51,6 +63,7 @@ test_msnprintfBackslashLiteralPercentm(void) {
exp_cnt = snprintf(exp_buf, sizeof(exp_buf), "\%%m");
errno = ENOENT;
act_cnt = msnprintf(act_buf, sizeof(act_buf), "\%%m");
+
TEST_ASSERT_EQUAL(exp_cnt, act_cnt);
TEST_ASSERT_EQUAL_STRING(exp_buf, act_buf);
}
@@ -66,6 +79,7 @@ test_msnprintfBackslashPercent(void) {
strerror(ENOENT));
errno = ENOENT;
act_cnt = msnprintf(act_buf, sizeof(act_buf), "\%m");
+
TEST_ASSERT_EQUAL(exp_cnt, act_cnt);
TEST_ASSERT_EQUAL_STRING(exp_buf, act_buf);
}
@@ -82,6 +96,7 @@ test_msnprintfHangingPercent(void) {
ZERO(act_buf);
exp_cnt = snprintf(exp_buf, sizeof(exp_buf), "%s", fmt);
act_cnt = msnprintf(act_buf, sizeof(act_buf), "%s", fmt);
+
TEST_ASSERT_EQUAL(exp_cnt, act_cnt);
TEST_ASSERT_EQUAL_STRING(exp_buf, act_buf);
TEST_ASSERT_EQUAL_STRING("", act_buf + 1 + strlen(act_buf));
@@ -95,6 +110,7 @@ test_format_errmsgHangingPercent(void) {
ZERO(act_buf);
format_errmsg(act_buf, sizeof(act_buf), fmt, ENOENT);
+
TEST_ASSERT_EQUAL_STRING(fmt, act_buf);
TEST_ASSERT_EQUAL_STRING("", act_buf + 1 + strlen(act_buf));
#else
@@ -110,6 +126,7 @@ test_msnprintfNullTarget(void) {
exp_cnt = snprintf(NULL, 0, "%d", 123);
errno = ENOENT;
act_cnt = msnprintf(NULL, 0, "%d", 123);
+
TEST_ASSERT_EQUAL(exp_cnt, act_cnt);
}
@@ -126,6 +143,7 @@ test_msnprintfTruncate(void) {
exp_cnt = snprintf(exp_buf, 3, "%s", strerror(ENOENT));
errno = ENOENT;
act_cnt = msnprintf(act_buf, 3, "%m");
+
TEST_ASSERT_EQUAL('\0', exp_buf[2]);
TEST_ASSERT_EQUAL('\0', act_buf[2]);
TEST_ASSERT_TRUE(act_cnt > 0);
OpenPOWER on IntegriCloud