PuzzleSDK
ConfigurationTest.cpp
浏览该文件的文档.
1/****************************************************************************
2 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
3
4 http://www.cocos2d-x.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 ****************************************************************************/
24
25
26#include "ConfigurationTest.h"
27#include "../testResource.h"
28#include "cocos2d.h"
29
31
32ConfigurationTests::ConfigurationTests()
33{
39}
40
41std::string ConfigurationBase::title() const
42{
43 return "Configuration Test";
44}
45
46//------------------------------------------------------------------
47//
48// ConfigurationLoadConfig
49//
50//------------------------------------------------------------------
52{
54
55 Configuration::getInstance()->loadConfigFile("configs/config-test-ok.plist");
56 std::string config = Configuration::getInstance()->getInfo();
57 log("%s\n", config.c_str());
58}
59
61{
62 return "Loading config file manually. See console";
63}
64
65//------------------------------------------------------------------
66//
67// ConfigurationQuery
68//
69//------------------------------------------------------------------
71{
73
74 log("cocos2d version: %s", Configuration::getInstance()->getValue("cocos2d.x.version").asString().c_str() );
75 log("OpenGL version: %s", Configuration::getInstance()->getValue("gl.version").asString().c_str() );
76}
77
79{
80 return "Check the console";
81}
82
83//------------------------------------------------------------------
84//
85// ConfigurationInvalid
86//
87//------------------------------------------------------------------
89{
91
92 Configuration::getInstance()->loadConfigFile("configs/config-test-invalid.plist");
93}
94
96{
97 return "Loading an invalid config file";
98}
99
100//------------------------------------------------------------------
101//
102// ConfigurationDefault
103//
104//------------------------------------------------------------------
106{
108
109 std::string c_value = Configuration::getInstance()->getValue("invalid.key", Value("no key")).asString();
110 if( c_value != "no key" )
111 log("1. Test failed!");
112 else
113 log("1. Test OK!");
114
115 bool b_value = Configuration::getInstance()->getValue("invalid.key", Value(true)).asBool();
116 if( ! b_value )
117 log("2. Test failed!");
118 else
119 log("2. Test OK!");
120
121 double d_value = Configuration::getInstance()->getValue("invalid.key", Value(42.42)).asDouble();
122 if( d_value != 42.42 )
123 log("3. Test failed!");
124 else
125 log("3. Test OK!");
126
127}
128
130{
131 return "Tests defaults values";
132}
133
134//------------------------------------------------------------------
135//
136// ConfigurationSet
137//
138//------------------------------------------------------------------
140{
142
143 Configuration *conf = Configuration::getInstance();
144
145 conf->setValue("this.is.an.int.value", Value(10) );
146 conf->setValue("this.is.a.bool.value", Value(true) );
147 conf->setValue("this.is.a.string.value", Value("hello world") );
148
149 auto str = conf->getInfo();
150 log("%s\n", str.c_str());
151}
152
153std::string ConfigurationSet::subtitle() const
154{
155 return "Tests setting values manually";
156}
157
#define ADD_TEST_CASE(__className__)
Definition: BaseTest.h:211
virtual std::string title() const override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual void onEnter() override
Definition: BaseTest.cpp:430