diff options
author | johannst <johannes.stoelp@gmail.com> | 2021-04-28 23:08:45 +0200 |
---|---|---|
committer | johannst <johannes.stoelp@gmail.com> | 2021-04-28 23:08:45 +0200 |
commit | d367355eb4c3569d422034b69737d8dc7022e13e (patch) | |
tree | f9f6768228235f4712466d65edeb0b745d904833 /test/checker.cc | |
parent | cf97ecd5b52c2f7a8953fd1674742d46fd15418a (diff) | |
parent | fc137e7d0263a0fe908ca1a150e34a9c8b9902d4 (diff) | |
download | dynld-d367355eb4c3569d422034b69737d8dc7022e13e.tar.gz dynld-d367355eb4c3569d422034b69737d8dc7022e13e.zip |
Merge branch 'dev04'
Diffstat (limited to 'test/checker.cc')
-rw-r--r-- | test/checker.cc | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/test/checker.cc b/test/checker.cc index 2707929..3d425bf 100644 --- a/test/checker.cc +++ b/test/checker.cc @@ -3,7 +3,8 @@ #include "test_helper.h" extern "C" { - #include <fmt.h> +#include <common.h> +#include <fmt.h> } void check_dec() { @@ -15,6 +16,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 +34,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); @@ -57,13 +85,39 @@ void check_exceed_len() { ASSERT_EQ('\0', have[7]); } +void check_memset() { + unsigned char d[7] = {0}; + void* ret = memset(d, '\x42', sizeof(d)); + + ASSERT_EQ(ret, d); + for (unsigned i = 0; i < sizeof(d); ++i) { + ASSERT_EQ(0x42, d[i]); + } +} + +void check_memcpy() { + unsigned char s[5] = {5, 4, 3, 2, 1}; + unsigned char d[5] = {0}; + void* ret = memcpy(d, s, sizeof(d)); + + ASSERT_EQ(ret, d); + for (unsigned i = 0; i < sizeof(d); ++i) { + ASSERT_EQ(5-i, d[i]); + } +} + 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); TEST_ADD(check_exceed_len); + TEST_ADD(check_memset); + TEST_ADD(check_memcpy); return TEST_RUN; } |