From 209c6412ae149cc7c503fd7da384f344a830423c Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 3 Feb 2013 20:03:36 +0100 Subject: Refactoring in tests infrastructure * all tests are now in /test/ subdirectory * unit tests concatenated to one executable (TODO: ui, common) * preparation for test environments (OpenGL and others) * removed old TestCBot --- src/ui/test/CMakeLists.txt | 36 ----- src/ui/test/edit_test.cpp | 73 --------- src/ui/test/mocks/text_mock.h | 21 --- src/ui/test/stubs/app_stub.cpp | 26 ---- src/ui/test/stubs/engine_stub.cpp | 79 ---------- src/ui/test/stubs/particle_stub.cpp | 291 ----------------------------------- src/ui/test/stubs/restext_stub.cpp | 11 -- src/ui/test/stubs/robotmain_stub.cpp | 17 -- 8 files changed, 554 deletions(-) delete mode 100644 src/ui/test/CMakeLists.txt delete mode 100644 src/ui/test/edit_test.cpp delete mode 100644 src/ui/test/mocks/text_mock.h delete mode 100644 src/ui/test/stubs/app_stub.cpp delete mode 100644 src/ui/test/stubs/engine_stub.cpp delete mode 100644 src/ui/test/stubs/particle_stub.cpp delete mode 100644 src/ui/test/stubs/restext_stub.cpp delete mode 100644 src/ui/test/stubs/robotmain_stub.cpp (limited to 'src/ui/test') diff --git a/src/ui/test/CMakeLists.txt b/src/ui/test/CMakeLists.txt deleted file mode 100644 index 452df43..0000000 --- a/src/ui/test/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -cmake_minimum_required(VERSION 2.8) - -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE debug) -endif(NOT CMAKE_BUILD_TYPE) -set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") - -include_directories( -. -../.. -../../.. -${GTEST_INCLUDE_DIR} -${GMOCK_INCLUDE_DIR} -) - - -add_executable(edit_test - ../../common/event.cpp - ../../common/logger.cpp - ../../common/misc.cpp - ../../common/iman.cpp - ../../common/stringutils.cpp - ../../graphics/engine/text.cpp - ../button.cpp - ../control.cpp - ../edit.cpp - ../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/src/ui/test/edit_test.cpp b/src/ui/test/edit_test.cpp deleted file mode 100644 index 489b873..0000000 --- a/src/ui/test/edit_test.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include "../edit.h" -#include "../../app/app.h" -#include "mocks/text_mock.h" -#include -#include -#include - -class CEditTest : public testing::Test -{ -public: - CEditTest(){}; - - virtual void SetUp() - { - m_engine = new Gfx::CEngine(&m_iMan, NULL); - - m_iMan.AddInstance(CLASS_ENGINE, m_engine); - m_edit = new Ui::CEdit; - } - - virtual void TearDown() - { - m_iMan.DeleteInstance(CLASS_ENGINE, m_engine); - delete m_engine; - m_engine = NULL; - delete m_edit; - m_edit = NULL; - - } - virtual ~CEditTest() - { - - }; - -protected: - CInstanceManager m_iMan; - CApplication m_app; - Gfx::CEngine * m_engine; - Ui::CEdit * m_edit; - CLogger m_logger; -}; - -using ::testing::_; -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(_, _, _)).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/src/ui/test/mocks/text_mock.h b/src/ui/test/mocks/text_mock.h deleted file mode 100644 index 59a6c48..0000000 --- a/src/ui/test/mocks/text_mock.h +++ /dev/null @@ -1,21 +0,0 @@ -#include "../../graphics/engine/text.h" -#include -#include "../../common/logger.h" - - -class CTextMock : public Gfx::CText -{ -public: - CTextMock(CInstanceManager *iMan, Gfx::CEngine* engine) : CText(iMan, engine) - { - } - - virtual ~CTextMock() - { - }; - - MOCK_METHOD4(GetCharWidth, float(Gfx::UTF8Char, Gfx::FontType, float, float)); - MOCK_METHOD3(GetStringWidth, float(const std::string &, Gfx::FontType, float)); - -}; - diff --git a/src/ui/test/stubs/app_stub.cpp b/src/ui/test/stubs/app_stub.cpp deleted file mode 100644 index 5dd79e4..0000000 --- a/src/ui/test/stubs/app_stub.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "../../app/app.h" -#include "../../graphics/opengl/gldevice.h" - -template<> CApplication* CSingleton::mInstance = nullptr; - -namespace Gfx { - -GLDeviceConfig::GLDeviceConfig() -{ -} - -} /* Gfx */ -CApplication::CApplication() -{ -} - -CApplication::~CApplication() -{ -} - -std::string CApplication::GetDataFilePath(DataDir /* dataDir */, const std::string& subpath) -{ - return subpath; -} - - diff --git a/src/ui/test/stubs/engine_stub.cpp b/src/ui/test/stubs/engine_stub.cpp deleted file mode 100644 index 6ec6006..0000000 --- a/src/ui/test/stubs/engine_stub.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include "../../graphics/engine/engine.h" -#include "../../graphics/engine/text.h" -#include "../mocks/text_mock.h" - -namespace Gfx { - -CEngine::CEngine(CInstanceManager* iMan, CApplication* app) : - m_iMan(iMan), m_app(app) -{ - m_text = new CTextMock(m_iMan, this); - m_text->Create(); -} - -CEngine::~CEngine() -{ - delete m_text; - m_text = NULL; -} - -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; -} - -} /* Gfx */ - diff --git a/src/ui/test/stubs/particle_stub.cpp b/src/ui/test/stubs/particle_stub.cpp deleted file mode 100644 index 41f07cc..0000000 --- a/src/ui/test/stubs/particle_stub.cpp +++ /dev/null @@ -1,291 +0,0 @@ -#include "graphics/engine/particle.h" - -#include "common/logger.h" - - -// Graphics module namespace -namespace Gfx { - - -CParticle::CParticle(CInstanceManager* iMan, CEngine* engine) -{ - GetLogger()->Trace("CParticle::CParticle() stub!\n"); - // TODO! -} - -CParticle::~CParticle() -{ - GetLogger()->Trace("CParticle::~CParticle() stub!\n"); - // TODO! -} - -void CParticle::SetDevice(CDevice* device) -{ - GetLogger()->Trace("CParticle::SetDevice() stub!\n"); - // TODO! -} - -void CParticle::FlushParticle() -{ - GetLogger()->Trace("CParticle::FlushParticle() stub!\n"); - // TODO! -} - -void CParticle::FlushParticle(int sheet) -{ - GetLogger()->Trace("CParticle::FlushParticle() stub!\n"); - // TODO! -} - -int CParticle::CreateParticle(Math::Vector pos, Math::Vector speed, Math::Point dim, - ParticleType type, float duration, float mass, - float windSensitivity, int sheet) -{ - GetLogger()->Trace("CParticle::CreateParticle() stub!\n"); - // TODO! - return 0; -} - -int CParticle::CreateFrag(Math::Vector pos, Math::Vector speed, EngineTriangle *triangle, - ParticleType type, float duration, float mass, - float windSensitivity, int sheet) -{ - GetLogger()->Trace("CParticle::CreateFrag() stub!\n"); - // TODO! - return 0; -} - -int CParticle::CreatePart(Math::Vector pos, Math::Vector speed, ParticleType type, - float duration, float mass, float weight, - float windSensitivity, int sheet) -{ - GetLogger()->Trace("CParticle::CreatePart() stub!\n"); - // TODO! - return 0; -} - -int CParticle::CreateRay(Math::Vector pos, Math::Vector goal, ParticleType type, Math::Point dim, - float duration, int sheet) -{ - GetLogger()->Trace("CParticle::CreateRay() stub!\n"); - // TODO! - return 0; -} - -int CParticle::CreateTrack(Math::Vector pos, Math::Vector speed, Math::Point dim, ParticleType type, - float duration, float mass, float length, float width) -{ - GetLogger()->Trace("CParticle::CreateTrack() stub!\n"); - // TODO! - return 0; -} - -void CParticle::CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3, - const Math::Vector &p4, ParticleType type) -{ - GetLogger()->Trace("CParticle::CreateWheelTrace() stub!\n"); - // TODO! -} - -void CParticle::DeleteParticle(ParticleType type) -{ - GetLogger()->Trace("CParticle::DeleteParticle() stub!\n"); - // TODO! -} - -void CParticle::DeleteParticle(int channel) -{ - GetLogger()->Trace("CParticle::DeleteParticle() stub!\n"); - // TODO! -} - -void CParticle::SetObjectLink(int channel, CObject *object) -{ - GetLogger()->Trace("CParticle::SetObjectLink() stub!\n"); - // TODO! -} - -void CParticle::SetObjectFather(int channel, CObject *object) -{ - GetLogger()->Trace("CParticle::SetObjectFather() stub!\n"); - // TODO! -} - -void CParticle::SetPosition(int channel, Math::Vector pos) -{ - GetLogger()->Trace("CParticle::SetPosition() stub!\n"); - // TODO! -} - -void CParticle::SetDimension(int channel, Math::Point dim) -{ - GetLogger()->Trace("CParticle::SetDimension() stub!\n"); - // TODO! -} - -void CParticle::SetZoom(int channel, float zoom) -{ - GetLogger()->Trace("CParticle::SetZoom() stub!\n"); - // TODO! -} - -void CParticle::SetAngle(int channel, float angle) -{ - GetLogger()->Trace("CParticle::SetAngle() stub!\n"); - // TODO! -} - -void CParticle::SetIntensity(int channel, float intensity) -{ - GetLogger()->Trace("CParticle::SetIntensity() stub!\n"); - // TODO! -} - -void CParticle::SetParam(int channel, Math::Vector pos, Math::Point dim, float zoom, float angle, float intensity) -{ - GetLogger()->Trace("CParticle::SetParam() stub!\n"); - // TODO! -} - -void CParticle::SetPhase(int channel, ParticlePhase phase, float duration) -{ - GetLogger()->Trace("CParticle::SetPhase() stub!\n"); - // TODO! -} - -bool CParticle::GetPosition(int channel, Math::Vector &pos) -{ - GetLogger()->Trace("CParticle::GetPosition() stub!\n"); - // TODO! - return true; -} - -Color CParticle::GetFogColor(Math::Vector pos) -{ - GetLogger()->Trace("CParticle::GetFogColor() stub!\n"); - // TODO! - return Color(); -} - -void CParticle::SetFrameUpdate(int sheet, bool update) -{ - GetLogger()->Trace("CParticle::SetFrameUpdate() stub!\n"); - // TODO! -} - -void CParticle::FrameParticle(float rTime) -{ - GetLogger()->Trace("CParticle::FrameParticle() stub!\n"); - // TODO! -} - -void CParticle::DrawParticle(int sheet) -{ - GetLogger()->Trace("CParticle::DrawParticle() stub!\n"); - // TODO! -} - -bool CParticle::WriteWheelTrace(const char *filename, int width, int height, Math::Vector dl, Math::Vector ur) -{ - GetLogger()->Trace("CParticle::WriteWheelTrace() stub!\n"); - // TODO! - return true; -} - -void CParticle::DeleteRank(int rank) -{ - GetLogger()->Trace("CParticle::DeleteRank() stub!\n"); - // TODO! -} - -bool CParticle::CheckChannel(int &channel) -{ - GetLogger()->Trace("CParticle::CheckChannel() stub!\n"); - // TODO! - return true; -} - -void CParticle::DrawParticleTriangle(int i) -{ - GetLogger()->Trace("CParticle::DrawParticleTriangle() stub!\n"); - // TODO! -} - -void CParticle::DrawParticleNorm(int i) -{ - GetLogger()->Trace("CParticle::DrawParticleNorm() stub!\n"); - // TODO! -} - -void CParticle::DrawParticleFlat(int i) -{ - GetLogger()->Trace("CParticle::DrawParticleFlat() stub!\n"); - // TODO! -} - -void CParticle::DrawParticleFog(int i) -{ - GetLogger()->Trace("CParticle::DrawParticleFog() stub!\n"); - // TODO! -} - -void CParticle::DrawParticleRay(int i) -{ - GetLogger()->Trace("CParticle::DrawParticleRay() stub!\n"); - // TODO! -} - -void CParticle::DrawParticleSphere(int i) -{ - GetLogger()->Trace("CParticle::DrawParticleSphere() stub!\n"); - // TODO! -} - -void CParticle::DrawParticleCylinder(int i) -{ - GetLogger()->Trace("CParticle::DrawParticleCylinder() stub!\n"); - // TODO! -} - -void CParticle::DrawParticleWheel(int i) -{ - GetLogger()->Trace("CParticle::DrawParticleWheel() stub!\n"); - // TODO! -} - -CObject* CParticle::SearchObjectGun(Math::Vector old, Math::Vector pos, ParticleType type, CObject *father) -{ - GetLogger()->Trace("CParticle::SearchObjectGun() stub!\n"); - // TODO! - return nullptr; -} - -CObject* CParticle::SearchObjectRay(Math::Vector pos, Math::Vector goal, ParticleType type, CObject *father) -{ - GetLogger()->Trace("CParticle::SearchObjectRay() stub!\n"); - // TODO! - return nullptr; -} - -void CParticle::Play(Sound sound, Math::Vector pos, float amplitude) -{ - GetLogger()->Trace("CParticle::Play() stub!\n"); - // TODO! -} - -bool CParticle::TrackMove(int i, Math::Vector pos, float progress) -{ - GetLogger()->Trace("CParticle::TrackMove() stub!\n"); - // TODO! - return true; -} - -void CParticle::TrackDraw(int i, ParticleType type) -{ - GetLogger()->Trace("CParticle::TrackDraw() stub!\n"); - // TODO! -} - - -} // namespace Gfx - diff --git a/src/ui/test/stubs/restext_stub.cpp b/src/ui/test/stubs/restext_stub.cpp deleted file mode 100644 index c1986ca..0000000 --- a/src/ui/test/stubs/restext_stub.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "../../common/restext.h" -bool GetResource(ResType /* type */, int /* num */, char* /* text */) -{ - return true; -} - -bool SearchKey(const char * /* cmd */, InputSlot & /* key */) -{ - return true; -} - diff --git a/src/ui/test/stubs/robotmain_stub.cpp b/src/ui/test/stubs/robotmain_stub.cpp deleted file mode 100644 index 93e0e82..0000000 --- a/src/ui/test/stubs/robotmain_stub.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "../../object/robotmain.h" - - -template<> CRobotMain* CSingleton::mInstance = nullptr; - -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