]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/sendmail/libsm/t-ixlen.c
Merge commit '850ef5ae11d69ea3381bd310f564f025fc8caea3'
[FreeBSD/FreeBSD.git] / contrib / sendmail / libsm / t-ixlen.c
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 #if _FFR_8BITENVADDR
21 extern bool SmTestVerbose;
22 static int Verbose = 0;
23
24 static void
25 chkilenx(str, len)
26         const char *str;
27         int len;
28 {
29         int xlen;
30
31         xlen = ilenx(str);
32         SM_TEST(len == xlen);
33         if (len != xlen)
34                 fprintf(stderr, "str=\"%s\", len=%d, expected=%d\n",
35                         str, xlen, len);
36 }
37
38 static void
39 chkilen(str)
40         char *str;
41 {
42         char *obp;
43         int outlen, leni, lenx, ilen;
44         char line_in[1024];
45         XLENDECL
46
47         lenx = strlen(str);
48         sm_strlcpy(line_in, str, sizeof(line_in));
49         obp = quote_internal_chars(str, NULL, &outlen, NULL);
50         leni = strlen(obp);
51
52         for (ilen = 0; *obp != '\0'; obp++, ilen++)
53         {
54                 XLEN(*obp);
55         }
56         if (Verbose)
57                 fprintf(stderr, "str=\"%s\", ilen=%d, xlen=%d\n",
58                         str, ilen, xlen);
59         SM_TEST(ilen == leni);
60         if (ilen != leni)
61                 fprintf(stderr, "str=\"%s\", ilen=%d, leni=%d\n",
62                         str, ilen, leni);
63         SM_TEST(xlen == lenx);
64         if (xlen != lenx)
65                 fprintf(stderr, "str=\"%s\", xlen=%d, lenx=%d\n",
66                         str, xlen, lenx);
67 }
68
69 static void
70 chkxleni(str, len)
71         const char *str;
72         int len;
73 {
74         int ilen;
75
76         ilen = xleni(str);
77         SM_TEST(len == ilen);
78         if (len != ilen)
79                 fprintf(stderr, "str=\"%s\", len=%d, expected=%d\n",
80                         str, ilen, len);
81 }
82
83
84 static void
85 usage(prg)
86         const char *prg;
87 {
88         fprintf(stderr, "usage: %s [options]\n", prg);
89         fprintf(stderr, "options:\n");
90         fprintf(stderr, "-x    xleni\n");
91 }
92
93 int
94 main(argc, argv)
95         int argc;
96         char *argv[];
97 {
98         int o, len;
99         bool x, both;
100         char line[1024];
101
102         x = both = false;
103         while ((o = getopt(argc, argv, "bxV")) != -1)
104         {
105                 switch ((char) o)
106                 {
107                   case 'b':
108                         both = true;
109                         break;
110
111                   case 'x':
112                         x = true;
113                         break;
114
115                   case 'V':
116                         Verbose++;
117                         break;
118
119                   default:
120                         usage(argv[0]);
121                         exit(1);
122                 }
123         }
124
125         sm_test_begin(argc, argv, "test ilenx");
126
127         if (both)
128         {
129                 while (fscanf(stdin, "%s\n", line) == 1)
130                         chkilen(line);
131                 return sm_test_end();
132         }
133         while (fscanf(stdin, "%d:%s\n", &len, line) == 2)
134         {
135                 if (x)
136                         chkxleni(line, len);
137                 else
138                         chkilenx(line, len);
139         }
140
141         return sm_test_end();
142 }
143 #else /* _FFR_8BITENVADDR */
144 int
145 main(argc, argv)
146         int argc;
147         char *argv[];
148 {
149         return 0;
150 }
151 #endif /* _FFR_8BITENVADDR */