Format all C++ and Java code via clang-format

Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
Konstantin Pastbin
2025-08-17 14:32:37 +07:00
parent 9f0290c0ec
commit bfffa1fff4
2169 changed files with 56441 additions and 64188 deletions

View File

@@ -13,9 +13,10 @@ class BenchmarkNTimes
{
public:
BenchmarkNTimes(int repeatCount, double maxSecondsToSucceed)
: m_repeatCount(repeatCount), m_maxSecondsToSucceed(maxSecondsToSucceed), m_iteration(0)
{
}
: m_repeatCount(repeatCount)
, m_maxSecondsToSucceed(maxSecondsToSucceed)
, m_iteration(0)
{}
~BenchmarkNTimes()
{
@@ -29,7 +30,8 @@ public:
/*
if (secondsElapsed / m_repeatCount * 1000 >= 10)
std::cout << static_cast<int>(secondsElapsed / m_repeatCount * 1000) << "ms each";
else */ if (secondsElapsed / m_repeatCount * 1000000 >= 10)
else */
if (secondsElapsed / m_repeatCount * 1000000 >= 10)
std::cout << static_cast<int>(secondsElapsed / m_repeatCount * 1000000) << "us each";
else
std::cout << static_cast<int>(secondsElapsed / m_repeatCount * 1000000000) << "ns each";

View File

@@ -12,8 +12,8 @@
// TestRegister is static to avoid this warning:
// No previous extern declaration for non-static variable 'g_testRegister_TESTNAME'
// note: declare 'static' if the variable is not intended to be used outside of this translation unit
#define UNIT_TEST(name) \
void UnitTest_##name(); \
#define UNIT_TEST(name) \
void UnitTest_##name(); \
static TestRegister g_testRegister_##name(#name, __FILE__, &UnitTest_##name); \
void UnitTest_##name()
@@ -70,189 +70,186 @@ CommandLineOptions const & GetTestingOptions();
do \
{ \
if (X) \
{ \
} \
{} \
else \
{ \
::base::OnTestFailed(SRC(), ::base::Message("TEST(" #X ")", ::base::Message msg)); \
} \
} while (0)
} \
while (0)
#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_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_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_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(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 \
{ \
::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) \
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) \
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(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(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) \
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) \
do \
{ \
if ((X) >= (Y)) \
{} \
else \
{ \
::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 (AlmostEqualULPs(X, Y)) \
{ \
} \
else \
{ \
::base::OnTestFailed(SRC(), ::base::Message("TEST(AlmostEqualULPs(" #X ", " #Y ")", \
::base::Message(X, Y), ::base::Message msg)); \
} \
} while (0)
#define TEST_ALMOST_EQUAL_ULPS(X, Y, msg) \
do \
{ \
if (AlmostEqualULPs(X, Y)) \
{} \
else \
{ \
::base::OnTestFailed( \
SRC(), ::base::Message("TEST(AlmostEqualULPs(" #X ", " #Y ")", ::base::Message(X, Y), ::base::Message msg)); \
} \
} \
while (0)
#define TEST_NOT_ALMOST_EQUAL_ULPS(X, Y, msg) \
do \
{ \
if (!AlmostEqualULPs(X, Y)) \
{ \
} \
else \
{ \
::base::OnTestFailed(SRC(), ::base::Message("TEST(!AlmostEqualULPs(" #X ", " #Y ")", \
::base::Message(X, Y), ::base::Message msg)); \
} \
} while (0)
#define TEST_NOT_ALMOST_EQUAL_ULPS(X, Y, msg) \
do \
{ \
if (!AlmostEqualULPs(X, Y)) \
{} \
else \
{ \
::base::OnTestFailed(SRC(), ::base::Message("TEST(!AlmostEqualULPs(" #X ", " #Y ")", ::base::Message(X, Y), \
::base::Message msg)); \
} \
} \
while (0)
#define TEST_ALMOST_EQUAL_ABS(X, Y, eps, msg) \
do \
{ \
if (AlmostEqualAbs(X, Y, eps)) \
{ \
} \
else \
{ \
::base::OnTestFailed(SRC(), \
::base::Message("TEST(!AlmostEqualAbs(" #X ", " #Y ", " #eps ")", \
::base::Message(X, Y, eps), ::base::Message msg)); \
} \
} while (0)
#define TEST_ALMOST_EQUAL_ABS(X, Y, eps, msg) \
do \
{ \
if (AlmostEqualAbs(X, Y, eps)) \
{} \
else \
{ \
::base::OnTestFailed(SRC(), ::base::Message("TEST(!AlmostEqualAbs(" #X ", " #Y ", " #eps ")", \
::base::Message(X, Y, eps), ::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 (std::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_THROW(X, exception, msg) \
do \
{ \
bool expected_exception = false; \
try \
{ \
X; \
} \
catch (std::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 (RootException const & ex) \
{ \
::base::OnTestFailed(SRC(), \
::base::Message("Unexpected exception at TEST(" #X ")", \
::base::Message(ex.Msg()), ::base::Message msg)); \
} \
catch (...) \
{ \
::base::OnTestFailed( \
SRC(), ::base::Message("Unexpected exception at TEST(" #X ")", ::base::Message msg)); \
} \
} while (0)
#define TEST_NO_THROW(X, msg) \
do \
{ \
try \
{ \
X; \
} \
catch (RootException const & ex) \
{ \
::base::OnTestFailed(SRC(), ::base::Message("Unexpected exception at TEST(" #X ")", ::base::Message(ex.Msg()), \
::base::Message msg)); \
} \
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)
#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)

View File

@@ -17,27 +17,27 @@
#include <vector>
#ifdef WITH_GL_MOCK
# include "base/scope_guard.hpp"
# include "drape/drape_tests/gl_mock_functions.hpp"
#include "base/scope_guard.hpp"
#include "drape/drape_tests/gl_mock_functions.hpp"
#endif
#ifdef OMIM_OS_IPHONE
# include <CoreFoundation/CoreFoundation.h>
#include <CoreFoundation/CoreFoundation.h>
#endif
#ifndef OMIM_UNIT_TEST_DISABLE_PLATFORM_INIT
# include "platform/platform.hpp"
#include "platform/platform.hpp"
#endif
#if defined(OMIM_UNIT_TEST_WITH_QT_EVENT_LOOP) && !defined(OMIM_OS_IPHONE)
#include <QtCore/Qt>
#ifdef OMIM_OS_MAC // on Mac OS X native run loop works only for QApplication :(
#include <QtWidgets/QApplication>
#define QAPP QApplication
#else
#include <QtCore/QCoreApplication>
#define QAPP QCoreApplication
#endif
#include <QtCore/Qt>
#ifdef OMIM_OS_MAC // on Mac OS X native run loop works only for QApplication :(
#include <QtWidgets/QApplication>
#define QAPP QApplication
#else
#include <QtCore/QCoreApplication>
#define QAPP QCoreApplication
#endif
#endif
namespace testing
@@ -50,7 +50,7 @@ void RunEventLoop()
{
#if defined(OMIM_OS_IPHONE)
CFRunLoopRun();
#elif defined (QAPP)
#elif defined(QAPP)
QAPP::exec();
#endif
}
@@ -100,18 +100,15 @@ void DisplayOption(ostream & os, char const * option, char const * description)
void DisplayOption(ostream & os, char const * option, char const * value, char const * description)
{
os << " " << setw(kOptionFieldWidth) << left << (string(option) + value) << " "
<< description << '\n';
os << " " << setw(kOptionFieldWidth) << left << (string(option) + value) << " " << description << '\n';
}
void Usage(char const * name)
{
cerr << "USAGE: " << name << " [options]\n\n";
cerr << "OPTIONS:\n";
DisplayOption(cerr, kFilterOption, "<ECMA Regexp>",
"Run tests with names corresponding to regexp.");
DisplayOption(cerr, kSuppressOption, "<ECMA Regexp>",
"Do not run tests with names corresponding to regexp.");
DisplayOption(cerr, kFilterOption, "<ECMA Regexp>", "Run tests with names corresponding to regexp.");
DisplayOption(cerr, kSuppressOption, "<ECMA Regexp>", "Do not run tests with names corresponding to regexp.");
DisplayOption(cerr, kDataPathOptions, "<Path>", "Path to data files.");
DisplayOption(cerr, kResourcePathOptions, "<Path>", "Path to resources, styles and classificators.");
DisplayOption(cerr, kListAllTestsOption, "List all the tests in the test suite and exit.");
@@ -215,19 +212,13 @@ int main(int argc, char * argv[])
}
int testIndex = 0;
for (TestRegister *test = TestRegister::FirstRegister(); test; ++testIndex, test = test->m_next)
for (TestRegister * test = TestRegister::FirstRegister(); test; ++testIndex, test = test->m_next)
{
auto const & testname = testnames[testIndex];
if (g_testingOptions.m_filterRegExp &&
!regex_search(testname.begin(), testname.end(), filterRegExp))
{
if (g_testingOptions.m_filterRegExp && !regex_search(testname.begin(), testname.end(), filterRegExp))
continue;
}
if (g_testingOptions.m_suppressRegExp &&
regex_search(testname.begin(), testname.end(), suppressRegExp))
{
if (g_testingOptions.m_suppressRegExp && regex_search(testname.begin(), testname.end(), suppressRegExp))
continue;
}
LOG(LINFO, ("Running", testname));
if (!g_lastTestOK)
@@ -257,7 +248,7 @@ int main(int argc, char * argv[])
++numFailedTests;
}
}
catch (TestFailureException const & )
catch (TestFailureException const &)
{
testResults[testIndex] = false;
++numFailedTests;
@@ -284,10 +275,8 @@ int main(int argc, char * argv[])
{
LOG(LINFO, (numFailedTests, " tests failed:"));
for (size_t i = 0; i < testnames.size(); ++i)
{
if (!testResults[i])
LOG(LINFO, (testnames[i]));
}
LOG(LINFO, ("Some tests FAILED."));
return STATUS_FAILED;
}
@@ -297,4 +286,7 @@ int main(int argc, char * argv[])
}
} // namespace testing
int main(int argc, char * argv[]) { return ::testing::main(argc, argv); }
int main(int argc, char * argv[])
{
return ::testing::main(argc, argv);
}

View File

@@ -7,7 +7,10 @@ class TestRegister
{
public:
TestRegister(char const * testname, char const * filename, std::function<void()> && fnTest)
: m_testname(testname), m_filename(filename), m_fn(std::move(fnTest)), m_next(nullptr)
: m_testname(testname)
, m_filename(filename)
, m_fn(std::move(fnTest))
, m_next(nullptr)
{
if (FirstRegister() == nullptr)
{