diff --git a/samples/Lua/TestLua/Resources/luaScript/UserDefaultTest/UserDefaultTest.lua b/samples/Lua/TestLua/Resources/luaScript/UserDefaultTest/UserDefaultTest.lua new file mode 100644 index 0000000000..4d82f995cc --- /dev/null +++ b/samples/Lua/TestLua/Resources/luaScript/UserDefaultTest/UserDefaultTest.lua @@ -0,0 +1,80 @@ +-- enable log + + +local function doTest() + cclog("********************** init value ***********************") + + -- set default value + + CCUserDefault:sharedUserDefault():setStringForKey("string", "value1") + CCUserDefault:sharedUserDefault():setIntegerForKey("integer", 10) + CCUserDefault:sharedUserDefault():setFloatForKey("float", 2.3) + CCUserDefault:sharedUserDefault():setDoubleForKey("double", 2.4) + CCUserDefault:sharedUserDefault():setBoolForKey("bool", true) + + -- print value + + local ret = CCUserDefault:sharedUserDefault():getStringForKey("string") + cclog("string is %s", ret) + + local d = CCUserDefault:sharedUserDefault():getDoubleForKey("double") + cclog("double is %f", d) + + local i = CCUserDefault:sharedUserDefault():getIntegerForKey("integer") + cclog("integer is %d", i) + + local f = CCUserDefault:sharedUserDefault():getFloatForKey("float") + cclog("float is %f", f) + + local b = CCUserDefault:sharedUserDefault():getBoolForKey("bool") + if b == true then + cclog("bool is true") + else + cclog("bool is false") + end + + --CCUserDefault:sharedUserDefault():flush() + + cclog("********************** after change value ***********************") + + -- change the value + + CCUserDefault:sharedUserDefault():setStringForKey("string", "value2") + CCUserDefault:sharedUserDefault():setIntegerForKey("integer", 11) + CCUserDefault:sharedUserDefault():setFloatForKey("float", 2.5) + CCUserDefault:sharedUserDefault():setDoubleForKey("double", 2.6) + CCUserDefault:sharedUserDefault():setBoolForKey("bool", false) + + CCUserDefault:sharedUserDefault():flush() + + -- print value + + ret = CCUserDefault:sharedUserDefault():getStringForKey("string") + cclog("string is %s", ret) + + d = CCUserDefault:sharedUserDefault():getDoubleForKey("double") + cclog("double is %f", d) + + i = CCUserDefault:sharedUserDefault():getIntegerForKey("integer") + cclog("integer is %d", i) + + f = CCUserDefault:sharedUserDefault():getFloatForKey("float") + cclog("float is %f", f) + + b = CCUserDefault:sharedUserDefault():getBoolForKey("bool") + if b == true then + cclog("bool is true") + else + cclog("bool is false") + end +end + +function UserDefaultTestMain() + local ret = CCScene:create() + local s = CCDirector:sharedDirector():getWinSize() + local label = CCLabelTTF:create("CCUserDefault test see log", "Arial", 28) + ret:addChild(label, 0) + label:setPosition( ccp(s.width/2, s.height-50) ) + doTest() + return ret +end diff --git a/samples/Lua/TestLua/Resources/luaScript/mainMenu.lua b/samples/Lua/TestLua/Resources/luaScript/mainMenu.lua index 8833e20430..658810a524 100644 --- a/samples/Lua/TestLua/Resources/luaScript/mainMenu.lua +++ b/samples/Lua/TestLua/Resources/luaScript/mainMenu.lua @@ -1,6 +1,35 @@ -require "luaScript/tests" require "luaScript/helper" require "luaScript/testResource" + +require "luaScript/ActionsTest/ActionsTest" +require "luaScript/TransitionsTest/TransitionsTest" +require "luaScript/ActionsProgressTest/ActionsProgressTest" +require "luaScript/EffectsTest/EffectsTest" +require "luaScript/ClickAndMoveTest/ClickAndMoveTest" +require "luaScript/RotateWorldTest/RotateWorldTest" +require "luaScript/ParticleTest/ParticleTest" +require "luaScript/ActionsEaseTest/ActionsEaseTest" +require "luaScript/MotionStreakTest/MotionStreakTest" +require "luaScript/DrawPrimitivesTest/DrawPrimitivesTest" +require "luaScript/NodeTest/NodeTest" +require "luaScript/TouchesTest/TouchesTest" +require "luaScript/SpriteTest/SpriteTest" +require "luaScript/LayerTest/LayerTest" +require "luaScript/PerformanceTest/PerformanceTest" +require "luaScript/LabelTest/LabelTest" +require "luaScript/ParallaxTest/ParallaxTest" +require "luaScript/TileMapTest/TileMapTest" +require "luaScript/ActionManagerTest/ActionManagerTest" +require "luaScript/MenuTest/MenuTest" +require "luaScript/IntervalTest/IntervalTest" +require "luaScript/SceneTest/SceneTest" +require "luaScript/Texture2dTest/Texture2dTest" +require "luaScript/RenderTextureTest/RenderTextureTest" +require "luaScript/ZwoptexTest/ZwoptexTest" +require "luaScript/FontTest/FontTest" +require "luaScript/CocosDenshionTest/CocosDenshionTest" +require "luaScript/EffectsAdvancedTest/EffectsAdvancedTest" +require "luaScript/UserDefaultTest/UserDefaultTest" ------------------------ @@ -46,7 +75,7 @@ local _allTests = { { isSupported = false, name = "PerformanceTest" , create_func= PerformanceTestMain }, { isSupported = true, name = "ZwoptexTest" , create_func = ZwoptexTestMain }, { isSupported = false, name = "CurlTest" , create_func= CurlTestMain }, - { isSupported = false, name = "UserDefaultTest" , create_func= UserDefaultTestMain }, + { isSupported = true, name = "UserDefaultTest" , create_func= UserDefaultTestMain }, { isSupported = false, name = "BugsTest" , create_func= BugsTestMain }, { isSupported = true, name = "FontTest" , create_func = FontTestMain }, { isSupported = false, name = "CurrentLanguageTest" , create_func= CurrentLanguageTestMain }, diff --git a/samples/Lua/TestLua/proj.nacl/main.cpp b/samples/Lua/TestLua/proj.nacl/main.cpp index da3cad3e64..4903b8748f 100644 --- a/samples/Lua/TestLua/proj.nacl/main.cpp +++ b/samples/Lua/TestLua/proj.nacl/main.cpp @@ -124,7 +124,6 @@ void* cocos_main(void* arg) "zwoptex/grossini.png", "luaScript/mainMenu.lua", "luaScript/helper.lua", - "luaScript/tests.lua", "luaScript/testResource.lua", "luaScript/ActionsTest/ActionsTest.lua", "luaScript/ActionsTest/ActionsName.lua",