~ubuntu-branches/ubuntu/oneiric/dejagnu/oneiric

« back to all changes in this revision

Viewing changes to testsuite/libdejagnu/unit.cc

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Jacobowitz
  • Date: 2006-12-11 09:06:59 UTC
  • mfrom: (2.1.6 edgy)
  • Revision ID: james.westby@ubuntu.com-20061211090659-w586kgi3giz84053
Tags: 1.4.4.cvs20060709-3
* Acknowledge previous NMUs.
* Fix permissions on /usr/share/dejagnu when building without fakeroot
  (Closes: #392589, #379809).

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
 
3
 
 
4
// This file is part of DejaGnu.
 
5
 
 
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.
 
10
 
 
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.
 
15
 
 
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.
2
19
 
3
20
#include <sys/types.h>
4
21
#include <iostream>
13
30
TestState runtest;
14
31
TestState test;
15
32
 
16
 
class TestClass1 {
 
33
class TestClass1
 
34
{
17
35
public:
18
 
        string tname;
19
 
        unsigned int tnum;
 
36
  string tname;
 
37
  unsigned int tnum;
20
38
};
21
39
 
22
40
TestClass1 testClass1, testClass2, testClass3;
23
41
TestClass1 *testClassPtr;
24
42
 
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[] = {
29
 
    "FAI: ",
30
 
    "PAS: ",
31
 
    "UNT: ",
32
 
    "UNR: "
 
47
    "FAI: ", "PAS: ", "UNT: ", "UNR: "
33
48
};
34
49
 
35
50
const char *os2[] = {
36
 
    "FAILED: ",
37
 
    "PASSED: ",
38
 
    "UNTESTED: ",
39
 
    "UNRESOLVED: "
 
51
    "FAILED: ", "PASSED: ", "UNTESTED: ", "UNRESOLVED: "
40
52
};
41
53
 
42
54
int
43
 
main (int argc, char *argv[]) {
44
 
    regex_t regex_pat;
45
 
 
46
 
//    char **os2 = outstate;
47
 
    outstate = os1;
48
 
 
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.
52
 
    char bbuuff[5120];
 
55
main (int argc, char *argv[])
 
56
{
 
57
  regex_t regex_pat;
 
58
  outstate = os1;
 
59
 
 
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.
 
63
  char buf[5120];
53
64
#ifdef __STDC_HOSTED__
54
 
    cout.rdbuf()->pubsetbuf(bbuuff, 5120);
 
65
  cout.rdbuf ()->pubsetbuf (buf, 5120);
55
66
#else
56
 
    cout.rdbuf()->setbuf(bbuuff, 5120);
 
67
  cout.rdbuf ()->setbuf (buf, 5120);
57
68
#endif
58
 
 
59
 
    testClass1.tname = "testType1";
60
 
    testClass1.tnum = 1;
61
 
    testClass2.tname = "testType2";
62
 
    testClass2.tnum = 2;
63
 
    testClass3.tname = "testType3";
64
 
    testClass3.tnum = 3;
65
 
 
66
 
    // Test the pass message
67
 
    test.pass ("bogus pass message for testing");
68
 
    outstate = os2;
69
 
    if (strncmp(bbuuff, "\tPAS: bogus pass message", 22) == 0) {
70
 
        runtest.pass ("Pass message");
71
 
    } else {
72
 
        runtest.fail ("Pass message");
73
 
    }
74
 
 
75
 
    // Test the fail message
76
 
    outstate = os1;
77
 
    test.fail ("bogus fail message for testing");
78
 
    cout.flush();
79
 
    outstate = os2;
80
 
    if (strncmp(bbuuff, "\tFAI: bogus fail message", 22) == 0) {
81
 
        runtest.pass ("Fail message");
82
 
    } else {
83
 
        runtest.fail ("Fail message");
84
 
    }
85
 
 
86
 
    // Test the untested message
87
 
    outstate = os1;
88
 
    test.untested ("bogus untested message for testing");
89
 
    cout.flush();
90
 
    outstate = os2;
91
 
    if (strncmp(bbuuff, "\tUNT: bogus untested message", 21) == 0) {
92
 
        runtest.pass ("Untested message");
93
 
    } else {
94
 
        runtest.fail ("Untested message");
95
 
    }
96
 
 
97
 
    // Test the unresolved message
98
 
    outstate = os1;
99
 
    test.unresolved ("bogus unresolved message for testing");
100
 
    cout.flush();
101
 
    outstate = os2;
102
 
    if (strncmp(bbuuff, "\tUNR: bogus unresolved message", 21) == 0) {
103
 
        runtest.pass ("Unresolved message");
104
 
    } else {
105
 
        runtest.fail ("Unresolved message");
106
 
    }
107
 
 
108
 
    // Make sure we got everything in the totals
109
 
    regcomp (&regex_pat, "\r\n\t#passed.*#failed.*#untested.*#unresolved", REG_NOSUB|REG_NEWLINE);
110
 
    if (regexec (&regex_pat, bbuuff, 0, (regmatch_t *)0, 0)) {
111
 
        runtest.pass ("Totals message");
112
 
    } else {
113
 
        runtest.fail ("Totals message");
114
 
    }
 
69
  
 
70
  testClass1.tname = "testType1";
 
71
  testClass1.tnum = 1;
 
72
  testClass2.tname = "testType2";
 
73
  testClass2.tnum = 2;
 
74
  testClass3.tname = "testType3";
 
75
  testClass3.tnum = 3;
 
76
  
 
77
  // Test the pass message.
 
78
  test.pass ("bogus pass message for testing");
 
79
  outstate = os2;
 
80
  if (strncmp (buf, "\tPAS: bogus pass message", 22) == 0)
 
81
    runtest.pass ("Pass message");
 
82
  else
 
83
    runtest.fail ("Pass message");
 
84
  
 
85
  // Test the fail message.
 
86
  outstate = os1;
 
87
  test.fail ("bogus fail message for testing");
 
88
  cout.flush ();
 
89
  outstate = os2;
 
90
  if (strncmp (buf, "\tFAI: bogus fail message", 22) == 0)
 
91
    runtest.pass ("Fail message");
 
92
  else
 
93
    runtest.fail ("Fail message");
 
94
  
 
95
  // Test the untested message.
 
96
  outstate = os1;
 
97
  test.untested ("bogus untested message for testing");
 
98
  cout.flush ();
 
99
  outstate = os2;
 
100
  if (strncmp (buf, "\tUNT: bogus untested message", 21) == 0) {
 
101
    runtest.pass ("Untested message");
 
102
  } else {
 
103
    runtest.fail ("Untested message");
 
104
  }
 
105
  
 
106
  // Test the unresolved message.
 
107
  outstate = os1;
 
108
  test.unresolved ("bogus unresolved message for testing");
 
109
  cout.flush ();
 
110
  outstate = os2;
 
111
  if (strncmp (buf, "\tUNR: bogus unresolved message", 21) == 0)
 
112
    runtest.pass ("Unresolved message");
 
113
  else
 
114
    runtest.fail ("Unresolved message");
 
115
  
 
116
  // Make sure we got everything in the totals.
 
117
  regcomp (&regex_pat,
 
118
           "\r\n\t#passed.*#failed.*#untested.*#unresolved",
 
119
           REG_NOSUB | REG_NEWLINE);
 
120
 
 
121
  if (regexec (&regex_pat, buf, 0, (regmatch_t *) 0, 0))
 
122
    runtest.pass ("Totals message");
 
123
  else
 
124
    runtest.fail ("Totals message");
 
125
 
 
126
  return 0;
115
127
}
116
128
 
117
129