xref: /freebsd/contrib/sendmail/libsm/t-string.c (revision ee7b0571c2c18bdec848ed2044223cc88db29bd8)
140266059SGregory Neil Shapiro /*
25dd76dd0SGregory Neil Shapiro  * Copyright (c) 2000-2001 Proofpoint, Inc. and its suppliers.
340266059SGregory Neil Shapiro  *	All rights reserved.
440266059SGregory Neil Shapiro  *
540266059SGregory Neil Shapiro  * By using this file, you agree to the terms and conditions set
640266059SGregory Neil Shapiro  * forth in the LICENSE file which can be found at the top level of
740266059SGregory Neil Shapiro  * the sendmail distribution.
840266059SGregory Neil Shapiro  */
940266059SGregory Neil Shapiro 
1040266059SGregory Neil Shapiro #include <sm/gen.h>
11*4313cc83SGregory Neil Shapiro SM_IDSTR(id, "@(#)$Id: t-string.c,v 1.12 2013-11-22 20:51:43 ca Exp $")
1240266059SGregory Neil Shapiro 
1340266059SGregory Neil Shapiro #include <sm/exc.h>
1440266059SGregory Neil Shapiro #include <sm/io.h>
1540266059SGregory Neil Shapiro #include <sm/string.h>
1640266059SGregory Neil Shapiro #include <sm/test.h>
1740266059SGregory Neil Shapiro 
1840266059SGregory Neil Shapiro int
1940266059SGregory Neil Shapiro main(argc, argv)
2040266059SGregory Neil Shapiro 	int argc;
2140266059SGregory Neil Shapiro 	char **argv;
2240266059SGregory Neil Shapiro {
2340266059SGregory Neil Shapiro 	char *s;
2440266059SGregory Neil Shapiro 	char buf[4096];
2540266059SGregory Neil Shapiro 	char foo[4];
2640266059SGregory Neil Shapiro 	char *r;
2740266059SGregory Neil Shapiro 	int n;
2840266059SGregory Neil Shapiro 
2940266059SGregory Neil Shapiro 	sm_test_begin(argc, argv, "test string utilities");
3040266059SGregory Neil Shapiro 
3140266059SGregory Neil Shapiro 	s = sm_stringf_x("%.3s%03d", "foobar", 42);
3240266059SGregory Neil Shapiro 	r = "foo042";
3340266059SGregory Neil Shapiro 	SM_TEST(strcmp(s, r) == 0);
3440266059SGregory Neil Shapiro 
3540266059SGregory Neil Shapiro 	s = sm_stringf_x("+%*x+", 2000, 0xCAFE);
3640266059SGregory Neil Shapiro 	sm_snprintf(buf, 4096, "+%*x+", 2000, 0xCAFE);
3740266059SGregory Neil Shapiro 	SM_TEST(strcmp(s, buf) == 0);
3840266059SGregory Neil Shapiro 
3940266059SGregory Neil Shapiro 	foo[3] = 1;
4040266059SGregory Neil Shapiro 	n = sm_snprintf(foo, sizeof(foo), "foobar%dbaz", 42);
4140266059SGregory Neil Shapiro 	SM_TEST(n == 11);
4240266059SGregory Neil Shapiro 	r = "foo";
4340266059SGregory Neil Shapiro 	SM_TEST(strcmp(foo, r) == 0);
4440266059SGregory Neil Shapiro 
4540266059SGregory Neil Shapiro 	return sm_test_end();
4640266059SGregory Neil Shapiro }
47