From 7962e0a0afdfb34e2823f273ca647c5d6722119f Mon Sep 17 00:00:00 2001 From: Osyotr Date: Fri, 14 Feb 2025 00:33:06 +0300 Subject: [PATCH] Fix some unit tests on Windows Signed-off-by: Osyotr --- base/base_tests/beam_tests.cpp | 2 +- cmake/OmimTesting.cmake | 4 +-- .../generate_tests.cpp | 32 ++++++++++--------- .../fake_map_files_downloader.cpp | 2 ++ testing/testingmain.cpp | 19 +++++++++++ 5 files changed, 41 insertions(+), 18 deletions(-) diff --git a/base/base_tests/beam_tests.cpp b/base/base_tests/beam_tests.cpp index 0cb4705c30..0541c1da01 100644 --- a/base/base_tests/beam_tests.cpp +++ b/base/base_tests/beam_tests.cpp @@ -32,7 +32,7 @@ void Smoke() vector expected; for (size_t i = 0; i < kCapacity; ++i) - expected.emplace_back(kTotal - 1 - i); + expected.emplace_back(static_cast(kTotal - 1 - i)); vector actual; actual.reserve(kCapacity); diff --git a/cmake/OmimTesting.cmake b/cmake/OmimTesting.cmake index 9d8b9f0bbf..19add9b688 100644 --- a/cmake/OmimTesting.cmake +++ b/cmake/OmimTesting.cmake @@ -10,12 +10,12 @@ endif() # TestServer fixture configuration add_test( NAME OmimStartTestServer - COMMAND start_server.py + COMMAND Python3::Interpreter start_server.py WORKING_DIRECTORY ${OMIM_ROOT}/tools/python/test_server ) add_test( NAME OmimStopTestServer - COMMAND stop_server.py + COMMAND Python3::Interpreter stop_server.py WORKING_DIRECTORY ${OMIM_ROOT}/tools/python/test_server ) set_tests_properties(OmimStartTestServer PROPERTIES FIXTURES_SETUP TestServer) diff --git a/search/search_integration_tests/generate_tests.cpp b/search/search_integration_tests/generate_tests.cpp index 369480e7ea..8052ae9ea6 100644 --- a/search/search_integration_tests/generate_tests.cpp +++ b/search/search_integration_tests/generate_tests.cpp @@ -66,25 +66,27 @@ UNIT_CLASS_TEST(GenerateTest, GenerateDeprecatedTypes) MakeFeature(builder, {{"leisure", "playground"}, {"sport", "tennis"}}, {1.0, 1.0}); } - FrozenDataSource dataSource; - TEST_EQUAL(dataSource.Register(file).second, MwmSet::RegResult::Success, ()); + { + FrozenDataSource dataSource; + TEST_EQUAL(dataSource.Register(file).second, MwmSet::RegResult::Success, ()); - // New types. - base::StringIL arr[] = {{"leisure", "dog_park"}, {"leisure", "playground"}, {"sport", "tennis"}}; + // New types. + base::StringIL arr[] = {{"leisure", "dog_park"}, {"leisure", "playground"}, {"sport", "tennis"}}; - Classificator const & cl = classif(); - set types; - for (auto const & s : arr) - types.insert(cl.GetTypeByPath(s)); + Classificator const & cl = classif(); + set types; + for (auto const & s : arr) + types.insert(cl.GetTypeByPath(s)); - int count = 0; - auto const fn = [&](FeatureType & ft) { - ++count; - ft.ForEachType([&](uint32_t t) { TEST(types.count(t) > 0, (cl.GetReadableObjectName(t))); }); - }; - dataSource.ForEachInScale(fn, scales::GetUpperScale()); + int count = 0; + auto const fn = [&](FeatureType & ft) { + ++count; + ft.ForEachType([&](uint32_t t) { TEST(types.count(t) > 0, (cl.GetReadableObjectName(t))); }); + }; + dataSource.ForEachInScale(fn, scales::GetUpperScale()); - TEST_EQUAL(count, 2, ()); + TEST_EQUAL(count, 2, ()); + } file.DeleteFromDisk(MapFileType::Map); } diff --git a/storage/storage_tests/fake_map_files_downloader.cpp b/storage/storage_tests/fake_map_files_downloader.cpp index 2d129d77f3..a6a0dd51d4 100644 --- a/storage/storage_tests/fake_map_files_downloader.cpp +++ b/storage/storage_tests/fake_map_files_downloader.cpp @@ -122,6 +122,8 @@ void FakeMapFilesDownloader::OnFileDownloaded(QueuedCountry const & queuedCountr auto const country = queuedCountry; m_queue.PopFront(); + m_writer.reset(); + m_taskRunner.PostTask([country, status]() { country.OnDownloadFinished(status); }); if (!m_queue.IsEmpty()) diff --git a/testing/testingmain.cpp b/testing/testingmain.cpp index db4f2a6b8f..cee69857e2 100644 --- a/testing/testingmain.cpp +++ b/testing/testingmain.cpp @@ -25,6 +25,10 @@ # include #endif +#ifdef OMIM_OS_WINDOWS +# include +#endif + #ifndef OMIM_UNIT_TEST_DISABLE_PLATFORM_INIT # include "platform/platform.hpp" #endif @@ -164,6 +168,21 @@ int main(int argc, char * argv[]) UNUSED_VALUE(argv); #endif +#if defined(OMIM_OS_WINDOWS) + if (!IsDebuggerPresent()) + { + DWORD const dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX); + SetErrorMode(dwMode | SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); + + _set_error_mode(_OUT_TO_STDERR); + + _set_abort_behavior(0x0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); + + (void)_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); + (void)_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); + } +#endif + base::ScopedLogLevelChanger const infoLogLevel(LINFO); #if defined(OMIM_OS_DESKTOP) || defined(OMIM_OS_IPHONE) base::SetLogMessageFn(base::LogMessageTests);