summaryrefslogtreecommitdiffstats
path: root/test/unit/ui
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2013-02-03 20:03:36 +0100
committerPiotr Dziwinski <piotrdz@gmail.com>2013-02-03 20:03:36 +0100
commit209c6412ae149cc7c503fd7da384f344a830423c (patch)
tree5baeaeb8dee2208b46bf80a118dfe59eb65f9389 /test/unit/ui
parent3f41f97fc47fca22634dc858c3ecdb39d0d27e32 (diff)
downloadcolobot-209c6412ae149cc7c503fd7da384f344a830423c.tar.gz
colobot-209c6412ae149cc7c503fd7da384f344a830423c.tar.bz2
colobot-209c6412ae149cc7c503fd7da384f344a830423c.zip
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
Diffstat (limited to 'test/unit/ui')
-rw-r--r--test/unit/ui/CMakeLists.txt29
-rw-r--r--test/unit/ui/edit_test.cpp74
-rw-r--r--test/unit/ui/mocks/text_mock.h21
-rw-r--r--test/unit/ui/stubs/app_stub.cpp26
-rw-r--r--test/unit/ui/stubs/engine_stub.cpp79
-rw-r--r--test/unit/ui/stubs/particle_stub.cpp205
-rw-r--r--test/unit/ui/stubs/restext_stub.cpp12
-rw-r--r--test/unit/ui/stubs/robotmain_stub.cpp17
8 files changed, 463 insertions, 0 deletions
diff --git a/test/unit/ui/CMakeLists.txt b/test/unit/ui/CMakeLists.txt
new file mode 100644
index 0000000..32af230
--- /dev/null
+++ b/test/unit/ui/CMakeLists.txt
@@ -0,0 +1,29 @@
+set(SRC_DIR ${colobot_SOURCE_DIR}/src)
+
+include_directories(
+.
+${SRC_DIR}
+${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/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
new file mode 100644
index 0000000..f878f4b
--- /dev/null
+++ b/test/unit/ui/edit_test.cpp
@@ -0,0 +1,74 @@
+#include "app/app.h"
+#include "ui/edit.h"
+#include "mocks/text_mock.h"
+
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+#include <fstream>
+
+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<CTextMock *>(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<char>(scriptFile)), std::istreambuf_iterator<char>());
+ 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
new file mode 100644
index 0000000..f0ad339
--- /dev/null
+++ b/test/unit/ui/mocks/text_mock.h
@@ -0,0 +1,21 @@
+#include "common/logger.h"
+#include "graphics/engine/text.h"
+
+#include <gmock/gmock.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/test/unit/ui/stubs/app_stub.cpp b/test/unit/ui/stubs/app_stub.cpp
new file mode 100644
index 0000000..70d9e82
--- /dev/null
+++ b/test/unit/ui/stubs/app_stub.cpp
@@ -0,0 +1,26 @@
+#include "app/app.h"
+#include "graphics/opengl/gldevice.h"
+
+template<> CApplication* CSingleton<CApplication>::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/test/unit/ui/stubs/engine_stub.cpp b/test/unit/ui/stubs/engine_stub.cpp
new file mode 100644
index 0000000..de7bbe7
--- /dev/null
+++ b/test/unit/ui/stubs/engine_stub.cpp
@@ -0,0 +1,79 @@
+#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/test/unit/ui/stubs/particle_stub.cpp b/test/unit/ui/stubs/particle_stub.cpp
new file mode 100644
index 0000000..c3bf6dc
--- /dev/null
+++ b/test/unit/ui/stubs/particle_stub.cpp
@@ -0,0 +1,205 @@
+#include "graphics/engine/particle.h"
+
+#include "common/logger.h"
+
+
+// Graphics module namespace
+namespace Gfx {
+
+
+CParticle::CParticle(CInstanceManager* /*iMan*/, 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
new file mode 100644
index 0000000..004da19
--- /dev/null
+++ b/test/unit/ui/stubs/restext_stub.cpp
@@ -0,0 +1,12 @@
+#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/test/unit/ui/stubs/robotmain_stub.cpp b/test/unit/ui/stubs/robotmain_stub.cpp
new file mode 100644
index 0000000..a36b1a1
--- /dev/null
+++ b/test/unit/ui/stubs/robotmain_stub.cpp
@@ -0,0 +1,17 @@
+#include "object/robotmain.h"
+
+
+template<> CRobotMain* CSingleton<CRobotMain>::mInstance = nullptr;
+
+bool CRobotMain::GetGlint()
+{
+ return false;
+}
+
+const InputBinding& CRobotMain::GetInputBinding(InputSlot slot)
+{
+ unsigned int index = static_cast<unsigned int>(slot);
+ assert(index >= 0 && index < INPUT_SLOT_MAX);
+ return m_inputBindings[index];
+}
+