X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fframework%2Fsrc%2Ftest_runner.cpp;h=726d4342399af1427f86e169e03e1b1692ef27b9;hb=89f2ab1b5f41c27e8b08dd27b4343778a991af0a;hp=b753cdd4ef5c2e62f8476313ea6702f1eb002ed3;hpb=5f8f8f6eb12ee0dce62fc92c46c704459f8e6329;p=platform%2Fcore%2Ftest%2Fsecurity-tests.git diff --git a/src/framework/src/test_runner.cpp b/src/framework/src/test_runner.cpp index b753cdd..726d434 100644 --- a/src/framework/src/test_runner.cpp +++ b/src/framework/src/test_runner.cpp @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* +/** * @file test_runner.cpp * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com) * @author Lukasz Wrzosek (l.wrzosek@samsung.com) @@ -21,6 +21,8 @@ * @brief This file is the implementation file of test runner */ #include +#include +#include #include #include #include @@ -31,9 +33,6 @@ #include #include #include -#include -#include -#include #include #include @@ -59,42 +58,6 @@ std::string getXMLNode(xmlNodePtr node) namespace DPL { namespace Test { -namespace // anonymous -{ -std::string BaseName(std::string aPath) -{ - ScopedFree path(strdup(aPath.c_str())); - if (nullptr == path.Get()) { - throw std::bad_alloc(); - } - char* baseName = basename(path.Get()); - std::string retValue = baseName; - return retValue; -} -} // namespace anonymous - -//! \brief Failed test message creator -//! -//! \param[in] aTest string for tested expression -//! \param[in] aFile source file name -//! \param[in] aLine source file line -//! \param[in] aMessage error message -TestRunner::TestFailed::TestFailed(const char* aTest, - const char* aFile, - int aLine, - const std::string &aMessage) -{ - std::ostringstream assertMsg; - assertMsg << "[" << BaseName(aFile) << ":" << aLine - << "] Assertion failed (" - << aTest << ") " << aMessage; - m_message = assertMsg.str(); -} - -TestRunner::TestFailed::TestFailed(const std::string &message) -{ - m_message = message; -} void TestRunner::RegisterTest(const char *testName, TestCase proc) { @@ -246,6 +209,7 @@ bool TestRunner::filterByXML(std::map & casesMap) void TestRunner::RunTestCase(const TestCaseStruct& testCase) { setCurrentTestCase(&(const_cast(testCase))); + m_deferDeepness = 0U; try { testCase.proc(); } catch (const TestFailed &e) { @@ -256,7 +220,7 @@ void TestRunner::RunTestCase(const TestCaseStruct& testCase) setCurrentTestCase(nullptr); return; - } catch (const Ignored &e) { + } catch (const TestIgnored &e) { if (m_runIgnored) { // Simple test have to be implemented CollectResult(testCase.name, @@ -723,5 +687,60 @@ bool TestRunner::GetAllowChildLogs() return m_allowChildLogs; } +void TestRunner::deferFailedException(const DPL::Test::TestFailed &ex) +{ + if (m_deferDeepness <= 0) + throw ex; + + if (m_deferredExceptionsMessages.empty()) { + m_firstDeferredFail = ex; + m_firstDeferredExceptionType = DeferredExceptionType::DEFERRED_FAILED; + } + m_deferredExceptionsMessages.push_back(ex.GetMessage()); +} + +void TestRunner::deferIgnoredException(const DPL::Test::TestIgnored &ex) +{ + if (m_deferDeepness <= 0) + throw ex; + + if (m_deferredExceptionsMessages.empty()) { + m_firstDeferredIgnore = ex; + m_firstDeferredExceptionType = DeferredExceptionType::DEFERRED_IGNORED; + } + m_deferredExceptionsMessages.push_back(ex.GetMessage()); +} + +void TestRunner::deferBegin() +{ + m_deferDeepness++; +} + +void TestRunner::deferEnd() +{ + if (m_deferDeepness > 0) + m_deferDeepness--; + + if (m_deferDeepness > 0) + return; + + bool oops = std::uncaught_exception(); + size_t additionalExceptions = oops ? 0 : 1; + for (size_t i = additionalExceptions; i < m_deferredExceptionsMessages.size(); ++i) + addFailReason(m_deferredExceptionsMessages[i]); + + if (!oops && !m_deferredExceptionsMessages.empty()) + { + m_deferredExceptionsMessages.clear(); + switch (m_firstDeferredExceptionType) { + case DeferredExceptionType::DEFERRED_FAILED: + throw m_firstDeferredFail; + case DeferredExceptionType::DEFERRED_IGNORED: + throw m_firstDeferredIgnore; + } + } + m_deferredExceptionsMessages.clear(); } + +} // namespace Test } // namespace DPL