xs/engine.xs

filter: Statementstmt 95.7% 91 / 95 Branchbran 74.6% 97 / 130 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 83.5% 188 / 225 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/abi.xs ↑ Summary include/tkz/tkz_local.h »
1 # Doors onto the engine, for the tests only.
2  
3 MODULE = Time::Keeper::Zone PACKAGE = Time::Keeper::Zone
4  
5 # (utoff, isdst, abbreviation) at a UTC instant.
6 void
7 _offset_at(name, t)
8 const char *name
9 SV *t
10 PREINIT:
11 int id;
12 int32_t utoff;
13 int isdst;
14 const char *abbr;
15 PPCODE:
16 20257 id = tkz_lookup_name(name, strlen(name));
17 20257 ▶ if (!tkz_offset_at(id, tkz_sv_i64(aTHX_ t), &utoff, &isdst, &abbr))
Branch: 1 branch
BranchTrueFalseTotal
if (!tkz_offset_at(id, tkz_sv_i64(aTHX_ t), &utoff, &isdst, &abbr)) 1 20256 20257
18 1 croak("no such zone");
19 20256 ▶ EXTEND(SP, 3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 3); 0 20256 20256
20 20256 mPUSHi(utoff);
21 20256 mPUSHi(isdst);
22 20256 mPUSHp(abbr, strlen(abbr));
23  
24 SV *
25 _next_change(name, t)
26 const char *name
27 SV *t
28 PREINIT:
29 int id;
30 int64_t n;
31 CODE:
32 4 id = tkz_lookup_name(name, strlen(name));
33 4 ▶ if (id < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (id < 0) 0 4 4
34 0 croak("no such zone");
35 4 n = tkz_next_change(id, tkz_sv_i64(aTHX_ t));
36 4 ▶ if (n == TKZ_NO_CHANGE)
Branch: 1 branch
BranchTrueFalseTotal
if (n == TKZ_NO_CHANGE) 2 2 4
37 2 XSRETURN_UNDEF;
38 2 RETVAL = tkz_newSVi64(aTHX_ n);
39 OUTPUT:
40 RETVAL
41  
42 # Every real change from t0 up to and including t1, each as
43 # [at, utoff, isdst, abbreviation].
44 void
45 _changes(name, t0, t1)
46 const char *name
47 SV *t0
48 SV *t1
49 PREINIT:
50 int id;
51 int64_t t, end;
52 PPCODE:
53 346 id = tkz_lookup_name(name, strlen(name));
54 346 ▶ if (id < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (id < 0) 0 346 346
55 0 croak("no such zone");
56 346 t = tkz_sv_i64(aTHX_ t0);
57 346 end = tkz_sv_i64(aTHX_ t1);
58 575 ▶ while ((t = tkz_next_change(id, t)) != TKZ_NO_CHANGE && t <= end) {
Branch: 2 branches
BranchTrueFalseTotal
while ((t = tkz_next_change(id, t)) != TKZ_NO_CHANGE && t <= end) { 336 239 575
while ((t = tkz_next_change(id, t)) != TKZ_NO_CHANGE && t <= end) { 229 107 336
59 int32_t utoff;
60 int isdst;
61 const char *abbr;
62 229 AV *row = newAV();
63 229 tkz_offset_at(id, t, &utoff, &isdst, &abbr);
64 229 av_push(row, tkz_newSVi64(aTHX_ t));
65 229 av_push(row, newSViv(utoff));
66 229 av_push(row, newSViv(isdst));
67 229 av_push(row, newSVpv(abbr, 0));
68 229 ▶ XPUSHs(sv_2mortal(newRV_noinc((SV *)row)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newRV_noinc((SV *)row))); 0 229 229
69 }
70  
71 # (result, utc or undef). gap: 0 croak, 1 forward, 2 backward; overlap: 0
72 # later, 1 earlier.
73 void
74 _resolve_local(name, local, gap, overlap)
75 const char *name
76 SV *local
77 int gap
78 int overlap
79 PREINIT:
80 int id, r;
81 42973 int64_t utc = 0;
82 PPCODE:
83 42973 id = tkz_lookup_name(name, strlen(name));
84 42973 ▶ if (id < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (id < 0) 0 42973 42973
85 0 croak("no such zone");
86 42973 r = tkz_resolve_local(id, tkz_sv_i64(aTHX_ local), gap, overlap, &utc);
87 42973 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 42973 42973
88 42973 mPUSHi(r);
89 42973 ▶ if (r == TKZ_LOCAL_GAP && gap == TKZ_GAP_CROAK)
Branch: 2 branches
BranchTrueFalseTotal
if (r == TKZ_LOCAL_GAP && gap == TKZ_GAP_CROAK) 1665 41308 42973
if (r == TKZ_LOCAL_GAP && gap == TKZ_GAP_CROAK) 333 1332 1665
90 333 PUSHs(&PL_sv_undef);
91 else
92 42640 mPUSHs(tkz_newSVi64(aTHX_ utc));
93  
94 # The local zone's name from a TZ value (undef for unset), files of the
95 # test's own and a Windows time zone key name; undef for any source skips
96 # it, so the system is never consulted.
97 SV *
98 _local_zone_from(tz, link, tzfile, clock, windows)
99 SV *tz
100 SV *link
101 SV *tzfile
102 SV *clock
103 SV *windows
104 PREINIT:
105 17 STRLEN len = 0;
106 17 const char *p = NULL;
107 CODE:
108 17 ▶ if (SvOK(tz))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(tz)) 8 9 17
109 8 p = SvPV(tz, len);
110 34 ▶ RETVAL = newSVpv(tkz_id_name(tkz_local_zone_from(p, len,
Branch: 4 branches
BranchTrueFalseTotal
RETVAL = newSVpv(tkz_id_name(tkz_local_zone_from(p, len, 5 12 17
RETVAL = newSVpv(tkz_id_name(tkz_local_zone_from(p, len, 3 14 17
RETVAL = newSVpv(tkz_id_name(tkz_local_zone_from(p, len, 4 13 17
RETVAL = newSVpv(tkz_id_name(tkz_local_zone_from(p, len, 5 12 17
111 SvOK(link) ? SvPV_nolen(link) : NULL,
112 SvOK(tzfile) ? SvPV_nolen(tzfile) : NULL,
113 SvOK(clock) ? SvPV_nolen(clock) : NULL,
114 SvOK(windows) ? SvPV_nolen(windows) : NULL)), 0);
115 OUTPUT:
116 RETVAL
117  
118 # The ABI table, called through its pointers, for t/04-abi.t.
119 void
120 _abi_call(what, ...)
121 const char *what
122 PREINIT:
123 33 const tkz_abi *a = &TKZ_ABI;
124 PPCODE:
125 33 ▶ if (strEQ(what, "lookup")) {
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(what, "lookup")) { 5 28 33
126 STRLEN len;
127 5 const char *p = SvPV(ST(1), len);
128 5 ▶ mXPUSHi((a->lookup)(p, len));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHi((a->lookup)(p, len)); 0 5 5
129 }
130 28 ▶ else if (strEQ(what, "name")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(what, "name")) { 4 24 28
131 4 const char *n = (a->name)((int)SvIV(ST(1)));
132 4 ▶ XPUSHs(n ? sv_2mortal(newSVpv(n, 0)) : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(n ? sv_2mortal(newSVpv(n, 0)) : &PL_sv_undef); 0 4 4
XPUSHs(n ? sv_2mortal(newSVpv(n, 0)) : &PL_sv_undef); 2 2 4
133 }
134 24 ▶ else if (strEQ(what, "canonical_name")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(what, "canonical_name")) { 1 23 24
135 1 const char *n = (a->canonical_name)((int)SvIV(ST(1)));
136 1 ▶ XPUSHs(n ? sv_2mortal(newSVpv(n, 0)) : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(n ? sv_2mortal(newSVpv(n, 0)) : &PL_sv_undef); 0 1 1
XPUSHs(n ? sv_2mortal(newSVpv(n, 0)) : &PL_sv_undef); 1 0 1
137 }
138 23 ▶ else if (strEQ(what, "is_link"))
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(what, "is_link")) 2 21 23
139 2 ▶ mXPUSHi((a->is_link)((int)SvIV(ST(1))));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHi((a->is_link)((int)SvIV(ST(1)))); 0 2 2
140 21 ▶ else if (strEQ(what, "offset_at")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(what, "offset_at")) { 2 19 21
141 int32_t u; int d; const char *ab;
142 2 int ok = (a->offset_at)((int)SvIV(ST(1)), tkz_sv_i64(aTHX_ ST(2)), &u, &d, &ab);
143 2 ▶ mXPUSHi(ok);
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHi(ok); 0 2 2
144 2 ▶ if (ok) { mXPUSHi(u); mXPUSHi(d); mXPUSHs(newSVpv(ab, 0)); }
Branch: 4 branches
BranchTrueFalseTotal
if (ok) { mXPUSHi(u); mXPUSHi(d); mXPUSHs(newSVpv(ab, 0)); } 1 1 2
if (ok) { mXPUSHi(u); mXPUSHi(d); mXPUSHs(newSVpv(ab, 0)); } 0 1 1
if (ok) { mXPUSHi(u); mXPUSHi(d); mXPUSHs(newSVpv(ab, 0)); } 0 1 1
if (ok) { mXPUSHi(u); mXPUSHi(d); mXPUSHs(newSVpv(ab, 0)); } 0 1 1
145 }
146 19 ▶ else if (strEQ(what, "next_change")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(what, "next_change")) { 1 18 19
147 1 int64_t n = (a->next_change)((int)SvIV(ST(1)), tkz_sv_i64(aTHX_ ST(2)));
148 1 ▶ XPUSHs(n == TKZ_NO_CHANGE ? &PL_sv_undef : sv_2mortal(tkz_newSVi64(aTHX_ n)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(n == TKZ_NO_CHANGE ? &PL_sv_undef : sv_2mortal(tkz_newSVi64(aTHX_ n))); 0 1 1
XPUSHs(n == TKZ_NO_CHANGE ? &PL_sv_undef : sv_2mortal(tkz_newSVi64(aTHX_ n))); 1 0 1
149 }
150 18 ▶ else if (strEQ(what, "resolve_local")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(what, "resolve_local")) { 2 16 18
151 2 int64_t u = 0;
152 2 int r = (a->resolve_local)((int)SvIV(ST(1)), tkz_sv_i64(aTHX_ ST(2)),
153 2 (int)SvIV(ST(3)), (int)SvIV(ST(4)), &u);
154 2 ▶ mXPUSHi(r);
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHi(r); 0 2 2
155 2 ▶ mXPUSHs(tkz_newSVi64(aTHX_ u));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(tkz_newSVi64(aTHX_ u)); 0 2 2
156 }
157 16 ▶ else if (strEQ(what, "local_zone")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(what, "local_zone")) { 1 15 16
158 1 STRLEN len = 0;
159 2 ▶ const char *p = SvOK(ST(1)) ? SvPV(ST(1), len) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
const char *p = SvOK(ST(1)) ? SvPV(ST(1), len) : NULL; 1 0 1
160 1 ▶ mXPUSHi((a->local_zone)(p, len));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHi((a->local_zone)(p, len)); 0 1 1
161 }
162 15 ▶ else if (strEQ(what, "tzdata_version"))
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(what, "tzdata_version")) 1 14 15
163 1 ▶ mXPUSHs(newSVpv((a->tzdata_version)(), 0));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSVpv((a->tzdata_version)(), 0)); 0 1 1
164 14 ▶ else if (strEQ(what, "zone_count"))
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(what, "zone_count")) 2 12 14
165 2 ▶ mXPUSHi((a->zone_count)());
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHi((a->zone_count)()); 0 2 2
166 12 ▶ else if (strEQ(what, "prev_change")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(what, "prev_change")) { 2 10 12
167 2 int64_t n = (a->prev_change)((int)SvIV(ST(1)), tkz_sv_i64(aTHX_ ST(2)));
168 2 ▶ XPUSHs(n == TKZ_NO_CHANGE ? &PL_sv_undef : sv_2mortal(tkz_newSVi64(aTHX_ n)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(n == TKZ_NO_CHANGE ? &PL_sv_undef : sv_2mortal(tkz_newSVi64(aTHX_ n))); 0 2 2
XPUSHs(n == TKZ_NO_CHANGE ? &PL_sv_undef : sv_2mortal(tkz_newSVi64(aTHX_ n))); 1 1 2
169 }
170 10 ▶ else if (strEQ(what, "resolve_local_all")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(what, "resolve_local_all")) { 4 6 10
171 int64_t u[2];
172 int32_t o[2];
173 4 int n = (a->resolve_local_all)((int)SvIV(ST(1)), tkz_sv_i64(aTHX_ ST(2)), u, o);
174 4 ▶ mXPUSHi(n);
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHi(n); 0 4 4
175 4 ▶ if (n >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (n >= 0) { 3 1 4
176 3 ▶ mXPUSHs(tkz_newSVi64(aTHX_ u[0]));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(tkz_newSVi64(aTHX_ u[0])); 0 3 3
177 3 ▶ mXPUSHi(o[0]);
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHi(o[0]); 0 3 3
178 3 ▶ mXPUSHs(tkz_newSVi64(aTHX_ u[1]));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(tkz_newSVi64(aTHX_ u[1])); 0 3 3
179 3 ▶ mXPUSHi(o[1]);
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHi(o[1]); 0 3 3
180 }
181 }
182 6 ▶ else if (strEQ(what, "standard_offset_at")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(what, "standard_offset_at")) { 2 4 6
183 int32_t u;
184 2 int ok = (a->standard_offset_at)((int)SvIV(ST(1)), tkz_sv_i64(aTHX_ ST(2)), &u);
185 2 ▶ mXPUSHi(ok);
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHi(ok); 0 2 2
186 2 ▶ if (ok) mXPUSHi(u);
Branch: 2 branches
BranchTrueFalseTotal
if (ok) mXPUSHi(u); 1 1 2
if (ok) mXPUSHi(u); 0 1 1
187 }
188 4 ▶ else if (strEQ(what, "country_of") || strEQ(what, "windows_name")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (strEQ(what, "country_of") || strEQ(what, "windows_name")) { 2 2 4
else if (strEQ(what, "country_of") || strEQ(what, "windows_name")) { 2 0 2
189 2 const char *n = what[0] == 'c' ? (a->country_of)((int)SvIV(ST(1)))
190 4 ▶ : (a->windows_name)((int)SvIV(ST(1)));
Branch: 1 branch
BranchTrueFalseTotal
: (a->windows_name)((int)SvIV(ST(1))); 2 2 4
191 4 ▶ XPUSHs(n ? sv_2mortal(newSVpv(n, 0)) : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(n ? sv_2mortal(newSVpv(n, 0)) : &PL_sv_undef); 0 4 4
XPUSHs(n ? sv_2mortal(newSVpv(n, 0)) : &PL_sv_undef); 2 2 4
192 }
193 else
194 0 croak("no ABI entry %s", what);
« xs/abi.xs ↑ Summary include/tkz/tkz_local.h »