Skip to content

Commit

Permalink
fpu64_trimmed: add unit tests
Browse files Browse the repository at this point in the history
(cherry picked from commit 6a775cd)
  • Loading branch information
sgliner-ledger authored and Xavier Chapron committed Aug 18, 2023
1 parent ed4dbf7 commit 3caaee0
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions unit-tests/lib_standard_app/test_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,32 @@ static void test_format_fpu64(void **state) {
assert_false(format_fpu64(temp2, sizeof(temp2) - 20, amount, 18));
}

static void test_format_fpu64_trimmed(void **state) {
(void) state;

char temp[22] = {0};

uint64_t amount = 100000000ull; // satoshi
memset(temp, 0, sizeof(temp));
assert_true(format_fpu64_trimmed(temp, sizeof(temp), amount, 8));
assert_string_equal(temp, "1"); // BTC

amount = 24964823ull; // satoshi
memset(temp, 0, sizeof(temp));
assert_true(format_fpu64_trimmed(temp, sizeof(temp), amount, 8));
assert_string_equal(temp, "0.24964823"); // BTC

amount = 100ull; // satoshi
memset(temp, 0, sizeof(temp));
assert_true(format_fpu64_trimmed(temp, sizeof(temp), amount, 8));
assert_string_equal(temp, "0.000001"); // BTC

amount = 1000000000ull; // satoshi
memset(temp, 0, sizeof(temp));
assert_true(format_fpu64_trimmed(temp, sizeof(temp), amount, 8));
assert_string_equal(temp, "10"); // BTC
}

static void test_format_hex(void **state) {
(void) state;

Expand All @@ -99,6 +125,7 @@ int main() {
const struct CMUnitTest tests[] = {cmocka_unit_test(test_format_i64),
cmocka_unit_test(test_format_u64),
cmocka_unit_test(test_format_fpu64),
cmocka_unit_test(test_format_fpu64_trimmed),
cmocka_unit_test(test_format_hex)};

return cmocka_run_group_tests(tests, NULL, NULL);
Expand Down

0 comments on commit 3caaee0

Please sign in to comment.