void inOutTraitRef_luaPassesInt_functionReceivesInputedValue() { InOutParamHelper helper(m_lua); EXPECT_CALL(helper.mock, ref(::testing::Eq(helper.input))).Times(1); m_lua->run_chunk("return function(object, input) return object:ref(input) end"); m_lua->call(1, helper.object, helper.input); }
void constructWithEnum_passedString_callReturnsFalse() { m_lua->register_class<Enums>(); m_lua->run_chunk("foo = function() " "local obj = Enums:new('foo') " "end"); CPPUNIT_ASSERT_EQUAL(false,m_lua->call("foo")); }
void constructWithEnum_passedString_throwsOoluaRuntimeError() { m_lua->register_class<Enums>(); m_lua->run_chunk("foo = function() " "local obj = Enums:new('foo') " "end"); CPPUNIT_ASSERT_THROW(m_lua->call("foo"),OOLUA::Runtime_error); }
void constructWithEnum_passedCoroutine_callReturnsFalse() { m_lua->register_class<Enums>(); m_lua->run_chunk("foo = function() " "local obj = Enums:new( coroutine.create (foo)) " "end"); CPPUNIT_ASSERT_EQUAL(false,m_lua->call("foo")); }
void inOutTraitRef_luaPassesInt_functionPushesBackNumber() { m_lua->register_class<IntegerFunctionInOutTraits>(); ::testing::NiceMock<IntegerFunctionInOutTraitsMock> fake; m_lua->run_chunk("return function(object) return object:ref(1) end"); m_lua->call(1, static_cast<IntegerFunctionInOutTraits*>(&fake)); CPPUNIT_ASSERT_EQUAL(LUA_TNUMBER, lua_type(*m_lua, -1)); }
/**[IntegerInOutParamUsage]*/ void inOutTraitRef_luaPassesIntCppAssignsNewValue_returnIsNewlyAssignedValue() { InOutParamHelper helper(m_lua); EXPECT_CALL(helper.mock, ref(::testing::_)).Times(1).WillOnce(::testing::SetArgReferee<0>(helper.expected)); m_lua->run_chunk("return function(object) return object:ref(1) end"); m_lua->call(1, helper.object); assert_top_of_stack_is_expected_value(helper.expected); }
void outTraitPtr_luaDoesNotPassIntCppAssignsNewValue_returnIsNewlyAssignedValue() { OutParamHelper helper(m_lua); EXPECT_CALL(helper.mock, ptr(::testing::_)).Times(1).WillOnce(::testing::SetArgumentPointee<0>(helper.expected)); m_lua->run_chunk("return function(object) return object:ptr() end"); m_lua->call(1, helper.object); assert_top_of_stack_is_expected_value(helper.expected); }
void globalData_addIntGlobalThenReturnItFromFunction_callReturnsTrue() { int input(1); OOLUA::set_global(*m_lua, "i", input); m_lua->run_chunk("foo = function() return i end"); bool result = m_lua->call("foo"); CPPUNIT_ASSERT_EQUAL(true,result); }
void globalData_addIntGlobalThenReturnItFromFunction_resultEqualsInput() { int input(1); OOLUA::set_global(*m_lua, "i", input); m_lua->run_chunk("foo = function() return i end"); m_lua->call("foo"); int result; OOLUA::pull2cpp(*m_lua,result); CPPUNIT_ASSERT_EQUAL(input,result); }
void constructWithEnum_passedValueGreen_functionReturnsGreen() { m_lua->register_class<Enums>(); m_lua->run_chunk("foo = function() " "local obj = Enums:new(Enums.GREEN) " "return obj:get_enum() " "end"); Enums::COLOUR result(Enums::INVALID); m_lua->call("foo"); OOLUA::pull2cpp(*m_lua,result); CPPUNIT_ASSERT_EQUAL(Enums::GREEN,result); }
void memberFunction_returnsEnum_defaultValueIsInvalid() { m_lua->register_class<Enums>(); m_lua->run_chunk("foo = function() " "local obj = Enums:new() " "return obj:get_enum() " "end"); Enums::COLOUR result(Enums::GREEN); m_lua->call("foo"); OOLUA::pull2cpp(*m_lua,result); CPPUNIT_ASSERT_EQUAL(Enums::INVALID,result); }
void memberFunctionSetsEnum_passedGreen_resultIsGreen() { m_lua->register_class<Enums>(); m_lua->run_chunk("foo = function() " "local obj = Enums:new() " "obj:set_enum(obj.GREEN) " "return obj:get_enum() " "end"); Enums::COLOUR result(Enums::INVALID); m_lua->call("foo"); OOLUA::pull2cpp(*m_lua,result); CPPUNIT_ASSERT_EQUAL(Enums::GREEN,result); }
void globalData_addFuncToGlobalThenCall_callReturnsTrue() { OOLUA::set_global(*m_lua, "global_func", dummy_c_function_returns_stack_count); bool result = m_lua->call("global_func"); CPPUNIT_ASSERT_EQUAL(true,result); }
void luaReturnsEnum0_resultIsEqualToEnum0() { m_lua->register_class<ClassWithEnums>(); m_lua->run_chunk("return ClassWithEnums.ENUM_0"); ClassWithEnums::ClassEnum return_value = ClassWithEnums::ENUM_1; OOLUA::pull(*m_lua, return_value); CPPUNIT_ASSERT_EQUAL(ClassWithEnums::ENUM_0, return_value); }
void Init() { if (!s_isInitted) { s_isInitted = true; OOLUA::Script *S = new OOLUA::Script; L = S->get_ptr(); luaL_openlibs(L); lua_register(L, "PiModule", register_module); RegisterPiLuaAPI(L); if (luaL_dofile(L, "data/pimodule.lua")) { Error("%s", lua_tostring(L, -1)); } DoAllLuaModuleFiles(L); ModsInitAll(); Pi::onPlayerChangeTarget.connect(sigc::bind(sigc::ptr_fun(&mods_event_dispatcher), "onPlayerChangeTarget")); } }
void scriptConstructor_checkStackSize_stackIsEmpty() { OOLUA::Script s; CPPUNIT_ASSERT_EQUAL(0, s.stack_count()); }
void registerClass_checkStackSize_stackIsEmpty() { OOLUA::Script s; s.register_class<Stub1>(); CPPUNIT_ASSERT_EQUAL(0, s.stack_count()); }