PuzzleSDK
TestGetContents类 参考

#include <FileUtilsTest.h>

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

Public 成员函数

 CREATE_FUNC (TestGetContents)
 
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::string _generatedFile
 

额外继承的成员函数

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

成员函数说明

◆ CREATE_FUNC()

TestGetContents::CREATE_FUNC ( TestGetContents  )

◆ onEnter()

void TestGetContents::onEnter ( )
overridevirtual

重载 TestCase .

在文件 FileUtilsTest.cpp596 行定义.

597{
599 auto fs = FileUtils::getInstance();
600
601 auto testIfCompiles = [fs]() {
602 fs->getContents("", (CustomBuffer*)(nullptr));
604 fs->getContents("", &buf);
605 };
606
607 (void)(testIfCompiles);
608
609 auto winSize = Director::getInstance()->getWinSize();
610
611 auto readResult = Label::createWithTTF("show readResult", "fonts/Thonburi.ttf", 16);
612 this->addChild(readResult);
613 readResult->setPosition(winSize.width / 2, winSize.height / 2);
614
615 std::vector<char> binary = {'\r','\n','\r','\n','\0','\0','\r','\n'};
616 _generatedFile = fs->getWritablePath() + "file-with-zeros-and-crlf";
618
619
620 auto runTests = [&]() {
621 // Test read string in binary mode
622 std::string bs;
623 fs->getContents(_generatedFile, &bs);
624 if ( bs.size() != binary.size() || !std::equal( bs.begin(), bs.end(), binary.begin() ) )
625 return std::string("failed: read as binary string");
626
627 // Text read string in text mode
628 std::string ts = fs->getStringFromFile(_generatedFile);
629 if (strcmp(ts.c_str(), "\r\n\r\n")!=0)
630 return std::string("failed: read as zero terminated string");
631
632
633 std::string files[] = {_generatedFile, "background.wav", "fileLookup.plist"};
634 for (auto& file : files) {
635 std::string sbuf;
636
637 auto serr = fs->getContents(file, &sbuf);
638 if (serr != FileUtils::Status::OK)
639 return std::string("failed: error: " + FileErrors[(int)serr]);
640
641 std::vector<int> vbuf;
642 auto verr = fs->getContents(file, &vbuf);
643 if (verr != FileUtils::Status::OK)
644 return std::string("failed: error: " + FileErrors[(int)verr]);
645
646 Data dbuf;
647 auto derr = fs->getContents(file, &dbuf);
648 if (derr != FileUtils::Status::OK)
649 return std::string("failed: error: " + FileErrors[(int)derr]);
650
651 if (memcmp(&sbuf.front(), &vbuf.front(), sbuf.size()) != 0)
652 return std::string("failed: error: sbuf != vbuf");
653
654 if (dbuf.getSize() != sbuf.size())
655 return std::string("failed: error: sbuf.size() != dbuf.getSize()");
656
657 if (memcmp(&sbuf.front(), dbuf.getBytes(), sbuf.size()) != 0)
658 return std::string("failed: error: sbuf != dbuf");
659 }
660 return std::string("read success");
661 };
662 readResult->setString("FileUtils::getContents() " + runTests());
663}
static NS_CC_END void saveAsBinaryText(const std::string &filename, const std::vector< char > &binary)
static const std::string FileErrors[]
virtual void onEnter() override
Definition: BaseTest.cpp:430
std::string _generatedFile

引用了 _generatedFile, FileErrors, TestCase::onEnter() , 以及 saveAsBinaryText().

+ 函数调用图:

◆ onExit()

void TestGetContents::onExit ( )
overridevirtual

在文件 FileUtilsTest.cpp665 行定义.

666{
667 if (!_generatedFile.empty())
668 FileUtils::getInstance()->removeFile(_generatedFile);
669
670 FileUtilsDemo::onExit();
671}

引用了 _generatedFile.

◆ subtitle()

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

重载 TestCase .

在文件 FileUtilsTest.cpp678 行定义.

679{
680 return "";
681}

◆ title()

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

重载 TestCase .

在文件 FileUtilsTest.cpp673 行定义.

674{
675 return "FileUtils: TestGetContents";
676}

类成员变量说明

◆ _generatedFile

std::string TestGetContents::_generatedFile
private

在文件 FileUtilsTest.h139 行定义.

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


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