PuzzleSDK
TestUnicodePath类 参考

#include <FileUtilsTest.h>

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

Public 成员函数

 CREATE_FUNC (TestUnicodePath)
 
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
 

额外继承的成员函数

- 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.h175 行定义.

成员函数说明

◆ CREATE_FUNC()

TestUnicodePath::CREATE_FUNC ( TestUnicodePath  )

◆ onEnter()

void TestUnicodePath::onEnter ( )
overridevirtual

重载 TestCase .

在文件 FileUtilsTest.cpp954 行定义.

955{
957 auto s = Director::getInstance()->getWinSize();
958 auto util = FileUtils::getInstance();
959
960 int x = s.width/2,
961 y = s.height/5;
962 Label* label = nullptr;
963
964 std::string dir = "中文路径/";
965 std::string filename = "测试文件.test";
966
967 std::string act;
968 auto getMsg = [&act](bool b, const std::string& path)-> std::string
969 {
970 char msg[512];
971 snprintf((char *)msg, 512, "%s for %s path: \"%s\"", b ? "success" : "failed", act.c_str(), path.c_str());
972 return std::string(msg);
973 };
974
975 // Check whether unicode dir should be create or not
976 std::string dirPath = util->getWritablePath() + dir;
977 if (!util->isDirectoryExist(dirPath))
978 {
979 util->createDirectory(dirPath);
980 }
981
982 act = "create";
983 bool isExist = util->isDirectoryExist(dirPath);
984 label = Label::createWithSystemFont(getMsg(isExist, dirPath), "", 12, Size(s.width, 0));
985 label->setPosition(x, y * 4);
986 this->addChild(label);
987
988 if (isExist)
989 {
990 // Check whether unicode file should be create or not
991 std::string filePath = dirPath + filename;
992 if (! util->isFileExist(filePath))
993 {
994 std::string writeDataStr = " 测试字符串.";
995 Data writeData;
996 writeData.copy((unsigned char *)writeDataStr.c_str(), writeDataStr.size());
997 util->writeDataToFile(writeData, filePath);
998 }
999
1000 isExist = util->isFileExist(filePath);
1001 label = Label::createWithSystemFont(getMsg(isExist, filePath), "", 12, Size(s.width, 0));
1002 label->setPosition(x, y * 3);
1003 this->addChild(label);
1004
1005 act = "remove";
1006 if (isExist)
1007 {
1008 // read file content and log it
1009 unsigned char* buffer = nullptr;
1010 Data readData = util->getDataFromFile(filePath);
1011 buffer = (unsigned char*)malloc(sizeof(unsigned char) * (readData.getSize() + 1));
1012 memcpy(buffer, readData.getBytes(), readData.getSize());
1013 buffer[readData.getSize()] = '\0';
1014 // vc can't treat unicode string correctly, don't use unicode string in code
1015 log("The content of file from writable path: %s", buffer);
1016 free(buffer);
1017
1018 // remove test file
1019 label = Label::createWithSystemFont(getMsg(util->removeFile(filePath), filePath), "", 12, Size(s.width, 0));
1020 label->setPosition(x, y * 2);
1021 this->addChild(label);
1022 }
1023
1024 // remove test dir
1025 label = Label::createWithSystemFont(getMsg(util->removeDirectory(dirPath), dirPath), "", 12, Size(s.width, 0));
1026 label->setPosition(x, y * 1);
1027 this->addChild(label);
1028 }
1029}
virtual void onEnter() override
Definition: BaseTest.cpp:430

引用了 TestCase::onEnter().

+ 函数调用图:

◆ onExit()

void TestUnicodePath::onExit ( )
overridevirtual

在文件 FileUtilsTest.cpp1031 行定义.

1032{
1033
1034 FileUtils *sharedFileUtils = FileUtils::getInstance();
1035 sharedFileUtils->purgeCachedEntries();
1036 sharedFileUtils->setFilenameLookupDictionary(ValueMap());
1037 FileUtilsDemo::onExit();
1038}

◆ subtitle()

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

重载 TestCase .

在文件 FileUtilsTest.cpp1045 行定义.

1046{
1047 return "";
1048}

◆ title()

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

重载 TestCase .

在文件 FileUtilsTest.cpp1040 行定义.

1041{
1042 return "FileUtils: check unicode path";
1043}

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