--- /dev/null
+#include "time_format.h"
+
+void get_time_str(time_t time, char* timestr)
+{
+ struct tm time_cal;
+
+ gmtime_r(&time, &time_cal);
+
+ sprintf(timestr, "%02d:%02d", time_cal.tm_hour, time_cal.tm_min);
+}
\ No newline at end of file
--- /dev/null
+#ifndef TIME_FORMAT_H
+#define TIME_FORMAT_H
+#include <time.h>
+
+void get_time_str(time_t time, char* timestr);
+
+#endif
\ No newline at end of file
TARGET_LINK_LIBRARIES(worktime_tests
${CMOCKA})
+ADD_EXECUTABLE(time_format_tests
+ time_format_tests.c
+ ../src/time_format.c)
+TARGET_LINK_LIBRARIES(time_format_tests
+ ${CMOCKA})
+
INCLUDE(CTest)
ADD_TEST(NAME break_tests
COMMAND break_tests)
ADD_TEST(NAME worktime_tests
COMMAND worktime_tests)
+ADD_TEST(NAME time_format_tests
+ COMMAND time_format_tests)
ADD_CUSTOM_TARGET(run-tests
ALL "ctest" "--verbose"
--- /dev/null
+#define UNIT_TESTING
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "../src/time_format.h"
+
+void get_zero_hour_and_fifteen_minutes()
+{
+ time_t time = 900;
+ char* timestring = malloc(sizeof(char) * 7);
+ memset(timestring, 0, 7);
+
+ get_time_str(time, timestring);
+
+ assert_string_equal(timestring, "00:15");
+
+ free(timestring);
+ timestring = NULL;
+}
+
+int main()
+{
+ const struct CMUnitTest tests[] = {
+ cmocka_unit_test(get_zero_hour_and_fifteen_minutes)
+ };
+
+ return cmocka_run_group_tests(tests, NULL, NULL);
+}
\ No newline at end of file