Files
comaps/map/mwm_tests/multithread_mwm_test.cpp
Konstantin Pastbin e3e4a1985a Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run:
  git remote add om-historic [om-historic.git repo url]
  git fetch --tags om-historic
  git replace squashed-history historic-commits
2025-05-08 21:10:51 +07:00

99 lines
2.1 KiB
C++

#include "testing/testing.hpp"
#include "map/features_fetcher.hpp"
#include "indexer/scales.hpp"
#include "base/macros.hpp"
#include "base/thread_pool_computational.hpp"
#include <algorithm>
namespace multithread_mwm_test
{
using SourceT = FeaturesFetcher;
class FeaturesLoader
{
public:
explicit FeaturesLoader(SourceT const & src) : m_src(src) {}
void operator()()
{
size_t const kCount = 2000;
for (size_t i = 0; i < kCount; ++i)
{
m2::RectD const r = GetRandomRect();
m_scale = scales::GetScaleLevel(r);
m_src.ForEachFeature(r, [this](FeatureType & ft)
{
ft.ParseHeader2();
(void)ft.GetOuterGeometryStats();
(void)ft.GetOuterTrianglesStats();
// Force load feature. We check asserts here. There is no any other constrains here.
CHECK(!ft.IsEmptyGeometry(m_scale), (ft.GetID()));
}, m_scale);
}
}
private:
// Get random rect inside m_src.
m2::RectD GetRandomRect() const
{
int const count = std::max(1, rand() % 50);
int const x = rand() % count;
int const y = rand() % count;
m2::RectD const r = m_src.GetWorldRect();
double const sizeX = r.SizeX() / count;
double const sizeY = r.SizeY() / count;
double const minX = r.minX() + x * sizeX;
double const minY = r.minY() + y * sizeY;
return m2::RectD(minX, minY, minX + sizeX, minY + sizeY);
}
SourceT const & m_src;
int m_scale = 0;
};
void RunTest(std::string const & file)
{
SourceT src;
src.InitClassificator();
UNUSED_VALUE(src.RegisterMap(platform::LocalCountryFile::MakeForTesting(file)));
// Check that country rect is valid and not infinity.
m2::RectD const r = src.GetWorldRect();
TEST(r.IsValid(), ());
m2::RectD world(mercator::Bounds::FullRect());
world.Inflate(-10.0, -10.0);
TEST(world.IsRectInside(r), ());
srand(666);
size_t const kCount = 20;
base::ComputationalThreadPool pool(kCount);
for (size_t i = 0; i < kCount; ++i)
pool.SubmitWork(FeaturesLoader(src));
pool.WaitingStop();
}
UNIT_TEST(Threading_ForEachFeature)
{
RunTest("minsk-pass");
}
} // namespace multithread_mwm_test