2013-05-23 08:56:05 +08:00
|
|
|
|
|
|
|
#include "ConfigurationTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
#include "cocos2d.h"
|
|
|
|
|
|
|
|
TESTLAYER_CREATE_FUNC(ConfigurationLoadConfig);
|
|
|
|
TESTLAYER_CREATE_FUNC(ConfigurationQuery);
|
2013-05-29 09:15:16 +08:00
|
|
|
TESTLAYER_CREATE_FUNC(ConfigurationInvalid);
|
2013-05-31 07:10:31 +08:00
|
|
|
TESTLAYER_CREATE_FUNC(ConfigurationDefault);
|
2013-06-04 04:49:06 +08:00
|
|
|
TESTLAYER_CREATE_FUNC(ConfigurationSet);
|
2013-05-23 08:56:05 +08:00
|
|
|
|
|
|
|
static NEWTESTFUNC createFunctions[] = {
|
|
|
|
CF(ConfigurationLoadConfig),
|
2013-05-29 09:15:16 +08:00
|
|
|
CF(ConfigurationQuery),
|
2013-05-31 07:10:31 +08:00
|
|
|
CF(ConfigurationInvalid),
|
2013-06-04 04:49:06 +08:00
|
|
|
CF(ConfigurationDefault),
|
|
|
|
CF(ConfigurationSet)
|
2013-05-23 08:56:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int sceneIdx=-1;
|
|
|
|
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
static Layer* nextAction()
|
2013-05-23 08:56:05 +08:00
|
|
|
{
|
|
|
|
sceneIdx++;
|
|
|
|
sceneIdx = sceneIdx % MAX_LAYER;
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* pLayer = (createFunctions[sceneIdx])();
|
2013-05-23 08:56:05 +08:00
|
|
|
pLayer->init();
|
|
|
|
pLayer->autorelease();
|
|
|
|
|
|
|
|
return pLayer;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
static Layer* backAction()
|
2013-05-23 08:56:05 +08:00
|
|
|
{
|
|
|
|
sceneIdx--;
|
|
|
|
int total = MAX_LAYER;
|
|
|
|
if( sceneIdx < 0 )
|
|
|
|
sceneIdx += total;
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* pLayer = (createFunctions[sceneIdx])();
|
2013-05-23 08:56:05 +08:00
|
|
|
pLayer->init();
|
|
|
|
pLayer->autorelease();
|
|
|
|
|
|
|
|
return pLayer;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
static Layer* restartAction()
|
2013-05-23 08:56:05 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* pLayer = (createFunctions[sceneIdx])();
|
2013-05-23 08:56:05 +08:00
|
|
|
pLayer->init();
|
|
|
|
pLayer->autorelease();
|
|
|
|
|
|
|
|
return pLayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigurationTestScene::runThisTest()
|
|
|
|
{
|
|
|
|
sceneIdx = -1;
|
|
|
|
addChild(nextAction());
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2013-05-23 08:56:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string ConfigurationBase::title()
|
|
|
|
{
|
|
|
|
return "Configuration Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ConfigurationBase::subtitle()
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigurationBase::onEnter()
|
|
|
|
{
|
2013-06-07 08:12:28 +08:00
|
|
|
BaseTest::onEnter();
|
2013-05-23 08:56:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigurationBase::onExit()
|
|
|
|
{
|
2013-06-07 08:12:28 +08:00
|
|
|
BaseTest::onExit();
|
2013-05-23 08:56:05 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void ConfigurationBase::restartCallback(Object* pSender)
|
2013-05-23 08:56:05 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene* s = new ConfigurationTestScene();
|
2013-05-23 08:56:05 +08:00
|
|
|
s->addChild( restartAction() );
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2013-05-23 08:56:05 +08:00
|
|
|
s->release();
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void ConfigurationBase::nextCallback(Object* pSender)
|
2013-05-23 08:56:05 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene* s = new ConfigurationTestScene();
|
2013-05-23 08:56:05 +08:00
|
|
|
s->addChild( nextAction() );
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2013-05-23 08:56:05 +08:00
|
|
|
s->release();
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void ConfigurationBase::backCallback(Object* pSender)
|
2013-05-23 08:56:05 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene* s = new ConfigurationTestScene();
|
2013-05-23 08:56:05 +08:00
|
|
|
s->addChild( backAction() );
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2013-05-23 08:56:05 +08:00
|
|
|
s->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ConfigurationLoadConfig
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ConfigurationLoadConfig::onEnter()
|
|
|
|
{
|
|
|
|
ConfigurationBase::onEnter();
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Configuration::getInstance()->loadConfigFile("configs/config-test-ok.plist");
|
|
|
|
Configuration::getInstance()->dumpInfo();
|
2013-05-23 08:56:05 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ConfigurationLoadConfig::subtitle()
|
|
|
|
{
|
|
|
|
return "Loading config file manually. See console";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ConfigurationQuery
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ConfigurationQuery::onEnter()
|
|
|
|
{
|
|
|
|
ConfigurationBase::onEnter();
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
CCLOG("cocos2d version: %s", Configuration::getInstance()->getCString("cocos2d.version") );
|
|
|
|
CCLOG("OpenGL version: %s", Configuration::getInstance()->getCString("gl.version") );
|
2013-05-23 08:56:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string ConfigurationQuery::subtitle()
|
|
|
|
{
|
|
|
|
return "Using getCString(). Check the console";
|
|
|
|
}
|
2013-05-29 09:15:16 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ConfigurationInvalid
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ConfigurationInvalid::onEnter()
|
|
|
|
{
|
|
|
|
ConfigurationBase::onEnter();
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Configuration::getInstance()->loadConfigFile("configs/config-test-invalid.plist");
|
2013-05-29 09:15:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string ConfigurationInvalid::subtitle()
|
|
|
|
{
|
|
|
|
return "Loading an invalid config file";
|
|
|
|
}
|
2013-05-31 07:10:31 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ConfigurationDefault
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ConfigurationDefault::onEnter()
|
|
|
|
{
|
|
|
|
ConfigurationBase::onEnter();
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
const char *c_value = Configuration::getInstance()->getCString("invalid.key", "no key");
|
2013-05-31 07:10:31 +08:00
|
|
|
if( strcmp(c_value, "no key") != 0 )
|
|
|
|
CCLOG("1. Test failed!");
|
|
|
|
else
|
|
|
|
CCLOG("1. Test OK!");
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
bool b_value = Configuration::getInstance()->getBool("invalid.key", true);
|
2013-05-31 07:10:31 +08:00
|
|
|
if( ! b_value )
|
|
|
|
CCLOG("2. Test failed!");
|
|
|
|
else
|
|
|
|
CCLOG("2. Test OK!");
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
double d_value = Configuration::getInstance()->getNumber("invalid.key", 42.42);
|
2013-05-31 07:10:31 +08:00
|
|
|
if( d_value != 42.42 )
|
|
|
|
CCLOG("3. Test failed!");
|
|
|
|
else
|
|
|
|
CCLOG("3. Test OK!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ConfigurationDefault::subtitle()
|
|
|
|
{
|
|
|
|
return "Tests defaults values";
|
|
|
|
}
|
2013-06-04 04:49:06 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ConfigurationSet
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ConfigurationSet::onEnter()
|
|
|
|
{
|
|
|
|
ConfigurationBase::onEnter();
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Configuration *conf = Configuration::getInstance();
|
2013-06-04 04:49:06 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
conf->setObject("this.is.an.int.value", Integer::create(10) );
|
|
|
|
conf->setObject("this.is.a.bool.value", Bool::create(true) );
|
|
|
|
conf->setObject("this.is.a.string.value", String::create("hello world") );
|
2013-06-04 04:49:06 +08:00
|
|
|
|
|
|
|
conf->dumpInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ConfigurationSet::subtitle()
|
|
|
|
{
|
|
|
|
return "Tests setting values manually";
|
|
|
|
}
|
|
|
|
|