Browse Source

tests: test trim_trailing_zeroes

Max Bruckner 8 years ago
parent
commit
0c0dd4a5b0
1 changed files with 17 additions and 0 deletions
  1. 17 0
      tests/print_number.c

+ 17 - 0
tests/print_number.c

@@ -87,6 +87,22 @@ static void print_number_should_print_non_number(void)
     /* assert_print_number("null", -INFTY); */
 }
 
+static void trim_trailing_zeroes_should_trim_trailing_zeroes(void)
+{
+    printbuffer buffer;
+    unsigned char number[100];
+    unsigned char *pointer = NULL;
+    buffer.length = sizeof(number);
+    buffer.buffer = number;
+
+    strcpy((char*)number, "10.00");
+    buffer.offset = sizeof("10.00") - 1;
+    pointer = trim_trailing_zeroes(&buffer);
+    TEST_ASSERT_EQUAL_UINT8('\0', *pointer);
+    TEST_ASSERT_EQUAL_STRING("10", number);
+    TEST_ASSERT_EQUAL_UINT(sizeof("10") - 1, buffer.offset);
+}
+
 int main(void)
 {
     /* initialize cJSON item */
@@ -98,6 +114,7 @@ int main(void)
     RUN_TEST(print_number_should_print_positive_reals);
     RUN_TEST(print_number_should_print_negative_reals);
     RUN_TEST(print_number_should_print_non_number);
+    RUN_TEST(trim_trailing_zeroes_should_trim_trailing_zeroes);
 
     return UNITY_END();
 }