File: eca-test-case.cpp

package info (click to toggle)
ecasound 2.9.3-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 6,292 kB
  • sloc: cpp: 39,475; sh: 4,335; lisp: 1,918; ansic: 1,883; makefile: 888; python: 617; ruby: 202
file content (130 lines) | stat: -rw-r--r-- 2,993 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// ------------------------------------------------------------------------
// eca-test-case.cpp: Abstract interface for implementing 
//                    test cases for component testing.
// Copyright (C) 2002,2009 Kai Vehmanen
//
// Attributes:
//     eca-style-version: 3 (see Ecasound Programmer's Guide)
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
// ------------------------------------------------------------------------

#include <iostream>
#include "kvu_numtostr.h"
#include "kvu_dbc.h"

#include "eca-test-case.h"

using namespace std;

ECA_TEST_CASE::ECA_TEST_CASE(void)
{
  success_rep = false;
}

ECA_TEST_CASE::~ECA_TEST_CASE(void)
{
}

void ECA_TEST_CASE::run_common_before(void)
{
  failures_rep.clear();
  success_rep = false;
  DBC_CHECK(failures_rep.size() == 0);
}

void ECA_TEST_CASE::run_common_after(void)
{
  if (failures_rep.size() > 0) {
    success_rep = false;
  }
  else {
    success_rep = true;
  }
}

/**
 * Runs the test case.
 */
void ECA_TEST_CASE::run(void)
{
  run_common_before();

  /* actual test implemention defined in a subclass */
  do_run();

  run_common_after();
}

/**
 * Runs the test cases passing a name argument.
 */
void ECA_TEST_CASE::run(const std::string &name)
{
  run_common_before();

  /* actual test implemention defined in a subclass */
  do_run(name);

  run_common_after();
}

/**
 * Returns the test case name.
 */
string ECA_TEST_CASE::name(void) const
{
  return do_name();
}

/**
 * Whether test was run successfully.
 */
bool ECA_TEST_CASE::success(void) const
{
  return success_rep;
}

/**
 * Returns a list of string describing all
 * failed assertations that occured during
 * testing.
 */
const std::list<std::string>& ECA_TEST_CASE::failures(void) const
{
  return failures_rep;
}

void ECA_TEST_CASE::do_run(const std::string& name)
{
  do_run();
}

/**
 * Reports a failed assertions.
 *
 * @param filename filename where failure occured
 * @param lineno line number 
 * @param description what kind of failure
 *
 * @see ECA_TEST_FAILURE
 */
void ECA_TEST_CASE::report_failure(const string& filename, int lineno, const string& description)
{
  string failure (filename + ":" + kvu_numtostr(lineno) + " " + description);
  cerr << failure << endl;
  failures_rep.push_back(filename + ":" + kvu_numtostr(lineno) + 
			 " " + description);
}