From d226b5726dc8890d9bac71d0e7ddb93359d95184 Mon Sep 17 00:00:00 2001 From: vng Date: Sun, 29 May 2011 20:30:46 +0300 Subject: [PATCH] Fix assertions in Release. Do not catch all exception in main. --- base/base.cpp | 10 ++++++++++ base/base_tests/assert_test.cpp | 20 ++++++++++++++++++++ base/base_tests/base_tests.pro | 1 + qt/main.cpp | 13 +++---------- 4 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 base/base_tests/assert_test.cpp diff --git a/base/base.cpp b/base/base.cpp index d4f88a7bef..9b2f189af1 100644 --- a/base/base.cpp +++ b/base/base.cpp @@ -1,8 +1,11 @@ #include "SRC_FIRST.hpp" #include "assert.hpp" + #include "../std/target_os.hpp" #include "../std/iostream.hpp" + #include +#include #ifdef OMIM_OS_BADA #include @@ -15,10 +18,17 @@ namespace my #ifdef OMIM_OS_BADA AppLog("ASSERT FAILED%s:%d:%s", srcPoint.FileName(), srcPoint.Line(), msg.c_str()); AppAssert(false); + #else std::cerr << "ASSERT FAILED\n" << srcPoint.FileName() << ":" << srcPoint.Line() << "\n" << msg << endl; + +#ifdef DEBUG assert(false); +#else + throw std::exception(msg.c_str()); +#endif + #endif } diff --git a/base/base_tests/assert_test.cpp b/base/base_tests/assert_test.cpp new file mode 100644 index 0000000000..62d650942b --- /dev/null +++ b/base/base_tests/assert_test.cpp @@ -0,0 +1,20 @@ +#include "../../base/SRC_FIRST.hpp" +#include "../../testing/testing.hpp" + +#include "../../base/base.hpp" + +UNIT_TEST(Assert_Smoke) +{ + int x = 5; + ASSERT_EQUAL ( x, 5, () ); + ASSERT_NOT_EQUAL ( x, 6, () ); + //ASSERT_EQUAL ( x, 666, ("Skip this to continue test") ); +} + +UNIT_TEST(Check_Smoke) +{ + int x = 5; + CHECK_EQUAL ( x, 5, () ); + CHECK_NOT_EQUAL ( x, 6, () ); + //CHECK_EQUAL ( x, 666, ("Skip this to continue test") ); +} diff --git a/base/base_tests/base_tests.pro b/base/base_tests/base_tests.pro index 8c66fff5b7..ee58014bfc 100644 --- a/base/base_tests/base_tests.pro +++ b/base/base_tests/base_tests.pro @@ -29,5 +29,6 @@ SOURCES += \ matrix_test.cpp \ commands_queue_test.cpp \ buffer_vector_test.cpp \ + assert_test.cpp \ HEADERS += diff --git a/qt/main.cpp b/qt/main.cpp index 58bbf0c7dc..37486bb498 100644 --- a/qt/main.cpp +++ b/qt/main.cpp @@ -98,21 +98,15 @@ int main(int argc, char *argv[]) eulaAccepted = (eulaDialog.exec() == 1); Settings::Set(SETTING_EULA_ACCEPTED, eulaAccepted); } + int returnCode = -1; - if (eulaAccepted) + if (eulaAccepted) // User has accepted EULA { - // User has accepted EULA qt::MainWindow w; - w.show(); - - try { returnCode = a.exec(); - } catch (std::exception const & e) - { - LOG(LERROR, (e.what())); - } } + // QTBUG: Fix memory leaks. Nobody delete created plugins. //#ifdef OMIM_OS_WINDOWS // QFactoryLoader * arr[] = { imageLoader(), bearerLoader() }; @@ -126,6 +120,5 @@ int main(int argc, char *argv[]) //#endif LOG(LINFO, ("MapsWithMe finished with code : ", returnCode)); - return returnCode; }