1 /*
2 * Copyright (c) 2020 Proofpoint, Inc. and its suppliers.
3 * All rights reserved.
4 *
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
8 */
9
10 #include <sm/gen.h>
11 SM_IDSTR(id, "@(#)$Id: t-qic.c,v 1.10 2013-11-22 20:51:43 ca Exp $")
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <unistd.h>
16 #include <sm/sendmail.h>
17 #include <sm/ixlen.h>
18 #include <sm/test.h>
19
20 extern bool SmTestVerbose;
21
22 static int
tstrncaseeq(s1,s2,len)23 tstrncaseeq(s1, s2, len)
24 char *s1;
25 char *s2;
26 size_t len;
27 {
28 return SM_STRNCASEEQ(s1, s2, len);
29 }
30
31 static void
usage(prg)32 usage(prg)
33 const char *prg;
34 {
35 fprintf(stderr, "usage: %s [options]\n", prg);
36 fprintf(stderr, "options:\n");
37 }
38
39 static void
hack(str)40 hack(str)
41 char *str;
42 {
43 char c;
44
45 /* replace just one \x char */
46 while ((c = *str++) != '\0')
47 {
48 if (c != '\\')
49 continue;
50 c = *str;
51 switch (c)
52 {
53 case 'n': c ='\n'; break;
54 case 't': c ='\t'; break;
55 case 'r': c ='\r'; break;
56 /* case 'X': c ='\X'; break; */
57 default: c ='\0'; break;
58 }
59 *(str - 1) = c;
60 *str = '\0';
61 break;
62 }
63 }
64
65 int
main(argc,argv)66 main(argc, argv)
67 int argc;
68 char *argv[];
69 {
70 int o, len;
71 #define MAXL 1024
72 char s1[MAXL], s2[MAXL];
73
74 while ((o = getopt(argc, argv, "h")) != -1)
75 {
76 switch ((char) o)
77 {
78 default:
79 usage(argv[0]);
80 exit(1);
81 }
82 }
83
84 sm_test_begin(argc, argv, "test strncaseeq");
85
86 while (fscanf(stdin, "%d:%s\n", &len, s1) == 2 &&
87 fscanf(stdin, "%d:%s\n", &o,s2) == 2)
88 {
89 int r;
90
91 hack(s1);
92 hack(s2);
93 SM_TEST(tstrncaseeq(s1, s2, len) == o);
94 if ((r = tstrncaseeq(s1, s2, len)) != o)
95 fprintf(stderr, "\"%s\"\n\"%s\"\n%d!=%d\n", s1, s2, o, r);
96 }
97
98 return sm_test_end();
99 }
100