4aa57d520978883b054cc5da5ee7522e4c73f385
[openafs.git] / tests / opr / fmt-t.c
1 /*
2  * Copyright 2014, Nathaniel Wesley Filardo.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to permit
9  * persons to whom the Software is furnished to do so, subject to the
10  * following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included
13  * in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
18  * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21  * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24
25 #include <afsconfig.h>
26 #include <afs/param.h>
27 #include <roken.h>
28 #include <tests/tap/basic.h>
29 #include <opr/fmt.h>
30
31 int
32 testfmtr(opr_fmt_ctx *ctx, char c, va_list va) {
33     const char *str = va_arg(va, const char *);
34     while(*str) { ctx->put(ctx, *str++); }
35     return 0;
36 }
37
38 int
39 testfmtr2(opr_fmt_ctx *ctx, char c, va_list va) {
40     char *str = ctx->user;
41     while (*str) { ctx->put(ctx, *str++); }
42     return 0;
43 }
44
45 int main()
46 {
47   static opr_fmtr fmtrs[256] = { ['s'] = testfmtr, ['t'] = testfmtr2 };
48   static char buf[100];
49
50   plan(1);
51
52   opr_fmt(fmtrs, "EHLO", buf, 100, "FOO %s %t", "abc");
53   ok(0 == strcmp(buf,"FOO abc EHLO"), "Basic substitution test");
54
55   return 0;
56 }