#pragma once #include "tstwidgets.hpp" #include "../../testing/testing.hpp" #include "../../map/qgl_render_context.hpp" #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) #include #else #include #endif template struct key_event_fn_bind { typedef T type; }; template struct mouse_event_fn_bind { typedef T type; }; template struct void_fn_bind { typedef T type; }; template )> struct init_with_context_fn_bind { typedef T type; }; template struct has_on_keypress { static const bool value = false; }; template struct has_on_keypress::type> { static const bool value = true; }; template struct has_on_mousemove { static const bool value = false; }; template struct has_on_mousemove::type > { static const bool value = true; }; template struct has_on_mousepress { static bool const value = false; }; template struct has_on_mousepress::type > { static const bool value = true; }; template struct has_init { static bool const value = false; }; template struct has_init::type > { static const bool value = true; }; template struct has_init_with_context { static bool const value = false; }; template struct has_init_with_context::type, RC > { static const bool value = true; }; template struct bool_tag{}; template class GLTestWidget : public tst::GLDrawWidget { public: TTest test; typedef tst::GLDrawWidget base_type; virtual void DoDraw(shared_ptr const & p) { p->beginFrame(); p->clear(graphics::Color(182, 182, 182, 255)); test.DoDraw(p); p->endFrame(); } virtual void DoResize(int, int) { } bool keyPressEventImpl(QKeyEvent * ev, bool_tag const &) { return test.OnKeyPress(ev); } bool keyPressEventImpl(QKeyEvent *, bool_tag const & ) { return false; } virtual void keyPressEvent(QKeyEvent * ev) { if (keyPressEventImpl(ev, bool_tag::value >())) repaint(); } bool mousePressEventImpl(QMouseEvent * ev, bool_tag const &) { return test.OnMousePress(ev); } bool mousePressEventImpl(QMouseEvent *, bool_tag const &) { return false; } virtual void mousePressEvent(QMouseEvent * ev) { if (mousePressEventImpl(ev, bool_tag::value >())) repaint(); } bool mouseMoveEventImpl(QMouseEvent * ev, bool_tag const &) { return test.OnMouseMove(ev); } bool mouseMoveEventImpl(QMouseEvent *, bool_tag const &) { return false; } void mouseMoveEvent(QMouseEvent * ev) { if (mouseMoveEventImpl(ev, bool_tag::value >())) repaint(); } void InitImpl(bool_tag const & ) { test.Init(); } void InitImpl(bool_tag const & ) {} void Init() { InitImpl(bool_tag::value >()); } void InitWithContextImpl(bool_tag const &) { test.Init(shared_ptr(new qt::gl::RenderContext(this))); } void InitWithContextImpl(bool_tag const &) {} void initializeGL() { tst::GLDrawWidget::initializeGL(); InitWithContextImpl(bool_tag::value>()); } }; template QWidget * create_widget() { GLTestWidget * w = new GLTestWidget(); w->Init(); return w; } #define UNIT_TEST_GL(name)\ void UnitTestGL_##name();\ TestRegister g_TestRegister_##name("Test::"#name, __FILE__, &UnitTestGL_##name);\ void UnitTestGL_##name()\ {\ char * argv[] = { const_cast(#name) };\ int argc = 1;\ QApplication app(argc, argv);\ QWidget * w = create_widget();\ w->show();\ app.exec();\ }