1
// unit.cc -- This is a test case for the Dejagnu.h classes.
1
// unit.cc -- This is a test case for the dejagnu.h classes.
2
// Copyright 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4
// This file is part of DejaGnu.
6
// DejaGnu is free software; you can redistribute it and/or modify it
7
// under the terms of the GNU General Public License as published by
8
// the Free Software Foundation; either version 2 of the License, or
9
// (at your option) any later version.
11
// DejaGnu is distributed in the hope that it will be useful, but
12
// WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
// General Public License for more details.
16
// You should have received a copy of the GNU General Public License
17
// along with DejaGnu; if not, write to the Free Software Foundation,
18
// Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
3
20
#include <sys/types.h>
22
40
TestClass1 testClass1, testClass2, testClass3;
23
41
TestClass1 *testClassPtr;
25
// We have to so this silly crap with renaming the output string, so the generic
26
// Tcl code that looks for the output state gets confused, and records random
27
// duplicate messages.
43
// We have to do this silly crap with renaming the output string, so
44
// the generic Tcl code that looks for the output state gets confused,
45
// and records random duplicate messages.
28
46
const char *os1[] = {
47
"FAI: ", "PAS: ", "UNT: ", "UNR: "
35
50
const char *os2[] = {
51
"FAILED: ", "PASSED: ", "UNTESTED: ", "UNRESOLVED: "
43
main (int argc, char *argv[]) {
46
// char **os2 = outstate;
49
// Replace the output buffer for cout, so we can examine it to
50
// see what was displayed. Otherwise, there is no way we can test
51
// the logging functions completely.
55
main (int argc, char *argv[])
60
// Replace the output buffer for cout, so we can examine it to see
61
// what was displayed. Otherwise, there is no way we can test the
62
// logging functions completely.
53
64
#ifdef __STDC_HOSTED__
54
cout.rdbuf()->pubsetbuf(bbuuff, 5120);
65
cout.rdbuf ()->pubsetbuf (buf, 5120);
56
cout.rdbuf()->setbuf(bbuuff, 5120);
67
cout.rdbuf ()->setbuf (buf, 5120);
59
testClass1.tname = "testType1";
61
testClass2.tname = "testType2";
63
testClass3.tname = "testType3";
66
// Test the pass message
67
test.pass ("bogus pass message for testing");
69
if (strncmp(bbuuff, "\tPAS: bogus pass message", 22) == 0) {
70
runtest.pass ("Pass message");
72
runtest.fail ("Pass message");
75
// Test the fail message
77
test.fail ("bogus fail message for testing");
80
if (strncmp(bbuuff, "\tFAI: bogus fail message", 22) == 0) {
81
runtest.pass ("Fail message");
83
runtest.fail ("Fail message");
86
// Test the untested message
88
test.untested ("bogus untested message for testing");
91
if (strncmp(bbuuff, "\tUNT: bogus untested message", 21) == 0) {
92
runtest.pass ("Untested message");
94
runtest.fail ("Untested message");
97
// Test the unresolved message
99
test.unresolved ("bogus unresolved message for testing");
102
if (strncmp(bbuuff, "\tUNR: bogus unresolved message", 21) == 0) {
103
runtest.pass ("Unresolved message");
105
runtest.fail ("Unresolved message");
108
// Make sure we got everything in the totals
109
regcomp (®ex_pat, "\r\n\t#passed.*#failed.*#untested.*#unresolved", REG_NOSUB|REG_NEWLINE);
110
if (regexec (®ex_pat, bbuuff, 0, (regmatch_t *)0, 0)) {
111
runtest.pass ("Totals message");
113
runtest.fail ("Totals message");
70
testClass1.tname = "testType1";
72
testClass2.tname = "testType2";
74
testClass3.tname = "testType3";
77
// Test the pass message.
78
test.pass ("bogus pass message for testing");
80
if (strncmp (buf, "\tPAS: bogus pass message", 22) == 0)
81
runtest.pass ("Pass message");
83
runtest.fail ("Pass message");
85
// Test the fail message.
87
test.fail ("bogus fail message for testing");
90
if (strncmp (buf, "\tFAI: bogus fail message", 22) == 0)
91
runtest.pass ("Fail message");
93
runtest.fail ("Fail message");
95
// Test the untested message.
97
test.untested ("bogus untested message for testing");
100
if (strncmp (buf, "\tUNT: bogus untested message", 21) == 0) {
101
runtest.pass ("Untested message");
103
runtest.fail ("Untested message");
106
// Test the unresolved message.
108
test.unresolved ("bogus unresolved message for testing");
111
if (strncmp (buf, "\tUNR: bogus unresolved message", 21) == 0)
112
runtest.pass ("Unresolved message");
114
runtest.fail ("Unresolved message");
116
// Make sure we got everything in the totals.
118
"\r\n\t#passed.*#failed.*#untested.*#unresolved",
119
REG_NOSUB | REG_NEWLINE);
121
if (regexec (®ex_pat, buf, 0, (regmatch_t *) 0, 0))
122
runtest.pass ("Totals message");
124
runtest.fail ("Totals message");