Repo created
This commit is contained in:
parent
4af19165ec
commit
68073add76
12458 changed files with 12350765 additions and 2 deletions
13
libs/drape_frontend/drape_frontend_tests/CMakeLists.txt
Normal file
13
libs/drape_frontend/drape_frontend_tests/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
project(drape_frontend_tests)
|
||||
|
||||
set(SRC
|
||||
frame_values_tests.cpp
|
||||
navigator_test.cpp
|
||||
path_text_test.cpp
|
||||
stylist_tests.cpp
|
||||
user_event_stream_tests.cpp
|
||||
)
|
||||
|
||||
omim_add_test(${PROJECT_NAME} ${SRC})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} drape_frontend)
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
#include "testing/testing.hpp"
|
||||
|
||||
#include "drape_frontend/frame_values.hpp"
|
||||
|
||||
#include "drape/glsl_types.hpp"
|
||||
|
||||
#include "shaders/program_params.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
glsl::mat4 const kTestMatrix1 =
|
||||
glsl::mat4(1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glsl::mat4 const kTestMatrix2 =
|
||||
glsl::mat4(4.0f, 3.0f, 2.0f, 1.0f, 4.0f, 3.0f, 2.0f, 1.0f, 4.0f, 3.0f, 2.0f, 1.0f, 4.0f, 3.0f, 2.0f, 1.0f);
|
||||
} // namespace
|
||||
|
||||
UNIT_TEST(FrameValues_SetTo)
|
||||
{
|
||||
df::FrameValues frameValues;
|
||||
frameValues.m_pivotTransform = kTestMatrix1;
|
||||
frameValues.m_projection = kTestMatrix2;
|
||||
frameValues.m_zScale = 42.0f;
|
||||
|
||||
gpu::MapProgramParams params;
|
||||
frameValues.SetTo(params);
|
||||
|
||||
TEST(params.m_pivotTransform == frameValues.m_pivotTransform, ());
|
||||
TEST(params.m_projection == frameValues.m_projection, ());
|
||||
TEST(params.m_zScale == frameValues.m_zScale, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(FrameValues_SetTo_Partial)
|
||||
{
|
||||
df::FrameValues frameValues;
|
||||
frameValues.m_pivotTransform = kTestMatrix1;
|
||||
frameValues.m_projection = kTestMatrix2;
|
||||
gpu::RouteProgramParams params;
|
||||
frameValues.SetTo(params);
|
||||
|
||||
TEST(params.m_pivotTransform == frameValues.m_pivotTransform, ());
|
||||
TEST(params.m_projection == frameValues.m_projection, ());
|
||||
}
|
||||
84
libs/drape_frontend/drape_frontend_tests/navigator_test.cpp
Normal file
84
libs/drape_frontend/drape_frontend_tests/navigator_test.cpp
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
#include "testing/testing.hpp"
|
||||
|
||||
#include "drape_frontend/navigator.hpp"
|
||||
#include "drape_frontend/visual_params.hpp"
|
||||
|
||||
#include "geometry/screenbase.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
// -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
||||
//
|
||||
// 7 +-----------------------------------------------+
|
||||
// | |
|
||||
// 6 | |
|
||||
// | |
|
||||
// 5 | |
|
||||
// | |
|
||||
// 4 | +-----------------------+ |
|
||||
// | | | |
|
||||
// 3 | | | |
|
||||
// | | | |
|
||||
// 2 | | | |
|
||||
// | | | |
|
||||
// 1 | | a B<-------b | |
|
||||
// | | | |
|
||||
// 0 | +-----------------------+ |
|
||||
// | |
|
||||
//-1 +-----------------------------------------------+
|
||||
|
||||
UNIT_TEST(Navigator_Scale2Points)
|
||||
{
|
||||
df::VisualParams::Init(1.0, 1024);
|
||||
df::Navigator navigator;
|
||||
|
||||
navigator.OnSize(200, 100);
|
||||
navigator.SetFromRect(m2::AnyRectD(m2::RectD(0, 0, 8, 4)));
|
||||
|
||||
ScreenBase const & screen = navigator.Screen();
|
||||
TEST_EQUAL(screen.ClipRect(), m2::RectD(0, 0, 8, 4), ());
|
||||
|
||||
navigator.StartScale(screen.GtoP(m2::PointD(1, 1)), screen.GtoP(m2::PointD(7, 1)));
|
||||
navigator.StopScale(screen.GtoP(m2::PointD(1, 1)), screen.GtoP(m2::PointD(4, 1)));
|
||||
TEST_EQUAL(screen.ClipRect(), m2::RectD(-1, -1, 15, 7), ());
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
void CheckNavigator(df::Navigator const & nav)
|
||||
{
|
||||
typedef m2::PointD P;
|
||||
m2::RectD clipR = nav.Screen().ClipRect();
|
||||
|
||||
P arr[] = {clipR.LeftTop(), clipR.RightTop(), clipR.RightBottom(), clipR.LeftBottom(), clipR.Center()};
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(arr); ++i)
|
||||
{
|
||||
P const & pxP = arr[i];
|
||||
P const gP = nav.PtoG(pxP);
|
||||
P const pxP2 = nav.GtoP(gP);
|
||||
TEST(AlmostEqualAbs(pxP.x, pxP2.x, 0.00001), (pxP.x, pxP2.x));
|
||||
TEST(AlmostEqualAbs(pxP.y, pxP2.y, 0.00001), (pxP.y, pxP2.y));
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
UNIT_TEST(Navigator_G2P_P2G)
|
||||
{
|
||||
df::VisualParams::Init(1.0, 1024);
|
||||
df::Navigator navigator;
|
||||
|
||||
// Initialize.
|
||||
navigator.OnSize(200, 100);
|
||||
m2::PointD center = navigator.Screen().PixelRect().Center();
|
||||
navigator.SetFromRect(m2::AnyRectD(m2::RectD(0, 0, 8, 4)));
|
||||
TEST_EQUAL(navigator.Screen().ClipRect(), m2::RectD(0, 0, 8, 4), ());
|
||||
|
||||
CheckNavigator(navigator);
|
||||
|
||||
navigator.Scale(center, 3.0);
|
||||
CheckNavigator(navigator);
|
||||
|
||||
navigator.Scale(center, 1 / 3.0);
|
||||
CheckNavigator(navigator);
|
||||
}
|
||||
58
libs/drape_frontend/drape_frontend_tests/path_text_test.cpp
Normal file
58
libs/drape_frontend/drape_frontend_tests/path_text_test.cpp
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#include "testing/testing.hpp"
|
||||
|
||||
#include "drape_frontend/path_text_handle.hpp"
|
||||
#include "drape_frontend/visual_params.hpp"
|
||||
|
||||
#include "base/logging.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
bool IsSmooth(m2::SplineEx const & spline)
|
||||
{
|
||||
for (size_t i = 0, sz = spline.GetDirections().size(); i + 1 < sz; ++i)
|
||||
if (!df::IsValidSplineTurn(spline.GetDirections()[i], spline.GetDirections()[i + 1]))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
UNIT_TEST(Rounding_Spline)
|
||||
{
|
||||
df::VisualParams::Init(1.0, 1024);
|
||||
|
||||
m2::SplineEx spline1;
|
||||
df::AddPointAndRound(spline1, m2::PointD(0, 200));
|
||||
df::AddPointAndRound(spline1, m2::PointD(0, 0));
|
||||
df::AddPointAndRound(spline1, m2::PointD(200, 0));
|
||||
TEST(IsSmooth(spline1), ());
|
||||
TEST(spline1.GetSize() == 8, ());
|
||||
|
||||
m2::SplineEx spline2;
|
||||
df::AddPointAndRound(spline2, m2::PointD(-200, 0));
|
||||
df::AddPointAndRound(spline2, m2::PointD(0, 0));
|
||||
df::AddPointAndRound(spline2, m2::PointD(200, 200));
|
||||
df::AddPointAndRound(spline2, m2::PointD(400, 200));
|
||||
TEST(IsSmooth(spline2), ());
|
||||
TEST(spline2.GetSize() == 8, ());
|
||||
|
||||
m2::SplineEx spline3;
|
||||
df::AddPointAndRound(spline3, m2::PointD(200, 100));
|
||||
df::AddPointAndRound(spline3, m2::PointD(0, 0));
|
||||
df::AddPointAndRound(spline3, m2::PointD(200, 0));
|
||||
TEST(!IsSmooth(spline3), ());
|
||||
TEST(spline3.GetSize() == 3, ());
|
||||
|
||||
m2::SplineEx spline4;
|
||||
df::AddPointAndRound(spline4, m2::PointD(-200, 5));
|
||||
df::AddPointAndRound(spline4, m2::PointD(0, 0));
|
||||
df::AddPointAndRound(spline4, m2::PointD(200, 5));
|
||||
TEST(IsSmooth(spline4), ());
|
||||
TEST(spline4.GetSize() == 3, ());
|
||||
|
||||
m2::SplineEx spline5;
|
||||
df::AddPointAndRound(spline5, m2::PointD(200, 5));
|
||||
df::AddPointAndRound(spline5, m2::PointD(0, 0));
|
||||
df::AddPointAndRound(spline5, m2::PointD(200, -5));
|
||||
TEST(!IsSmooth(spline5), ());
|
||||
TEST(spline5.GetSize() == 3, ());
|
||||
}
|
||||
24
libs/drape_frontend/drape_frontend_tests/stylist_tests.cpp
Normal file
24
libs/drape_frontend/drape_frontend_tests/stylist_tests.cpp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#include "testing/testing.hpp"
|
||||
|
||||
#include "drape_frontend/stylist.hpp"
|
||||
|
||||
#include "indexer/classificator.hpp"
|
||||
#include "indexer/classificator_loader.hpp"
|
||||
|
||||
UNIT_TEST(Stylist_IsHatching)
|
||||
{
|
||||
classificator::Load();
|
||||
auto const & cl = classif();
|
||||
|
||||
auto const & checker = df::IsHatchingTerritoryChecker::Instance();
|
||||
|
||||
TEST(checker(cl.GetTypeByPath({"boundary", "protected_area", "1"})), ());
|
||||
TEST(!checker(cl.GetTypeByPath({"boundary", "protected_area", "2"})), ());
|
||||
TEST(!checker(cl.GetTypeByPath({"boundary", "protected_area"})), ());
|
||||
|
||||
TEST(checker(cl.GetTypeByPath({"boundary", "national_park"})), ());
|
||||
|
||||
TEST(checker(cl.GetTypeByPath({"landuse", "military", "danger_area"})), ());
|
||||
|
||||
TEST(checker(cl.GetTypeByPath({"amenity", "prison"})), ());
|
||||
}
|
||||
|
|
@ -0,0 +1,198 @@
|
|||
#include "testing/testing.hpp"
|
||||
|
||||
#include "drape_frontend/user_event_stream.hpp"
|
||||
|
||||
#include "base/thread.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
|
||||
using namespace std::placeholders;
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
namespace
|
||||
{
|
||||
class UserEventStreamTest : df::UserEventStream::Listener
|
||||
{
|
||||
public:
|
||||
explicit UserEventStreamTest(bool filtrateTouches) : m_filtrate(filtrateTouches)
|
||||
{
|
||||
m_stream.SetTestBridge(std::bind(&UserEventStreamTest::TestBridge, this, _1));
|
||||
}
|
||||
|
||||
void OnTap(m2::PointD const & pt, bool isLong) override {}
|
||||
void OnForceTap(m2::PointD const & pt) override {}
|
||||
void OnDoubleTap(m2::PointD const & pt) override {}
|
||||
void OnTwoFingersTap() override {}
|
||||
bool OnSingleTouchFiltrate(m2::PointD const & pt, df::TouchEvent::ETouchType type) override { return m_filtrate; }
|
||||
void OnDragStarted() override {}
|
||||
void OnDragEnded(m2::PointD const & /* distance */) override {}
|
||||
void OnRotated() override {}
|
||||
void OnScrolled(m2::PointD const & distance) override {}
|
||||
|
||||
void OnScaleStarted() override {}
|
||||
void CorrectScalePoint(m2::PointD & pt) const override {}
|
||||
void CorrectScalePoint(m2::PointD & pt1, m2::PointD & pt2) const override {}
|
||||
void CorrectGlobalScalePoint(m2::PointD & pt) const override {}
|
||||
void OnScaleEnded() override {}
|
||||
void OnTouchMapAction(df::TouchEvent::ETouchType touchType, bool isMapTouch) override {}
|
||||
void OnAnimatedScaleEnded() override {}
|
||||
bool OnNewVisibleViewport(m2::RectD const & oldViewport, m2::RectD const & newViewport, bool needOffset,
|
||||
m2::PointD & gOffset) override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void AddUserEvent(df::TouchEvent const & event) { m_stream.AddEvent(make_unique_dp<df::TouchEvent>(event)); }
|
||||
|
||||
void SetRect(m2::RectD const & r)
|
||||
{
|
||||
m_stream.AddEvent(make_unique_dp<df::SetRectEvent>(r, false /* rotate */, -1, false /* isAnim */,
|
||||
false /* useVisibleViewport */,
|
||||
nullptr /* parallelAnimCreator */));
|
||||
}
|
||||
|
||||
void AddExpectation(char const * action) { m_expectation.push_back(action); }
|
||||
|
||||
void RunTest()
|
||||
{
|
||||
bool dummy1, dummy2, dummy3;
|
||||
m_stream.ProcessEvents(dummy1, dummy2, dummy3);
|
||||
TEST_EQUAL(m_expectation.empty(), true, ());
|
||||
}
|
||||
|
||||
private:
|
||||
void TestBridge(char const * action)
|
||||
{
|
||||
TEST(!m_expectation.empty(), ());
|
||||
char const * a = m_expectation.front();
|
||||
TEST_EQUAL(strcmp(action, a), 0, ());
|
||||
m_expectation.pop_front();
|
||||
}
|
||||
|
||||
private:
|
||||
df::UserEventStream m_stream;
|
||||
std::list<char const *> m_expectation;
|
||||
bool m_filtrate;
|
||||
};
|
||||
|
||||
int touchTimeStamp = 1;
|
||||
|
||||
df::TouchEvent MakeTouchEvent(m2::PointD const & pt1, m2::PointD const & pt2, df::TouchEvent::ETouchType type)
|
||||
{
|
||||
df::TouchEvent e;
|
||||
df::Touch t1;
|
||||
t1.m_location = pt1;
|
||||
t1.m_id = 1;
|
||||
e.SetFirstTouch(t1);
|
||||
|
||||
df::Touch t2;
|
||||
t2.m_location = pt2;
|
||||
t2.m_id = 2;
|
||||
e.SetSecondTouch(t2);
|
||||
|
||||
e.SetTouchType(type);
|
||||
e.SetFirstMaskedPointer(0);
|
||||
e.SetSecondMaskedPointer(1);
|
||||
e.SetTimeStamp(touchTimeStamp++);
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
df::TouchEvent MakeTouchEvent(m2::PointD const & pt, df::TouchEvent::ETouchType type)
|
||||
{
|
||||
df::TouchEvent e;
|
||||
|
||||
df::Touch t1;
|
||||
t1.m_location = pt;
|
||||
t1.m_id = 1;
|
||||
e.SetFirstTouch(t1);
|
||||
|
||||
e.SetTouchType(type);
|
||||
e.SetFirstMaskedPointer(0);
|
||||
e.SetTimeStamp(touchTimeStamp++);
|
||||
|
||||
return e;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
UNIT_TEST(SimpleTap)
|
||||
{
|
||||
UserEventStreamTest test(false);
|
||||
test.AddExpectation(df::UserEventStream::TRY_FILTER);
|
||||
test.AddExpectation(df::UserEventStream::BEGIN_TAP_DETECTOR);
|
||||
test.AddExpectation(df::UserEventStream::SHORT_TAP_DETECTED);
|
||||
|
||||
test.AddUserEvent(MakeTouchEvent(m2::PointD::Zero(), df::TouchEvent::TOUCH_DOWN));
|
||||
test.AddUserEvent(MakeTouchEvent(m2::PointD::Zero(), df::TouchEvent::TOUCH_UP));
|
||||
|
||||
test.RunTest();
|
||||
}
|
||||
|
||||
UNIT_TEST(SimpleLongTap)
|
||||
{
|
||||
UserEventStreamTest test(false);
|
||||
test.AddExpectation(df::UserEventStream::TRY_FILTER);
|
||||
test.AddExpectation(df::UserEventStream::BEGIN_TAP_DETECTOR);
|
||||
test.AddUserEvent(MakeTouchEvent(m2::PointD::Zero(), df::TouchEvent::TOUCH_DOWN));
|
||||
test.RunTest();
|
||||
|
||||
threads::Sleep(1100);
|
||||
test.AddExpectation(df::UserEventStream::LONG_TAP_DETECTED);
|
||||
test.RunTest();
|
||||
|
||||
test.AddUserEvent(MakeTouchEvent(m2::PointD::Zero(), df::TouchEvent::TOUCH_UP));
|
||||
test.RunTest();
|
||||
}
|
||||
|
||||
UNIT_TEST(SimpleDrag)
|
||||
{
|
||||
size_t const moveEventCount = 5;
|
||||
UserEventStreamTest test(false);
|
||||
test.AddExpectation(df::UserEventStream::TRY_FILTER);
|
||||
test.AddExpectation(df::UserEventStream::BEGIN_TAP_DETECTOR);
|
||||
test.AddExpectation(df::UserEventStream::CANCEL_TAP_DETECTOR);
|
||||
test.AddExpectation(df::UserEventStream::BEGIN_DRAG);
|
||||
for (size_t i = 0; i < moveEventCount - 2; ++i)
|
||||
test.AddExpectation(df::UserEventStream::DRAG);
|
||||
test.AddExpectation(df::UserEventStream::END_DRAG);
|
||||
|
||||
m2::PointD pointer = m2::PointD::Zero();
|
||||
test.AddUserEvent(MakeTouchEvent(pointer, df::TouchEvent::TOUCH_DOWN));
|
||||
for (size_t i = 0; i < 5; ++i)
|
||||
{
|
||||
pointer += m2::PointD(100.0, 0.0);
|
||||
test.AddUserEvent(MakeTouchEvent(pointer, df::TouchEvent::TOUCH_MOVE));
|
||||
}
|
||||
test.AddUserEvent(MakeTouchEvent(pointer, df::TouchEvent::TOUCH_UP));
|
||||
test.RunTest();
|
||||
}
|
||||
|
||||
UNIT_TEST(SimpleScale)
|
||||
{
|
||||
size_t const moveEventCount = 5;
|
||||
UserEventStreamTest test(false);
|
||||
test.SetRect(m2::RectD(-250.0, -250.0, 250.0, 250.0));
|
||||
|
||||
test.AddExpectation(df::UserEventStream::TWO_FINGERS_TAP);
|
||||
test.AddExpectation(df::UserEventStream::BEGIN_SCALE);
|
||||
for (size_t i = 0; i < moveEventCount - 1; ++i)
|
||||
test.AddExpectation(df::UserEventStream::SCALE);
|
||||
test.AddExpectation(df::UserEventStream::END_SCALE);
|
||||
|
||||
m2::PointD pointer1 = m2::PointD::Zero() + m2::PointD(10.0, 10.0);
|
||||
m2::PointD pointer2 = m2::PointD::Zero() - m2::PointD(10.0, 10.0);
|
||||
test.AddUserEvent(MakeTouchEvent(pointer1, pointer2, df::TouchEvent::TOUCH_DOWN));
|
||||
for (size_t i = 0; i < moveEventCount; ++i)
|
||||
{
|
||||
pointer1 += m2::PointD(20.0, 0.0);
|
||||
pointer2 -= m2::PointD(20.0, 0.0);
|
||||
test.AddUserEvent(MakeTouchEvent(pointer1, pointer2, df::TouchEvent::TOUCH_MOVE));
|
||||
}
|
||||
test.AddUserEvent(MakeTouchEvent(pointer1, pointer2, df::TouchEvent::TOUCH_UP));
|
||||
test.RunTest();
|
||||
}
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue