Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[TestExamples] Fixed some bugs.

  • Loading branch information...
commit 82008a43d9f4fd9bd1d6e2a58bcff3ff701ce240 1 parent 9476467
Mikael Kindborg authored
View
50 TestExperiments/MATestExample/Test.cpp
@@ -40,7 +40,6 @@ namespace MATest
void TestListener::expectation(const MAUtil::String& assertionName) {}
void TestListener::timedOut(const MAUtil::String& testCaseName) {}
-
/* ========== Class TestCaseTimeOutListener ========== */
void TestCaseTimeOutListener::setTestCase(TestCase* testCase)
@@ -137,9 +136,8 @@ namespace MATest
TestSuite::TestSuite(const MAUtil::String& name) :
mName(name),
- mCurrentTestCase(0),
- mRunCounter(0),
- mTestCaseDefaultTimeOut(20000) // 20 seconds
+ mCurrentTestCase(-1),
+ mRunCounter(0)
{
}
@@ -153,11 +151,6 @@ namespace MATest
testCase->setSuite(this);
}
- void TestSuite::setTestCaseDefaultTimeout(int ms)
- {
- mTestCaseDefaultTimeOut = ms;
- }
-
// TODO: Why is this commented out?
// This code seems to run all test cases sequentially.
#if 0
@@ -182,6 +175,15 @@ namespace MATest
}
#endif
+#if(0)
+ // TODO: Should we use this rather than resetting
+ // mCurrentTestCase in runNextCaseHelper()?
+ void TestSuite::reset()
+ {
+ mCurrentTestCase = -1;
+ }
+#endif
+
// Note: This method is called from TestCase::runNextTestCase().
void TestSuite::runNextCase()
{
@@ -222,45 +224,43 @@ namespace MATest
// There must be test cases to run.
if (mTestCases.size() > 0)
{
+ // Increment test case index.
+ mCurrentTestCase ++;
+
// Is this the first test case?
if (0 == mCurrentTestCase)
{
// Signal beginning of the test suite.
fireBeginTestSuite(mName);
}
+ // If this is not the first test case then
+ // signal the end of the previous test case.
+ else
+ {
+ // Close/clear the previous test case.
+ testCase = mTestCases[mCurrentTestCase - 1];
+ testCase->clearTimeOut();
+ testCase->close();
+ fireEndTestCase();
+ }
// If last test case has been run, reset the
// test case index and end the suite.
if (mCurrentTestCase >= mTestCases.size())
{
- mCurrentTestCase = 0;
+ mCurrentTestCase = -1;
fireEndTestSuite();
return;
}
- // If this is not the first test case then
- // signal the end of the previous test case.
- if (mCurrentTestCase > 0)
- {
- // Close/clear the current test case.
- testCase = mTestCases[mCurrentTestCase];
- testCase->clearTimeOut();
- testCase->close();
- fireEndTestCase();
- }
-
// Get the current test case.
testCase = mTestCases[mCurrentTestCase];
- // Increment test case index.
- mCurrentTestCase ++;
-
// Open the current test case.
fireBeginTestCase(testCase->getName());
testCase->open();
// Run current test case.
- testCase->setTimeOut(mTestCaseDefaultTimeOut);
testCase->start();
// Note: We do not call fireEndTestCase() here,
View
16 TestExperiments/MATestExample/Test.h
@@ -259,11 +259,6 @@ namespace MATest
virtual void addTestCase(TestCase* testCase);
/**
- * @brief Set the default timeout for test cases.
- */
- virtual void setTestCaseDefaultTimeout(int ms);
-
- /**
* @brief Run the next test case.
*/
virtual void runNextCase();
@@ -340,13 +335,14 @@ namespace MATest
* @brief Counter that tracks calls to runNextCase.
*/
int mRunCounter;
-
- /**
- * @brief Default value for test case timeout.
- */
- int mTestCaseDefaultTimeOut;
};
} // namespace
#endif
+
+// Include this for backwards compatibility for
+// code that includes Test.h and and uses
+// XMLOutputTestListener (previously this class
+// was declared in Test.h).
+#include "XMLOutputTestListener.h"
View
8 TestExperiments/MATestExample/TestRunner.cpp
@@ -60,11 +60,6 @@ namespace MATest
mSuite.addTestListener(listener);
}
- void TestRunner::setTestCaseDefaultTimeout(int ms)
- {
- mSuite.setTestCaseDefaultTimeout(ms);
- }
-
void TestRunner::runTests()
{
mSuite.runNextCase();
@@ -177,6 +172,7 @@ namespace MATest
const MAUtil::String& testCaseName)
{
mCurrentTestCaseName = testCaseName;
+ //printf("Running testcase: %s\n", testCaseName.c_str());
}
void HighLevelTestListener::endTestCase()
@@ -186,7 +182,7 @@ namespace MATest
// Helper function for removing an entry from the expected list.
void eraseExpected(
- MAUtil::Vector<MAUtil::String> v,
+ MAUtil::Vector<MAUtil::String>& v,
const MAUtil::String& s)
{
for (int i = 0; i < v.size(); ++i)
View
8 TestExperiments/MATestExample/TestRunner.h
@@ -70,11 +70,6 @@ namespace MATest
void addTestListener(MATest::TestListener* listener);
/**
- * @brief Set the default timeout for test cases.
- */
- void setTestCaseDefaultTimeout(int ms);
-
- /**
* @brief Start running tests.
*/
void runTests();
@@ -206,6 +201,9 @@ namespace MATest
/**
* @brief Saves the name of the current test case.
+ * If you override this method, make sure you save
+ * the test case name, call the superclass method
+ * (the method in this class) to do so.
*/
virtual void beginTestCase(const MAUtil::String& testCaseName);
View
2  TestExperiments/MATestExample/Tests/TestDownloader.cpp
@@ -17,6 +17,8 @@ class TestDownloader :
void start()
{
+ setTimeOut(5000);
+
expect("DataDownloaded");
mDownloader.addDownloadListener(this);
Please sign in to comment.
Something went wrong with that request. Please try again.