1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

tests: added unittests for fmt_s16_[dfp|dec]()

This commit is contained in:
Hauke Petersen 2016-03-29 15:20:37 +02:00
parent 2a4b7cbc91
commit 0610c20914

View File

@ -120,6 +120,95 @@ static void test_fmt_s32_dec(void)
TEST_ASSERT_EQUAL_STRING("-9876", (char *) out);
}
static void test_rmt_s16_dec(void)
{
char out[7] = "-------";
int16_t val;
size_t len;
val = 0;
len = fmt_s16_dec(out, val);
out[len] = '\0';
TEST_ASSERT_EQUAL_INT(1, len);
TEST_ASSERT_EQUAL_STRING("0", (char *)out);
val = -32000;
len = fmt_s16_dec(out, val);
out[len] = '\0';
TEST_ASSERT_EQUAL_INT(6, len);
TEST_ASSERT_EQUAL_STRING("-32000", (char *)out);
val = 12345;
len = fmt_s16_dec(out, val);
out[len] = '\0';
TEST_ASSERT_EQUAL_INT(5, len);
TEST_ASSERT_EQUAL_STRING("12345", (char *)out);
}
static void test_rmt_s16_dfp(void)
{
char out[8] = "--------";
int16_t val;
unsigned fpp;
size_t len;
val = 0;
fpp = 3;
len = fmt_s16_dfp(out, val, fpp);
out[len] = '\0';
TEST_ASSERT_EQUAL_INT(5, len);
TEST_ASSERT_EQUAL_STRING("0.000", (char *)out);
val = 12345;
fpp = 4;
len = fmt_s16_dfp(out, val, fpp);
out[len] = '\0';
TEST_ASSERT_EQUAL_INT(6, len);
TEST_ASSERT_EQUAL_STRING("1.2345", (char *)out);
val = 12030;
fpp = 3;
len = fmt_s16_dfp(out, val, fpp);
out[len] = '\0';
TEST_ASSERT_EQUAL_INT(6, len);
TEST_ASSERT_EQUAL_STRING("12.030", (char *)out);
val = -3548;
fpp = 2;
len = fmt_s16_dfp(out, val, fpp);
out[len] = '\0';
TEST_ASSERT_EQUAL_INT(6, len);
TEST_ASSERT_EQUAL_STRING("-35.48", (char *)out);
val = -23;
fpp = 4;
len = fmt_s16_dfp(out, val, fpp);
out[len] = '\0';
TEST_ASSERT_EQUAL_INT(7, len);
TEST_ASSERT_EQUAL_STRING("-0.0023", (char *)out);
val = 50;
fpp = 3;
len = fmt_s16_dfp(out, val, fpp);
out[len] = '\0';
TEST_ASSERT_EQUAL_INT(5, len);
TEST_ASSERT_EQUAL_STRING("0.050", (char *)out);
val = -12345;
fpp = 0;
len = fmt_s16_dfp(out, val, fpp);
out[len] = '\0';
TEST_ASSERT_EQUAL_INT(6, len);
TEST_ASSERT_EQUAL_STRING("-12345", (char *)out);
val = 31987;
fpp = 5;
len = fmt_s16_dfp(out, val, fpp);
out[len] = '\0';
TEST_ASSERT_EQUAL_INT(0, len);
TEST_ASSERT_EQUAL_STRING("", (char *)out);
}
static void test_fmt_strlen(void)
{
const char *empty_str = "";
@ -160,6 +249,8 @@ Test *tests_fmt_tests(void)
new_TestFixture(test_fmt_u32_dec),
new_TestFixture(test_fmt_u16_dec),
new_TestFixture(test_fmt_s32_dec),
new_TestFixture(test_rmt_s16_dec),
new_TestFixture(test_rmt_s16_dfp),
new_TestFixture(test_fmt_strlen),
new_TestFixture(test_fmt_str),
new_TestFixture(test_scn_u32_dec),