t-string.c revision 303975
1249259Sdim/*
2249259Sdim * Copyright (c) 2000-2001 Proofpoint, Inc. and its suppliers.
3249259Sdim *	All rights reserved.
4249259Sdim *
5249259Sdim * By using this file, you agree to the terms and conditions set
6249259Sdim * forth in the LICENSE file which can be found at the top level of
7249259Sdim * the sendmail distribution.
8249259Sdim */
9249259Sdim
10249259Sdim#include <sm/gen.h>
11249259SdimSM_IDSTR(id, "@(#)$Id: t-string.c,v 1.12 2013-11-22 20:51:43 ca Exp $")
12249259Sdim
13249259Sdim#include <sm/exc.h>
14249259Sdim#include <sm/io.h>
15249259Sdim#include <sm/string.h>
16249259Sdim#include <sm/test.h>
17249259Sdim
18249259Sdimint
19249259Sdimmain(argc, argv)
20249259Sdim	int argc;
21249259Sdim	char **argv;
22249259Sdim{
23249259Sdim	char *s;
24249259Sdim	char buf[4096];
25249259Sdim	char foo[4];
26249259Sdim	char *r;
27249259Sdim	int n;
28249259Sdim
29249259Sdim	sm_test_begin(argc, argv, "test string utilities");
30249259Sdim
31249259Sdim	s = sm_stringf_x("%.3s%03d", "foobar", 42);
32249259Sdim	r = "foo042";
33249259Sdim	SM_TEST(strcmp(s, r) == 0);
34249259Sdim
35249259Sdim	s = sm_stringf_x("+%*x+", 2000, 0xCAFE);
36249259Sdim	sm_snprintf(buf, 4096, "+%*x+", 2000, 0xCAFE);
37249259Sdim	SM_TEST(strcmp(s, buf) == 0);
38249259Sdim
39249259Sdim	foo[3] = 1;
40249259Sdim	n = sm_snprintf(foo, sizeof(foo), "foobar%dbaz", 42);
41249259Sdim	SM_TEST(n == 11);
42249259Sdim	r = "foo";
43249259Sdim	SM_TEST(strcmp(foo, r) == 0);
44249259Sdim
45249259Sdim	return sm_test_end();
46249259Sdim}
47249259Sdim