diff --git a/tests/lua-tests/project/Classes/AppDelegate.cpp b/tests/lua-tests/project/Classes/AppDelegate.cpp index cbcd0f6821..3bad5648b8 100644 --- a/tests/lua-tests/project/Classes/AppDelegate.cpp +++ b/tests/lua-tests/project/Classes/AppDelegate.cpp @@ -47,9 +47,11 @@ bool AppDelegate::applicationDidFinishLaunching() // register lua engine LuaEngine* pEngine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(pEngine); + + LuaStack* stack = pEngine->getLuaStack(); + stack->setXXTEAKeyAndSign("2dxLua", strlen("2dxLua"), "XXTEA", strlen("XXTEA")); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID ||CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) - LuaStack* stack = pEngine->getLuaStack(); register_assetsmanager_test_sample(stack->getLuaState()); #endif diff --git a/tests/lua-tests/src/ByteCodeEncryptTest/ByteCodeAndEncryptTest.luac b/tests/lua-tests/src/ByteCodeEncryptTest/ByteCodeAndEncryptTest.luac new file mode 100644 index 0000000000..a80fd1e678 Binary files /dev/null and b/tests/lua-tests/src/ByteCodeEncryptTest/ByteCodeAndEncryptTest.luac differ diff --git a/tests/lua-tests/src/ByteCodeEncryptTest/ByteCodeEncryptTest.lua b/tests/lua-tests/src/ByteCodeEncryptTest/ByteCodeEncryptTest.lua new file mode 100644 index 0000000000..c8d20a7bf4 --- /dev/null +++ b/tests/lua-tests/src/ByteCodeEncryptTest/ByteCodeEncryptTest.lua @@ -0,0 +1,104 @@ +require("src/ByteCodeEncryptTest/ByteCodeTest") +require("src/ByteCodeEncryptTest/ByteCodeAndEncryptTest") + +local LINE_SPACE = 40 +local ItemTagBasic = 1000 + +local ByteCodeEncryptEnum = +{ + TEST_BYTECODE = 0, + TEST_BYTECODE_ENCRYPT = 1, + TEST_MAX_COUNT = 2, +} + +local TestsName = +{ + "ByteCodeFileTest", + "ByteCodeAndEncryptFileTest", +} + +local CreateByteCodeEncryptTestTable = +{ + runByteCodeFileTest, + runByteCodeAndEncryptFileTest, +} + +local function byteCodeEncryptMainLayer() + local size = cc.Director:getInstance():getWinSize() + + local function createByteCodeEncryptTestScene(index) + local newScene = CreateByteCodeEncryptTestTable[index]() + return newScene + end + + local function menuCallback(tag, sender) + local scene = nil + local index = sender:getLocalZOrder() - ItemTagBasic + local byteCodeEncryptScene = createByteCodeEncryptTestScene(index) + if nil ~= byteCodeEncryptScene then + cc.Director:getInstance():replaceScene(byteCodeEncryptScene) + end + end + + local layer = cc.Layer:create() + local menu = cc.Menu:create() + menu:setPosition(cc.p(0, 0)) + cc.MenuItemFont:setFontName("Arial") + cc.MenuItemFont:setFontSize(24) + + for i = 1, ByteCodeEncryptEnum.TEST_MAX_COUNT do + local item = cc.MenuItemFont:create(TestsName[i]) + item:registerScriptTapHandler(menuCallback) + item:setPosition(size.width / 2, size.height - i * LINE_SPACE) + menu:addChild(item, ItemTagBasic + i) + end + + layer:addChild(menu) + + -- handling touch events + local beginPos = {x = 0, y = 0} + local function onTouchesBegan(touches, event) + beginPos = touches[1]:getLocation() + end + + local function onTouchesMoved(touches, event) + local location = touches[1]:getLocation() + + local nMoveY = location.y - beginPos.y + local curPosx, curPosy = menu:getPosition() + local nextPosy = curPosy + nMoveY + local winSize = cc.Director:getInstance():getWinSize() + if nextPosy < 0 then + menu:setPosition(0, 0) + return + end + + if nextPosy > ((ByteCodeEncryptEnum.TEST_MAX_COUNT + 1) * LINE_SPACE - winSize.height) then + menu:setPosition(0, ((ByteCodeEncryptEnum.TEST_MAX_COUNT + 1) * LINE_SPACE - winSize.height)) + return + end + + menu:setPosition(curPosx, nextPosy) + beginPos = {x = location.x, y = location.y} + end + + local listener = cc.EventListenerTouchAllAtOnce:create() + listener:registerScriptHandler(onTouchesBegan,cc.Handler.EVENT_TOUCHES_BEGAN ) + listener:registerScriptHandler(onTouchesMoved,cc.Handler.EVENT_TOUCH_MOVED ) + + local eventDispatcher = layer:getEventDispatcher() + eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layer) + + return layer +end +------------------------------------- +-- ByteCodeEncrypt Test +------------------------------------- +function ByteCodeEncryptTestMain() + local scene = cc.Scene:create() + + scene:addChild(byteCodeEncryptMainLayer()) + scene:addChild(CreateBackMenuItem()) + + return scene +end diff --git a/tests/lua-tests/src/ByteCodeEncryptTest/ByteCodeTest.luac b/tests/lua-tests/src/ByteCodeEncryptTest/ByteCodeTest.luac new file mode 100644 index 0000000000..9f782fc431 Binary files /dev/null and b/tests/lua-tests/src/ByteCodeEncryptTest/ByteCodeTest.luac differ diff --git a/tests/lua-tests/src/mainMenu.lua b/tests/lua-tests/src/mainMenu.lua index 8d2241a1f4..ce3f86c60c 100644 --- a/tests/lua-tests/src/mainMenu.lua +++ b/tests/lua-tests/src/mainMenu.lua @@ -15,6 +15,7 @@ require "src/ActionsProgressTest/ActionsProgressTest" require "src/ActionsTest/ActionsTest" require "src/AssetsManagerTest/AssetsManagerTest" require "src/BugsTest/BugsTest" +require "src/ByteCodeEncryptTest/ByteCodeEncryptTest" require "src/ClickAndMoveTest/ClickAndMoveTest" require "src/CocosDenshionTest/CocosDenshionTest" require "src/CocoStudioTest/CocoStudioTest" @@ -70,6 +71,7 @@ local _allTests = { { isSupported = false, name = "Box2dTest" , create_func= Box2dTestMain }, { isSupported = false, name = "Box2dTestBed" , create_func= Box2dTestBedMain }, { isSupported = true, name = "BugsTest" , create_func= BugsTestMain }, + { isSupported = true, name = "ByteCodeEncryptTest" , create_func= ByteCodeEncryptTestMain }, { isSupported = false, name = "ChipmunkAccelTouchTest" , create_func= ChipmunkAccelTouchTestMain }, { isSupported = true, name = "ClickAndMoveTest" , create_func = ClickAndMoveTest }, { isSupported = true, name = "CocosDenshionTest" , create_func = CocosDenshionTestMain },