t-ixlen.c (2fb4f839f3fc72ce2bab12f9ba4760f97f73e97f) t-ixlen.c (d39bd2c1388b520fcba9abed1932acacead60fba)
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 */

--- 5 unchanged lines hidden (view full) ---

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
21extern bool SmTestVerbose;
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 */

--- 5 unchanged lines hidden (view full) ---

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
21extern bool SmTestVerbose;
22static int Verbose = 0;
22
23static void
24chkilenx(str, len)
25 const char *str;
26 int len;
27{
28 int xlen;
29
30 xlen = ilenx(str);
31 SM_TEST(len == xlen);
32 if (len != xlen)
23
24static void
25chkilenx(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)
33 fprintf(stderr, "str=\"%s\", len=%d, excpected=%d\n",
34 fprintf(stderr, "str=\"%s\", len=%d, expected=%d\n",
34 str, xlen, len);
35}
36
37static void
35 str, xlen, len);
36}
37
38static void
39chkilen(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
69static void
38chkxleni(str, len)
39 const char *str;
40 int len;
41{
42 int ilen;
43
44 ilen = xleni(str);
45 SM_TEST(len == ilen);
46 if (len != ilen)
70chkxleni(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)
47 fprintf(stderr, "str=\"%s\", len=%d, excpected=%d\n",
79 fprintf(stderr, "str=\"%s\", len=%d, expected=%d\n",
48 str, ilen, len);
49}
50
51
52static void
53usage(prg)
54 const char *prg;
55{
56 fprintf(stderr, "usage: %s [options]\n", prg);
57 fprintf(stderr, "options:\n");
58 fprintf(stderr, "-x xleni\n");
59}
60
61int
62main(argc, argv)
63 int argc;
64 char *argv[];
65{
66 int o, len;
80 str, ilen, len);
81}
82
83
84static void
85usage(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
93int
94main(argc, argv)
95 int argc;
96 char *argv[];
97{
98 int o, len;
67 bool x;
99 bool x, both;
68 char line[1024];
69
100 char line[1024];
101
70 x = false;
71 while ((o = getopt(argc, argv, "x")) != -1)
102 x = both = false;
103 while ((o = getopt(argc, argv, "bxV")) != -1)
72 {
73 switch ((char) o)
74 {
104 {
105 switch ((char) o)
106 {
107 case 'b':
108 both = true;
109 break;
110
75 case 'x':
76 x = true;
77 break;
78
111 case 'x':
112 x = true;
113 break;
114
115 case 'V':
116 Verbose++;
117 break;
118
79 default:
80 usage(argv[0]);
81 exit(1);
82 }
83 }
84
85 sm_test_begin(argc, argv, "test ilenx");
86
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 }
87 while (fscanf(stdin, "%d:%s\n", &len, line) == 2)
88 {
89 if (x)
90 chkxleni(line, len);
91 else
92 chkilenx(line, len);
93 }
94
95 return sm_test_end();
96}
97#else /* _FFR_8BITENVADDR */
98int
99main(argc, argv)
100 int argc;
101 char *argv[];
102{
103 return 0;
104}
105#endif /* _FFR_8BITENVADDR */
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 */
144int
145main(argc, argv)
146 int argc;
147 char *argv[];
148{
149 return 0;
150}
151#endif /* _FFR_8BITENVADDR */