initial load of upstream version 1.06.32
[xmlrpc-c] / src / cpp / test / tools.cpp
1 #include <string>
2 #include <sstream>
3 #include <iostream>
4 #include "xmlrpc-c/girerr.hpp"
5 using girerr::error;
6 using girerr::throwf;
7
8 #include "tools.hpp"
9
10 using namespace std;
11
12 testSuite::~testSuite() {
13 }
14
15
16
17 void
18 testSuite::run(unsigned int const indentation) {
19     try {
20         cout << string(indentation*2, ' ') 
21              << "Running " << suiteName() << endl;
22         this->runtests(indentation);
23     } catch (error const& error) {
24         throwf("%s failed.  %s", suiteName().c_str(), error.what());
25     } catch (...) {
26         throw(error(suiteName() + string(" failed.  ") +
27                     string("It threw an unexpected type of object")));
28     }
29     cout << string(indentation*2, ' ') 
30          << suiteName() << " tests passed." << endl;
31 }
32
33
34
35 // This is a good place to set a breakpoint.
36 void 
37 logFailedTest(const char * const fileName, 
38               unsigned int const lineNum, 
39               const char * const statement) {
40
41     ostringstream msg;
42
43     msg << endl
44         << fileName << ":" << lineNum 
45         << ": expected (" << statement << ")" << endl;
46
47     throw(error(msg.str()));
48 }
49
50
51 error
52 fileLineError(string       const filename,
53               unsigned int const lineNumber,
54               string       const description) {
55     
56     ostringstream combined;
57     
58     combined << filename << ":" << lineNumber << " " << description;
59     
60     return error(combined.str());
61 }
62
63
64