Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Pimenov <m@maps.me>2018-09-14 21:08:09 +0300
committerVlad Mihaylenko <vxmihaylenko@gmail.com>2018-09-18 14:46:56 +0300
commit412387c84eefba2ec4c267ee2748bf78f03ce327 (patch)
tree8d79b6b480fb91a5458a21aec10ac689de54db9f /testing
parentbef147b46fb8fd5160fc8e3b13f3548906ae5ef7 (diff)
[base] Replaced the namespace my with base.
Diffstat (limited to 'testing')
-rw-r--r--testing/benchmark.hpp29
-rw-r--r--testing/testing.hpp324
-rw-r--r--testing/testingmain.cpp6
-rw-r--r--testing/testregister.hpp1
4 files changed, 183 insertions, 177 deletions
diff --git a/testing/benchmark.hpp b/testing/benchmark.hpp
index dea7407714..f4a1018cf0 100644
--- a/testing/benchmark.hpp
+++ b/testing/benchmark.hpp
@@ -1,10 +1,13 @@
#pragma once
+
#include "testing/testing.hpp"
#include "testing/testregister.hpp"
+
#include "base/timer.hpp"
-#include "std/iostream.hpp"
-namespace my
+#include <iostream>
+
+namespace base
{
class BenchmarkNTimes
{
@@ -19,24 +22,24 @@ namespace my
double const secondsElapsed = m_Timer.ElapsedSeconds();
TEST_GREATER(m_RepeatCount, 0, ());
TEST_LESS_OR_EQUAL(secondsElapsed, m_MaxSecondsToSucceed, (m_RepeatCount));
- cout << secondsElapsed << "s total";
+ std::cout << secondsElapsed << "s total";
if (secondsElapsed > 0)
{
- cout << ", " << static_cast<int>(m_RepeatCount / secondsElapsed) << "/s, ";
+ std::cout << ", " << static_cast<int>(m_RepeatCount / secondsElapsed) << "/s, ";
/*
if (secondsElapsed / m_RepeatCount * 1000 >= 10)
- cout << static_cast<int>(secondsElapsed / m_RepeatCount * 1000) << "ms each";
+ std::cout << static_cast<int>(secondsElapsed / m_RepeatCount * 1000) << "ms each";
else */ if (secondsElapsed / m_RepeatCount * 1000000 >= 10)
- cout << static_cast<int>(secondsElapsed / m_RepeatCount * 1000000) << "us each";
+ std::cout << static_cast<int>(secondsElapsed / m_RepeatCount * 1000000) << "us each";
else
- cout << static_cast<int>(secondsElapsed / m_RepeatCount * 1000000000) << "ns each";
+ std::cout << static_cast<int>(secondsElapsed / m_RepeatCount * 1000000000) << "ns each";
}
- cout << " ...";
+ std::cout << " ...";
}
- inline int Iteration() const { return m_Iteration; }
- inline bool ContinueIterating() const { return m_Iteration < m_RepeatCount; }
- inline void NextIteration() { ++m_Iteration; }
+ int Iteration() const { return m_Iteration; }
+ bool ContinueIterating() const { return m_Iteration < m_RepeatCount; }
+ void NextIteration() { ++m_Iteration; }
private:
int const m_RepeatCount;
@@ -44,7 +47,7 @@ namespace my
int m_Iteration;
Timer m_Timer;
};
-}
+} // namespace base
#define BENCHMARK_TEST(name) \
void Benchmark_##name(); \
@@ -52,5 +55,5 @@ namespace my
void Benchmark_##name()
#define BENCHMARK_N_TIMES(times, maxTimeToSucceed) \
- for (::my::BenchmarkNTimes benchmark(times, maxTimeToSucceed); \
+ for (::base::BenchmarkNTimes benchmark(times, maxTimeToSucceed); \
benchmark.ContinueIterating(); benchmark.NextIteration())
diff --git a/testing/testing.hpp b/testing/testing.hpp
index 8d9d404c00..d0347d4ae9 100644
--- a/testing/testing.hpp
+++ b/testing/testing.hpp
@@ -1,4 +1,5 @@
#pragma once
+
#include "testing/testregister.hpp"
#include "base/exception.hpp"
@@ -6,39 +7,37 @@
#include "base/math.hpp"
#include "base/src_point.hpp"
-#include "std/iostream.hpp"
-#include "std/string.hpp"
-
-
-#define UNIT_TEST(name) \
- void UnitTest_##name(); \
- TestRegister g_TestRegister_##name(#name, __FILE__, &UnitTest_##name); \
- void UnitTest_##name()
-
-#define UNIT_CLASS_TEST(CLASS, NAME) \
- struct UnitClass_##CLASS##_##NAME : public CLASS \
- { \
- public: \
- void NAME(); \
- }; \
- UNIT_TEST(CLASS##_##NAME) \
- { \
- UnitClass_##CLASS##_##NAME instance; \
- instance.NAME(); \
- } \
+#include <string>
+
+#define UNIT_TEST(name) \
+ void UnitTest_##name(); \
+ TestRegister g_TestRegister_##name(#name, __FILE__, &UnitTest_##name); \
+ void UnitTest_##name()
+
+#define UNIT_CLASS_TEST(CLASS, NAME) \
+ struct UnitClass_##CLASS##_##NAME : public CLASS \
+ { \
+ public: \
+ void NAME(); \
+ }; \
+ UNIT_TEST(CLASS##_##NAME) \
+ { \
+ UnitClass_##CLASS##_##NAME instance; \
+ instance.NAME(); \
+ } \
void UnitClass_##CLASS##_##NAME::NAME()
DECLARE_EXCEPTION(TestFailureException, RootException);
-namespace my
+namespace base
{
- inline void OnTestFailed(SrcPoint const & srcPoint, string const & msg)
- {
- LOG(LINFO, ("FAILED"));
- LOG(LINFO, (::DebugPrint(srcPoint.FileName()) + ":" + ::DebugPrint(srcPoint.Line()), msg));
- MYTHROW(TestFailureException, (srcPoint.FileName(), srcPoint.Line(), msg));
- }
+inline void OnTestFailed(SrcPoint const & srcPoint, std::string const & msg)
+{
+ LOG(LINFO, ("FAILED"));
+ LOG(LINFO, (::DebugPrint(srcPoint.FileName()) + ":" + ::DebugPrint(srcPoint.Line()), msg));
+ MYTHROW(TestFailureException, (srcPoint.FileName(), srcPoint.Line(), msg));
}
+} // namespace base
namespace testing
{
@@ -53,8 +52,11 @@ void Notify();
struct CommandLineOptions
{
CommandLineOptions()
- : m_filterRegExp(nullptr), m_suppressRegExp(nullptr),
- m_dataPath(nullptr), m_resourcePath(nullptr), m_help(false)
+ : m_filterRegExp(nullptr)
+ , m_suppressRegExp(nullptr)
+ , m_dataPath(nullptr)
+ , m_resourcePath(nullptr)
+ , m_help(false)
{
}
@@ -68,171 +70,173 @@ struct CommandLineOptions
};
CommandLineOptions const & GetTestingOptions();
-#define TEST(X, msg) \
- do \
- { \
- if (X) \
- { \
- } \
- else \
- { \
- ::my::OnTestFailed(SRC(), ::my::impl::Message("TEST(" #X ")", ::my::impl::Message msg)); \
- } \
+#define TEST(X, msg) \
+ do \
+ { \
+ if (X) \
+ { \
+ } \
+ else \
+ { \
+ ::base::OnTestFailed(SRC(), ::base::Message("TEST(" #X ")", ::base::Message msg)); \
+ } \
} while (0)
-#define TEST_EQUAL(X, Y, msg) \
- do \
- { \
- if ((X) == (Y)) \
- { \
- } \
- else \
- { \
- ::my::OnTestFailed(SRC(), \
- ::my::impl::Message("TEST(" #X " == " #Y ")", ::my::impl::Message(X, Y), \
- ::my::impl::Message msg)); \
- } \
- } while (0)
-#define TEST_NOT_EQUAL(X, Y, msg) \
- do \
- { \
- if ((X) != (Y)) \
- { \
- } \
- else \
- { \
- ::my::OnTestFailed(SRC(), \
- ::my::impl::Message("TEST(" #X " != " #Y ")", ::my::impl::Message(X, Y), \
- ::my::impl::Message msg)); \
- } \
+
+#define TEST_EQUAL(X, Y, msg) \
+ do \
+ { \
+ if ((X) == (Y)) \
+ { \
+ } \
+ else \
+ { \
+ ::base::OnTestFailed(SRC(), ::base::Message("TEST(" #X " == " #Y ")", ::base::Message(X, Y), \
+ ::base::Message msg)); \
+ } \
} while (0)
-#define TEST_LESS(X, Y, msg) \
- do \
- { \
- if ((X) < (Y)) \
- { \
- } \
- else \
- { \
- ::my::OnTestFailed(SRC(), \
- ::my::impl::Message("TEST(" #X " < " #Y ")", ::my::impl::Message(X, Y), \
- ::my::impl::Message msg)); \
- } \
+
+#define TEST_NOT_EQUAL(X, Y, msg) \
+ do \
+ { \
+ if ((X) != (Y)) \
+ { \
+ } \
+ else \
+ { \
+ ::base::OnTestFailed(SRC(), ::base::Message("TEST(" #X " != " #Y ")", ::base::Message(X, Y), \
+ ::base::Message msg)); \
+ } \
} while (0)
-#define TEST_LESS_OR_EQUAL(X, Y, msg) \
+
+#define TEST_LESS(X, Y, msg) \
do \
{ \
- if ((X) <= (Y)) \
+ if ((X) < (Y)) \
{ \
} \
else \
{ \
- ::my::OnTestFailed(SRC(), \
- ::my::impl::Message("TEST(" #X " <= " #Y ")", ::my::impl::Message(X, Y), \
- ::my::impl::Message msg)); \
+ ::base::OnTestFailed(SRC(), ::base::Message("TEST(" #X " < " #Y ")", ::base::Message(X, Y), \
+ ::base::Message msg)); \
} \
} while (0)
-#define TEST_GREATER(X, Y, msg) \
- do \
- { \
- if ((X) > (Y)) \
- { \
- } \
- else \
- { \
- ::my::OnTestFailed(SRC(), \
- ::my::impl::Message("TEST(" #X " > " #Y ")", ::my::impl::Message(X, Y), \
- ::my::impl::Message msg)); \
- } \
+
+#define TEST_LESS_OR_EQUAL(X, Y, msg) \
+ do \
+ { \
+ if ((X) <= (Y)) \
+ { \
+ } \
+ else \
+ { \
+ ::base::OnTestFailed(SRC(), ::base::Message("TEST(" #X " <= " #Y ")", ::base::Message(X, Y), \
+ ::base::Message msg)); \
+ } \
} while (0)
-#define TEST_GREATER_OR_EQUAL(X, Y, msg) \
+
+#define TEST_GREATER(X, Y, msg) \
do \
{ \
- if ((X) >= (Y)) \
+ if ((X) > (Y)) \
{ \
} \
else \
{ \
- ::my::OnTestFailed(SRC(), \
- ::my::impl::Message("TEST(" #X " >= " #Y ")", ::my::impl::Message(X, Y), \
- ::my::impl::Message msg)); \
+ ::base::OnTestFailed(SRC(), ::base::Message("TEST(" #X " > " #Y ")", ::base::Message(X, Y), \
+ ::base::Message msg)); \
} \
} while (0)
-#define TEST_ALMOST_EQUAL_ULPS(X, Y, msg) \
- do \
- { \
- if (::my::AlmostEqualULPs(X, Y)) \
- { \
- } \
- else \
- { \
- ::my::OnTestFailed(SRC(), \
- ::my::impl::Message("TEST(my::AlmostEqualULPs(" #X ", " #Y ")", \
- ::my::impl::Message(X, Y), ::my::impl::Message msg)); \
- } \
- } while (0)
-#define TEST_NOT_ALMOST_EQUAL_ULPS(X, Y, msg) \
+
+#define TEST_GREATER_OR_EQUAL(X, Y, msg) \
do \
{ \
- if (!::my::AlmostEqualULPs(X, Y)) \
+ if ((X) >= (Y)) \
{ \
} \
else \
{ \
- ::my::OnTestFailed(SRC(), \
- ::my::impl::Message("TEST(!my::AlmostEqualULPs(" #X ", " #Y ")", \
- ::my::impl::Message(X, Y), ::my::impl::Message msg)); \
+ ::base::OnTestFailed(SRC(), ::base::Message("TEST(" #X " >= " #Y ")", ::base::Message(X, Y), \
+ ::base::Message msg)); \
} \
} while (0)
-// TODO(AlexZ): Add more cool macroses (or switch all unit tests to gtest).
-#define TEST_THROW(X, exception, msg) \
- do \
- { \
- bool expected_exception = false; \
- try \
- { \
- X; \
- } \
- catch (exception const &) \
- { \
- expected_exception = true; \
- } \
- catch (...) \
- { \
- ::my::OnTestFailed(SRC(), ::my::impl::Message("Unexpected exception at TEST(" #X ")", \
- ::my::impl::Message msg)); \
- } \
- if (!expected_exception) \
- ::my::OnTestFailed(SRC(), ::my::impl::Message("Expected exception " #exception \
- " was not thrown in TEST(" #X ")", \
- ::my::impl::Message msg)); \
- } while (0)
-#define TEST_NO_THROW(X, msg) \
- do \
- { \
- try \
- { \
- X; \
- } \
- catch (...) \
- { \
- ::my::OnTestFailed(SRC(), ::my::impl::Message("Unexpected exception at TEST(" #X ")", \
- ::my::impl::Message msg)); \
- } \
+#define TEST_ALMOST_EQUAL_ULPS(X, Y, msg) \
+ do \
+ { \
+ if (::base::AlmostEqualULPs(X, Y)) \
+ { \
+ } \
+ else \
+ { \
+ ::base::OnTestFailed(SRC(), ::base::Message("TEST(base::AlmostEqualULPs(" #X ", " #Y ")", \
+ ::base::Message(X, Y), ::base::Message msg)); \
+ } \
} while (0)
-#define TEST_ANY_THROW(X, msg) \
+
+#define TEST_NOT_ALMOST_EQUAL_ULPS(X, Y, msg) \
do \
{ \
- bool was_exception = false; \
- try \
+ if (!::base::AlmostEqualULPs(X, Y)) \
{ \
- X; \
} \
- catch (...) \
+ else \
{ \
- was_exception = true; \
+ ::base::OnTestFailed(SRC(), ::base::Message("TEST(!base::AlmostEqualULPs(" #X ", " #Y ")", \
+ ::base::Message(X, Y), ::base::Message msg)); \
} \
- if (!was_exception) \
- ::my::OnTestFailed(SRC(), ::my::impl::Message("No exceptions were thrown in TEST(" #X ")", \
- ::my::impl::Message msg)); \
+ } while (0)
+
+// TODO(AlexZ): Add more cool macroses (or switch all unit tests to gtest).
+#define TEST_THROW(X, exception, msg) \
+ do \
+ { \
+ bool expected_exception = false; \
+ try \
+ { \
+ X; \
+ } \
+ catch (exception const &) \
+ { \
+ expected_exception = true; \
+ } \
+ catch (...) \
+ { \
+ ::base::OnTestFailed( \
+ SRC(), ::base::Message("Unexpected exception at TEST(" #X ")", ::base::Message msg)); \
+ } \
+ if (!expected_exception) \
+ ::base::OnTestFailed(SRC(), ::base::Message("Expected exception " #exception \
+ " was not thrown in TEST(" #X ")", \
+ ::base::Message msg)); \
+ } while (0)
+
+#define TEST_NO_THROW(X, msg) \
+ do \
+ { \
+ try \
+ { \
+ X; \
+ } \
+ catch (...) \
+ { \
+ ::base::OnTestFailed( \
+ SRC(), ::base::Message("Unexpected exception at TEST(" #X ")", ::base::Message msg)); \
+ } \
+ } while (0)
+
+#define TEST_ANY_THROW(X, msg) \
+ do \
+ { \
+ bool was_exception = false; \
+ try \
+ { \
+ X; \
+ } \
+ catch (...) \
+ { \
+ was_exception = true; \
+ } \
+ if (!was_exception) \
+ ::base::OnTestFailed(SRC(), ::base::Message("No exceptions were thrown in TEST(" #X ")", \
+ ::base::Message msg)); \
} while (0)
diff --git a/testing/testingmain.cpp b/testing/testingmain.cpp
index 35d1a24348..309f74d4f4 100644
--- a/testing/testingmain.cpp
+++ b/testing/testingmain.cpp
@@ -153,9 +153,9 @@ int main(int argc, char * argv[])
UNUSED_VALUE(argv);
#endif
- my::ScopedLogLevelChanger const infoLogLevel(LINFO);
+ base::ScopedLogLevelChanger const infoLogLevel(LINFO);
#if defined(OMIM_OS_MAC) || defined(OMIM_OS_LINUX) || defined(OMIM_OS_IPHONE)
- my::SetLogMessageFn(my::LogMessageTests);
+ base::SetLogMessageFn(base::LogMessageTests);
#endif
vector<string> testNames;
@@ -231,7 +231,7 @@ int main(int argc, char * argv[])
return STATUS_BROKEN_FRAMEWORK;
}
- my::HighResTimer timer(true);
+ base::HighResTimer timer(true);
try
{
diff --git a/testing/testregister.hpp b/testing/testregister.hpp
index 0c2ab2351c..1f36498063 100644
--- a/testing/testregister.hpp
+++ b/testing/testregister.hpp
@@ -1,6 +1,5 @@
#pragma once
-
class TestRegister
{
public: