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.
12 SM_IDSTR(id
, "@(#)$Id: t-strl.c,v 1.15 2001/09/11 04:04:49 gshapiro Exp $")
17 #include <sm/string.h>
31 char src1
[N
][SIZE
], dst1
[SIZE
], dst2
[SIZE
];
34 sm_test_begin(argc
, argv
, "test strl* string functions");
37 s3
= sm_malloc_x(MAXL
);
39 SM_TEST(sm_strlcpy(s3
, s1
, 4) == 3);
40 SM_TEST(strcmp(s1
, s3
) == 0);
42 SM_TEST(sm_strlcat(s3
, s2
, 8) == 6);
44 SM_TEST(strcmp(s3
, r
) == 0);
46 SM_TEST(sm_strlcpy(s3
, s1
, 2) == 3);
48 SM_TEST(strcmp(s3
, r
) == 0);
50 SM_TEST(sm_strlcat(s3
, s2
, 3) == 4);
52 SM_TEST(strcmp(s3
, r
) == 0);
54 SM_TEST(sm_strlcpy(s3
, s1
, 4) == 3);
56 SM_TEST(sm_strlcat2(s3
, r
, s2
, MAXL
) == 7);
58 SM_TEST(strcmp(s3
, r
) == 0);
60 SM_TEST(sm_strlcpy(s3
, s1
, 4) == 3);
62 SM_TEST(sm_strlcat2(s3
, r
, s2
, 6) == 7);
64 SM_TEST(strcmp(s3
, r
) == 0);
66 SM_TEST(sm_strlcpy(s3
, s1
, 4) == 3);
68 SM_TEST(sm_strlcat2(s3
, r
, s2
, 2) == 7);
70 SM_TEST(strcmp(s3
, r
) == 0);
72 SM_TEST(sm_strlcpy(s3
, s1
, 4) == 3);
74 SM_TEST(sm_strlcat2(s3
, r
, s2
, 4) == 7);
76 SM_TEST(strcmp(s3
, r
) == 0);
78 SM_TEST(sm_strlcpy(s3
, s1
, 4) == 3);
80 SM_TEST(sm_strlcat2(s3
, r
, s2
, 5) == 7);
82 SM_TEST(strcmp(s3
, r
) == 0);
84 SM_TEST(sm_strlcpy(s3
, s1
, 4) == 3);
86 SM_TEST(sm_strlcat2(s3
, r
, s2
, 6) == 7);
88 SM_TEST(strcmp(s3
, r
) == 0);
90 for (k
= 0; k
< N
; k
++)
92 (void) sm_strlcpy(src1
[k
], "abcdef", sizeof src1
);
95 one
= sm_strlcpyn(dst1
, sizeof dst1
, 3, src1
[0], "/", src1
[1]);
96 two
= sm_snprintf(dst2
, sizeof dst2
, "%s/%s", src1
[0], src1
[1]);
98 SM_TEST(strcmp(dst1
, dst2
) == 0);
99 one
= sm_strlcpyn(dst1
, 10, 3, src1
[0], "/", src1
[1]);
100 two
= sm_snprintf(dst2
, 10, "%s/%s", src1
[0], src1
[1]);
102 SM_TEST(strcmp(dst1
, dst2
) == 0);
103 one
= sm_strlcpyn(dst1
, 5, 3, src1
[0], "/", src1
[1]);
104 two
= sm_snprintf(dst2
, 5, "%s/%s", src1
[0], src1
[1]);
106 SM_TEST(strcmp(dst1
, dst2
) == 0);
107 one
= sm_strlcpyn(dst1
, 0, 3, src1
[0], "/", src1
[1]);
108 two
= sm_snprintf(dst2
, 0, "%s/%s", src1
[0], src1
[1]);
110 SM_TEST(strcmp(dst1
, dst2
) == 0);
111 one
= sm_strlcpyn(dst1
, sizeof dst1
, 5, src1
[0], "/", src1
[1], "/", src1
[2]);
112 two
= sm_snprintf(dst2
, sizeof dst2
, "%s/%s/%s", src1
[0], src1
[1], src1
[2]);
114 SM_TEST(strcmp(dst1
, dst2
) == 0);
115 one
= sm_strlcpyn(dst1
, 15, 5, src1
[0], "/", src1
[1], "/", src1
[2]);
116 two
= sm_snprintf(dst2
, 15, "%s/%s/%s", src1
[0], src1
[1], src1
[2]);
118 SM_TEST(strcmp(dst1
, dst2
) == 0);
119 one
= sm_strlcpyn(dst1
, 20, 5, src1
[0], "/", src1
[1], "/", src1
[2]);
120 two
= sm_snprintf(dst2
, 20, "%s/%s/%s", src1
[0], src1
[1], src1
[2]);
122 SM_TEST(strcmp(dst1
, dst2
) == 0);
124 one
= sm_strlcpyn(dst1
, sizeof dst1
, 0);
127 SM_TEST(strcmp(dst1
, r
) == 0);
128 one
= sm_strlcpyn(dst1
, 20, 1, src1
[0]);
129 two
= sm_snprintf(dst2
, 20, "%s", src1
[0]);
131 one
= sm_strlcpyn(dst1
, 2, 1, src1
[0]);
132 two
= sm_snprintf(dst2
, 2, "%s", src1
[0]);
135 return sm_test_end();