TC: Expand tc for libc/timer module API's
authorLokesh B V <lokesh.bv@partner.samsung.com>
Wed, 19 Jul 2017 07:01:00 +0000 (12:31 +0530)
committerLokesh B V <lokesh.bv@partner.samsung.com>
Tue, 1 Aug 2017 09:55:09 +0000 (15:25 +0530)
Expands tc for strftime() API.
 - includes tc with format options %e, %h, %b, %h, %j, &l, %k and %p to strftime().

Signed-off-by: Lokesh B V <lokesh.bv@partner.samsung.com>
apps/examples/testcase/le_tc/kernel/tc_libc_timer.c

index c0b20dd..cc6b197 100644 (file)
 #include <signal.h>
 #include <spawn.h>
 #include <syslog.h>
-#include <tinyara/time.h>
+#include <time.h>
 #include <sys/types.h>
+#include <math.h>
+#include <float.h>
 #include "tc_internal.h"
 
 #define BUFF_SIZE 64
@@ -325,7 +327,7 @@ static void tc_libc_timer_strftime(void)
        TC_ASSERT_EQ("strftime", atoi(buffer), st_time.tm_mon + 1);
 
        /* Check the abbreviated month name */
-       strftime(buffer, BUFF_SIZE, "%b", &st_time);
+       strftime(buffer, BUFF_SIZE, "%h", &st_time);
        TC_ASSERT_EQ("strftime", strcmp(buffer, "Jun"), 0);
 
        /* Check the full month name */
@@ -340,6 +342,12 @@ static void tc_libc_timer_strftime(void)
        strftime(buffer, BUFF_SIZE, "%d", &st_time);
        TC_ASSERT_EQ("strftime", atoi(buffer), st_time.tm_mday);
 
+       /* Check the day of month as a decimal number but a leading zero
+        * is replaced by a space. (range 1 to 31)
+        */
+       strftime(buffer, BUFF_SIZE, "%e", &st_time);
+       TC_ASSERT_EQ("strftime", atoi(buffer), st_time.tm_mday);
+
        /* Check the hour as a decimal number using a 24-hour clock (range 00 to 23) */
        strftime(buffer, BUFF_SIZE, "%H", &st_time);
        TC_ASSERT_EQ("strftime", atoi(buffer), st_time.tm_hour);
@@ -352,6 +360,18 @@ static void tc_libc_timer_strftime(void)
        strftime(buffer, BUFF_SIZE, "%j", &st_time);
        TC_ASSERT_EQ("strftime", atoi(buffer), clock_daysbeforemonth(st_time.tm_mon, false) + st_time.tm_mday);
 
+       /* Check the hour as a decimal number using a 24-hour clock (range 0 to 23)
+        * single digits are preceded by a blank.
+        */
+       strftime(buffer, BUFF_SIZE, "%k", &st_time);
+       TC_ASSERT_EQ("strftime", atoi(buffer), st_time.tm_hour);
+
+       /* Check the hour as a decimal number using a 12-hour clock (range 01 to 12)
+        * single digits are preceded by a blank.
+        */
+       strftime(buffer, BUFF_SIZE, "%l", &st_time);
+       TC_ASSERT_EQ("strftime", atoi(buffer), st_time.tm_hour - 12);
+
        /* Check either "AM" or "PM" according to the given time value, Noon is treated as "PM" and midnight as "AM" */
        strftime(buffer, BUFF_SIZE, "%p", &st_time);
        TC_ASSERT_EQ("strftime", strcmp(buffer, "PM"), 0);
@@ -360,6 +380,15 @@ static void tc_libc_timer_strftime(void)
        strftime(buffer, BUFF_SIZE, "%P", &st_time);
        TC_ASSERT_EQ("strftime", strcmp(buffer, "pm"), 0);
 
+       st_time.tm_hour = 3;
+       /* Check either "AM" or "PM" according to the given time value, Noon is treated as "PM" and midnight as "AM" */
+       strftime(buffer, BUFF_SIZE, "%p", &st_time);
+       TC_ASSERT_EQ("strftime", strcmp(buffer, "AM"), 0);
+
+       /* Check either "am" or "pm" according to the given time value, Noon is treated as "pm" and midnight as "am" */
+       strftime(buffer, BUFF_SIZE, "%P", &st_time);
+       TC_ASSERT_EQ("strftime", strcmp(buffer, "am"), 0);
+
        /* Check the second as a decimal number (range 00 to 60) */
        strftime(buffer, BUFF_SIZE, "%S", &st_time);
        TC_ASSERT_EQ("strftime", atoi(buffer), st_time.tm_sec);