xref: /onnv-gate/usr/src/cmd/sendmail/libsm/t-string.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
3*0Sstevel@tonic-gate  *	All rights reserved.
4*0Sstevel@tonic-gate  *
5*0Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
6*0Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
7*0Sstevel@tonic-gate  * the sendmail distribution.
8*0Sstevel@tonic-gate  */
9*0Sstevel@tonic-gate 
10*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
11*0Sstevel@tonic-gate 
12*0Sstevel@tonic-gate #include <sm/gen.h>
13*0Sstevel@tonic-gate SM_IDSTR(id, "@(#)$Id: t-string.c,v 1.9 2001/01/26 03:28:43 ca Exp $")
14*0Sstevel@tonic-gate 
15*0Sstevel@tonic-gate #include <sm/exc.h>
16*0Sstevel@tonic-gate #include <sm/io.h>
17*0Sstevel@tonic-gate #include <sm/string.h>
18*0Sstevel@tonic-gate #include <sm/test.h>
19*0Sstevel@tonic-gate 
20*0Sstevel@tonic-gate int
21*0Sstevel@tonic-gate main(argc, argv)
22*0Sstevel@tonic-gate 	int argc;
23*0Sstevel@tonic-gate 	char **argv;
24*0Sstevel@tonic-gate {
25*0Sstevel@tonic-gate 	char *s;
26*0Sstevel@tonic-gate 	char buf[4096];
27*0Sstevel@tonic-gate 	char foo[4];
28*0Sstevel@tonic-gate 	char *r;
29*0Sstevel@tonic-gate 	int n;
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate 	sm_test_begin(argc, argv, "test string utilities");
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate 	s = sm_stringf_x("%.3s%03d", "foobar", 42);
34*0Sstevel@tonic-gate 	r = "foo042";
35*0Sstevel@tonic-gate 	SM_TEST(strcmp(s, r) == 0);
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate 	s = sm_stringf_x("+%*x+", 2000, 0xCAFE);
38*0Sstevel@tonic-gate 	sm_snprintf(buf, 4096, "+%*x+", 2000, 0xCAFE);
39*0Sstevel@tonic-gate 	SM_TEST(strcmp(s, buf) == 0);
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate 	foo[3] = 1;
42*0Sstevel@tonic-gate 	n = sm_snprintf(foo, sizeof(foo), "foobar%dbaz", 42);
43*0Sstevel@tonic-gate 	SM_TEST(n == 11);
44*0Sstevel@tonic-gate 	r = "foo";
45*0Sstevel@tonic-gate 	SM_TEST(strcmp(foo, r) == 0);
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate 	return sm_test_end();
48*0Sstevel@tonic-gate }
49