From b0ffc532104f2ef93ca9cc4a2877da2d6b54bfee Mon Sep 17 00:00:00 2001 From: "Patrice.J" <397136899@qq.com> Date: Fri, 16 Nov 2018 11:59:11 +0800 Subject: [PATCH 1/5] allow re-add plist & add testcase --- cocos/2d/CCSpriteFrameCache.cpp | 30 +++++++------- .../SpriteFrameCacheTest.cpp | 41 +++++++++++++++++++ .../SpriteFrameCacheTest.h | 17 ++++++++ 3 files changed, 74 insertions(+), 14 deletions(-) diff --git a/cocos/2d/CCSpriteFrameCache.cpp b/cocos/2d/CCSpriteFrameCache.cpp index 4788da85e767..ab447c90d4d8 100644 --- a/cocos/2d/CCSpriteFrameCache.cpp +++ b/cocos/2d/CCSpriteFrameCache.cpp @@ -349,11 +349,11 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(ValueMap& dict, const std:: } void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist, Texture2D *texture) -{ - if (_spriteFramesCache.hasPlist(plist)) - { - return; // We already added it - } +{ //// allow redundant adding + //if (_spriteFramesCache.hasPlist(plist)) + //{ + // return; // We already added it + //} std::string fullPath = FileUtils::getInstance()->fullPathForFilename(plist); ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(fullPath); @@ -370,10 +370,11 @@ void SpriteFrameCache::addSpriteFramesWithFileContent(const std::string& plist_c void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist, const std::string& textureFileName) { CCASSERT(textureFileName.size()>0, "texture name should not be null"); - if (_spriteFramesCache.hasPlist(plist)) - { - return; // We already added it - } + //// allow redundant adding + //if (_spriteFramesCache.hasPlist(plist)) + //{ + // return; // We already added it + //} const std::string fullPath = FileUtils::getInstance()->fullPathForFilename(plist); ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(fullPath); addSpriteFramesWithDictionary(dict, textureFileName, plist); @@ -391,8 +392,8 @@ void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist) return; } - if (!_spriteFramesCache.hasPlist(plist)) - { + //if (!_spriteFramesCache.hasPlist(plist)) //should allow redundant adding + //{ ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(fullPath); string texturePath(""); @@ -424,7 +425,7 @@ void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist) CCLOG("cocos2d: SpriteFrameCache: Trying to use file %s as texture", texturePath.c_str()); } addSpriteFramesWithDictionary(dict, texturePath, plist); - } + //} } bool SpriteFrameCache::isSpriteFramesWithFileLoaded(const std::string& plist) const @@ -813,8 +814,9 @@ bool SpriteFrameCache::PlistFramesCache::hasFrame(const std::string &frame) cons bool SpriteFrameCache::PlistFramesCache::hasPlist(const std::string &plist) const { - return _indexPlist2Frames.find(plist) != _indexPlist2Frames.end(); -} + auto frames = _indexPlist2Frames.find(plist); + return frames != _indexPlist2Frames.end() && frames->second.size() > 0; +} SpriteFrame * SpriteFrameCache::PlistFramesCache::at(const std::string &frame) { diff --git a/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp b/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp index bf17d4f83c44..4d0e811cc9b7 100644 --- a/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp +++ b/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp @@ -34,6 +34,7 @@ USING_NS_CC; SpriteFrameCacheTests::SpriteFrameCacheTests() { ADD_TEST_CASE(SpriteFrameCachePixelFormatTest); + ADD_TEST_CASE(SpriteFrameCacheLoadMultipleTimes); } SpriteFrameCachePixelFormatTest::SpriteFrameCachePixelFormatTest() @@ -82,6 +83,46 @@ void SpriteFrameCachePixelFormatTest::loadSpriteFrames(const std::string &file, const std::string textureInfo = StringUtils::format("%s: %.2f KB\r\n", texture->getStringForFormat(), memorySize); infoLabel->setString(infoLabel->getString() + textureInfo); + SpriteFrameCache::getInstance()->removeSpriteFramesFromFile(file); + Director::getInstance()->getTextureCache()->removeTexture(texture); +} + + + + +SpriteFrameCacheLoadMultipleTimes::SpriteFrameCacheLoadMultipleTimes() +{ + const Size screenSize = Director::getInstance()->getWinSize(); + + infoLabel = Label::create(); + infoLabel->setAnchorPoint(Point(0.5f, 1.0f)); + infoLabel->setAlignment(cocos2d::TextHAlignment::CENTER); + infoLabel->setPosition(screenSize.width * 0.5f, screenSize.height * 0.7f); + addChild(infoLabel); + + // load atlas definition with specified PixelFormat and check that it matches to expected format + loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", Texture2D::PixelFormat::RGBA8888); + loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", Texture2D::PixelFormat::RGBA8888); + loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", Texture2D::PixelFormat::RGBA8888); + loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", Texture2D::PixelFormat::RGBA8888); + + +} + + +void SpriteFrameCacheLoadMultipleTimes::loadSpriteFrames(const std::string &file, cocos2d::Texture2D::PixelFormat expectedFormat) +{ + SpriteFrameCache::getInstance()->addSpriteFramesWithFile(file); + SpriteFrameCache::getInstance()->addSpriteFramesWithFile(file); + SpriteFrame *spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("grossini.png"); + Texture2D *texture = spriteFrame->getTexture(); + const ssize_t bitsPerKB = 8 * 1024; + const double memorySize = 1.0 * texture->getBitsPerPixelForFormat() * texture->getContentSizeInPixels().width * texture->getContentSizeInPixels().height / bitsPerKB; + CC_ASSERT(texture->getPixelFormat() == expectedFormat); + + const std::string textureInfo = StringUtils::format("%s: %.2f KB\r\n", texture->getStringForFormat(), memorySize); + infoLabel->setString(infoLabel->getString() + textureInfo); + SpriteFrameCache::getInstance()->removeSpriteFramesFromFile(file); Director::getInstance()->getTextureCache()->removeTexture(texture); } \ No newline at end of file diff --git a/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.h b/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.h index 5a55ff1f5388..017bd374c0ea 100644 --- a/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.h +++ b/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.h @@ -43,6 +43,23 @@ class SpriteFrameCachePixelFormatTest : public TestCase private: void loadSpriteFrames(const std::string &file, cocos2d::Texture2D::PixelFormat expectedFormat); +private: + cocos2d::Label *infoLabel; +}; + +class SpriteFrameCacheLoadMultipleTimes : public TestCase +{ +public: + CREATE_FUNC(SpriteFrameCacheLoadMultipleTimes); + + virtual std::string title() const override { return "Load same plist multiple times"; } + virtual std::string subtitle() const override { return "It shouldn't crash"; } + + SpriteFrameCacheLoadMultipleTimes(); + +private: + void loadSpriteFrames(const std::string &file, cocos2d::Texture2D::PixelFormat expectedFormat); + private: cocos2d::Label *infoLabel; }; \ No newline at end of file From 4856b68094fee449ab7d0020e0a815c973e0822d Mon Sep 17 00:00:00 2001 From: "Patrice.J" <397136899@qq.com> Date: Fri, 16 Nov 2018 13:57:15 +0800 Subject: [PATCH 2/5] remove comments/rename method/update testcase --- cocos/2d/CCSpriteFrameCache.cpp | 78 +++++++------------ cocos/2d/CCSpriteFrameCache.h | 4 +- .../SpriteFrameCacheTest.cpp | 3 +- 3 files changed, 31 insertions(+), 54 deletions(-) diff --git a/cocos/2d/CCSpriteFrameCache.cpp b/cocos/2d/CCSpriteFrameCache.cpp index ab447c90d4d8..75c94cb13214 100644 --- a/cocos/2d/CCSpriteFrameCache.cpp +++ b/cocos/2d/CCSpriteFrameCache.cpp @@ -349,12 +349,7 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(ValueMap& dict, const std:: } void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist, Texture2D *texture) -{ //// allow redundant adding - //if (_spriteFramesCache.hasPlist(plist)) - //{ - // return; // We already added it - //} - +{ std::string fullPath = FileUtils::getInstance()->fullPathForFilename(plist); ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(fullPath); @@ -370,11 +365,6 @@ void SpriteFrameCache::addSpriteFramesWithFileContent(const std::string& plist_c void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist, const std::string& textureFileName) { CCASSERT(textureFileName.size()>0, "texture name should not be null"); - //// allow redundant adding - //if (_spriteFramesCache.hasPlist(plist)) - //{ - // return; // We already added it - //} const std::string fullPath = FileUtils::getInstance()->fullPathForFilename(plist); ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(fullPath); addSpriteFramesWithDictionary(dict, textureFileName, plist); @@ -392,45 +382,42 @@ void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist) return; } - //if (!_spriteFramesCache.hasPlist(plist)) //should allow redundant adding - //{ - ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(fullPath); + ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(fullPath); - string texturePath(""); + string texturePath(""); - if (dict.find("metadata") != dict.end()) - { - ValueMap& metadataDict = dict["metadata"].asValueMap(); - // try to read texture file name from meta data - texturePath = metadataDict["textureFileName"].asString(); - } + if (dict.find("metadata") != dict.end()) + { + ValueMap& metadataDict = dict["metadata"].asValueMap(); + // try to read texture file name from meta data + texturePath = metadataDict["textureFileName"].asString(); + } - if (!texturePath.empty()) - { - // build texture path relative to plist file - texturePath = FileUtils::getInstance()->fullPathFromRelativeFile(texturePath, plist); - } - else - { - // build texture path by replacing file extension - texturePath = plist; + if (!texturePath.empty()) + { + // build texture path relative to plist file + texturePath = FileUtils::getInstance()->fullPathFromRelativeFile(texturePath, plist); + } + else + { + // build texture path by replacing file extension + texturePath = plist; - // remove .xxx - size_t startPos = texturePath.find_last_of("."); - texturePath = texturePath.erase(startPos); + // remove .xxx + size_t startPos = texturePath.find_last_of("."); + texturePath = texturePath.erase(startPos); - // append .png - texturePath = texturePath.append(".png"); + // append .png + texturePath = texturePath.append(".png"); - CCLOG("cocos2d: SpriteFrameCache: Trying to use file %s as texture", texturePath.c_str()); - } - addSpriteFramesWithDictionary(dict, texturePath, plist); - //} + CCLOG("cocos2d: SpriteFrameCache: Trying to use file %s as texture", texturePath.c_str()); + } + addSpriteFramesWithDictionary(dict, texturePath, plist); } bool SpriteFrameCache::isSpriteFramesWithFileLoaded(const std::string& plist) const { - return _spriteFramesCache.hasPlist(plist); + return _spriteFramesCache.isPlistUsed(plist); } void SpriteFrameCache::addSpriteFrame(SpriteFrame* frame, const std::string& frameName) @@ -687,7 +674,7 @@ bool SpriteFrameCache::reloadTexture(const std::string& plist) { CCASSERT(plist.size()>0, "plist filename should not be nullptr"); - if (_spriteFramesCache.hasPlist(plist)) { + if (_spriteFramesCache.isPlistUsed(plist)) { _spriteFramesCache.erasePlistIndex(plist); } else @@ -750,13 +737,6 @@ void SpriteFrameCache::PlistFramesCache::insertFrame(const std::string &plist, c _indexFrame2plist[frame] = plist; //insert index frameName->plist } -bool SpriteFrameCache::PlistFramesCache::isPlistUsed(const std::string &plist) const -{ - //plist loaded && not empty - auto it = _indexPlist2Frames.find(plist); - return it != _indexPlist2Frames.end() && !it->second.empty(); -} - bool SpriteFrameCache::PlistFramesCache::eraseFrame(const std::string &frame) { _spriteFrames.erase(frame); //drop SpriteFrame @@ -812,7 +792,7 @@ bool SpriteFrameCache::PlistFramesCache::hasFrame(const std::string &frame) cons return _indexFrame2plist.find(frame) != _indexFrame2plist.end(); } -bool SpriteFrameCache::PlistFramesCache::hasPlist(const std::string &plist) const +bool SpriteFrameCache::PlistFramesCache::isPlistUsed(const std::string &plist) const { auto frames = _indexPlist2Frames.find(plist); return frames != _indexPlist2Frames.end() && frames->second.size() > 0; diff --git a/cocos/2d/CCSpriteFrameCache.h b/cocos/2d/CCSpriteFrameCache.h index ca8e48ab1255..19d4b681ff2f 100644 --- a/cocos/2d/CCSpriteFrameCache.h +++ b/cocos/2d/CCSpriteFrameCache.h @@ -116,13 +116,11 @@ class CC_DLL SpriteFrameCache : public Ref void clear(); inline bool hasFrame(const std::string &frame) const; - inline bool hasPlist(const std::string &plist) const; + inline bool isPlistUsed(const std::string &plist) const; inline SpriteFrame *at(const std::string &frame); inline Map& getSpriteFrames(); - inline bool isPlistUsed(const std::string &plist) const; - private: Map _spriteFrames; std::unordered_map> _indexPlist2Frames; diff --git a/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp b/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp index 4d0e811cc9b7..64b20a8a6e38 100644 --- a/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp +++ b/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp @@ -112,7 +112,6 @@ SpriteFrameCacheLoadMultipleTimes::SpriteFrameCacheLoadMultipleTimes() void SpriteFrameCacheLoadMultipleTimes::loadSpriteFrames(const std::string &file, cocos2d::Texture2D::PixelFormat expectedFormat) { - SpriteFrameCache::getInstance()->addSpriteFramesWithFile(file); SpriteFrameCache::getInstance()->addSpriteFramesWithFile(file); SpriteFrame *spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("grossini.png"); Texture2D *texture = spriteFrame->getTexture(); @@ -123,6 +122,6 @@ void SpriteFrameCacheLoadMultipleTimes::loadSpriteFrames(const std::string &file const std::string textureInfo = StringUtils::format("%s: %.2f KB\r\n", texture->getStringForFormat(), memorySize); infoLabel->setString(infoLabel->getString() + textureInfo); - SpriteFrameCache::getInstance()->removeSpriteFramesFromFile(file); + SpriteFrameCache::getInstance()->removeSpriteFrameByName("grossini.png"); Director::getInstance()->getTextureCache()->removeTexture(texture); } \ No newline at end of file From 57291984ad033ce7f0a55cf78d85f4d2a5c1580b Mon Sep 17 00:00:00 2001 From: "Patrice.J" <397136899@qq.com> Date: Fri, 16 Nov 2018 14:54:53 +0800 Subject: [PATCH 3/5] fix isSpriteFramesWithFileLoaded & add testcase --- cocos/2d/CCSpriteFrameCache.cpp | 8 +++- cocos/2d/CCSpriteFrameCache.h | 7 +++ .../SpriteFrameCacheTest.cpp | 43 +++++++++++++------ .../SpriteFrameCacheTest.h | 16 ++++++- 4 files changed, 59 insertions(+), 15 deletions(-) diff --git a/cocos/2d/CCSpriteFrameCache.cpp b/cocos/2d/CCSpriteFrameCache.cpp index 75c94cb13214..0e39b2d802a2 100644 --- a/cocos/2d/CCSpriteFrameCache.cpp +++ b/cocos/2d/CCSpriteFrameCache.cpp @@ -293,6 +293,7 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(ValueMap& dictionary, Textu // add sprite frame _spriteFramesCache.insertFrame(plist, spriteFrameName, spriteFrame); } + _spriteFramesCache.markPlistFull(plist, true); CC_SAFE_DELETE(image); } @@ -417,7 +418,7 @@ void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist) bool SpriteFrameCache::isSpriteFramesWithFileLoaded(const std::string& plist) const { - return _spriteFramesCache.isPlistUsed(plist); + return _spriteFramesCache.isPlistUsed(plist) && _spriteFramesCache.isPlistFull(plist); } void SpriteFrameCache::addSpriteFrame(SpriteFrame* frame, const std::string& frameName) @@ -744,11 +745,14 @@ bool SpriteFrameCache::PlistFramesCache::eraseFrame(const std::string &frame) if (itFrame != _indexFrame2plist.end()) { auto plist = itFrame->second; + markPlistFull(plist, false); _indexPlist2Frames[plist].erase(frame); //update index plist->[frameNames] _indexFrame2plist.erase(itFrame); //update index frame->plist // erase plist index if all frames was erased if (_indexFrame2plist.empty()) + { _indexPlist2Frames.erase(plist); + } return true; } return false; @@ -777,6 +781,7 @@ bool SpriteFrameCache::PlistFramesCache::erasePlistIndex(const std::string &plis _indexFrame2plist.erase(f); //erase plist frame frameName->plist } _indexPlist2Frames.erase(plist); //update index plist->[frameNames] + _isPlistFull.erase(plist); //erase full status return true; } @@ -785,6 +790,7 @@ void SpriteFrameCache::PlistFramesCache::clear() _indexPlist2Frames.clear(); _indexFrame2plist.clear(); _spriteFrames.clear(); + _isPlistFull.clear(); } bool SpriteFrameCache::PlistFramesCache::hasFrame(const std::string &frame) const diff --git a/cocos/2d/CCSpriteFrameCache.h b/cocos/2d/CCSpriteFrameCache.h index 19d4b681ff2f..0f5e689a8b34 100644 --- a/cocos/2d/CCSpriteFrameCache.h +++ b/cocos/2d/CCSpriteFrameCache.h @@ -121,10 +121,17 @@ class CC_DLL SpriteFrameCache : public Ref inline SpriteFrame *at(const std::string &frame); inline Map& getSpriteFrames(); + void markPlistFull(const std::string &plist, bool full) { _isPlistFull[plist] = full; } + bool isPlistFull(const std::string &plist) const + { + auto it = _isPlistFull.find(plist); + return it == _isPlistFull.end() ? false : it->second; + } private: Map _spriteFrames; std::unordered_map> _indexPlist2Frames; std::unordered_map _indexFrame2plist; + std::unordered_map _isPlistFull; }; public: diff --git a/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp b/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp index 64b20a8a6e38..bfff0ac2680c 100644 --- a/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp +++ b/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp @@ -26,6 +26,8 @@ #include "SpriteFrameCacheTest.h" +#include + // enable log #define COCOS2D_DEBUG 1 @@ -35,6 +37,7 @@ SpriteFrameCacheTests::SpriteFrameCacheTests() { ADD_TEST_CASE(SpriteFrameCachePixelFormatTest); ADD_TEST_CASE(SpriteFrameCacheLoadMultipleTimes); + ADD_TEST_CASE(SpriteFrameCacheFullCheck); } SpriteFrameCachePixelFormatTest::SpriteFrameCachePixelFormatTest() @@ -88,28 +91,18 @@ void SpriteFrameCachePixelFormatTest::loadSpriteFrames(const std::string &file, } - - SpriteFrameCacheLoadMultipleTimes::SpriteFrameCacheLoadMultipleTimes() { const Size screenSize = Director::getInstance()->getWinSize(); - infoLabel = Label::create(); - infoLabel->setAnchorPoint(Point(0.5f, 1.0f)); - infoLabel->setAlignment(cocos2d::TextHAlignment::CENTER); - infoLabel->setPosition(screenSize.width * 0.5f, screenSize.height * 0.7f); - addChild(infoLabel); - // load atlas definition with specified PixelFormat and check that it matches to expected format loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", Texture2D::PixelFormat::RGBA8888); loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", Texture2D::PixelFormat::RGBA8888); loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", Texture2D::PixelFormat::RGBA8888); loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", Texture2D::PixelFormat::RGBA8888); - } - void SpriteFrameCacheLoadMultipleTimes::loadSpriteFrames(const std::string &file, cocos2d::Texture2D::PixelFormat expectedFormat) { SpriteFrameCache::getInstance()->addSpriteFramesWithFile(file); @@ -119,9 +112,33 @@ void SpriteFrameCacheLoadMultipleTimes::loadSpriteFrames(const std::string &file const double memorySize = 1.0 * texture->getBitsPerPixelForFormat() * texture->getContentSizeInPixels().width * texture->getContentSizeInPixels().height / bitsPerKB; CC_ASSERT(texture->getPixelFormat() == expectedFormat); - const std::string textureInfo = StringUtils::format("%s: %.2f KB\r\n", texture->getStringForFormat(), memorySize); - infoLabel->setString(infoLabel->getString() + textureInfo); - SpriteFrameCache::getInstance()->removeSpriteFrameByName("grossini.png"); Director::getInstance()->getTextureCache()->removeTexture(texture); +} + + +SpriteFrameCacheFullCheck::SpriteFrameCacheFullCheck() +{ + const Size screenSize = Director::getInstance()->getWinSize(); + // load atlas definition with specified PixelFormat and check that it matches to expected format + loadSpriteFrames("Images/test_polygon.plist", Texture2D::PixelFormat::RGBA8888); +} + +void SpriteFrameCacheFullCheck::loadSpriteFrames(const std::string &file, cocos2d::Texture2D::PixelFormat expectedFormat) +{ + auto cache = SpriteFrameCache::getInstance(); + + CCASSERT(cache->isSpriteFramesWithFileLoaded("plist which not exists") == false, "Plist not exists"); + + cache->addSpriteFramesWithFile(file); + CCASSERT(cache->isSpriteFramesWithFileLoaded(file) == true, "Plist should be full after loaded"); + + cache->removeSpriteFrameByName("not_exists_grossinis_sister.png"); + CCASSERT(cache->isSpriteFramesWithFileLoaded(file) == true, "Plist should not be still full"); + + cache->removeSpriteFrameByName("grossinis_sister1.png"); + CCASSERT(cache->isSpriteFramesWithFileLoaded(file) == false, "Plist should not be full after remove any sprite"); + + cache->addSpriteFramesWithFile(file); + CCASSERT(cache->isSpriteFramesWithFileLoaded(file) == true, "Plist should be full after reloaded"); } \ No newline at end of file diff --git a/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.h b/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.h index 017bd374c0ea..99377028182c 100644 --- a/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.h +++ b/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.h @@ -60,6 +60,20 @@ class SpriteFrameCacheLoadMultipleTimes : public TestCase private: void loadSpriteFrames(const std::string &file, cocos2d::Texture2D::PixelFormat expectedFormat); +}; + + +class SpriteFrameCacheFullCheck: public TestCase +{ +public: + CREATE_FUNC(SpriteFrameCacheFullCheck); + + virtual std::string title() const override { return "Test isSpriteFramesWithFileLoaded"; } + virtual std::string subtitle() const override { return "It shouldn't crash"; } + + SpriteFrameCacheFullCheck(); + private: - cocos2d::Label *infoLabel; + void loadSpriteFrames(const std::string &file, cocos2d::Texture2D::PixelFormat expectedFormat); + }; \ No newline at end of file From 38fdfc8c95b23bd57b985c21758674c6cbca1598 Mon Sep 17 00:00:00 2001 From: "Patrice.J" <397136899@qq.com> Date: Fri, 16 Nov 2018 16:34:18 +0800 Subject: [PATCH 4/5] remove used variable --- .../Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp b/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp index bfff0ac2680c..c1aacad03695 100644 --- a/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp +++ b/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp @@ -109,7 +109,6 @@ void SpriteFrameCacheLoadMultipleTimes::loadSpriteFrames(const std::string &file SpriteFrame *spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("grossini.png"); Texture2D *texture = spriteFrame->getTexture(); const ssize_t bitsPerKB = 8 * 1024; - const double memorySize = 1.0 * texture->getBitsPerPixelForFormat() * texture->getContentSizeInPixels().width * texture->getContentSizeInPixels().height / bitsPerKB; CC_ASSERT(texture->getPixelFormat() == expectedFormat); SpriteFrameCache::getInstance()->removeSpriteFrameByName("grossini.png"); From 8fa9d4269ab6170247a2b21356a467f05783bcd9 Mon Sep 17 00:00:00 2001 From: patricejiang Date: Mon, 19 Nov 2018 09:36:52 +0800 Subject: [PATCH 5/5] remove unused variable --- .../Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp b/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp index c1aacad03695..5e1fe346633f 100644 --- a/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp +++ b/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp @@ -108,7 +108,6 @@ void SpriteFrameCacheLoadMultipleTimes::loadSpriteFrames(const std::string &file SpriteFrameCache::getInstance()->addSpriteFramesWithFile(file); SpriteFrame *spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("grossini.png"); Texture2D *texture = spriteFrame->getTexture(); - const ssize_t bitsPerKB = 8 * 1024; CC_ASSERT(texture->getPixelFormat() == expectedFormat); SpriteFrameCache::getInstance()->removeSpriteFrameByName("grossini.png"); @@ -140,4 +139,4 @@ void SpriteFrameCacheFullCheck::loadSpriteFrames(const std::string &file, cocos2 cache->addSpriteFramesWithFile(file); CCASSERT(cache->isSpriteFramesWithFileLoaded(file) == true, "Plist should be full after reloaded"); -} \ No newline at end of file +}