aboutsummaryrefslogtreecommitdiffstats
path: root/tests/testRunner.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/testRunner.cpp')
-rw-r--r--tests/testRunner.cpp139
1 files changed, 74 insertions, 65 deletions
diff --git a/tests/testRunner.cpp b/tests/testRunner.cpp
index 08a06930..f1f13b25 100644
--- a/tests/testRunner.cpp
+++ b/tests/testRunner.cpp
@@ -1,6 +1,6 @@
//
// VMime library (http://www.vmime.org)
-// Copyright (C) 2002-2013 Vincent Richard <[email protected]>
+// Copyright (C) 2002 Vincent Richard <[email protected]>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
@@ -45,19 +45,19 @@
#include "vmime/platforms/posix/posixHandler.hpp"
-class Clock
-{
+class Clock {
+
public:
- void reset()
- {
+ void reset() {
+
struct timezone tz;
gettimeofday(&m_start, &tz);
}
- double getDuration() const
- {
+ double getDuration() const {
+
struct timeval tv;
struct timezone tz;
@@ -73,18 +73,19 @@ private:
};
-class XmlTestListener : public CppUnit::TestListener
-{
+class XmlTestListener : public CppUnit::TestListener {
+
public:
XmlTestListener()
- : m_doc("utf-8"), m_testElt(NULL)
- {
+ : m_doc("utf-8"),
+ m_testElt(NULL) {
+
m_doc.setRootElement(new CppUnit::XmlElement("TestRun"));
}
- void startTest(CppUnit::Test* test)
- {
+ void startTest(CppUnit::Test* test) {
+
m_testElt = new CppUnit::XmlElement("Test");
m_suiteElt.back()->addElement(m_testElt);
@@ -93,16 +94,17 @@ public:
m_chrono.reset();
}
- void addFailure(const CppUnit::TestFailure& failure)
- {
+ void addFailure(const CppUnit::TestFailure& failure) {
+
CppUnit::XmlElement* failElt = new CppUnit::XmlElement("Failure");
m_testElt->addElement(failElt);
- failElt->addElement(new CppUnit::XmlElement("FailureType",
- failure.isError() ? "Error" : "Assertion"));
+ failElt->addElement(
+ new CppUnit::XmlElement("FailureType", failure.isError() ? "Error" : "Assertion")
+ );
+
+ if (failure.sourceLine().isValid()) {
- if (failure.sourceLine().isValid())
- {
CppUnit::XmlElement* locElt = new CppUnit::XmlElement("Location");
failElt->addElement(locElt);
@@ -116,8 +118,8 @@ public:
exElt->addElement(new CppUnit::XmlElement("Message", failure.thrownException()->what()));
}
- void endTest(CppUnit::Test* /* test */)
- {
+ void endTest(CppUnit::Test* /* test */) {
+
std::ostringstream ossTime;
ossTime << (m_chrono.getDuration() * 1000.0);
@@ -126,39 +128,42 @@ public:
m_testElt = NULL;
}
- void startSuite(CppUnit::Test* suite)
- {
- if (suite->getName() == "All Tests")
+ void startSuite(CppUnit::Test* suite) {
+
+ if (suite->getName() == "All Tests") {
return;
+ }
CppUnit::XmlElement* suiteElt = new CppUnit::XmlElement("Suite");
- if (m_suiteElt.size() == 0)
+ if (m_suiteElt.size() == 0) {
m_doc.rootElement().addElement(suiteElt);
- else
+ } else {
m_suiteElt.back()->addElement(suiteElt);
+ }
m_suiteElt.push_back(suiteElt);
suiteElt->addElement(new CppUnit::XmlElement("Name", suite->getName()));
}
- void endSuite(CppUnit::Test* /* suite */)
- {
- if (m_suiteElt.size())
+ void endSuite(CppUnit::Test* /* suite */) {
+
+ if (m_suiteElt.size()) {
m_suiteElt.pop_back();
+ }
}
- void startTestRun(CppUnit::Test* /* test */, CppUnit::TestResult* /* eventManager */)
- {
+ void startTestRun(CppUnit::Test* /* test */, CppUnit::TestResult* /* eventManager */) {
+
}
- void endTestRun(CppUnit::Test* /* test */, CppUnit::TestResult* /* eventManager */)
- {
+ void endTestRun(CppUnit::Test* /* test */, CppUnit::TestResult* /* eventManager */) {
+
}
- void output(std::ostream& os)
- {
+ void output(std::ostream& os) {
+
os << m_doc.toString();
}
@@ -175,43 +180,46 @@ private:
// see testUtils.hpp
-std::vector <std::string>& getTestModules()
-{
+std::vector <std::string>& getTestModules() {
+
static std::vector <std::string> allModules;
return allModules;
}
-void registerTestModule(const char* name_)
-{
+void registerTestModule(const char* name_) {
+
std::vector <std::string>& testModules = getTestModules();
std::string name(name_);
- if (std::find(testModules.begin(), testModules.end(), name) == testModules.end())
+ if (std::find(testModules.begin(), testModules.end(), name) == testModules.end()) {
testModules.push_back(name);
+ }
}
-const std::string getNormalizedPath(const std::string& path)
-{
+const std::string getNormalizedPath(const std::string& path) {
+
std::string res = path;
- for (std::size_t i = 0, n = res.length() ; i < n ; ++i)
- {
- if (res[i] == '\\')
+ for (std::size_t i = 0, n = res.length() ; i < n ; ++i) {
+
+ if (res[i] == '\\') {
res[i] = '/';
+ }
}
return res;
}
-const std::string getFileNameFromPath(const std::string& path)
-{
+const std::string getFileNameFromPath(const std::string& path) {
+
const std::size_t pos = path.find_last_of('/');
- if (pos == std::string::npos)
+ if (pos == std::string::npos) {
return "";
+ }
return path.substr(pos + 1);
}
@@ -220,8 +228,8 @@ const std::string getFileNameFromPath(const std::string& path)
static char g_moduleNameBuffer[2048];
-const char* getTestModuleNameFromSourceFile(const char *path_)
-{
+const char* getTestModuleNameFromSourceFile(const char *path_) {
+
static const std::string testRunnerPath(getNormalizedPath(__FILE__));
static const std::string testRunnerFileName(getFileNameFromPath(testRunnerPath));
@@ -244,29 +252,31 @@ const char* getTestModuleNameFromSourceFile(const char *path_)
}
-int main(int argc, char* argv[])
-{
+int main(int argc, char* argv[]) {
+
// Parse arguments
bool xmlOutput = false;
- for (int c = 1 ; c < argc ; ++c)
- {
+ for (int c = 1 ; c < argc ; ++c) {
+
const std::string arg = argv[c];
- if (arg == "--xml")
+ if (arg == "--xml") {
xmlOutput = true;
+ }
}
// Run the tests
- if (xmlOutput)
- {
+ if (xmlOutput) {
+
// Get the test suites from the registry and add them to the list of tests to run
CppUnit::TestRunner runner;
- for (unsigned int i = 0 ; i < getTestModules().size() ; ++i)
- {
- runner.addTest(CppUnit::TestFactoryRegistry::
- getRegistry(getTestModules()[i]).makeTest());
+ for (unsigned int i = 0 ; i < getTestModules().size() ; ++i) {
+
+ runner.addTest(
+ CppUnit::TestFactoryRegistry::getRegistry(getTestModules()[i]).makeTest()
+ );
}
XmlTestListener xmlListener;
@@ -283,9 +293,9 @@ int main(int argc, char* argv[])
// Return error code 1 if a test failed
return result.wasSuccessful() ? 0 : 1;
- }
- else
- {
+
+ } else {
+
// Get the top level suite from the registry
CppUnit::TextUi::TestRunner runner;
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
@@ -293,4 +303,3 @@ int main(int argc, char* argv[])
return runner.run() ? 0 : 1;
}
}
-