1 /* Copyright 2013-2015 IBM Corp.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 * implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <config.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <assert.h>
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define __TEST__
25
26 #include "../time-utils.c"
27
main(void)28 int main(void)
29 {
30 struct tm *t = malloc(sizeof(struct tm));
31 uint32_t *ymd = malloc(sizeof(uint32_t));
32 uint64_t *hms = malloc(sizeof(uint64_t));
33
34 t->tm_year = 1982;
35 t->tm_mon = 0;
36 t->tm_mday = 29;
37 t->tm_hour = 7;
38 t->tm_min = 42;
39 t->tm_sec = 24;
40
41 tm_to_datetime(t, ymd, hms);
42
43 assert(*ymd == 0x19820129);
44 assert(*hms == 0x742240000000000ULL);
45
46 memset(t, 0, sizeof(struct tm));
47
48 *ymd = 0x19760412;
49
50 datetime_to_tm(*ymd, *hms, t);
51 assert(t->tm_year == 1976);
52 assert(t->tm_mon == 03);
53 assert(t->tm_mday == 12);
54 assert(t->tm_hour == 7);
55 assert(t->tm_min == 42);
56 assert(t->tm_sec == 24);
57
58 free(t);
59 free(ymd);
60 free(hms);
61 return 0;
62 }
63
64