@@@ much mess, mostly manpages
[mLib] / test / example / testex.c
CommitLineData
c4ccbbf9
MW
1/* -*-c-*-
2 *
3 * Example test program
4 *
5 * (c) 2024 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 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.
16 *
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.
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 Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25 * USA.
26 */
27
28/*----- Header files ------------------------------------------------------*/
29
30#include "tvec.h"
31
32#include "example.h"
33
34/*----- Register allocation -----------------------------------------------*/
35
36enum {
37 /* add */ /* greet */
38 RZ, RMSG = RZ,
39 RRC,
40
41 NROUT,
42
43 RX = NROUT, RNAME = RX,
44 RY, RSZ = RY,
45
46 NREG
47};
48
49/*----- Addition test -----------------------------------------------------*/
50
51void test_add(const struct tvec_reg *in, struct tvec_reg *out, void *ctx)
52 { out[RZ].v.i = add(in[RX].v.i, in[RY].v.i); }
53
54static const struct tvec_regdef add_regs[] = {
55 { "x", &tvty_int, RX, 0, { &tvrange_int } },
56 { "y", &tvty_int, RY, 0, { &tvrange_int } },
57 { "z", &tvty_int, RZ, 0, { &tvrange_int } },
58 TVEC_ENDREGS
59};
60
61#define ADD_TEST \
62 { "add", add_regs, 0, test_add }
63
64/*----- Greeting test -----------------------------------------------------*/
65
66void test_greet(const struct tvec_reg *in, struct tvec_reg *out, void *ctx)
67{
68 tvec_alloctext(&out[RMSG].v, in[RSZ].v.u);
69 out[RRC].v.i = greet(out[RMSG].v.text.p, in[RSZ].v.u, in[RNAME].v.text.p);
70 out[RMSG].v.text.sz = strlen(out[RMSG].v.text.p);
71}
72
73static const struct tvec_regdef greet_regs[] = {
74 { "name", &tvty_text, RNAME, 0 },
75 { "sz", &tvty_size, RSZ, 0, { &tvrange_size } },
76 { "msg", &tvty_text, RMSG, TVRF_UNSET },
77 { "rc", &tvty_int, RRC, 0, { &tvrange_int } },
78 TVEC_ENDREGS
79};
80
81#define GREET_TEST \
82 { "greet", greet_regs, 0, test_greet }
83
84/*----- Main program ------------------------------------------------------*/
85
86static const struct tvec_test tests[] = {
87 ADD_TEST,
88 GREET_TEST,
89 TVEC_ENDTESTS
90};
91
92static const struct tvec_config test_config =
93 { tests, NROUT, NREG, sizeof(struct tvec_reg) };
94
95int main(int argc, char *argv[])
96 { return (tvec_main(argc, argv, &test_config, 0)); }
97
98/*----- That's all, folks -------------------------------------------------*/