Ver código fonte

faux.time: Test testc_faux_timespec_now()

Serj Kalichev 3 anos atrás
pai
commit
6c318f7c52
2 arquivos alterados com 27 adições e 0 exclusões
  1. 1 0
      faux/testc_module/testc_module.c
  2. 26 0
      faux/time/testc_time.c

+ 1 - 0
faux/testc_module/testc_module.c

@@ -24,6 +24,7 @@ const char *testc_module[][2] = {
 	{"testc_faux_nsec_timespec_conversion", "Converts nsec from/to struct timespec"},
 	{"testc_faux_timespec_diff", "Diff beetween timespec structures"},
 	{"testc_faux_timespec_sum", "Sum of timespec structures"},
+	{"testc_faux_timespec_now", "Timespec now and before now functions"},
 
 	// log
 	{"testc_faux_log_facility_id", "Converts syslog facility string to id"},

+ 26 - 0
faux/time/testc_time.c

@@ -6,6 +6,7 @@
 
 #include "faux/time.h"
 
+
 #define TNUM1 3
 int testc_faux_nsec_timespec_conversion(void)
 {
@@ -104,6 +105,7 @@ int testc_faux_timespec_diff(void)
 	return ret;
 }
 
+
 #define TNUM3 2
 int testc_faux_timespec_sum(void)
 {
@@ -144,3 +146,27 @@ int testc_faux_timespec_sum(void)
 
 	return ret;
 }
+
+
+int testc_faux_timespec_now(void)
+{
+	int ret = 0;
+	struct timespec before = {};
+	struct timespec now = {};
+	struct timespec after = {};
+	struct timespec interval = {};
+
+	faux_nsec_to_timespec(&interval, 1000000l);
+	faux_timespec_now(&now);
+	faux_timespec_diff(&before, &now, &interval);
+	faux_timespec_sum(&after, &now, &interval);
+
+	if (!faux_timespec_before_now(&before))
+		ret = -1;
+	if (!faux_timespec_before_now(&now)) // Formally now is before now
+		ret = -1;
+	if (faux_timespec_before_now(&after))
+		ret = -1;
+
+	return ret;
+}