#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
static bool
test_read_ex(const char *str, const long expected_sec, const long expected_usec) {
if (t.tv_sec != expected_sec) {
fprintf(stderr,
"The sec value %ld does not match the expected %ld\n",
t.tv_sec,
expected_sec);
return false;
}
if (t.tv_usec != expected_usec) {
fprintf(stderr,
"The usec value %li does not match the expected %li\n",
t.tv_usec,
expected_usec);
return false;
}
return true;
}
static bool test_read() {
return test_read_ex("1483228862.529000", 1483228862, 529000);
}
static bool test_write() {
struct timeval t;
t.tv_sec = 1562377512;
t.tv_usec = 671;
if (strcmp(tmp, "1562377512.671") == 0) {
free(tmp);
return true;
}
fprintf(stderr,
"Formatted time %s does not match the expected value 1562377512.671\n",
tmp);
free(tmp);
return false;
}
int main(
int argc,
char **argv) {
if (test_read()) {
if (test_write()) {
return EXIT_SUCCESS;
}
}
return EXIT_FAILURE;
}
int main(int argc, char **argv)
Definition: gru_list_test.c:198
char * gru_time_write_str(const gru_timestamp_t *t)
Write a timeval structure to a string.
Definition: gru_time_utils.c:80
gru_timestamp_t gru_time_read_str(const char *str)
Read a string in the format seconds.microseconds and return a struct timeval.
Definition: gru_time_utils.c:51