2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-09 22:23:34 +08:00
|
|
|
https://axis-project.github.io/
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-05-23 08:56:05 +08:00
|
|
|
#include "ConfigurationTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
#include "cocos2d.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2015-04-09 12:23:47 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
ConfigurationTests::ConfigurationTests()
|
2013-05-23 08:56:05 +08:00
|
|
|
{
|
2015-04-03 14:31:03 +08:00
|
|
|
ADD_TEST_CASE(ConfigurationLoadConfig);
|
|
|
|
ADD_TEST_CASE(ConfigurationQuery);
|
|
|
|
ADD_TEST_CASE(ConfigurationInvalid);
|
|
|
|
ADD_TEST_CASE(ConfigurationDefault);
|
|
|
|
ADD_TEST_CASE(ConfigurationSet);
|
2013-05-23 08:56:05 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ConfigurationBase::title() const
|
2013-05-23 08:56:05 +08:00
|
|
|
{
|
|
|
|
return "Configuration Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ConfigurationLoadConfig
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ConfigurationLoadConfig::onEnter()
|
|
|
|
{
|
|
|
|
ConfigurationBase::onEnter();
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
Configuration::getInstance()->loadConfigFile("configs/config-test-ok.plist");
|
2014-01-15 09:22:45 +08:00
|
|
|
std::string config = Configuration::getInstance()->getInfo();
|
|
|
|
log("%s\n", config.c_str());
|
2013-05-23 08:56:05 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ConfigurationLoadConfig::subtitle() const
|
2013-05-23 08:56:05 +08:00
|
|
|
{
|
|
|
|
return "Loading config file manually. See console";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ConfigurationQuery
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ConfigurationQuery::onEnter()
|
|
|
|
{
|
|
|
|
ConfigurationBase::onEnter();
|
|
|
|
|
2022-07-09 22:23:34 +08:00
|
|
|
log("cocos2d version: %s", Configuration::getInstance()->getValue("axis.version").asString().c_str());
|
2021-12-28 16:06:23 +08:00
|
|
|
log("OpenGL version: %s", Configuration::getInstance()->getValue("gl.version").asString().c_str());
|
2013-05-23 08:56:05 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ConfigurationQuery::subtitle() const
|
2013-05-23 08:56:05 +08:00
|
|
|
{
|
2013-12-11 15:08:00 +08:00
|
|
|
return "Check the console";
|
2013-05-23 08:56:05 +08:00
|
|
|
}
|
2013-05-29 09:15:16 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ConfigurationInvalid
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ConfigurationInvalid::onEnter()
|
|
|
|
{
|
|
|
|
ConfigurationBase::onEnter();
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
Configuration::getInstance()->loadConfigFile("configs/config-test-invalid.plist");
|
2013-05-29 09:15:16 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ConfigurationInvalid::subtitle() const
|
2013-05-29 09:15:16 +08:00
|
|
|
{
|
|
|
|
return "Loading an invalid config file";
|
|
|
|
}
|
2013-05-31 07:10:31 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ConfigurationDefault
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ConfigurationDefault::onEnter()
|
|
|
|
{
|
|
|
|
ConfigurationBase::onEnter();
|
|
|
|
|
2020-08-18 11:33:18 +08:00
|
|
|
std::string c_value = Configuration::getInstance()->getValue("invalid.key", Value("no key")).asString();
|
2021-12-28 16:06:23 +08:00
|
|
|
if (c_value != "no key")
|
|
|
|
log("1. Test failed!");
|
|
|
|
else
|
|
|
|
log("1. Test OK!");
|
|
|
|
|
|
|
|
bool b_value = Configuration::getInstance()->getValue("invalid.key", Value(true)).asBool();
|
|
|
|
if (!b_value)
|
|
|
|
log("2. Test failed!");
|
|
|
|
else
|
|
|
|
log("2. Test OK!");
|
|
|
|
|
|
|
|
double d_value = Configuration::getInstance()->getValue("invalid.key", Value(42.42)).asDouble();
|
|
|
|
if (d_value != 42.42)
|
|
|
|
log("3. Test failed!");
|
|
|
|
else
|
|
|
|
log("3. Test OK!");
|
2013-05-31 07:10:31 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ConfigurationDefault::subtitle() const
|
2013-05-31 07:10:31 +08:00
|
|
|
{
|
|
|
|
return "Tests defaults values";
|
|
|
|
}
|
2013-06-04 04:49:06 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ConfigurationSet
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ConfigurationSet::onEnter()
|
|
|
|
{
|
|
|
|
ConfigurationBase::onEnter();
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
Configuration* conf = Configuration::getInstance();
|
2013-06-04 04:49:06 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
conf->setValue("this.is.an.int.value", Value(10));
|
|
|
|
conf->setValue("this.is.a.bool.value", Value(true));
|
|
|
|
conf->setValue("this.is.a.string.value", Value("hello world"));
|
2013-06-04 04:49:06 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto str = conf->getInfo();
|
2014-01-15 09:22:45 +08:00
|
|
|
log("%s\n", str.c_str());
|
2013-06-04 04:49:06 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ConfigurationSet::subtitle() const
|
2013-06-04 04:49:06 +08:00
|
|
|
{
|
|
|
|
return "Tests setting values manually";
|
|
|
|
}
|