5 * (c) 2024 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the mLib utilities library.
12 * mLib is free software: you can redistribute it and/or modify it under
13 * the terms of the GNU Library General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or (at
15 * your option) any later version.
17 * mLib is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
20 * License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with mLib. If not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28 /*----- Header files ------------------------------------------------------*/
31 #include "tvec-types.h"
35 /*----- Register allocation -----------------------------------------------*/
44 RX
= NROUT
, RNAME
= RX
,
50 /*----- Addition test -----------------------------------------------------*/
52 static const struct tvec_regdef add_regs
[] = {
53 { "x", &tvty_int
, RX
, 0, { &tvrange_int
} },
54 { "y", &tvty_int
, RY
, 0, { &tvrange_int
} },
55 { "z", &tvty_int
, RZ
, 0, { &tvrange_int
} },
59 void test_add(const struct tvec_reg
*in
, struct tvec_reg
*out
, void *ctx
)
60 { out
[RZ
].v
.i
= add(in
[RX
].v
.i
, in
[RY
].v
.i
); }
62 static const struct tvec_test add_test
=
63 { "add", add_regs
, 0, test_add
};
65 /*----- Greeting test -----------------------------------------------------*/
67 void test_greet(const struct tvec_reg
*in
, struct tvec_reg
*out
, void *ctx
)
69 tvec_alloctext(&out
[RMSG
].v
, in
[RSZ
].v
.u
);
70 out
[RRC
].v
.i
= greet(out
[RMSG
].v
.text
.p
, in
[RSZ
].v
.u
, in
[RNAME
].v
.text
.p
);
71 out
[RMSG
].v
.text
.sz
= strlen(out
[RMSG
].v
.text
.p
);
74 static const struct tvec_regdef greet_regs
[] = {
75 { "name", &tvty_text
, RNAME
, 0 },
76 { "sz", &tvty_size
, RSZ
, 0, { &tvrange_size
} },
77 { "msg", &tvty_text
, RMSG
, TVRF_UNSET
},
78 { "rc", &tvty_int
, RRC
, 0, { &tvrange_int
} },
82 static const struct tvec_test greet_test
=
83 { "greet", greet_regs
, 0, test_greet
};
85 /*----- Main program ------------------------------------------------------*/
87 static const struct tvec_test
*const tests
[] = {
93 static const struct tvec_config test_config
=
94 { tests
, NROUT
, NREG
, sizeof(struct tvec_reg
) };
96 int main(int argc
, char *argv
[])
97 { return (tvec_main(argc
, argv
, &test_config
, 0)); }
99 /*----- That's all, folks -------------------------------------------------*/