xref: /freebsd/contrib/sendmail/libsm/t-str2prt.c (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /*
2  * Copyright (c) 2006 Proofpoint, Inc. and its suppliers.
3  *	All rights reserved.
4  *
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.
8  */
9 
10 #include <sm/gen.h>
11 SM_IDSTR(id, "@(#)$Id: t-qic.c,v 1.10 2013-11-22 20:51:43 ca Exp $")
12 
13 #include <stdio.h>
14 #include <sm/sendmail.h>
15 #include <sm/assert.h>
16 #include <sm/heap.h>
17 #include <sm/string.h>
18 #include <sm/test.h>
19 
20 extern bool SmTestVerbose;
21 
22 struct sm_qic_S
23 {
24 	char		*qic_in;
25 	char		*qic_out;
26 	int		 qic_exp;
27 };
28 typedef struct sm_qic_S sm_qic_T;
29 
30 int
31 main(argc, argv)
32 	int argc;
33 	char *argv[];
34 {
35 	char *obp;
36 	int i, cmp;
37 	sm_qic_T inout[] = {
38 		  { "", "",	0 }
39 		, { "abcdef", "abcdef",	0 }
40 		, { "01234567890123456789", "01234567890123456789",	0 }
41 		, { "\\", "\\\\",	0 }
42 		, { "\\001", "\\\\001",	0 }
43 		, { "01234567890123456789\\001", "01234567890123456789\\\\001",
44 			0 }
45 		, { NULL, NULL,	0 }
46 	};
47 
48 	sm_test_begin(argc, argv, "test meta quoting");
49 	for (i = 0; inout[i].qic_in != NULL; i++)
50 	{
51 		obp = str2prt(inout[i].qic_in);
52 		cmp = strcmp(inout[i].qic_out, obp);
53 		SM_TEST(inout[i].qic_exp == cmp);
54 		if (inout[i].qic_exp != cmp && SmTestVerbose)
55 		{
56 			fprintf(stderr, "in: %s\n", inout[i].qic_in);
57 			fprintf(stderr, "got: %s\n", obp);
58 			fprintf(stderr, "exp: %s\n", inout[i].qic_out);
59 			fprintf(stderr, "cmp=%d\n", cmp);
60 		}
61 	}
62 
63 	return sm_test_end();
64 }
65