aboutsummaryrefslogtreecommitdiff
path: root/test/checker.cc
diff options
context:
space:
mode:
authorjohannst <johannes.stoelp@gmail.com>2021-04-19 21:50:29 +0200
committerjohannst <johannes.stoelp@gmail.com>2021-04-19 21:50:29 +0200
commit3155439c1a96f1964aaee799b008331d0b362db3 (patch)
tree2bc409669917f8df1254205b5deb35ae65f463d2 /test/checker.cc
parent287f736e614a2931f57e9aabf42105e3cf3e8992 (diff)
downloaddynld-3155439c1a96f1964aaee799b008331d0b362db3.tar.gz
dynld-3155439c1a96f1964aaee799b008331d0b362db3.zip
added tests for fmt() char, long nums
Diffstat (limited to 'test/checker.cc')
-rw-r--r--test/checker.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/checker.cc b/test/checker.cc
index 2707929..d687b72 100644
--- a/test/checker.cc
+++ b/test/checker.cc
@@ -15,6 +15,15 @@ void check_dec() {
ASSERT_EQ('\0', have[len]);
}
+void check_dec_long() {
+ char have[32];
+ int len = fmt(have, sizeof(have), "%ld %d", 8589934592 /* 2^33 */, 8589934592 /* 2^33 */);
+
+ ASSERT_EQ("8589934592 0", have);
+ ASSERT_EQ(12, len);
+ ASSERT_EQ('\0', have[len]);
+}
+
void check_hex() {
char have[16];
int len = fmt(have, sizeof(have), "%x %x", 0xdeadbeef, 0xcafe);
@@ -24,6 +33,24 @@ void check_hex() {
ASSERT_EQ('\0', have[len]);
}
+void check_hex_long() {
+ char have[32];
+ int len = fmt(have, sizeof(have), "%lx %x", 0x1111222233334444, 0x1111222233334444);
+
+ ASSERT_EQ("1111222233334444 33334444", have);
+ ASSERT_EQ(25, len);
+ ASSERT_EQ('\0', have[len]);
+}
+
+void check_char() {
+ char have[4];
+ int len = fmt(have, sizeof(have), "%c%c%c", 'A', 'a', '\x01' /* non printable */);
+
+ ASSERT_EQ("Aa\x01", have);
+ ASSERT_EQ(3, len);
+ ASSERT_EQ('\0', have[len]);
+}
+
void check_ptr() {
char have[16];
int len = fmt(have, sizeof(have), "%p %p", (void*)0xabcd, (void*)0x0);
@@ -60,7 +87,10 @@ void check_exceed_len() {
int main() {
TEST_INIT;
TEST_ADD(check_dec);
+ TEST_ADD(check_dec_long);
TEST_ADD(check_hex);
+ TEST_ADD(check_hex_long);
+ TEST_ADD(check_char);
TEST_ADD(check_ptr);
TEST_ADD(check_null);
TEST_ADD(check_exact_len);