PuzzleSDK
TestSearchPath类 参考

#include <FileUtilsTest.h>

+ 类 TestSearchPath 继承关系图:
+ TestSearchPath 的协作图:

Public 成员函数

 CREATE_FUNC (TestSearchPath)
 
virtual void onEnter () override
 
virtual void onExit () override
 
virtual std::string title () const override
 
virtual std::string subtitle () const override
 
- Public 成员函数 继承自 TestCase
 TestCase ()
 
 ~TestCase ()
 
virtual Type getTestType () const
 
virtual float getDuration () const
 
virtual std::string getExpectedOutput () const
 
virtual std::string getActualOutput () const
 
virtual void restartTestCallback (cocos2d::Ref *sender)
 
virtual void nextTestCallback (cocos2d::Ref *sender)
 
virtual void priorTestCallback (cocos2d::Ref *sender)
 
virtual void onBackCallback (cocos2d::Ref *sender)
 
void setTestSuite (TestSuite *testSuite)
 
TestSuitegetTestSuite () const
 
float getRunTime () const
 
void setTestCaseName (const std::string &name)
 
std::string getTestCaseName () const
 
const cocos2d::Label * getSubtitleLable () const
 
const cocos2d::MenuItemImage * getRestartTestItem () const
 

Private 属性

std::vector< std::string > _defaultSearchPathArray
 
std::vector< std::string > _defaultResolutionsOrderArray
 

额外继承的成员函数

- Public 类型 继承自 TestCase
enum class  Type { ROBUSTNESS , UNIT , GRAPHICAL_STATIC , MANUAL }
 
- Public 属性 继承自 TestCase
CC_CONSTRUCTOR_ACCESS __pad0__: virtual bool init() override
 
- Protected 属性 继承自 TestCase
cocos2d::MenuItemImage * _priorTestItem
 
cocos2d::MenuItemImage * _restartTestItem
 
cocos2d::MenuItemImage * _nextTestItem
 
cocos2d::Label * _titleLabel
 
cocos2d::Label * _subtitleLabel
 

详细描述

在文件 FileUtilsTest.h52 行定义.

成员函数说明

◆ CREATE_FUNC()

TestSearchPath::CREATE_FUNC ( TestSearchPath  )

◆ onEnter()

void TestSearchPath::onEnter ( )
overridevirtual

重载 TestCase .

在文件 FileUtilsTest.cpp109 行定义.

110{
112 auto sharedFileUtils = FileUtils::getInstance();
113
114 std::string ret;
115
116 sharedFileUtils->purgeCachedEntries();
117 _defaultSearchPathArray = sharedFileUtils->getOriginalSearchPaths();
118 std::vector<std::string> searchPaths = _defaultSearchPathArray;
119 std::string writablePath = sharedFileUtils->getWritablePath();
120 std::string fileName = writablePath+"external.txt";
121 char szBuf[100] = "Hello Cocos2d-x!";
122 FILE* fp = fopen(fileName.c_str(), "wb");
123 if (fp)
124 {
125 size_t ret = fwrite(szBuf, 1, strlen(szBuf), fp);
126 CCASSERT(ret != 0, "fwrite function returned zero value");
127 fclose(fp);
128 if (ret != 0)
129 log("Writing file to writable path succeed.");
130 }
131
132 searchPaths.insert(searchPaths.begin(), writablePath);
133 searchPaths.insert(searchPaths.begin()+1, "Misc/searchpath1");
134 searchPaths.insert(searchPaths.begin()+2, "Misc/searchpath2");
135 sharedFileUtils->setSearchPaths(searchPaths);
136
137 _defaultResolutionsOrderArray = sharedFileUtils->getSearchResolutionsOrder();
138 std::vector<std::string> resolutionsOrder = _defaultResolutionsOrderArray;
139
140 resolutionsOrder.insert(resolutionsOrder.begin(), "resources-ipad");
141 sharedFileUtils->setSearchResolutionsOrder(resolutionsOrder);
142
143 for( int i=1; i<3; i++) {
144 auto filename = StringUtils::format("file%d.txt", i);
145 ret = sharedFileUtils->fullPathForFilename(filename);
146 log("%s -> %s", filename.c_str(), ret.c_str());
147 }
148
149 // Gets external.txt from writable path
150 std::string fullPath = sharedFileUtils->fullPathForFilename("external.txt");
151 log("external file path = %s", fullPath.c_str());
152 if (fullPath.length() > 0)
153 {
154 fp = fopen(fullPath.c_str(), "rb");
155 if (fp)
156 {
157 char szReadBuf[100] = {0};
158 size_t read = fread(szReadBuf, 1, strlen(szReadBuf), fp);
159 if (read > 0)
160 log("The content of file from writable path: %s", szReadBuf);
161 fclose(fp);
162 }
163 }
164
165 // FIXME: should fix the issue on Android
166#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID)
167
168 // Save old resource root path
169 std::string oldDefaultRootPath = sharedFileUtils->getDefaultResourceRootPath();
170 sharedFileUtils->setDefaultResourceRootPath(oldDefaultRootPath + "extensions");
171 auto sp1 = Sprite::create("orange_edit.png");
172 sp1->setPosition(VisibleRect::center());
173 addChild(sp1);
174
175 // Recover resource root path
176 sharedFileUtils->setDefaultResourceRootPath(oldDefaultRootPath);
177
178 auto oldSearchPaths = sharedFileUtils->getOriginalSearchPaths();
179 sharedFileUtils->addSearchPath("Images");
180 auto sp2 = Sprite::create("btn-about-normal.png");
181 sp2->setPosition(VisibleRect::center() + Vec2(0, -50));
182 addChild(sp2);
183
184 // Recover old search paths
185 sharedFileUtils->setSearchPaths(oldSearchPaths);
186#endif
187}
virtual void onEnter() override
Definition: BaseTest.cpp:430
std::vector< std::string > _defaultSearchPathArray
Definition: FileUtilsTest.h:62
std::vector< std::string > _defaultResolutionsOrderArray
Definition: FileUtilsTest.h:63
static cocos2d::Vec2 center()
Definition: VisibleRect.cpp:69

引用了 _defaultResolutionsOrderArray, _defaultSearchPathArray, VisibleRect::center() , 以及 TestCase::onEnter().

+ 函数调用图:

◆ onExit()

void TestSearchPath::onExit ( )
overridevirtual

在文件 FileUtilsTest.cpp189 行定义.

190{
191 FileUtils *sharedFileUtils = FileUtils::getInstance();
192
193 // reset search path
194 sharedFileUtils->setSearchPaths(_defaultSearchPathArray);
195 sharedFileUtils->setSearchResolutionsOrder(_defaultResolutionsOrderArray);
196 FileUtilsDemo::onExit();
197}

引用了 _defaultResolutionsOrderArray , 以及 _defaultSearchPathArray.

◆ subtitle()

std::string TestSearchPath::subtitle ( ) const
overridevirtual

重载 TestCase .

在文件 FileUtilsTest.cpp204 行定义.

205{
206 return "See the console, can see a orange box and a 'about' picture, except Android";
207}

◆ title()

std::string TestSearchPath::title ( ) const
overridevirtual

重载 TestCase .

在文件 FileUtilsTest.cpp199 行定义.

200{
201 return "FileUtils: search path";
202}

类成员变量说明

◆ _defaultResolutionsOrderArray

std::vector<std::string> TestSearchPath::_defaultResolutionsOrderArray
private

在文件 FileUtilsTest.h63 行定义.

被这些函数引用 onEnter() , 以及 onExit().

◆ _defaultSearchPathArray

std::vector<std::string> TestSearchPath::_defaultSearchPathArray
private

在文件 FileUtilsTest.h62 行定义.

被这些函数引用 onEnter() , 以及 onExit().


该类的文档由以下文件生成: