From 212f2e41f88a85ad7f47bc526b79fae2b4952d3a Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Wed, 27 Mar 2013 23:48:44 +0100 Subject: Fixed edit_test --- test/unit/ui/CMakeLists.txt | 54 +++++++++++++++++++++-------------- test/unit/ui/edit_test.cpp | 13 +++++++-- test/unit/ui/mocks/text_mock.h | 3 ++ test/unit/ui/stubs/robotmain_stub.cpp | 8 ++++++ 4 files changed, 54 insertions(+), 24 deletions(-) (limited to 'test') diff --git a/test/unit/ui/CMakeLists.txt b/test/unit/ui/CMakeLists.txt index b0d9ce2..c899834 100644 --- a/test/unit/ui/CMakeLists.txt +++ b/test/unit/ui/CMakeLists.txt @@ -7,25 +7,35 @@ ${GTEST_INCLUDE_DIR} ${GMOCK_INCLUDE_DIR} ) -# add_executable(edit_test -# ${SRC_DIR}/common/event.cpp -# ${SRC_DIR}/common/logger.cpp -# ${SRC_DIR}/common/misc.cpp -# ${SRC_DIR}/common/profile.cpp -# ${SRC_DIR}/common/iman.cpp -# ${SRC_DIR}/common/stringutils.cpp -# ${SRC_DIR}/graphics/engine/text.cpp -# ${SRC_DIR}/ui/button.cpp -# ${SRC_DIR}/ui/control.cpp -# ${SRC_DIR}/ui/edit.cpp -# ${SRC_DIR}/ui/scroll.cpp -# stubs/app_stub.cpp -# stubs/engine_stub.cpp -# stubs/particle_stub.cpp -# stubs/restext_stub.cpp -# stubs/robotmain_stub.cpp -# edit_test.cpp) -# target_link_libraries(edit_test gtest gmock ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES}) -# -# TODO: Edit test doesn't work, comment it away for now -# add_test(edit_test ./edit_test) +# Platform-dependent implementation of CSystemUtils +if (${PLATFORM_WINDOWS}) + set(SYSTEM_CPP_MODULE "system_windows.cpp") +elseif(${PLATFORM_LINUX}) + set(SYSTEM_CPP_MODULE "system_linux.cpp") +else() + set(SYSTEM_CPP_MODULE "system_other.cpp") +endif() + +add_executable(edit_test +${SRC_DIR}/app/system.cpp +${SRC_DIR}/app/${SYSTEM_CPP_MODULE} +${SRC_DIR}/common/event.cpp +${SRC_DIR}/common/logger.cpp +${SRC_DIR}/common/misc.cpp +${SRC_DIR}/common/profile.cpp +${SRC_DIR}/common/iman.cpp +${SRC_DIR}/common/stringutils.cpp +${SRC_DIR}/graphics/engine/text.cpp +${SRC_DIR}/ui/button.cpp +${SRC_DIR}/ui/control.cpp +${SRC_DIR}/ui/edit.cpp +${SRC_DIR}/ui/scroll.cpp +stubs/app_stub.cpp +stubs/engine_stub.cpp +stubs/particle_stub.cpp +stubs/restext_stub.cpp +stubs/robotmain_stub.cpp +edit_test.cpp) +target_link_libraries(edit_test gtest gmock ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES}) + +add_test(edit_test ./edit_test) diff --git a/test/unit/ui/edit_test.cpp b/test/unit/ui/edit_test.cpp index 2f31a89..428b66a 100644 --- a/test/unit/ui/edit_test.cpp +++ b/test/unit/ui/edit_test.cpp @@ -9,10 +9,16 @@ class CEditTest : public testing::Test { public: - CEditTest(){}; + CEditTest() + : m_robotMain(nullptr) + , m_engine(nullptr) + , m_edit(nullptr) + {} virtual void SetUp() { + m_robotMain = new CRobotMain(&m_app); + m_engine = new Gfx::CEngine(nullptr); m_edit = new Ui::CEdit; @@ -20,6 +26,8 @@ public: virtual void TearDown() { + delete m_robotMain; + m_robotMain = nullptr; delete m_engine; m_engine = nullptr; delete m_edit; @@ -33,6 +41,7 @@ public: protected: CApplication m_app; + CRobotMain* m_robotMain; Gfx::CEngine * m_engine; Ui::CEdit * m_edit; CLogger m_logger; @@ -46,7 +55,7 @@ TEST_F(CEditTest, WriteTest) ASSERT_TRUE(true); CTextMock * text = dynamic_cast(m_engine->GetText()); EXPECT_CALL(*text, GetCharWidth(_, _, _, _)).WillRepeatedly(Return(1.0f)); - EXPECT_CALL(*text, GetStringWidth(_, _, _)).WillOnce(Return(1.0f)); + EXPECT_CALL(*text, GetStringWidth(_, _, _, _)).WillOnce(Return(1.0f)); std::string filename = "test.file"; m_edit->SetMaxChar(Ui::EDITSTUDIOMAX); m_edit->SetAutoIndent(true); diff --git a/test/unit/ui/mocks/text_mock.h b/test/unit/ui/mocks/text_mock.h index 9289481..f38b977 100644 --- a/test/unit/ui/mocks/text_mock.h +++ b/test/unit/ui/mocks/text_mock.h @@ -16,6 +16,9 @@ public: }; MOCK_METHOD4(GetCharWidth, float(Gfx::UTF8Char, Gfx::FontType, float, float)); + MOCK_METHOD4(GetStringWidth, float(const std::string &text, + std::vector::iterator format, + std::vector::iterator end, float size)); MOCK_METHOD3(GetStringWidth, float(const std::string &, Gfx::FontType, float)); }; diff --git a/test/unit/ui/stubs/robotmain_stub.cpp b/test/unit/ui/stubs/robotmain_stub.cpp index c332d5a..7988e9d 100644 --- a/test/unit/ui/stubs/robotmain_stub.cpp +++ b/test/unit/ui/stubs/robotmain_stub.cpp @@ -3,6 +3,14 @@ template<> CRobotMain* CSingleton::m_instance = nullptr; +CRobotMain::CRobotMain(CApplication* app) +{ +} + +CRobotMain::~CRobotMain() +{ +} + bool CRobotMain::GetGlint() { return false; -- cgit v1.2.3-1-g7c22