Instructions Jenkins Doxygen

[Added] unit test for onPlayerCreated, onPlayerLoggedIn, 02/902/4
authorLoshult <loshult@swgemu.com>
Sun, 13 Oct 2013 19:16:51 +0000 (19:16 +0000)
committergerrit <gerrit@review.swgemu.com>
Sun, 13 Oct 2013 19:08:52 +0000 (19:08 +0000)
onPlayerLoggedOut, checkForceStatusCommand, useHolocron methods in
the jedi manager.

Change-Id: I297ae184874b018681b7c5acf0d480e6aaead4a2

MMOCoreORB/src/server/zone/managers/director/DirectorManager.h
MMOCoreORB/src/server/zone/managers/jedi/JediManager.cpp
MMOCoreORB/src/server/zone/managers/jedi/tests/JediManagerTest.cpp
MMOCoreORB/src/server/zone/objects/creature/CreatureObject.h
MMOCoreORB/src/server/zone/objects/creature/CreatureObject.idl
MMOCoreORB/utils/engine/lua/MockLuaFunction.h

index dc00dfd..25e31bf 100644 (file)
@@ -68,7 +68,7 @@ namespace server {
                ConversationScreen* getNextConversationScreen(const String& luaClass, ConversationTemplate* conversationTemplate, CreatureObject* conversingPlayer, int selectedOption, CreatureObject* conversingNPC);
                ConversationScreen* runScreenHandlers(const String& luaClass, ConversationTemplate* conversationTemplate, CreatureObject* conversingPlayer, CreatureObject* conversingNPC, int selectedOption, ConversationScreen* conversationScreen);
 
-               Lua* getLuaInstance();
+               virtual Lua* getLuaInstance();
                int runScreenPlays();
 
                static int writeScreenPlayData(lua_State* L);
index db2b963..ef9c363 100644 (file)
@@ -89,41 +89,41 @@ void JediManager::loadConfiguration(Lua* luaEngine) {
 
 void JediManager::onPlayerCreated(CreatureObject* creature) {
        Lua* lua = DirectorManager::instance()->getLuaInstance();
-       LuaFunction luaOnPlayerCreated(lua->getLuaState(), getJediManagerName(), "onPlayerCreated", 0);
-       luaOnPlayerCreated << creature;
+       Reference<LuaFunction*> luaOnPlayerCreated = lua->createFunction(getJediManagerName(), "onPlayerCreated", 0);
+       *luaOnPlayerCreated << creature;
 
-       luaOnPlayerCreated.callFunction();
+       luaOnPlayerCreated->callFunction();
 }
 
 void JediManager::onPlayerLoggedIn(CreatureObject* creature) {
        Lua* lua = DirectorManager::instance()->getLuaInstance();
-       LuaFunction luaOnPlayerLoggedIn(lua->getLuaState(), getJediManagerName(), "onPlayerLoggedIn", 0);
-       luaOnPlayerLoggedIn << creature;
+       Reference<LuaFunction*> luaOnPlayerLoggedIn = lua->createFunction(getJediManagerName(), "onPlayerLoggedIn", 0);
+       *luaOnPlayerLoggedIn << creature;
 
-       luaOnPlayerLoggedIn.callFunction();
+       luaOnPlayerLoggedIn->callFunction();
 }
 
 void JediManager::onPlayerLoggedOut(CreatureObject* creature) {
        Lua* lua = DirectorManager::instance()->getLuaInstance();
-       LuaFunction luaOnPlayerLoggedOut(lua->getLuaState(), getJediManagerName(), "onPlayerLoggedOut", 0);
-       luaOnPlayerLoggedOut << creature;
+       Reference<LuaFunction*> luaOnPlayerLoggedOut = lua->createFunction(getJediManagerName(), "onPlayerLoggedOut", 0);
+       *luaOnPlayerLoggedOut << creature;
 
-       luaOnPlayerLoggedOut.callFunction();
+       luaOnPlayerLoggedOut->callFunction();
 }
 
 void JediManager::checkForceStatusCommand(CreatureObject* creature) {
        Lua* lua = DirectorManager::instance()->getLuaInstance();
-       LuaFunction luaCheckForceStatusCommand(lua->getLuaState(), getJediManagerName(), "checkForceStatusCommand", 0);
-       luaCheckForceStatusCommand << creature;
+       Reference<LuaFunction*> luaCheckForceStatusCommand = lua->createFunction(getJediManagerName(), "checkForceStatusCommand", 0);
+       *luaCheckForceStatusCommand << creature;
 
-       luaCheckForceStatusCommand.callFunction();
+       luaCheckForceStatusCommand->callFunction();
 }
 
 void JediManager::useHolocron(SceneObject* holocron, CreatureObject* creature) {
        Lua* lua = DirectorManager::instance()->getLuaInstance();
-       LuaFunction luaUseHolocron(lua->getLuaState(), getJediManagerName(), "useHolocron", 0);
-       luaUseHolocron << holocron;
-       luaUseHolocron << creature;
+       Reference<LuaFunction*> luaUseHolocron = lua->createFunction(getJediManagerName(), "useHolocron", 0);
+       *luaUseHolocron << holocron;
+       *luaUseHolocron << creature;
 
-       luaUseHolocron.callFunction();
+       luaUseHolocron->callFunction();
 }
index 2a87d65..31da15f 100644 (file)
@@ -53,6 +53,8 @@ which carries forward this exception.
 using ::testing::_;
 using ::testing::Return;
 using ::testing::AnyNumber;
+using ::testing::TypedEq;
+using ::testing::An;
 
 namespace server {
 namespace zone {
@@ -60,11 +62,11 @@ namespace managers {
 namespace jedi {
 namespace tests {
 
-class JediManagerTest : public ::testing::Test {
+class JediManagerTest : public ::testing::Test, public Logger {
 public:
        JediManager* jediManager;
 
-       JediManagerTest() {
+       JediManagerTest() : Logger("JediManagerTest") {
                // Perform creation setup here.
        }
 
@@ -166,10 +168,107 @@ TEST_F(JediManagerTest, ShouldReadTheJediProgressionSystemNameAtLoadConfiguratio
        jediManager->loadConfiguration(&mockLua);
 }
 
-//TODO Add test of the onPlayerCreation method.
-//TODO Add test of the onPlayerLogin method.
-//TODO Add test of the onPlayerLogout method.
-//TODO Add test of the checkForceStatusCommand. Needs an updated engine.
+TEST_F(JediManagerTest, OnPlayerCreatedShouldCallTheOnPlayerCreatedMethodInTheLuaJediManager) {
+       MockLua mockLua;
+       Reference<MockLuaFunction*> mockLuaFunction = new MockLuaFunction();
+       Reference<MockDirectorManager*> mockDirectorManager = new MockDirectorManager();
+       Reference<MockCreatureObject*> mockCreatureObject = new MockCreatureObject();
+
+       EXPECT_CALL(*mockDirectorManager, getLuaInstance()).WillOnce(Return(&mockLua));
+       EXPECT_CALL(mockLua, createFunction(String("JediManager"), String("onPlayerCreated"), 0)).WillOnce(Return(mockLuaFunction));
+       EXPECT_CALL(*mockLuaFunction, addArgument(TypedEq<void*>(mockCreatureObject))).Times(1);
+       EXPECT_CALL(*mockLuaFunction, callFunction()).Times(1);
+
+       Reference<DirectorManager*> realDirectorManager = DirectorManager::instance();
+
+       DirectorManager::setSingletonInstance(mockDirectorManager);
+
+       JediManager::instance()->onPlayerCreated(mockCreatureObject);
+
+       DirectorManager::setSingletonInstance(realDirectorManager);
+}
+
+TEST_F(JediManagerTest, OnPlayerLoggedInShouldCallTheOnPlayerLoggedInMethodInTheLuaJediManager) {
+       MockLua mockLua;
+       Reference<MockLuaFunction*> mockLuaFunction = new MockLuaFunction();
+       Reference<MockDirectorManager*> mockDirectorManager = new MockDirectorManager();
+       Reference<MockCreatureObject*> mockCreatureObject = new MockCreatureObject();
+
+       EXPECT_CALL(*mockDirectorManager, getLuaInstance()).WillOnce(Return(&mockLua));
+       EXPECT_CALL(mockLua, createFunction(String("JediManager"), String("onPlayerLoggedIn"), 0)).WillOnce(Return(mockLuaFunction));
+       EXPECT_CALL(*mockLuaFunction, addArgument(TypedEq<void*>(mockCreatureObject))).Times(1);
+       EXPECT_CALL(*mockLuaFunction, callFunction()).Times(1);
+
+       Reference<DirectorManager*> realDirectorManager = DirectorManager::instance();
+
+       DirectorManager::setSingletonInstance(mockDirectorManager);
+
+       JediManager::instance()->onPlayerLoggedIn(mockCreatureObject);
+
+       DirectorManager::setSingletonInstance(realDirectorManager);
+}
+
+TEST_F(JediManagerTest, OnPlayerLoggedOutShouldCallTheOnPlayerLoggedOutMethodInTheLuaJediManager) {
+       MockLua mockLua;
+       Reference<MockLuaFunction*> mockLuaFunction = new MockLuaFunction();
+       Reference<MockDirectorManager*> mockDirectorManager = new MockDirectorManager();
+       Reference<MockCreatureObject*> mockCreatureObject = new MockCreatureObject();
+
+       EXPECT_CALL(*mockDirectorManager, getLuaInstance()).WillOnce(Return(&mockLua));
+       EXPECT_CALL(mockLua, createFunction(String("JediManager"), String("onPlayerLoggedOut"), 0)).WillOnce(Return(mockLuaFunction));
+       EXPECT_CALL(*mockLuaFunction, addArgument(TypedEq<void*>(mockCreatureObject))).Times(1);
+       EXPECT_CALL(*mockLuaFunction, callFunction()).Times(1);
+
+       Reference<DirectorManager*> realDirectorManager = DirectorManager::instance();
+
+       DirectorManager::setSingletonInstance(mockDirectorManager);
+
+       JediManager::instance()->onPlayerLoggedOut(mockCreatureObject);
+
+       DirectorManager::setSingletonInstance(realDirectorManager);
+}
+
+TEST_F(JediManagerTest, CheckForceStatusCommandShouldCallTheCheckForceStatusCommandMethodInTheLuaJediManager) {
+       MockLua mockLua;
+       Reference<MockLuaFunction*> mockLuaFunction = new MockLuaFunction();
+       Reference<MockDirectorManager*> mockDirectorManager = new MockDirectorManager();
+       Reference<MockCreatureObject*> mockCreatureObject = new MockCreatureObject();
+
+       EXPECT_CALL(*mockDirectorManager, getLuaInstance()).WillOnce(Return(&mockLua));
+       EXPECT_CALL(mockLua, createFunction(String("JediManager"), String("checkForceStatusCommand"), 0)).WillOnce(Return(mockLuaFunction));
+       EXPECT_CALL(*mockLuaFunction, addArgument(TypedEq<void*>(mockCreatureObject))).Times(1);
+       EXPECT_CALL(*mockLuaFunction, callFunction()).Times(1);
+
+       Reference<DirectorManager*> realDirectorManager = DirectorManager::instance();
+
+       DirectorManager::setSingletonInstance(mockDirectorManager);
+
+       JediManager::instance()->checkForceStatusCommand(mockCreatureObject);
+
+       DirectorManager::setSingletonInstance(realDirectorManager);
+}
+
+TEST_F(JediManagerTest, UseHolocronShouldCallTheUseHolocronMethodInTheLuaJediManager) {
+       MockLua mockLua;
+       Reference<MockLuaFunction*> mockLuaFunction = new MockLuaFunction();
+       Reference<MockDirectorManager*> mockDirectorManager = new MockDirectorManager();
+       Reference<MockCreatureObject*> mockCreatureObject = new MockCreatureObject();
+       Reference<MockSceneObject*> mockSceneObject = new MockSceneObject();
+
+       EXPECT_CALL(*mockDirectorManager, getLuaInstance()).WillOnce(Return(&mockLua));
+       EXPECT_CALL(mockLua, createFunction(String("JediManager"), String("useHolocron"), 0)).WillOnce(Return(mockLuaFunction));
+       EXPECT_CALL(*mockLuaFunction, addArgument(An<void*>())).Times(2);
+       EXPECT_CALL(*mockLuaFunction, callFunction()).Times(1);
+
+       Reference<DirectorManager*> realDirectorManager = DirectorManager::instance();
+
+       DirectorManager::setSingletonInstance(mockDirectorManager);
+
+       JediManager::instance()->useHolocron(mockSceneObject, mockCreatureObject);
+
+       DirectorManager::setSingletonInstance(realDirectorManager);
+}
+
 
 }
 }
index a1f68e4..006fc3a 100644 (file)
@@ -257,6 +257,8 @@ class AttributeListMessage;
 
 using namespace server::zone::packets::scene;
 
+#include "gmock/gmock.h"
+
 #include "server/zone/objects/creature/variables/CooldownTimerMap.h"
 
 #include "server/zone/objects/creature/buffs/BuffList.h"
@@ -2342,6 +2344,16 @@ public:
        friend class Singleton<CreatureObjectHelper>;
 };
 
+class MockCreatureObject : public CreatureObject {
+public:
+
+       MOCK_METHOD0(getWorldPositionX,float());
+       MOCK_METHOD0(getWorldPositionY,float());
+       MOCK_METHOD0(getWorldPositionZ,float());
+       MOCK_METHOD0(getWorldPosition,Vector3());
+
+};
+
 } // namespace creature
 } // namespace objects
 } // namespace zone
index 3480067..bedcd49 100644 (file)
@@ -88,6 +88,7 @@ import engine.service.proto.BasePacket;
 import server.zone.packets.scene.AttributeListMessage;
 import system.thread.Mutex;
 
+@mock
 class CreatureObject extends TangibleObject {
        protected transient ZoneClientSession owner;
 
index ed41aa6..4493b4b 100644 (file)
@@ -52,7 +52,6 @@ namespace lua {
 
 class MockLuaFunction: public LuaFunction {
 public:
-       MockLuaFunction(lua_State* l, const String& object, const String& func, int argsToReturn) : LuaFunction(l, object, func, argsToReturn) {}
 
        MOCK_METHOD0(callFunction, lua_State*());
        MOCK_METHOD1(addArgument, void(int number));