Skip to content

Commit 553adee

Browse files
committed
Initial commit of time extension test
1 parent 31828b3 commit 553adee

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

tests/test-time.c

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#include <libfyaml.h>
2+
#include <stddef.h>
3+
#include <stdint.h>
4+
5+
#include "munit.h"
6+
#include "util.h"
7+
8+
#include <asdf/core/asdf.h>
9+
#include <asdf/core/extension_metadata.h>
10+
#include "asdf/core/time.h"
11+
#include <asdf/core/history_entry.h>
12+
#include <asdf/file.h>
13+
14+
15+
MU_TEST(test_asdf_time) {
16+
const char *path = get_fixture_file_path("time.asdf");
17+
assert_not_null(path);
18+
19+
asdf_file_t *file = asdf_open_file(path, "r");
20+
assert_not_null(file);
21+
22+
asdf_value_t *value = NULL;
23+
24+
// buffer for time string
25+
char time_str[255] = {0};
26+
const int format_type[] = {
27+
ASDF_TIME_FORMAT_ISO_TIME,
28+
ASDF_TIME_FORMAT_DATETIME,
29+
ASDF_TIME_FORMAT_YDAY,
30+
ASDF_TIME_FORMAT_UNIX,
31+
ASDF_TIME_FORMAT_JD,
32+
ASDF_TIME_FORMAT_MJD,
33+
ASDF_TIME_FORMAT_BYEAR,
34+
};
35+
36+
asdf_time_t *t = NULL;
37+
for (size_t i = 0; i < sizeof(format_type) / sizeof(format_type[0]); i++) {
38+
const char *fixture_key[] = {
39+
"t_iso_time",
40+
"t_datetime",
41+
"t_yday",
42+
"t_unix",
43+
"t_jd",
44+
"t_mjd",
45+
"t_byear",
46+
};
47+
48+
const char *key = fixture_key[i];
49+
assert_true(asdf_is_time(file, key));
50+
51+
value = asdf_get_value(file, key);
52+
if (asdf_value_as_time(value, &t) != ASDF_VALUE_OK) {
53+
fprintf(stderr, "asdf_value_as_time failed: %s\n", key);
54+
asdf_time_destroy(t);
55+
return 1;
56+
};
57+
assert_true(t != NULL);
58+
assert_true(t->value != NULL);
59+
time_t x = t->info.ts.tv_sec;
60+
strftime(time_str, sizeof(time_str), "%m/%d/%Y %T %Z", gmtime(&x));
61+
printf("[%zu] key: %10s, value: %30s, time: %10s\n", i, key, t->value, time_str);
62+
show_asdf_time_info(&t->info);
63+
64+
asdf_time_destroy(t);
65+
t = NULL;
66+
memset(time_str, 0, sizeof(time_str));
67+
asdf_value_destroy(value);
68+
}
69+
70+
asdf_close(file);
71+
72+
return MUNIT_OK;
73+
}
74+
75+
MU_TEST_SUITE(
76+
test_asdf_time_extension,
77+
MU_RUN_TEST(test_asdf_time)
78+
);
79+
80+
81+
MU_RUN_SUITE(test_asdf_time_extension);

0 commit comments

Comments
 (0)