From 74312b0405d6fb5ed75c675ceed471e1e5086f00 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Tue, 12 Aug 2014 20:03:56 +0200 Subject: Better CMake organization and unit test cleanups * created a static library containing most source modules to avoid compiling source modules twice in code and unit tests * moved profile_test to main unit tests executable * removed image_test and edit_test as not really useful --- test/unit/ui/CMakeLists.txt | 46 -------- test/unit/ui/edit_test.cpp | 90 --------------- test/unit/ui/mocks/text_mock.h | 35 ------ test/unit/ui/stubs/app_stub.cpp | 42 ------- test/unit/ui/stubs/engine_stub.cpp | 104 ----------------- test/unit/ui/stubs/particle_stub.cpp | 205 ---------------------------------- test/unit/ui/stubs/restext_stub.cpp | 12 -- test/unit/ui/stubs/robotmain_stub.cpp | 25 ----- 8 files changed, 559 deletions(-) delete mode 100644 test/unit/ui/CMakeLists.txt delete mode 100644 test/unit/ui/edit_test.cpp delete mode 100644 test/unit/ui/mocks/text_mock.h delete mode 100644 test/unit/ui/stubs/app_stub.cpp delete mode 100644 test/unit/ui/stubs/engine_stub.cpp delete mode 100644 test/unit/ui/stubs/particle_stub.cpp delete mode 100644 test/unit/ui/stubs/restext_stub.cpp delete mode 100644 test/unit/ui/stubs/robotmain_stub.cpp (limited to 'test/unit/ui') diff --git a/test/unit/ui/CMakeLists.txt b/test/unit/ui/CMakeLists.txt deleted file mode 100644 index 7f7b2f8..0000000 --- a/test/unit/ui/CMakeLists.txt +++ /dev/null @@ -1,46 +0,0 @@ -set(SRC_DIR ${colobot_SOURCE_DIR}/src) - -include_directories( -. -${SRC_DIR} -${GTEST_INCLUDE_DIR} -${GMOCK_INCLUDE_DIR} -${CLIPBOARD_INCLUDE_DIR} -) - -# Platform-dependent implementation of CSystemUtils -if(PLATFORM_WINDOWS) -elseif(PLATFORM_MACOSX) - set(ADDITIONAL_LIB "${X11_X11_LIB}") -else() - set(ADDITIONAL_LIB "-lX11") -endif() - -add_executable(edit_test -${SRC_DIR}/app/gamedata.cpp -${SRC_DIR}/app/system.cpp -${SRC_DIR}/app/${SYSTEM_CPP_MODULE} -${SRC_DIR}/app/system_other.cpp -${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 clipboard ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES} ${ADDITIONAL_LIB}) - - - -add_test(edit_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/edit_test) diff --git a/test/unit/ui/edit_test.cpp b/test/unit/ui/edit_test.cpp deleted file mode 100644 index 34af013..0000000 --- a/test/unit/ui/edit_test.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include "app/app.h" -#include "app/gamedata.h" - -#include "ui/edit.h" - -#include "mocks/text_mock.h" - -#include - -#include -#include - -class CEditTest : public testing::Test -{ -public: - CEditTest() - : m_robotMain(nullptr) - , m_gameData(nullptr) - , m_engine(nullptr) - , m_edit(nullptr) - {} - - virtual void SetUp() - { - m_robotMain = new CRobotMain(&m_app, false); - - m_gameData = new CGameData(); - - m_engine = new Gfx::CEngine(nullptr); - - m_edit = new Ui::CEdit; - } - - virtual void TearDown() - { - delete m_edit; - m_edit = nullptr; - delete m_engine; - m_engine = nullptr; - delete m_gameData; - m_gameData = nullptr; - delete m_robotMain; - m_robotMain = nullptr; - } - virtual ~CEditTest() - { - - }; - -protected: - CApplication m_app; - CRobotMain* m_robotMain; - CGameData * m_gameData; - Gfx::CEngine * m_engine; - Ui::CEdit * m_edit; - CLogger m_logger; -}; - -using ::testing::_; -using ::testing::An; -using ::testing::Return; - -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(An(), _, _, _)).WillOnce(Return(1.0f)); - std::string filename = "test.file"; - m_edit->SetMaxChar(Ui::EDITSTUDIOMAX); - m_edit->SetAutoIndent(true); - std::string inputScript = "{\ntext1\ntext2\n\ntext3\n{\ntext4\n}\n}"; - std::string expectedScript = "{\r\n\ttext1\r\n\ttext2\r\n\t\r\n\ttext3\r\n\t{\r\n\t\ttext4\r\n\t}\r\n}"; - m_edit->SetText(inputScript.c_str(), true); - GetLogger()->Info("Writing text \n"); - m_edit->WriteText("script.txt"); - - std::fstream scriptFile; - - scriptFile.open("script.txt", std::ios_base::binary | std::ios_base::in); - std::string outputScript((std::istreambuf_iterator(scriptFile)), std::istreambuf_iterator()); - ASSERT_STREQ(expectedScript.c_str(), outputScript.c_str()); -} - -int main(int argc, char *argv[]) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - diff --git a/test/unit/ui/mocks/text_mock.h b/test/unit/ui/mocks/text_mock.h deleted file mode 100644 index b9af6d3..0000000 --- a/test/unit/ui/mocks/text_mock.h +++ /dev/null @@ -1,35 +0,0 @@ -#include "common/logger.h" - -#include "graphics/engine/text.h" - -#include - -class CTextMock : public Gfx::CText -{ -public: - CTextMock(Gfx::CEngine* engine) : CText(engine) - { - } - - virtual ~CTextMock() - { - }; - - MOCK_METHOD4(GetCharWidth, float(Gfx::UTF8Char ch, - Gfx::FontType type, - float size, - float offset)); - MOCK_METHOD4(GetStringWidth, float(const std::string &text, - std::vector::iterator format, - std::vector::iterator end, - float size)); - MOCK_METHOD3(GetStringWidth, float(std::string text, - Gfx::FontType font, - float size)); - MOCK_METHOD4(GetStringWidth, float(Gfx::UTF8Char ch, - Gfx::FontType font, - float size, - float offset)); - -}; - diff --git a/test/unit/ui/stubs/app_stub.cpp b/test/unit/ui/stubs/app_stub.cpp deleted file mode 100644 index 95430d8..0000000 --- a/test/unit/ui/stubs/app_stub.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "app/app.h" - -#include "graphics/opengl/gldevice.h" - -template<> CApplication* CSingleton::m_instance = nullptr; - -namespace Gfx { - -GLDeviceConfig::GLDeviceConfig() -{ -} - -} /* Gfx */ - - -CApplication::CApplication() -{ -} - -CApplication::~CApplication() -{ -} - -CSoundInterface* CApplication::GetSound() -{ - return nullptr; -} - -CEventQueue* CApplication::GetEventQueue() -{ - return nullptr; -} - -Event CApplication::CreateUpdateEvent() -{ - return Event(EVENT_NULL); -} - -char CApplication::GetLanguageChar() const -{ - return 'E'; -} diff --git a/test/unit/ui/stubs/engine_stub.cpp b/test/unit/ui/stubs/engine_stub.cpp deleted file mode 100644 index 0a2777c..0000000 --- a/test/unit/ui/stubs/engine_stub.cpp +++ /dev/null @@ -1,104 +0,0 @@ -#include "graphics/engine/engine.h" -#include "graphics/engine/text.h" - -#include "mocks/text_mock.h" - -template<> Gfx::CEngine* CSingleton::m_instance = nullptr; - -namespace Gfx { - -CEngine::CEngine(CApplication* app) : - m_app(app) -{ - m_text = new CTextMock(this); - m_text->Create(); -} - -CEngine::~CEngine() -{ - delete m_text; - m_text = nullptr; -} - -CParticle* CEngine::GetParticle() -{ - return nullptr; -} - -Math::Point CEngine::WindowToInterfaceSize(Math::IntPoint size) -{ - return Math::Point(size.x, size.y); -} - -void CEngine::SetState(int state, const Color& color) -{ - if (state == m_lastState && color == m_lastColor) - return; - - m_lastState = state; - m_lastColor = color; -} - -Math::IntPoint CEngine::GetWindowSize() -{ - return m_size; -} - -void CEngine::AddStatisticTriangle(int count) -{ - m_statisticTriangle += count; -} - -void CEngine::SetMouseType(EngineMouseType type) -{ - m_mouseType = type; -} - -bool CEngine::SetTexture(const std::string& /* name */, int /* stage */) -{ - return true; -} - -CText* CEngine::GetText() -{ - return m_text; -} - -CDevice* CEngine::GetDevice() -{ - return m_device; -} - -int CEngine::GetEditIndentValue() -{ - return m_editIndentValue; -} - -void CEngine::DeleteTexture(const std::string& /* texName */) -{ -} - -Texture CEngine::LoadTexture(const std::string& /* name */) -{ - Texture texture; - return texture; -} - -Math::Vector CEngine::GetEyePt() -{ - return Math::Vector(); -} - -Math::Vector CEngine::GetLookatPt() -{ - return Math::Vector(); -} - -bool CEngine::GetPause() -{ - return false; -} - - -} /* Gfx */ - diff --git a/test/unit/ui/stubs/particle_stub.cpp b/test/unit/ui/stubs/particle_stub.cpp deleted file mode 100644 index 34cf973..0000000 --- a/test/unit/ui/stubs/particle_stub.cpp +++ /dev/null @@ -1,205 +0,0 @@ -#include "graphics/engine/particle.h" - -#include "common/logger.h" - - -// Graphics module namespace -namespace Gfx { - - -CParticle::CParticle(CEngine* /*engine*/) -{ -} - -CParticle::~CParticle() -{ -} - -void CParticle::SetDevice(CDevice* /*device*/) -{ -} - -void CParticle::FlushParticle() -{ -} - -void CParticle::FlushParticle(int /*sheet*/) -{ -} - -int CParticle::CreateParticle(Math::Vector /*pos*/, Math::Vector /*speed*/, Math::Point /*dim*/, - ParticleType /*type*/, float /*duration*/, float /*mass*/, - float /*windSensitivity*/, int /*sheet*/) -{ - return 0; -} - -int CParticle::CreateFrag(Math::Vector /*pos*/, Math::Vector /*speed*/, EngineTriangle */*triangle*/, - ParticleType /*type*/, float /*duration*/, float /*mass*/, - float /*windSensitivity*/, int /*sheet*/) -{ - return 0; -} - -int CParticle::CreatePart(Math::Vector /*pos*/, Math::Vector /*speed*/, ParticleType /*type*/, - float /*duration*/, float /*mass*/, float /*weight*/, - float /*windSensitivity*/, int /*sheet*/) -{ - return 0; -} - -int CParticle::CreateRay(Math::Vector /*pos*/, Math::Vector /*goal*/, ParticleType /*type*/, Math::Point /*dim*/, - float /*duration*/, int /*sheet*/) -{ - return 0; -} - -int CParticle::CreateTrack(Math::Vector /*pos*/, Math::Vector /*speed*/, Math::Point /*dim*/, ParticleType /*type*/, - float /*duration*/, float /*mass*/, float /*length*/, float /*width*/) -{ - return 0; -} - -void CParticle::CreateWheelTrace(const Math::Vector &/*p1*/, const Math::Vector &/*p2*/, const Math::Vector &/*p3*/, - const Math::Vector &/*p4*/, ParticleType /*type*/) -{ -} - -void CParticle::DeleteParticle(ParticleType /*type*/) -{ -} - -void CParticle::DeleteParticle(int /*channel*/) -{ -} - -void CParticle::SetObjectLink(int /*channel*/, CObject */*object*/) -{ -} - -void CParticle::SetObjectFather(int /*channel*/, CObject */*object*/) -{ -} - -void CParticle::SetPosition(int /*channel*/, Math::Vector /*pos*/) -{ -} - -void CParticle::SetDimension(int /*channel*/, Math::Point /*dim*/) -{ -} - -void CParticle::SetZoom(int /*channel*/, float /*zoom*/) -{ -} - -void CParticle::SetAngle(int /*channel*/, float /*angle*/) -{ -} - -void CParticle::SetIntensity(int /*channel*/, float /*intensity*/) -{ -} - -void CParticle::SetParam(int /*channel*/, Math::Vector /*pos*/, Math::Point /*dim*/, float /*zoom*/, float /*angle*/, float /*intensity*/) -{ -} - -void CParticle::SetPhase(int /*channel*/, ParticlePhase /*phase*/, float /*duration*/) -{ -} - -bool CParticle::GetPosition(int /*channel*/, Math::Vector &/*pos*/) -{ - return true; -} - -Color CParticle::GetFogColor(Math::Vector /*pos*/) -{ - return Color(); -} - -void CParticle::SetFrameUpdate(int /*sheet*/, bool /*update*/) -{ -} - -void CParticle::FrameParticle(float /*rTime*/) -{ -} - -void CParticle::DrawParticle(int /*sheet*/) -{ -} - -bool CParticle::WriteWheelTrace(const char */*filename*/, int /*width*/, int /*height*/, Math::Vector /*dl*/, Math::Vector /*ur*/) -{ - return true; -} - -void CParticle::DeleteRank(int /*rank*/) -{ -} - -bool CParticle::CheckChannel(int &/*channel*/) -{ - return true; -} - -void CParticle::DrawParticleTriangle(int /*i*/) -{ -} - -void CParticle::DrawParticleNorm(int /*i*/) -{ -} - -void CParticle::DrawParticleFlat(int /*i*/) -{ -} - -void CParticle::DrawParticleFog(int /*i*/) -{ -} - -void CParticle::DrawParticleRay(int /*i*/) -{ -} - -void CParticle::DrawParticleSphere(int /*i*/) -{ -} - -void CParticle::DrawParticleCylinder(int /*i*/) -{ -} - -void CParticle::DrawParticleWheel(int /*i*/) -{ -} - -CObject* CParticle::SearchObjectGun(Math::Vector /*old*/, Math::Vector /*pos*/, ParticleType /*type*/, CObject */*father*/) -{ - return nullptr; -} - -CObject* CParticle::SearchObjectRay(Math::Vector /*pos*/, Math::Vector /*goal*/, ParticleType /*type*/, CObject */*father*/) -{ - return nullptr; -} - -void CParticle::Play(Sound /*sound*/, Math::Vector /*pos*/, float /*amplitude*/) -{ -} - -bool CParticle::TrackMove(int /*i*/, Math::Vector /*pos*/, float /*progress*/) -{ - return true; -} - -void CParticle::TrackDraw(int /*i*/, ParticleType /*type*/) -{ -} - - -} // namespace Gfx - diff --git a/test/unit/ui/stubs/restext_stub.cpp b/test/unit/ui/stubs/restext_stub.cpp deleted file mode 100644 index fa47da6..0000000 --- a/test/unit/ui/stubs/restext_stub.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "common/restext.h" - -bool GetResource(ResType /* type */, int /* num */, std::string& /* text */) -{ - return true; -} - -bool SearchKey(const char * /* cmd */, InputSlot & /* key */) -{ - return true; -} - diff --git a/test/unit/ui/stubs/robotmain_stub.cpp b/test/unit/ui/stubs/robotmain_stub.cpp deleted file mode 100644 index 692f67f..0000000 --- a/test/unit/ui/stubs/robotmain_stub.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "object/robotmain.h" - - -template<> CRobotMain* CSingleton::m_instance = nullptr; - -CRobotMain::CRobotMain(CApplication* app, bool loadProfile) -{ -} - -CRobotMain::~CRobotMain() -{ -} - -bool CRobotMain::GetGlint() -{ - return false; -} - -const InputBinding& CRobotMain::GetInputBinding(InputSlot slot) -{ - unsigned int index = static_cast(slot); - assert(index >= 0 && index < INPUT_SLOT_MAX); - return m_inputBindings[index]; -} - -- cgit v1.2.3-1-g7c22