1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
#if defined HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include "dt-core.h"
#define CHECK_RES(rc, pred, args...) \
if (pred) { \
fprintf(stderr, args); \
res = rc; \
}
#define CHECK(pred, args...) \
CHECK_RES(1, pred, args)
#define CHECK_EQ(slot, val, args...) \
CHECK(slot != val, args, slot, val)
static int
conv_chk(struct dt_dt_s tes, struct dt_dt_s ref)
{
int res = 0;
CHECK(tes.typ != ref.typ,
" TYPE DIFFERS %u ... should be %u\n",
(unsigned int)tes.typ,
(unsigned int)ref.typ);
if (!ref.xxx) {
CHECK(tes.xxx, " FORMER DURATION BIT SET\n");
} else {
CHECK(!tes.xxx, " FORMER DURATION BIT NOT SET\n");
}
if (!ref.neg) {
CHECK(tes.neg, " NEGATED BIT SET\n");
} else {
CHECK(!tes.neg, " NEGATED BIT NOT SET\n");
}
if (tes.typ == DT_SEXY || tes.typ == DT_SEXYTAI) {
/* make sure the padding leaves no garbage */
CHECK_RES(1, tes.sexy != ref.sexy,
" VALUES DIFFER %u v %u\n",
(unsigned int)tes.sexy, (unsigned int)ref.sexy);
}
return res;
}
int
main(void)
{
int rc = 0;
struct dt_dt_s t;
struct dt_dt_s res;
struct dt_dt_s chk;
/* conv, then check */
t = (struct dt_dt_s){DT_UNK};
t.sandwich = 1;
t.d.typ = DT_YMD;
t.d.ymd.y = 2012;
t.d.ymd.m = 6;
t.d.ymd.d = 30;
t.t.typ = DT_HMS;
t.t.hms.h = 23;
t.t.hms.m = 59;
t.t.hms.s = 59;
chk = (struct dt_dt_s){DT_UNK};
chk.typ = DT_SEXY;
chk.sexy = 1341100799;
if (res = dt_dtconv(DT_SEXY, t), conv_chk(res, chk)) {
rc = 1;
}
/* conv, then check */
t = (struct dt_dt_s){DT_UNK};
t.sandwich = 1;
t.d.typ = DT_YMD;
t.d.ymd.y = 2012;
t.d.ymd.m = 7;
t.d.ymd.d = 1;
t.t.typ = DT_HMS;
t.t.hms.h = 00;
t.t.hms.m = 00;
t.t.hms.s = 00;
chk = (struct dt_dt_s){DT_UNK};
chk.typ = DT_SEXY;
chk.sexy = 1341100800;
if (res = dt_dtconv(DT_SEXY, t), conv_chk(res, chk)) {
rc = 1;
}
#if defined WITH_LEAP_SECONDS
/* conv, then check */
t = (struct dt_dt_s){DT_UNK};
t.sandwich = 1;
t.d.typ = DT_YMD;
t.d.ymd.y = 2012;
t.d.ymd.m = 6;
t.d.ymd.d = 30;
t.t.typ = DT_HMS;
t.t.hms.h = 23;
t.t.hms.m = 59;
t.t.hms.s = 59;
chk = (struct dt_dt_s){DT_UNK};
chk.typ = DT_SEXYTAI;
chk.sexy = 1341100799 + 34;
if (res = dt_dtconv(DT_SEXYTAI, t), conv_chk(res, chk)) {
rc = 1;
}
/* conv, then check */
t = (struct dt_dt_s){DT_UNK};
t.sandwich = 1;
t.d.typ = DT_YMD;
t.d.ymd.y = 2012;
t.d.ymd.m = 7;
t.d.ymd.d = 1;
t.t.typ = DT_HMS;
t.t.hms.h = 00;
t.t.hms.m = 00;
t.t.hms.s = 00;
chk = (struct dt_dt_s){DT_UNK};
chk.typ = DT_SEXYTAI;
chk.sexy = 1341100800 + 35;
if (res = dt_dtconv(DT_SEXYTAI, t), conv_chk(res, chk)) {
rc = 1;
}
#endif /* WITH_LEAP_SECONDS */
return rc;
}
/* dtcore-conv.c ends here */
|