Commit | Line | Data |
---|---|---|
3048fcf9 MW |
1 | /* -*-c-*- |
2 | * | |
3 | * Test rig for versioncmp | |
4 | * | |
5 | * (c) 2008 Straylight/Edgeware | |
6 | */ | |
7 | ||
8 | /*----- Licensing notice --------------------------------------------------* | |
9 | * | |
10 | * This file is part of the mLib utilities library. | |
11 | * | |
12 | * mLib is free software; you can redistribute it and/or modify | |
13 | * it under the terms of the GNU Library General Public License as | |
14 | * published by the Free Software Foundation; either version 2 of the | |
15 | * License, or (at your option) any later version. | |
16 | * | |
17 | * mLib is distributed in the hope that it will be useful, | |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | * GNU Library General Public License for more details. | |
21 | * | |
22 | * You should have received a copy of the GNU Library General Public | |
23 | * License along with mLib; if not, write to the Free | |
24 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, | |
25 | * MA 02111-1307, USA. | |
26 | */ | |
27 | ||
b64eb60f | 28 | #include "tvec.h" |
b1a20bee MW |
29 | #include "tvec-types.h" |
30 | ||
3048fcf9 MW |
31 | #include "versioncmp.h" |
32 | ||
b64eb60f MW |
33 | enum { |
34 | RRC, NROUT, | |
35 | RV0 = NROUT, RV1, NREG | |
36 | }; | |
37 | ||
b1a20bee MW |
38 | static const struct tvec_regdef versioncmp_regs[] = { |
39 | { "v0", &tvty_text, RV0, 0 }, | |
40 | { "v1", &tvty_text, RV1, 0 }, | |
41 | { "rc", &tvty_ienum, RRC, 0, { &tvenum_cmp } }, | |
42 | TVEC_ENDREGS | |
43 | }; | |
b64eb60f | 44 | |
e63124bc | 45 | static void swap_test(struct tvec_state *tv, tvec_testfn *fn, void *ctx) |
3048fcf9 | 46 | { |
b64eb60f MW |
47 | struct tvec_reg rt; |
48 | ||
e63124bc MW |
49 | fn(tv->in, tv->out, 0); tvec_check(tv, "vanilla"); |
50 | tvec_resetoutputs(tv); | |
b64eb60f MW |
51 | rt = tv->in[RV0]; tv->in[RV0] = tv->in[RV1]; tv->in[RV1] = rt; |
52 | tv->in[RRC].v.i = -tv->in[RRC].v.i; | |
e63124bc | 53 | fn(tv->in, tv->out, 0); tvec_check(tv, "swapped"); |
3048fcf9 MW |
54 | } |
55 | ||
b1a20bee MW |
56 | static void test_versioncmp(const struct tvec_reg *in, struct tvec_reg *out, |
57 | void *ctx) | |
58 | { out[RRC].v.i = versioncmp(in[RV0].v.text.p, in[RV1].v.text.p); } | |
3048fcf9 | 59 | |
b1a20bee MW |
60 | static const struct tvec_env swap_testenv = { 0, 0, 0, 0, swap_test, 0, 0 }; |
61 | static const struct tvec_test versioncmp_test = | |
62 | { "versioncmp", versioncmp_regs, &swap_testenv, test_versioncmp }; | |
63 | ||
64 | static const struct tvec_test *const tests[] = { &versioncmp_test, 0 }; | |
b64eb60f | 65 | |
c5e0e403 | 66 | static const struct tvec_config testconfig = |
b64eb60f MW |
67 | { tests, NROUT, NREG, sizeof(struct tvec_reg) }; |
68 | ||
3048fcf9 | 69 | int main(int argc, char *argv[]) |
c5e0e403 | 70 | { return (tvec_main(argc, argv, &testconfig, 0)); } |
3048fcf9 MW |
71 | |
72 | /*----- That's all, folks -------------------------------------------------*/ |