2 * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
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.
11 #pragma ident "%Z%%M% %I% %E% SMI"
14 SM_IDSTR(id
, "@(#)$Id: t-strl.c,v 1.13 2001/08/27 23:00:05 gshapiro Exp $")
19 #include <sm/string.h>
33 char src1
[N
][SIZE
], dst1
[SIZE
], dst2
[SIZE
];
36 sm_test_begin(argc
, argv
, "test strl* string functions");
39 s3
= sm_malloc_x(MAXL
);
41 SM_TEST(sm_strlcpy(s3
, s1
, 4) == 3);
42 SM_TEST(strcmp(s1
, s3
) == 0);
44 SM_TEST(sm_strlcat(s3
, s2
, 8) == 6);
46 SM_TEST(strcmp(s3
, r
) == 0);
48 SM_TEST(sm_strlcpy(s3
, s1
, 2) == 3);
50 SM_TEST(strcmp(s3
, r
) == 0);
52 SM_TEST(sm_strlcat(s3
, s2
, 3) == 4);
54 SM_TEST(strcmp(s3
, r
) == 0);
56 SM_TEST(sm_strlcpy(s3
, s1
, 4) == 3);
58 SM_TEST(sm_strlcat2(s3
, r
, s2
, MAXL
) == 7);
60 SM_TEST(strcmp(s3
, r
) == 0);
62 SM_TEST(sm_strlcpy(s3
, s1
, 4) == 3);
64 SM_TEST(sm_strlcat2(s3
, r
, s2
, 6) == 7);
66 SM_TEST(strcmp(s3
, r
) == 0);
68 SM_TEST(sm_strlcpy(s3
, s1
, 4) == 3);
70 SM_TEST(sm_strlcat2(s3
, r
, s2
, 2) == 7);
72 SM_TEST(strcmp(s3
, r
) == 0);
74 SM_TEST(sm_strlcpy(s3
, s1
, 4) == 3);
76 SM_TEST(sm_strlcat2(s3
, r
, s2
, 4) == 7);
78 SM_TEST(strcmp(s3
, r
) == 0);
80 SM_TEST(sm_strlcpy(s3
, s1
, 4) == 3);
82 SM_TEST(sm_strlcat2(s3
, r
, s2
, 5) == 7);
84 SM_TEST(strcmp(s3
, r
) == 0);
86 SM_TEST(sm_strlcpy(s3
, s1
, 4) == 3);
88 SM_TEST(sm_strlcat2(s3
, r
, s2
, 6) == 7);
90 SM_TEST(strcmp(s3
, r
) == 0);
92 for (k
= 0; k
< N
; k
++)
94 (void) sm_strlcpy(src1
[k
], "abcdef", sizeof src1
);
97 one
= sm_strlcpyn(dst1
, sizeof dst1
, 3, src1
[0], "/", src1
[1]);
98 two
= sm_snprintf(dst2
, sizeof dst2
, "%s/%s", src1
[0], src1
[1]);
100 SM_TEST(strcmp(dst1
, dst2
) == 0);
101 one
= sm_strlcpyn(dst1
, 10, 3, src1
[0], "/", src1
[1]);
102 two
= sm_snprintf(dst2
, 10, "%s/%s", src1
[0], src1
[1]);
104 SM_TEST(strcmp(dst1
, dst2
) == 0);
105 one
= sm_strlcpyn(dst1
, 5, 3, src1
[0], "/", src1
[1]);
106 two
= sm_snprintf(dst2
, 5, "%s/%s", src1
[0], src1
[1]);
108 SM_TEST(strcmp(dst1
, dst2
) == 0);
109 one
= sm_strlcpyn(dst1
, 0, 3, src1
[0], "/", src1
[1]);
110 two
= sm_snprintf(dst2
, 0, "%s/%s", src1
[0], src1
[1]);
112 SM_TEST(strcmp(dst1
, dst2
) == 0);
113 one
= sm_strlcpyn(dst1
, sizeof dst1
, 5, src1
[0], "/", src1
[1], "/", src1
[2]);
114 two
= sm_snprintf(dst2
, sizeof dst2
, "%s/%s/%s", src1
[0], src1
[1], src1
[2]);
116 SM_TEST(strcmp(dst1
, dst2
) == 0);
117 one
= sm_strlcpyn(dst1
, 15, 5, src1
[0], "/", src1
[1], "/", src1
[2]);
118 two
= sm_snprintf(dst2
, 15, "%s/%s/%s", src1
[0], src1
[1], src1
[2]);
120 SM_TEST(strcmp(dst1
, dst2
) == 0);
121 one
= sm_strlcpyn(dst1
, 20, 5, src1
[0], "/", src1
[1], "/", src1
[2]);
122 two
= sm_snprintf(dst2
, 20, "%s/%s/%s", src1
[0], src1
[1], src1
[2]);
124 SM_TEST(strcmp(dst1
, dst2
) == 0);
126 one
= sm_strlcpyn(dst1
, sizeof dst1
, 0);
129 SM_TEST(strcmp(dst1
, r
) == 0);
130 one
= sm_strlcpyn(dst1
, 20, 1, src1
[0]);
131 two
= sm_snprintf(dst2
, 20, "%s", src1
[0]);
133 one
= sm_strlcpyn(dst1
, 2, 1, src1
[0]);
134 two
= sm_snprintf(dst2
, 2, "%s", src1
[0]);
137 return sm_test_end();