1 /**
2  * \file
3  * @brief display messages to support unit testing
4  */
5 
6 /*
7  * Copyright (c) 2013, NLNet Labs, Verisign, Inc.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  *   notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright
15  *   notice, this list of conditions and the following disclaimer in the
16  *   documentation and/or other materials provided with the distribution.
17  * * Neither the names of the copyright holders nor the
18  *   names of its contributors may be used to endorse or promote products
19  *   derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
25  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <strings.h>
36 #include <string.h>
37 #include "testmessages.h"
38 
39 static char *testprog = NULL;
40 static char **cases = NULL;
41 static int ncases = 0;
42 
43 void
tstmsg_prog_begin(char * prognm)44 tstmsg_prog_begin(char *prognm)
45 {
46 	if (testprog != NULL) {
47 		tstmsg_prog_end();
48 	}
49 	testprog = strdup(prognm);
50 	printf("TESTPROG %s START\n", testprog);
51 }				/* tstmsg_prog_begin */
52 
53 void
tstmsg_prog_end()54 tstmsg_prog_end()
55 {
56 	printf("TESTPROG %s END\n", testprog);
57 	free(testprog);
58 }				/* tstmsg_prog_end */
59 
60 void
tstmsg_case_begin(char * casenm)61 tstmsg_case_begin(char *casenm)
62 {
63 	ncases++;
64 	cases = (char **) realloc(cases, sizeof(char *) * ncases);
65 	cases[ncases - 1] = strdup(casenm);
66 
67 	printf("TESTCASE %s:%s BEGIN\n", testprog, cases[ncases - 1]);
68 }				/* tstmsg_case_begin */
69 
70 void
tstmsg_case_end(void)71 tstmsg_case_end(void)
72 {
73 	if (ncases > 0) {
74 		printf("TESTCASE %s:%s END\n", testprog, cases[ncases - 1]);
75 		ncases--;
76 		free(cases[ncases]);
77 		if (ncases) {
78 			cases =
79 			    (char **) realloc(cases, sizeof(char *) * ncases);
80 		} else {
81 			cases = NULL;
82 		}
83 	}
84 }				/* tstmsg_case_end */
85 
86 void
tstmsg_case_msg(char * msg)87 tstmsg_case_msg(char *msg)
88 {
89 	printf("  %s:%s: %s\n", testprog, cases[ncases - 1], msg);
90 }				/* tstmsg_case_msg */
91 
92 /* testmessages.c */
93