32#define COCOS2D_DEBUG 1
36SpriteFrameCacheTests::SpriteFrameCacheTests()
45 const Size screenSize = Director::getInstance()->getWinSize();
48 infoLabel->setAnchorPoint(Point(0.5f, 1.0f));
49 infoLabel->setAlignment(cocos2d::TextHAlignment::CENTER);
50 infoLabel->setPosition(screenSize.width * 0.5f, screenSize.height * 0.7f);
54 loadSpriteFrames(
"Images/sprite_frames_test/test_A8.plist", backend::PixelFormat::A8);
55 loadSpriteFrames(
"Images/sprite_frames_test/test_RGBA8888.plist", backend::PixelFormat::RGBA8888);
56 loadSpriteFrames(
"Images/sprite_frames_test/test_AI88.plist", backend::PixelFormat::AI88);
57 loadSpriteFrames(
"Images/sprite_frames_test/test_RGBA8888.plist", backend::PixelFormat::RGBA8888);
58 loadSpriteFrames(
"Images/sprite_frames_test/test_RGB565.plist", backend::PixelFormat::RGB565);
59 loadSpriteFrames(
"Images/sprite_frames_test/test_RGB888.plist", backend::PixelFormat::RGB888);
60 loadSpriteFrames(
"Images/sprite_frames_test/test_RGBA4444.plist", backend::PixelFormat::RGBA4444);
61 loadSpriteFrames(
"Images/sprite_frames_test/test_RGBA5551.plist", backend::PixelFormat::RGB5A1);
63 if (Configuration::getInstance()->supportsPVRTC()) {
64 loadSpriteFrames(
"Images/sprite_frames_test/test_PVRTC2.plist", backend::PixelFormat::PVRTC2A);
65 loadSpriteFrames(
"Images/sprite_frames_test/test_PVRTC4.plist", backend::PixelFormat::PVRTC4A);
66 loadSpriteFrames(
"Images/sprite_frames_test/test_PVRTC2_NOALPHA.plist", backend::PixelFormat::PVRTC2);
70 Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGB5A1);
71 loadSpriteFrames(
"Images/sprite_frames_test/test_NoFormat.plist", backend::PixelFormat::RGB5A1);
74 Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGBA8888);
79 SpriteFrameCache::getInstance()->addSpriteFramesWithFile(file);
80 SpriteFrame *spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(
"grossini.png");
81 Texture2D *texture = spriteFrame->getTexture();
82 const ssize_t bitsPerKB = 8 * 1024;
83 const double memorySize = 1.0 * texture->getBitsPerPixelForFormat() * texture->getContentSizeInPixels().width * texture->getContentSizeInPixels().height / bitsPerKB;
85 CC_ASSERT(texture->getPixelFormat() == expectedFormat);
87 const std::string textureInfo = StringUtils::format(
"%s: %.2f KB\r\n", texture->getStringForFormat(), memorySize);
90 SpriteFrameCache::getInstance()->removeSpriteFramesFromFile(file);
91 Director::getInstance()->getTextureCache()->removeTexture(texture);
97 const Size screenSize = Director::getInstance()->getWinSize();
100 loadSpriteFrames(
"Images/sprite_frames_test/test_RGBA8888.plist", backend::PixelFormat::RGBA8888);
101 loadSpriteFrames(
"Images/sprite_frames_test/test_RGBA8888.plist", backend::PixelFormat::RGBA8888);
102 loadSpriteFrames(
"Images/sprite_frames_test/test_RGBA8888.plist", backend::PixelFormat::RGBA8888);
103 loadSpriteFrames(
"Images/sprite_frames_test/test_RGBA8888.plist", backend::PixelFormat::RGBA8888);
109 SpriteFrameCache::getInstance()->addSpriteFramesWithFile(file);
110 SpriteFrame *spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(
"grossini.png");
111 Texture2D *texture = spriteFrame->getTexture();
112 CC_ASSERT(texture->getPixelFormat() == expectedFormat);
114 SpriteFrameCache::getInstance()->removeSpriteFrameByName(
"grossini.png");
115 Director::getInstance()->getTextureCache()->removeTexture(texture);
121 const Size screenSize = Director::getInstance()->getWinSize();
123 loadSpriteFrames(
"Images/test_polygon.plist", backend::PixelFormat::RGBA8888);
128 auto cache = SpriteFrameCache::getInstance();
130 CCASSERT(cache->isSpriteFramesWithFileLoaded(
"plist which not exists") ==
false,
"Plist not exists");
132 cache->addSpriteFramesWithFile(file);
133 CCASSERT(cache->isSpriteFramesWithFileLoaded(file) ==
true,
"Plist should be full after loaded");
135 cache->removeSpriteFrameByName(
"not_exists_grossinis_sister.png");
136 CCASSERT(cache->isSpriteFramesWithFileLoaded(file) ==
true,
"Plist should not be still full");
138 cache->removeSpriteFrameByName(
"grossinis_sister1.png");
139 CCASSERT(cache->isSpriteFramesWithFileLoaded(file) ==
false,
"Plist should not be full after remove any sprite");
141 cache->addSpriteFramesWithFile(file);
142 CCASSERT(cache->isSpriteFramesWithFileLoaded(file) ==
true,
"Plist should be full after reloaded");
#define ADD_TEST_CASE(__className__)
void loadSpriteFrames(const std::string &file, cocos2d::backend::PixelFormat expectedFormat)
SpriteFrameCacheFullCheck()
SpriteFrameCacheLoadMultipleTimes()
void loadSpriteFrames(const std::string &file, cocos2d::backend::PixelFormat expectedFormat)