code:
#ifndef _SPRITE_TEST_H_
#define _SPRITE_TEST_H_

#include "cocos2d.h"
#include "../testBasic.h"

class SpriteTestDemo : public CCLayer
{
protected:
	std::string	m_strTitle;

public:
	SpriteTestDemo(void);
	~SpriteTestDemo(void);

	virtual std::string title();
	virtual std::string subtitle();
	virtual void onEnter();

	void restartCallback(CCObject* pSender);
	void nextCallback(CCObject* pSender);
	void backCallback(CCObject* pSender);
};

class Sprite1 : public SpriteTestDemo
{
public:
	Sprite1();
	virtual std::string title();

	void addNewSpriteWithCoords(CCPoint p);
	void ccTouchesEnded(CCSet* touches, CCEvent* event);
};

class SpriteBatchNode1: public SpriteTestDemo
{
public:
	SpriteBatchNode1();
	void addNewSpriteWithCoords(CCPoint p);
	virtual void ccTouchesEnded(CCSet* touches, CCEvent* event);
	virtual std::string title();
};

class SpriteColorOpacity : public SpriteTestDemo
{
public:
	SpriteColorOpacity();
	void removeAndAddSprite(ccTime dt);
	virtual std::string title();
};

class SpriteBatchNodeColorOpacity : public SpriteTestDemo
{
public:
	SpriteBatchNodeColorOpacity();
	void removeAndAddSprite(ccTime dt);
	virtual std::string title();
};

class SpriteZOrder : public SpriteTestDemo
{
	int		m_dir;
public:
	SpriteZOrder();
	void reorderSprite(ccTime dt);
	virtual std::string title();
};

class SpriteBatchNodeZOrder: public SpriteTestDemo
{
	int		m_dir;
public:
	SpriteBatchNodeZOrder();
	void reorderSprite(ccTime dt);
	virtual std::string title();
};

class SpriteBatchNodeReorder : public SpriteTestDemo
{
public:
	SpriteBatchNodeReorder();
	virtual std::string title();
	std::string subtitle();
};

class SpriteBatchNodeReorderIssue744: public SpriteTestDemo
{
public:
	SpriteBatchNodeReorderIssue744();
	virtual std::string title();
	std::string subtitle();
};

class SpriteBatchNodeReorderIssue766 : public SpriteTestDemo
{
public:
    SpriteBatchNodeReorderIssue766();
    virtual std::string title();
    virtual std::string subtitle();
    void reorderSprite(ccTime dt);
    CCSprite* makeSpriteZ(int aZ);

private:
    CCSpriteBatchNode *batchNode;
    CCSprite *sprite1;
    CCSprite *sprite2;
    CCSprite *sprite3;
};

class SpriteBatchNodeReorderIssue767 : public SpriteTestDemo
{
public:
    SpriteBatchNodeReorderIssue767();
    virtual std::string title();
    virtual std::string subtitle();
    void reorderSprites(ccTime dt);
};

class SpriteZVertex: public SpriteTestDemo
{
	int		m_dir;
	float	m_time;
public:
	virtual void onEnter();
	virtual void onExit();
	SpriteZVertex();
	virtual std::string title();
};

class SpriteBatchNodeZVertex: public SpriteTestDemo
{
	int		m_dir;
	float	m_time;
public:
	virtual void onEnter();
	virtual void onExit();
	SpriteBatchNodeZVertex();
	virtual std::string title();
};

class SpriteAnchorPoint : public SpriteTestDemo
{
public:
	SpriteAnchorPoint();
	virtual std::string title();
};

class SpriteBatchNodeAnchorPoint : public SpriteTestDemo
{
public:
	SpriteBatchNodeAnchorPoint();
	virtual std::string title();
};

class Sprite6 : public SpriteTestDemo
{
public:
	Sprite6();
	virtual std::string title();
};

class SpriteFlip : public SpriteTestDemo
{
public:
	SpriteFlip();
	void flipSprites(ccTime dt);
	virtual std::string title();
};

class SpriteBatchNodeFlip : public SpriteTestDemo
{
public:
	SpriteBatchNodeFlip();
	void flipSprites(ccTime dt);
	virtual std::string title();
};

class SpriteAliased : public SpriteTestDemo
{
public:
	SpriteAliased();
	virtual void onEnter();
	virtual void onExit();
	virtual std::string title();
};

class SpriteBatchNodeAliased : public SpriteTestDemo
{
public:
	SpriteBatchNodeAliased();
	virtual void onEnter();
	virtual void onExit();
	virtual std::string title();
};

class SpriteNewTexture : public SpriteTestDemo
{
	bool                        m_usingTexture1;
	CCTexture2D*	m_texture1;
	CCTexture2D*	m_texture2;

public:
	SpriteNewTexture();
	virtual ~SpriteNewTexture();
	void addNewSprite();
	void ccTouchesEnded(CCSet* touches, CCEvent* event);
	virtual std::string title();
};

class SpriteBatchNodeNewTexture : public SpriteTestDemo
{
	CCTexture2D*	m_texture1;
	CCTexture2D*	m_texture2;

public:
	SpriteBatchNodeNewTexture();
	virtual ~SpriteBatchNodeNewTexture();
	void addNewSprite();
	void ccTouchesEnded(CCSet* touches, CCEvent* event);
	virtual std::string title();
};

class SpriteFrameTest: public SpriteTestDemo
{
public:
    virtual void onEnter();
	virtual void onExit();
	virtual std::string title();
    virtual std::string subtitle();

    void startIn05Secs(ccTime dt);
    void flipSprites(ccTime dt);
private:
    CCSprite *m_pSprite1;
    CCSprite *m_pSprite2;
    int      m_nCounter;
};

class SpriteFrameAliasNameTest : public SpriteTestDemo
{
public:
    virtual void onEnter();
    virtual void onExit();
    virtual std::string title();
    virtual std::string subtitle();
};

class SpriteOffsetAnchorRotation: public SpriteTestDemo
{
public:
	SpriteOffsetAnchorRotation();
	virtual void onExit();
	virtual std::string title();
};

class SpriteBatchNodeOffsetAnchorRotation: public SpriteTestDemo
{
public:
	SpriteBatchNodeOffsetAnchorRotation();
	virtual void onExit();
	virtual std::string title();
};

class SpriteOffsetAnchorScale: public SpriteTestDemo
{
public:
	SpriteOffsetAnchorScale();
	virtual void onExit();
	virtual std::string title();
};

class SpriteBatchNodeOffsetAnchorScale: public SpriteTestDemo
{
public:
	SpriteBatchNodeOffsetAnchorScale();
	virtual void onExit();
	virtual std::string title();
};

class SpriteOffsetAnchorSkew : public SpriteTestDemo
{
public:
	SpriteOffsetAnchorSkew();
	~SpriteOffsetAnchorSkew();
	virtual std::string title();
};

class SpriteBatchNodeOffsetAnchorSkew : public SpriteTestDemo
{
public:
	SpriteBatchNodeOffsetAnchorSkew();
    ~SpriteBatchNodeOffsetAnchorSkew();
	virtual std::string title();
};

class SpriteOffsetAnchorSkewScale : public SpriteTestDemo
{
public:
	SpriteOffsetAnchorSkewScale();
	~SpriteOffsetAnchorSkewScale();
	virtual std::string title();
};

class SpriteBatchNodeOffsetAnchorSkewScale : public SpriteTestDemo
{
public:
	SpriteBatchNodeOffsetAnchorSkewScale();
	~SpriteBatchNodeOffsetAnchorSkewScale();
	virtual std::string title();
};

class SpriteOffsetAnchorFlip : public SpriteTestDemo
{
public:
	SpriteOffsetAnchorFlip();
	~SpriteOffsetAnchorFlip();
	virtual std::string title();
	virtual std::string subtitle();
};

class SpriteBatchNodeOffsetAnchorFlip : public SpriteTestDemo
{
public:
	SpriteBatchNodeOffsetAnchorFlip();
	~SpriteBatchNodeOffsetAnchorFlip();
	virtual std::string title();
	virtual std::string subtitle();
};

class SpriteAnimationSplit : public SpriteTestDemo
{
public:
	SpriteAnimationSplit();
	virtual void onExit();
	virtual std::string title();
};

class SpriteHybrid: public SpriteTestDemo
{
	bool 	m_usingSpriteBatchNode;
public:
	SpriteHybrid();
	void reparentSprite(ccTime dt);
	virtual std::string title();
	virtual void onExit();
};

class SpriteBatchNodeChildren: public SpriteTestDemo
{
public:
	SpriteBatchNodeChildren();
	virtual void onExit();
	virtual std::string title();
};

class SpriteBatchNodeChildren2: public SpriteTestDemo
{
public:
	SpriteBatchNodeChildren2();
	virtual void onExit();
	virtual std::string title();
};

class SpriteBatchNodeChildrenZ : public SpriteTestDemo
{
public:
	SpriteBatchNodeChildrenZ();
	virtual void onExit();
	virtual std::string title();
};

class SpriteChildrenVisibility: public SpriteTestDemo
{
public:
	SpriteChildrenVisibility();
	virtual void onExit();
	virtual std::string title();
};

class SpriteChildrenVisibilityIssue665 : public SpriteTestDemo
{
public:
    SpriteChildrenVisibilityIssue665();
    ~SpriteChildrenVisibilityIssue665();
    virtual std::string title();
    virtual std::string subtitle();
};

class SpriteChildrenAnchorPoint: public SpriteTestDemo
{
public:
	SpriteChildrenAnchorPoint();
	virtual void onExit();
	virtual std::string title();
};

class SpriteBatchNodeChildrenAnchorPoint: public SpriteTestDemo
{
public:
	SpriteBatchNodeChildrenAnchorPoint();
	virtual void onExit();
	virtual std::string title();
};

class SpriteBatchNodeChildrenScale: public SpriteTestDemo
{
public:
	SpriteBatchNodeChildrenScale();
	virtual std::string title();
};

class SpriteChildrenChildren: public SpriteTestDemo
{
public:
	SpriteChildrenChildren();
	virtual std::string title();
};

class SpriteBatchNodeChildrenChildren: public SpriteTestDemo
{
public:
	SpriteBatchNodeChildrenChildren();
	virtual std::string title();
};

class SpriteNilTexture: public SpriteTestDemo
{
public:
	SpriteNilTexture();
	virtual std::string title();
	std::string subtitle();
};

class SpriteSubclass : public SpriteTestDemo
{
public:
    SpriteSubclass();
    virtual std::string title();
    virtual std::string subtitle();
};

class AnimationCache : public SpriteTestDemo
{
public:
    AnimationCache();
    virtual std::string title();
    virtual std::string subtitle();
};

class SpriteTestScene : public TestScene
{
public:
    virtual void runThisTest();
};

#endif

license: mit


code:
// #define COCOS2D_DEBUG   1

#include "TextInputTest.h"

//////////////////////////////////////////////////////////////////////////
// local function
//////////////////////////////////////////////////////////////////////////

enum
{
    kTextFieldTTFDefaultTest = 0,
    kTextFieldTTFActionTest,
    kTextInputTestsCount,
};

#define FONT_NAME                       "Thonburi"
#define FONT_SIZE                       36

static int testIdx = -1;

KeyboardNotificationLayer* createTextInputTest(int nIndex)
{
    switch(nIndex)
    {
    case kTextFieldTTFDefaultTest: return new TextFieldTTFDefaultTest();
    case kTextFieldTTFActionTest: return new TextFieldTTFActionTest();
    default: return 0;
    }
}

CCLayer* restartTextInputTest()
{
    TextInputTest* pContainerLayer = new TextInputTest;
    pContainerLayer->autorelease();

    KeyboardNotificationLayer* pTestLayer = createTextInputTest(testIdx);
    pTestLayer->autorelease();
    pContainerLayer->addKeyboardNotificationLayer(pTestLayer);

    return pContainerLayer;
}

CCLayer* nextTextInputTest()
{
    testIdx++;
    testIdx = testIdx % kTextInputTestsCount;

    return restartTextInputTest();
}

CCLayer* backTextInputTest()
{
    testIdx--;
    int total = kTextInputTestsCount;
    if( testIdx < 0 )
        testIdx += total;

    return restartTextInputTest();
}

static CCRect getRect(CCNode * pNode)
{
    CCRect rc;
    rc.origin = pNode->getPosition();
    rc.size = pNode->getContentSize();
    rc.origin.x -= rc.size.width / 2;
    rc.origin.y -= rc.size.height / 2;
    return rc;
}

//////////////////////////////////////////////////////////////////////////
// implement TextInputTest
//////////////////////////////////////////////////////////////////////////

TextInputTest::TextInputTest()
: m_pNotificationLayer(0)
{

}

void TextInputTest::restartCallback(CCObject* pSender)
{
    CCScene* s = new TextInputTestScene();
    s->addChild(restartTextInputTest());

    CCDirector::sharedDirector()->replaceScene(s);
    s->release();
}

void TextInputTest::nextCallback(CCObject* pSender)
{
    CCScene* s = new TextInputTestScene();
    s->addChild( nextTextInputTest() );
    CCDirector::sharedDirector()->replaceScene(s);
    s->release();
}

void TextInputTest::backCallback(CCObject* pSender)
{
    CCScene* s = new TextInputTestScene();
    s->addChild( backTextInputTest() );
    CCDirector::sharedDirector()->replaceScene(s);
    s->release();
}

void TextInputTest::addKeyboardNotificationLayer(KeyboardNotificationLayer * pLayer)
{
    m_pNotificationLayer = pLayer;
    addChild(pLayer);
}

std::string TextInputTest::title()
{
    return "text input test";
}

void TextInputTest::onEnter()
{
    CCLayer::onEnter();

    CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCLabelTTF* label = CCLabelTTF::labelWithString(title().c_str(), "Arial", 24);
    addChild(label);
    label->setPosition(ccp(s.width/2, s.height-50));

    std::string subTitle = m_pNotificationLayer->subtitle();
    if(! subTitle.empty())
    {
        CCLabelTTF* l = CCLabelTTF::labelWithString(subTitle.c_str(), "Thonburi", 16);
        addChild(l, 1);
        l->setPosition(ccp(s.width/2, s.height-80));
    }

    CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage("Images/b1.png", "Images/b2.png", this, menu_selector(TextInputTest::backCallback));
    CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage("Images/r1.png","Images/r2.png", this, menu_selector(TextInputTest::restartCallback) );
    CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage("Images/f1.png", "Images/f2.png", this, menu_selector(TextInputTest::nextCallback) );

    CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL);
    menu->setPosition(CCPointZero);
    item1->setPosition(ccp( s.width/2 - 100,30));
    item2->setPosition(ccp( s.width/2, 30));
    item3->setPosition(ccp( s.width/2 + 100,30));

    addChild(menu, 1);
}

//////////////////////////////////////////////////////////////////////////
// implement KeyboardNotificationLayer
//////////////////////////////////////////////////////////////////////////

KeyboardNotificationLayer::KeyboardNotificationLayer()
: m_pTrackNode(0)
{
    setIsTouchEnabled(true);
}

void KeyboardNotificationLayer::registerWithTouchDispatcher()
{
    CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, false);
}

void KeyboardNotificationLayer::keyboardWillShow(CCIMEKeyboardNotificationInfo& info)
{
    CCLOG("TextInputTest:keyboardWillShowAt(origin:%f,%f, size:%f,%f)",
        info.end.origin.x, info.end.origin.y, info.end.size.width, info.end.size.height);

    if (! m_pTrackNode)
    {
        return;
    }

    CCRect rectTracked = getRect(m_pTrackNode);
    CCLOG("TextInputTest:trackingNodeAt(origin:%f,%f, size:%f,%f)",
        rectTracked.origin.x, rectTracked.origin.y, rectTracked.size.width, rectTracked.size.height);

    // if the keyboard area doesn't intersect with the tracking node area, nothing need to do.
    if (! CCRect::CCRectIntersectsRect(rectTracked, info.end))
    {
        return;
    }

    // assume keyboard at the bottom of screen, calculate the vertical adjustment.
    float adjustVert = CCRect::CCRectGetMaxY(info.end) - CCRect::CCRectGetMinY(rectTracked);
    CCLOG("TextInputTest:needAdjustVerticalPosition(%f)", adjustVert);

    // move all the children node of KeyboardNotificationLayer
    CCArray * children = getChildren();
    CCNode * node = 0;
    int count = children->count();
    CCPoint pos;
    for (int i = 0; i < count; ++i)
    {
        node = (CCNode*)children->objectAtIndex(i);
        pos = node->getPosition();
        pos.y += adjustVert;
        node->setPosition(pos);
    }
}

// CCLayer function

bool KeyboardNotificationLayer::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
    CCLOG("++++++++++++++++++++++++++++++++++++++++++++");
    m_beginPos = pTouch->locationInView();
    m_beginPos = CCDirector::sharedDirector()->convertToGL(m_beginPos);
    return true;
}

void KeyboardNotificationLayer::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
{
    if (! m_pTrackNode)
    {
        return;
    }

    CCPoint endPos = pTouch->locationInView();
    endPos = CCDirector::sharedDirector()->convertToGL(endPos);

    float delta = 5.0f;
    if (::abs(endPos.x - m_beginPos.x) > delta
        || ::abs(endPos.y - m_beginPos.y) > delta)
    {
        // not click
        m_beginPos.x = m_beginPos.y = -1;
        return;
    }

    // decide the trackNode is clicked.
    CCRect rect;
    CCPoint point = convertTouchToNodeSpaceAR(pTouch);
    CCLOG("KeyboardNotificationLayer:clickedAt(%f,%f)", point.x, point.y);

    rect = getRect(m_pTrackNode);
    CCLOG("KeyboardNotificationLayer:TrackNode at(origin:%f,%f, size:%f,%f)",
        rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);

    this->onClickTrackNode(CCRect::CCRectContainsPoint(rect, point));
    CCLOG("----------------------------------");
}

//////////////////////////////////////////////////////////////////////////
// implement TextFieldTTFDefaultTest
//////////////////////////////////////////////////////////////////////////

std::string TextFieldTTFDefaultTest::subtitle()
{
    return "TextFieldTTF with default behavior test";
}

void TextFieldTTFDefaultTest::onClickTrackNode(bool bClicked)
{
    CCTextFieldTTF * pTextField = (CCTextFieldTTF*)m_pTrackNode;
    if (bClicked)
    {
        // TextFieldTTFTest be clicked
        CCLOG("TextFieldTTFDefaultTest:CCTextFieldTTF attachWithIME");
        pTextField->attachWithIME();
    }
    else
    {
        // TextFieldTTFTest not be clicked
        CCLOG("TextFieldTTFDefaultTest:CCTextFieldTTF detachWithIME");
        pTextField->detachWithIME();
    }
}

void TextFieldTTFDefaultTest::onEnter()
{
    KeyboardNotificationLayer::onEnter();

    // add CCTextFieldTTF
    CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCTextFieldTTF * pTextField = CCTextFieldTTF::textFieldWithPlaceHolder("<click here for input>",
        FONT_NAME,
        FONT_SIZE);
    addChild(pTextField);

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
	// on android, CCTextFieldTTF cannot auto adjust its position when soft-keyboard pop up
	// so we had to set a higher position to make it visable
	pTextField->setPosition(ccp(s.width / 2, s.height/2 + 50));
#else
	pTextField->setPosition(ccp(s.width / 2, s.height / 2));
#endif

    m_pTrackNode = pTextField;
}

//////////////////////////////////////////////////////////////////////////
// implement TextFieldTTFActionTest
//////////////////////////////////////////////////////////////////////////

std::string TextFieldTTFActionTest::subtitle()
{
    return "CCTextFieldTTF with action and char limit test";
}

void TextFieldTTFActionTest::onClickTrackNode(bool bClicked)
{
    CCTextFieldTTF * pTextField = (CCTextFieldTTF*)m_pTrackNode;
    if (bClicked)
    {
        // TextFieldTTFTest be clicked
        CCLOG("TextFieldTTFActionTest:CCTextFieldTTF attachWithIME");
        pTextField->attachWithIME();
    }
    else
    {
        // TextFieldTTFTest not be clicked
        CCLOG("TextFieldTTFActionTest:CCTextFieldTTF detachWithIME");
        pTextField->detachWithIME();
    }
}

void TextFieldTTFActionTest::onEnter()
{
    KeyboardNotificationLayer::onEnter();

    m_nCharLimit = 12;

    m_pTextFieldAction = CCRepeatForever::actionWithAction(
        (CCActionInterval*)CCSequence::actions(
            CCFadeOut::actionWithDuration(0.25),
            CCFadeIn::actionWithDuration(0.25),
            0
        ));
    m_pTextFieldAction->retain();
    m_bAction = false;

    // add CCTextFieldTTF
    CCSize s = CCDirector::sharedDirector()->getWinSize();

    m_pTextField = CCTextFieldTTF::textFieldWithPlaceHolder("<click here for input>",
        FONT_NAME,
        FONT_SIZE);
    addChild(m_pTextField);

    m_pTextField->setDelegate(this);

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
	// on android, CCTextFieldTTF cannot auto adjust its position when soft-keyboard pop up
	// so we had to set a higher position
	m_pTextField->setPosition(ccp(s.width / 2, s.height/2 + 50));
#else
	m_pTextField->setPosition(ccp(s.width / 2, s.height / 2));
#endif

    m_pTrackNode = m_pTextField;
}

void TextFieldTTFActionTest::onExit()
{
    KeyboardNotificationLayer::onExit();
    m_pTextFieldAction->release();
}

// CCTextFieldDelegate protocol
bool TextFieldTTFActionTest::onTextFieldAttachWithIME(CCTextFieldTTF * pSender)
{
    if (! m_bAction)
    {
        m_pTextField->runAction(m_pTextFieldAction);
        m_bAction = true;
    }
    return false;
}

bool TextFieldTTFActionTest::onTextFieldDetachWithIME(CCTextFieldTTF * pSender)
{
    if (m_bAction)
    {
        m_pTextField->stopAction(m_pTextFieldAction);
        m_pTextField->setOpacity(255);
        m_bAction = false;
    }
    return false;
}

bool TextFieldTTFActionTest::onTextFieldInsertText(CCTextFieldTTF * pSender, const char * text, int nLen)
{
    // if insert enter, treat as default to detach with ime
    if ('\n' == *text)
    {
        return false;
    }

    // if the textfield's char count more than m_nCharLimit, doesn't insert text anymore.
    if (pSender->getCharCount() >= m_nCharLimit)
    {
        return true;
    }

    // create a insert text sprite and do some action
    CCLabelTTF * label = CCLabelTTF::labelWithString(text, FONT_NAME, FONT_SIZE);
    this->addChild(label);
    ccColor3B color = { 226, 121, 7};
    label->setColor(color);

    // move the sprite from top to position
    CCPoint endPos = pSender->getPosition();
    if (pSender->getCharCount())
    {
        endPos.x += pSender->getContentSize().width / 2;
    }
    CCSize  inputTextSize = label->getContentSize();
    CCPoint beginPos(endPos.x, CCDirector::sharedDirector()->getWinSize().height - inputTextSize.height * 2);

    ccTime duration = 0.5;
    label->setPosition(beginPos);
    label->setScale(8);

    CCAction * seq = CCSequence::actions(
        CCSpawn::actions(
            CCMoveTo::actionWithDuration(duration, endPos),
            CCScaleTo::actionWithDuration(duration, 1),
            CCFadeOut::actionWithDuration(duration),
        0),
        CCCallFuncN::actionWithTarget(this, callfuncN_selector(TextFieldTTFActionTest::callbackRemoveNodeWhenDidAction)),
        0);
    label->runAction(seq);
    return false;
}

bool TextFieldTTFActionTest::onTextFieldDeleteBackward(CCTextFieldTTF * pSender, const char * delText, int nLen)
{
    // create a delete text sprite and do some action
    CCLabelTTF * label = CCLabelTTF::labelWithString(delText, FONT_NAME, FONT_SIZE);
    this->addChild(label);

    // move the sprite to fly out
    CCPoint beginPos = pSender->getPosition();
    CCSize textfieldSize = pSender->getContentSize();
    CCSize labelSize = label->getContentSize();
    beginPos.x += (textfieldSize.width - labelSize.width) / 2.0f;

    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    CCPoint endPos(- winSize.width / 4.0f, winSize.height * (0.5 + (float)rand() / (2.0f * RAND_MAX)));

    ccTime duration = 1;
    ccTime rotateDuration = 0.2f;
    int repeatTime = 5;
    label->setPosition(beginPos);

    CCAction * seq = CCSequence::actions(
        CCSpawn::actions(
            CCMoveTo::actionWithDuration(duration, endPos),
            CCRepeat::actionWithAction(
                CCRotateBy::actionWithDuration(rotateDuration, (rand()%2) ? 360 : -360),
                repeatTime),
            CCFadeOut::actionWithDuration(duration),
        0),
        CCCallFuncN::actionWithTarget(this, callfuncN_selector(TextFieldTTFActionTest::callbackRemoveNodeWhenDidAction)),
        0);
    label->runAction(seq);
    return false;
}

bool TextFieldTTFActionTest::onDraw(CCTextFieldTTF * pSender)
{
    return false;
}

void TextFieldTTFActionTest::callbackRemoveNodeWhenDidAction(CCNode * pNode)
{
    this->removeChild(pNode, true);
}

//////////////////////////////////////////////////////////////////////////
// implement TextInputTestScene
//////////////////////////////////////////////////////////////////////////

void TextInputTestScene::runThisTest()
{
    CCLayer* pLayer = nextTextInputTest();
    addChild(pLayer);

    CCDirector::sharedDirector()->replaceScene(this);
}


code:
#ifndef __TEXT_INPUT_TEST_H__
#define __TEXT_INPUT_TEST_H__

#include "../testBasic.h"

class KeyboardNotificationLayer;

/**
@brief	TextInputTest for retain prev, reset, next, main menu buttons.
*/
class TextInputTest : public CCLayer
{
    KeyboardNotificationLayer * m_pNotificationLayer;
public:
    TextInputTest();

    void restartCallback(CCObject* pSender);
    void nextCallback(CCObject* pSender);
    void backCallback(CCObject* pSender);

    std::string title();
    void addKeyboardNotificationLayer(KeyboardNotificationLayer * pLayer);

    virtual void onEnter();
};

//////////////////////////////////////////////////////////////////////////
// KeyboardNotificationLayer for test IME keyboard notification.
//////////////////////////////////////////////////////////////////////////

class KeyboardNotificationLayer : public CCLayer, public CCIMEDelegate
{
public:
    KeyboardNotificationLayer();

    virtual std::string subtitle() = 0;
    virtual void onClickTrackNode(bool bClicked) = 0;

    virtual void registerWithTouchDispatcher();
    virtual void keyboardWillShow(CCIMEKeyboardNotificationInfo& info);

    // CCLayer
    virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
    virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);

protected:
    CCNode * m_pTrackNode;
    CCPoint  m_beginPos;
};

//////////////////////////////////////////////////////////////////////////
// TextFieldTTFDefaultTest for test TextFieldTTF default behavior.
//////////////////////////////////////////////////////////////////////////

class TextFieldTTFDefaultTest : public KeyboardNotificationLayer
{
public:
    // KeyboardNotificationLayer
    virtual std::string subtitle();
    virtual void onClickTrackNode(bool bClicked);

    // CCLayer
    virtual void onEnter();
};

//////////////////////////////////////////////////////////////////////////
// TextFieldTTFActionTest
//////////////////////////////////////////////////////////////////////////

class TextFieldTTFActionTest : public KeyboardNotificationLayer, public CCTextFieldDelegate
{
    CCTextFieldTTF *    m_pTextField;
    CCAction *          m_pTextFieldAction;
    bool                m_bAction;
    int                 m_nCharLimit;       // the textfield max char limit

public:
    void callbackRemoveNodeWhenDidAction(CCNode * pNode);

    // KeyboardNotificationLayer
    virtual std::string subtitle();
    virtual void onClickTrackNode(bool bClicked);

    // CCLayer
    virtual void onEnter();
    virtual void onExit();

    // CCTextFieldDelegate
    virtual bool onTextFieldAttachWithIME(CCTextFieldTTF * pSender);
    virtual bool onTextFieldDetachWithIME(CCTextFieldTTF * pSender);
    virtual bool onTextFieldInsertText(CCTextFieldTTF * pSender, const char * text, int nLen);
    virtual bool onTextFieldDeleteBackward(CCTextFieldTTF * pSender, const char * delText, int nLen);
    virtual bool onDraw(CCTextFieldTTF * pSender);
};

class TextInputTestScene : public TestScene
{
public:
    virtual void runThisTest();
};

#endif	// __TEXT_INPUT_TEST_H__


code:
// local import
#include "Texture2dTest.h"
#include "../testResource.h"

enum {
	kTagLabel = 1,
	kTagSprite1 = 2,
	kTagSprite2 = 3,
};

#define TEST_CASE_COUNT     30

static int sceneIdx=-1;
CCLayer* createTextureTest(int index)
{
    CCLayer* pLayer = NULL;

    switch (index)
    {
    case 0:
        pLayer = new TextureAlias(); break;
    case 1:
        pLayer = new TextureMipMap(); break;
    case 2:
        pLayer = new TexturePVRMipMap(); break;
    case 3:
        pLayer = new TexturePVRMipMap2(); break;
    case 4:
        pLayer = new TexturePVRNonSquare(); break;
    case 5:
        pLayer = new TexturePVRNPOT4444(); break;
    case 6:
        pLayer = new TexturePVRNPOT8888(); break;
    case 7:
        pLayer = new TexturePVR2BPP(); break;
    case 8:
        pLayer = new TexturePVRRaw(); break;
    case 9:
        pLayer = new TexturePVR(); break;
    case 10:
        pLayer = new TexturePVR4BPP(); break;
    case 11:
        pLayer = new TexturePVRRGBA8888(); break;
    case 12:
        pLayer = new TexturePVRBGRA8888(); break;
    case 13:
        pLayer = new TexturePVRRGBA4444(); break;
    case 14:
        pLayer = new TexturePVRRGBA4444GZ(); break;
    case 15:
        pLayer = new TexturePVRRGBA4444CCZ(); break;
    case 16:
        pLayer = new TexturePVRRGBA5551(); break;
    case 17:
        pLayer = new TexturePVRRGB565(); break;
    case 18:
        pLayer = new TexturePVRA8(); break;
    case 19:
        pLayer = new TexturePVRI8(); break;
    case 20:
        pLayer = new TexturePVRAI88(); break;
    case 21:
        pLayer = new TexturePVRBadEncoding(); break;
    case 22:
        pLayer = new TexturePNG(); break;
    case 23:
        pLayer = new TextureJPEG(); break;
    case 24:
        pLayer = new TexturePixelFormat(); break;
    case 25:
        pLayer = new TextureBlend(); break;
    case 26:
        pLayer = new TextureGlClamp(); break;
    case 27:
        pLayer = new TextureGlRepeat(); break;
    case 28:
        pLayer = new TextureSizeTest(); break;
    case 29:
        pLayer = new TextureCache1(); break;
    default:
        break;
    }

    if (pLayer)
    {
        pLayer->autorelease();
    }

    return pLayer;
}

CCLayer* nextTextureTest();
CCLayer* backTextureTest();
CCLayer* restartTextureTest();

CCLayer* nextTextureTest()
{
	sceneIdx++;
	sceneIdx = sceneIdx % TEST_CASE_COUNT;

	return createTextureTest(sceneIdx);
}

CCLayer* backTextureTest()
{
	sceneIdx--;
	if( sceneIdx < 0 )
		sceneIdx = TEST_CASE_COUNT -1;

	return createTextureTest(sceneIdx);
}

CCLayer* restartTextureTest()
{
	return createTextureTest(sceneIdx);
}

//------------------------------------------------------------------
//
// TextureDemo
//
//------------------------------------------------------------------
void TextureDemo::onEnter()
{
    CCLayer::onEnter();

    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    CCLabelTTF *label = CCLabelTTF::labelWithString(title().c_str(), "Arial", 26);
	addChild(label, 1, kTagLabel);
	label->setPosition(ccp(s.width/2, s.height-50));

    std::string strSubtitle = subtitle();
    if(strSubtitle.length())
    {
        CCLabelTTF *l = CCLabelTTF::labelWithString(strSubtitle.c_str(), "Thonburi", 16);
        addChild(l, 1);
        l->setPosition(ccp(s.width/2, s.height-80));
    }

    CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(TextureDemo::backCallback) );
    CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(TextureDemo::restartCallback) );
    CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(TextureDemo::nextCallback) );

    CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL);
	menu->setPosition(CCPointZero);
	item1->setPosition(ccp( s.width/2 - 100,30));
	item2->setPosition(ccp( s.width/2, 30));
	item3->setPosition(ccp( s.width/2 + 100,30));
	addChild(menu, 1);
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

TextureDemo::~TextureDemo()
{
    CCTextureCache::sharedTextureCache()->removeUnusedTextures();
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

void TextureDemo::restartCallback(CCObject* pSender)
{
    CCScene *s = new TextureTestScene();
	s->addChild(restartTextureTest());
    CCDirector::sharedDirector()->replaceScene(s);
    s->autorelease();
}

void TextureDemo::nextCallback(CCObject* pSender)
{
    CCScene *s = new TextureTestScene();
    s->addChild(nextTextureTest());
    CCDirector::sharedDirector()->replaceScene(s);
    s->autorelease();
}

void TextureDemo::backCallback(CCObject* pSender)
{
    CCScene *s = new TextureTestScene();
    s->addChild(backTextureTest());
    CCDirector::sharedDirector()->replaceScene(s);
    s->autorelease();
}

std::string TextureDemo::title()
{
	return "No title";
}

std::string TextureDemo::subtitle()
{
    return "";
}

//------------------------------------------------------------------
//
// TexturePNG
//
//------------------------------------------------------------------
void TexturePNG::onEnter()
{
    TextureDemo::onEnter();

    CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::spriteWithFile("Images/test_image.png");
	img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
	addChild(img);
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePNG::title()
{
	return "PNG Test";
}

//------------------------------------------------------------------
//
// TextureJPEG
//
//------------------------------------------------------------------
void TextureJPEG::onEnter()
{
	TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::spriteWithFile("Images/test_image.jpeg");
	img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
	addChild(img);
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TextureJPEG::title()
{
	return "JPEG Test";
}

//------------------------------------------------------------------
//
// TextureMipMap
//
//------------------------------------------------------------------
void TextureMipMap::onEnter()
{
    TextureDemo::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCTexture2D *texture0 = CCTextureCache::sharedTextureCache()->addImage("Images/grossini_dance_atlas.png");
	texture0->generateMipmap();
	ccTexParams texParams = { GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE };
	texture0->setTexParameters(&texParams);

	CCTexture2D *texture1 = CCTextureCache::sharedTextureCache()->addImage("Images/grossini_dance_atlas_nomipmap.png");

    CCSprite *img0 = CCSprite::spriteWithTexture(texture0);
	img0->setTextureRect(CCRectMake(85, 121, 85, 121));
	img0->setPosition(ccp( s.width/3.0f, s.height/2.0f));
	addChild(img0);

    CCSprite *img1 = CCSprite::spriteWithTexture(texture1);
	img1->setTextureRect(CCRectMake(85, 121, 85, 121));
	img1->setPosition(ccp( 2*s.width/3.0f, s.height/2.0f));
	addChild(img1);

    CCEaseOut* scale1 = CCEaseOut::actionWithAction(CCScaleBy::actionWithDuration(4, 0.01f), 3);
	CCActionInterval* sc_back = scale1->reverse();

	CCEaseOut* scale2 = (CCEaseOut*) (scale1->copy());
    scale2->autorelease();
	CCActionInterval* sc_back2 = scale2->reverse();

    img0->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)(CCSequence::actions(scale1, sc_back, NULL))));
    img1->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)(CCSequence::actions(scale2, sc_back2, NULL))));
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TextureMipMap::title()
{
	return "Texture Mipmap";
}

std::string TextureMipMap::subtitle()
{
	return "Left image uses mipmap. Right image doesn't";
}

//------------------------------------------------------------------
//
// TexturePVRMipMap
// To generate PVR images read this article:
// http://developer.apple.com/iphone/library/qa/qa2008/qa1611.html
//
//------------------------------------------------------------------
void TexturePVRMipMap::onEnter()
{
    TextureDemo::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *imgMipMap = CCSprite::spriteWithFile("Images/logo-mipmap.pvr");
	if( imgMipMap )
    {
	    imgMipMap->setPosition(ccp( s.width/2.0f-100, s.height/2.0f));
		addChild(imgMipMap);

		// support mipmap filtering
		ccTexParams texParams = { GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE };
		imgMipMap->getTexture()->setTexParameters(&texParams);
	}

    CCSprite *img = CCSprite::spriteWithFile("Images/logo-nomipmap.pvr");
	if( img )
    {
		img->setPosition(ccp( s.width/2.0f+100, s.height/2.0f));
		addChild(img);

        CCEaseOut* scale1 = CCEaseOut::actionWithAction(CCScaleBy::actionWithDuration(4, 0.01f), 3);
        CCActionInterval* sc_back = scale1->reverse();

        CCEaseOut* scale2 = (CCEaseOut*) (scale1->copy());
        scale2->autorelease();
        CCActionInterval* sc_back2 = scale2->reverse();

        imgMipMap->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)(CCSequence::actions(scale1, sc_back, NULL))));
        img->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)(CCSequence::actions(scale2, sc_back2, NULL))));
	}
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRMipMap::title()
{
	return "PVRTC MipMap Test";
}
std::string TexturePVRMipMap::subtitle()
{
	return "Left image uses mipmap. Right image doesn't";
}

//------------------------------------------------------------------
//
// TexturePVRMipMap2
//
//------------------------------------------------------------------
void TexturePVRMipMap2::onEnter()
{
    TextureDemo::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *imgMipMap = CCSprite::spriteWithFile("Images/test_image_rgba4444_mipmap.pvr");
	imgMipMap->setPosition(ccp( s.width/2.0f-100, s.height/2.0f));
	addChild(imgMipMap);

	// support mipmap filtering
	ccTexParams texParams = { GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE };
	imgMipMap->getTexture()->setTexParameters(&texParams);

    CCSprite *img = CCSprite::spriteWithFile("Images/test_image.png");
	img->setPosition(ccp( s.width/2.0f+100, s.height/2.0f));
	addChild(img);

    CCEaseOut* scale1 = CCEaseOut::actionWithAction(CCScaleBy::actionWithDuration(4, 0.01f), 3);
    CCActionInterval* sc_back = scale1->reverse();

    CCEaseOut* scale2 = (CCEaseOut*) (scale1->copy());
    scale2->autorelease();
    CCActionInterval* sc_back2 = scale2->reverse();

    imgMipMap->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)(CCSequence::actions(scale1, sc_back, NULL))));
    img->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)(CCSequence::actions(scale2, sc_back2, NULL))));
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRMipMap2::title()
{
	return "PVR MipMap Test #2";
}

std::string TexturePVRMipMap2::subtitle()
{
	return "Left image uses mipmap. Right image doesn't";
}

//------------------------------------------------------------------
//
// TexturePVR2BPP
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVR2BPP::onEnter()
{
    TextureDemo::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::spriteWithFile("Images/test_image_pvrtc2bpp.pvr");

	if( img )
    {
		img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
		addChild(img);
	}
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVR2BPP::title()
{
	return "PVR TC 2bpp Test";
}

//------------------------------------------------------------------
//
// TexturePVRRaw
// To generate PVR images read this article:
// http://developer.apple.com/iphone/library/qa/qa2008/qa1611.html
//
//------------------------------------------------------------------
void TexturePVRRaw::onEnter()
{
    TextureDemo::onEnter();
#ifdef CC_SUPPORT_PVRTC
	CCSize s = CCDirector::sharedDirector()->getWinSize();

	CCTexture2D *tex = CCTextureCache::sharedTextureCache()->addPVRTCImage("Images/test_image.pvrraw", 4, true, 128);
    CCSprite *img = CCSprite::spriteWithTexture(tex);
	img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
	addChild(img);
#else
    CCLog("Not support PVRTC!");
#endif

	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRRaw::title()
{
	return "PVR TC 4bpp Test #1 (Raw)";
}

//------------------------------------------------------------------
//
// TexturePVR
// To generate PVR images read this article:
// http://developer.apple.com/iphone/library/qa/qa2008/qa1611.html
//
//------------------------------------------------------------------
void TexturePVR::onEnter()
{
    TextureDemo::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::spriteWithFile("Images/test_image.pvr");

	if( img )
    {
		img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
		addChild(img);
	}
    else
    {
        CCLog("This test is not supported.");
	}
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();

}

std::string TexturePVR::title()
{
	return "PVR TC 4bpp Test #2";
}

//------------------------------------------------------------------
//
// TexturePVR4BPP
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVR4BPP::onEnter()
{
    TextureDemo::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::spriteWithFile("Images/test_image_pvrtc4bpp.pvr");

	if( img )
    {
		img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
		addChild(img);
	}
    else
    {
		CCLog("This test is not supported in cocos2d-mac");
	}
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVR4BPP::title()
{
	return "PVR TC 4bpp Test #3";
}

//------------------------------------------------------------------
//
// TexturePVRRGBA8888
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRRGBA8888::onEnter()
{
    TextureDemo::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::spriteWithFile("Images/test_image_rgba8888.pvr");
	img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
	addChild(img);
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRRGBA8888::title()
{
	return "PVR + RGBA  8888 Test";
}

//------------------------------------------------------------------
//
// TexturePVRBGRA8888
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRBGRA8888::onEnter()
{
	TextureDemo::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::spriteWithFile("Images/test_image_bgra8888.pvr");
	if( img )
    {
		img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
		addChild(img);
	}
    else
    {
		CCLog("BGRA8888 images are not supported");
	}
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRBGRA8888::title()
{
	return "PVR + BGRA 8888 Test";
}

//------------------------------------------------------------------
//
// TexturePVRRGBA5551
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRRGBA5551::onEnter()
{
	TextureDemo::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::spriteWithFile("Images/test_image_rgba5551.pvr");
	img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
	addChild(img);
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRRGBA5551::title()
{
	return "PVR + RGBA 5551 Test";
}

//------------------------------------------------------------------
//
// TexturePVRRGBA4444
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRRGBA4444::onEnter()
{
    TextureDemo::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::spriteWithFile("Images/test_image_rgba4444.pvr");
	img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
	addChild(img);
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRRGBA4444::title()
{
	return "PVR + RGBA 4444 Test";
}

//------------------------------------------------------------------
//
// TexturePVRRGBA4444GZ
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRRGBA4444GZ::onEnter()
{
    TextureDemo::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
	// android can not pack .gz file into apk file
    CCSprite *img = CCSprite::spriteWithFile("Images/test_image_rgba4444.pvr");
#else
    CCSprite *img = CCSprite::spriteWithFile("Images/test_image_rgba4444.pvr.gz");
#endif
	img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
	addChild(img);
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRRGBA4444GZ::title()
{
	return "PVR + RGBA 4444 + GZ Test";
}

std::string TexturePVRRGBA4444GZ::subtitle()
{
	return "This is a gzip PVR image";
}

//------------------------------------------------------------------
//
// TexturePVRRGBA4444CCZ
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRRGBA4444CCZ::onEnter()
{
    TextureDemo::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::spriteWithFile("Images/test_image_rgba4444.pvr.ccz");
	img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
	addChild(img);
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRRGBA4444CCZ::title()
{
	return "PVR + RGBA 4444 + CCZ Test";
}

std::string TexturePVRRGBA4444CCZ::subtitle()
{
	return "This is a ccz PVR image";
}

//------------------------------------------------------------------
//
// TexturePVRRGB565
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRRGB565::onEnter()
{
    TextureDemo::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::spriteWithFile("Images/test_image_rgb565.pvr");
	img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
	addChild(img);
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRRGB565::title()
{
	return "PVR + RGB 565 Test";
}

//------------------------------------------------------------------
//
// TexturePVRA8
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRA8::onEnter()
{
	TextureDemo::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::spriteWithFile("Images/test_image_a8.pvr");
	img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
	addChild(img);
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();

}

std::string TexturePVRA8::title()
{
	return "PVR + A8 Test";
}

//------------------------------------------------------------------
//
// TexturePVRI8
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRI8::onEnter()
{
    TextureDemo::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::spriteWithFile("Images/test_image_i8.pvr");
	img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
	addChild(img);
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRI8::title()
{
	return "PVR + I8 Test";
}

//------------------------------------------------------------------
//
// TexturePVRAI88
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRAI88::onEnter()
{
    TextureDemo::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::spriteWithFile("Images/test_image_ai88.pvr");
	img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
	addChild(img);
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRAI88::title()
{
	return "PVR + AI88 Test";
}

//------------------------------------------------------------------
//
// TexturePVRBadEncoding
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRBadEncoding::onEnter()
{
    TextureDemo::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::spriteWithFile("Images/test_image-bad_encoding.pvr");
	if( img )
    {
		img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
		addChild(img);
	}
}

std::string TexturePVRBadEncoding::title()
{
	return "PVR Unsupported encoding";
}

std::string TexturePVRBadEncoding::subtitle()
{
	return "You should not see any image";
}

//------------------------------------------------------------------
//
// TexturePVRNonSquare
//
//------------------------------------------------------------------
void TexturePVRNonSquare::onEnter()
{
    TextureDemo::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::spriteWithFile("Images/grossini_128x256_mipmap.pvr");
	img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
	addChild(img);
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRNonSquare::title()
{
	return "PVR + Non square texture";
}

std::string TexturePVRNonSquare::subtitle()
{
	return "Loading a 128x256 texture";
}

//------------------------------------------------------------------
//
// TexturePVRNPOT4444
//
//------------------------------------------------------------------
void TexturePVRNPOT4444::onEnter()
{
    TextureDemo::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::spriteWithFile("Images/grossini_pvr_rgba4444.pvr");
	if ( img )
    {
		img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
		addChild(img);
	}
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRNPOT4444::title()
{
	return "PVR RGBA4 + NPOT texture";
}

std::string TexturePVRNPOT4444::subtitle()
{
	return "Loading a 81x121 RGBA4444 texture.";
}

//------------------------------------------------------------------
//
// TexturePVRNPOT8888
//
//------------------------------------------------------------------
void TexturePVRNPOT8888::onEnter()
{
    TextureDemo::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::spriteWithFile("Images/grossini_pvr_rgba8888.pvr");
	if( img )
    {
		img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
		addChild(img);
	}
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRNPOT8888::title()
{
	return "PVR RGBA8 + NPOT texture";
}

std::string TexturePVRNPOT8888::subtitle()
{
	return "Loading a 81x121 RGBA8888 texture.";
}

//------------------------------------------------------------------
//
// TextureAlias
//
//------------------------------------------------------------------
void TextureAlias::onEnter()
{
    TextureDemo::onEnter();
	CCSize s = CCDirector::sharedDirector()->getWinSize();

	//
	// Sprite 1: GL_LINEAR
	//
	// Default filter is GL_LINEAR

    CCSprite *sprite = CCSprite::spriteWithFile("Images/grossinis_sister1.png");
	sprite->setPosition(ccp( s.width/3.0f, s.height/2.0f));
	addChild(sprite);

	// this is the default filterting
	sprite->getTexture()->setAntiAliasTexParameters();

	//
	// Sprite 1: GL_NEAREST
	//

    CCSprite *sprite2 = CCSprite::spriteWithFile("Images/grossinis_sister2.png");
	sprite2->setPosition(ccp( 2*s.width/3.0f, s.height/2.0f));
	addChild(sprite2);

	// Use Nearest in this one
	sprite2->getTexture()->setAliasTexParameters();

	// scale them to show
    CCScaleBy* sc = CCScaleBy::actionWithDuration(3, 8.0f);
	CCScaleBy* sc_back = (CCScaleBy*) (sc->reverse());
    CCRepeatForever* scaleforever = CCRepeatForever::actionWithAction((CCActionInterval*) (CCSequence::actions(sc, sc_back, NULL)));
    CCRepeatForever* scaleToo = (CCRepeatForever*) (scaleforever->copy());
    scaleToo->autorelease();

	sprite2->runAction(scaleforever);
	sprite->runAction(scaleToo);
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TextureAlias::title()
{
	return "AntiAlias / Alias textures";
}

std::string TextureAlias::subtitle()
{
	return "Left image is antialiased. Right image is aliases";
}

//------------------------------------------------------------------
//
// TexturePixelFormat
//
//------------------------------------------------------------------
void TexturePixelFormat::onEnter()
{
	//
	// This example displays 1 png images 4 times.
	// Each time the image is generated using:
	// 1- 32-bit RGBA8
	// 2- 16-bit RGBA4
	// 3- 16-bit RGB5A1
	// 4- 16-bit RGB565
    TextureDemo::onEnter();

	CCLabelTTF *label = (CCLabelTTF*) getChildByTag(kTagLabel);
	label->setColor(ccc3(16,16,255));

	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCLayerColor *background = CCLayerColor::layerWithColorWidthHeight(ccc4f(128,128,128,255), s.width, s.height);
	addChild(background, -1);

	// RGBA 8888 image (32-bit)
    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA8888);
    CCSprite *sprite1 = CCSprite::spriteWithFile("Images/test-rgba1.png");
	sprite1->setPosition(ccp(1*s.width/6, s.height/2+32));
	addChild(sprite1, 0);

	// remove texture from texture manager
	CCTextureCache::sharedTextureCache()->removeTexture(sprite1->getTexture());

	// RGBA 4444 image (16-bit)
    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444);
    CCSprite *sprite2 = CCSprite::spriteWithFile("Images/test-rgba1.png");
	sprite2->setPosition(ccp(2*s.width/6, s.height/2-32));
	addChild(sprite2, 0);

	// remove texture from texture manager
	CCTextureCache::sharedTextureCache()->removeTexture(sprite2->getTexture());

	// RGB5A1 image (16-bit)
    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGB5A1);
    CCSprite *sprite3 = CCSprite::spriteWithFile("Images/test-rgba1.png");
	sprite3->setPosition(ccp(3*s.width/6, s.height/2+32));
	addChild(sprite3, 0);

	// remove texture from texture manager
	CCTextureCache::sharedTextureCache()->removeTexture(sprite3->getTexture());

	// RGB565 image (16-bit)
    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGB565);
    CCSprite *sprite4 = CCSprite::spriteWithFile("Images/test-rgba1.png");
	sprite4->setPosition(ccp(4*s.width/6, s.height/2-32));
	addChild(sprite4, 0);

	// remove texture from texture manager
	CCTextureCache::sharedTextureCache()->removeTexture(sprite4->getTexture());

	// A8 image (8-bit)
    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_A8);
    CCSprite *sprite5 = CCSprite::spriteWithFile("Images/test-rgba1.png");
	sprite5->setPosition(ccp(5*s.width/6, s.height/2+32));
	addChild(sprite5, 0);

	// remove texture from texture manager
	CCTextureCache::sharedTextureCache()->removeTexture(sprite5->getTexture());

    CCFadeOut* fadeout = CCFadeOut::actionWithDuration(2);
    CCFadeIn*  fadein  = CCFadeIn::actionWithDuration(2);
    CCFiniteTimeAction* seq = CCSequence::actions(CCDelayTime::actionWithDuration(2), fadeout, fadein, NULL);
    CCRepeatForever* seq_4ever = CCRepeatForever::actionWithAction((CCActionInterval*) seq);
    CCRepeatForever* seq_4ever2 = (CCRepeatForever*) (seq_4ever->copy()); seq_4ever2->autorelease();
    CCRepeatForever* seq_4ever3 = (CCRepeatForever*) (seq_4ever->copy()); seq_4ever3->autorelease();
    CCRepeatForever* seq_4ever4 = (CCRepeatForever*) (seq_4ever->copy()); seq_4ever4->autorelease();
    CCRepeatForever* seq_4ever5 = (CCRepeatForever*) (seq_4ever->copy()); seq_4ever5->autorelease();

	sprite1->runAction(seq_4ever);
	sprite2->runAction(seq_4ever2);
    sprite3->runAction(seq_4ever3);
    sprite4->runAction(seq_4ever4);
	sprite5->runAction(seq_4ever5);

	// restore default
    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_Default);
	CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePixelFormat::title()
{
	return "Texture Pixel Formats";
}

std::string TexturePixelFormat::subtitle()
{
	return "Textures: RGBA8888, RGBA4444, RGB5A1, RGB565, A8";
}

//------------------------------------------------------------------
//
// TextureBlend
//
//------------------------------------------------------------------
void TextureBlend::onEnter()
{
    TextureDemo::onEnter();

	for( int i=0;i < 15;i++ )
    {
		// BOTTOM sprites have alpha pre-multiplied
		// they use by default GL_ONE, GL_ONE_MINUS_SRC_ALPHA
        CCSprite *cloud = CCSprite::spriteWithFile("Images/test_blend.png");
		addChild(cloud, i+1, 100+i);
		cloud->setPosition(ccp(50+25*i, 80));
        ccBlendFunc blendFunc1 = { GL_ONE, GL_ONE_MINUS_SRC_ALPHA };
		cloud->setBlendFunc(blendFunc1);

		// CENTER sprites have also alpha pre-multiplied
		// they use by default GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
        cloud = CCSprite::spriteWithFile("Images/test_blend.png");
		addChild(cloud, i+1, 200+i);
		cloud->setPosition(ccp(50+25*i, 160));
        ccBlendFunc blendFunc2 = { GL_ONE_MINUS_DST_COLOR, GL_ZERO };
		cloud->setBlendFunc(blendFunc2);

		// UPPER sprites are using custom blending function
		// You can set any blend function to your sprites
        cloud = CCSprite::spriteWithFile("Images/test_blend.png");
		addChild(cloud, i+1, 200+i);
		cloud->setPosition(ccp(50+25*i, 320-80));
        ccBlendFunc blendFunc3 = { GL_SRC_ALPHA, GL_ONE };
		cloud->setBlendFunc(blendFunc3);  // additive blending
	}
}

std::string TextureBlend::title()
{
	return "Texture Blending";
}

std::string TextureBlend::subtitle()
{
	return "Testing 3 different blending modes";
}

//------------------------------------------------------------------
//
// TextureGlClamp
//
//------------------------------------------------------------------
void TextureGlClamp::onEnter()
{
    TextureDemo::onEnter();

    CCSize size = CCDirector::sharedDirector()->getWinSize();

	// The .png image MUST be power of 2 in order to create a continue effect.
	// eg: 32x64, 512x128, 256x1024, 64x64, etc..
    CCSprite *sprite = CCSprite::spriteWithFile("Images/pattern1.png", CCRectMake(0,0,512,256));
	addChild(sprite, -1, kTagSprite1);
	sprite->setPosition(ccp(size.width/2,size.height/2));
	ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE};
	sprite->getTexture()->setTexParameters(&params);

    CCRotateBy* rotate = CCRotateBy::actionWithDuration(4, 360);
	sprite->runAction(rotate);
    CCScaleBy* scale = CCScaleBy::actionWithDuration(2, 0.04f);
	CCScaleBy* scaleBack = (CCScaleBy*) (scale->reverse());
    CCFiniteTimeAction* seq = CCSequence::actions(scale, scaleBack, NULL);
	sprite->runAction(seq);
}

std::string TextureGlClamp::title()
{
	return "Texture GL_CLAMP";
}

TextureGlClamp::~TextureGlClamp()
{
    CCTextureCache::sharedTextureCache()->removeUnusedTextures();
}

//------------------------------------------------------------------
//
// TextureGlRepeat
//
//------------------------------------------------------------------
void TextureGlRepeat::onEnter()
{
    TextureDemo::onEnter();

    CCSize size = CCDirector::sharedDirector()->getWinSize();

	// The .png image MUST be power of 2 in order to create a continue effect.
	// eg: 32x64, 512x128, 256x1024, 64x64, etc..
    CCSprite *sprite = CCSprite::spriteWithFile("Images/pattern1.png", CCRectMake(0, 0, 4096, 4096));
	addChild(sprite, -1, kTagSprite1);
	sprite->setPosition(ccp(size.width/2,size.height/2));
	ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
	sprite->getTexture()->setTexParameters(&params);

    CCRotateBy* rotate = CCRotateBy::actionWithDuration(4, 360);
	sprite->runAction(rotate);
    CCScaleBy* scale = CCScaleBy::actionWithDuration(2, 0.04f);
	CCScaleBy* scaleBack = (CCScaleBy*) (scale->reverse());
    CCFiniteTimeAction* seq = CCSequence::actions(scale, scaleBack, NULL);
	sprite->runAction(seq);
}

std::string TextureGlRepeat::title()
{
	return "Texture GL_REPEAT";
}

TextureGlRepeat::~TextureGlRepeat()
{
    CCTextureCache::sharedTextureCache()->removeUnusedTextures();
}

//------------------------------------------------------------------
//
// TextureSizeTest
//
//------------------------------------------------------------------
void TextureSizeTest::onEnter()
{
    TextureDemo::onEnter();
	CCSprite *sprite = NULL;

	CCLog("Loading 512x512 image...");
    sprite = CCSprite::spriteWithFile("Images/texture512x512.png");
	if( sprite )
		CCLog("OK\n");
	else
		CCLog("Error\n");

	CCLog("Loading 1024x1024 image...");
	sprite = CCSprite::spriteWithFile("Images/texture1024x1024.png");
	if( sprite )
		CCLog("OK\n");
	else
		CCLog("Error\n");
// 	@todo
// 	CCLog("Loading 2048x2048 image...");
// 	sprite = CCSprite::spriteWithFile("Images/texture2048x2048.png");
// 	if( sprite )
// 		CCLog("OK\n");
// 	else
// 		CCLog("Error\n");
//
// 	CCLog("Loading 4096x4096 image...");
// 	sprite = CCSprite::spriteWithFile("Images/texture4096x4096.png");
// 	if( sprite )
// 		CCLog("OK\n");
// 	else
// 		CCLog("Error\n");
}

std::string TextureSizeTest::title()
{
	return "Different Texture Sizes";
}

std::string TextureSizeTest::subtitle()
{
	return "512x512, 1024x1024. See the console.";
}

//------------------------------------------------------------------
//
// TextureCache1
//
//------------------------------------------------------------------
void TextureCache1::onEnter()
{
    TextureDemo::onEnter();

	CCSize s = CCDirector::sharedDirector()->getWinSize();

	CCSprite *sprite;

    sprite = CCSprite::spriteWithFile("Images/grossinis_sister1.png");
	sprite->setPosition(ccp(s.width/5*1, s.height/2));
	sprite->getTexture()->setAliasTexParameters();
	sprite->setScale(2);
	addChild(sprite);

	CCTextureCache::sharedTextureCache()->removeTexture(sprite->getTexture());

    sprite = CCSprite::spriteWithFile("Images/grossinis_sister1.png");
    sprite->setPosition(ccp(s.width/5*2, s.height/2));
	sprite->getTexture()->setAntiAliasTexParameters();
	sprite->setScale(2);
	addChild(sprite);

	// 2nd set of sprites

    sprite = CCSprite::spriteWithFile("Images/grossinis_sister2.png");
	sprite->setPosition(ccp(s.width/5*3, s.height/2));
	sprite->getTexture()->setAliasTexParameters();
	sprite->setScale(2);
	addChild(sprite);

	CCTextureCache::sharedTextureCache()->removeTextureForKey("Images/grossinis_sister2.png");

    sprite = CCSprite::spriteWithFile("Images/grossinis_sister2.png");
	sprite->setPosition(ccp(s.width/5*4, s.height/2));
	sprite->getTexture()->setAntiAliasTexParameters();
	sprite->setScale(2);
	addChild(sprite);
}

std::string TextureCache1::title()
{
	return "CCTextureCache: remove";
}

std::string TextureCache1::subtitle()
{
	return "4 images should appear: alias, antialias, alias, antilias";
}

//------------------------------------------------------------------
//
// TextureTestScene
//
//------------------------------------------------------------------
void TextureTestScene::runThisTest()
{
    CCLayer* pLayer = nextTextureTest();
    addChild(pLayer);
    CCDirector::sharedDirector()->replaceScene(this);
}


code:
#ifndef __TEXTURE2D_TEST_H__
#define __TEXTURE2D_TEST_H__

#include "../testBasic.h"

class TextureDemo : public CCLayer
{
public:
    virtual ~TextureDemo();
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();

    void restartCallback(CCObject* pSender);
    void nextCallback(CCObject* pSender);
    void backCallback(CCObject* pSender);
};

class TexturePNG : public TextureDemo
{
public:
    virtual std::string title();
    virtual void onEnter();
};

class TextureJPEG : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};

class TextureMipMap : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVR : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};

class TexturePVR2BPP : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};

class TexturePVR4BPP : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};

class TexturePVRRGBA8888 : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};

class TexturePVRBGRA8888 : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};

class TexturePVRRGBA4444 : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};

class TexturePVRRGBA4444GZ : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVRRGBA4444CCZ : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVRRGBA5551 : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};

class TexturePVRRGB565 : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};

class TexturePVRA8 : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};

class TexturePVRI8 : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};

class TexturePVRAI88 : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};

class TexturePVRBadEncoding : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVRMipMap : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVRMipMap2 : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVRNonSquare : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVRNPOT4444 : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVRNPOT8888 : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVRRaw : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};

class TextureAlias : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePixelFormat : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TextureBlend : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TextureGlRepeat : public TextureDemo
{
public:
    virtual ~TextureGlRepeat();
    virtual std::string title();

    virtual void onEnter();
};

class TextureGlClamp : public TextureDemo
{
public:
    virtual ~TextureGlClamp();
    virtual std::string title();

    virtual void onEnter();
};

class TextureSizeTest : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TextureCache1 : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TextureTestScene : public TestScene
{
public:
    virtual void runThisTest();
};

#endif // __TEXTURE2D_TEST_H__


code:
// enable log
#define COCOS2D_DEBUG 1

#include "TextureCacheTest.h"

using namespace cocos2d;

TextureCacheTest::TextureCacheTest()
: m_nNumberOfSprites(20)
, m_nNumberOfLoadedSprites(0)
{
	CCSize size = CCDirector::sharedDirector()->getWinSize();

	m_pLabelLoading = CCLabelTTF::labelWithString("loading...", "Arial", 15);
	m_pLabelPercent = CCLabelTTF::labelWithString("%0", "Arial", 15);

	m_pLabelLoading->setPosition(CCPointMake(size.width / 2, size.height / 2 - 20));
	m_pLabelPercent->setPosition(CCPointMake(size.width / 2, size.height / 2 + 20));

	this->addChild(m_pLabelLoading);
	this->addChild(m_pLabelPercent);

	// load textrues
	CCTextureCache::sharedTextureCache()->addImageAsync("Images/HelloWorld.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
	CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
	CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_01.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
	CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_02.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
	CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_03.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
	CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_04.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
	CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_05.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
	CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_06.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
	CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_07.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
	CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_08.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
	CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_09.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
	CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_10.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
	CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_11.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
	CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_12.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
	CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_13.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
	CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_14.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
	CCTextureCache::sharedTextureCache()->addImageAsync("Images/background1.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
	CCTextureCache::sharedTextureCache()->addImageAsync("Images/background2.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
	CCTextureCache::sharedTextureCache()->addImageAsync("Images/background3.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
	CCTextureCache::sharedTextureCache()->addImageAsync("Images/blocks.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
}

void TextureCacheTest::loadingCallBack(CCObject *obj)
{
	++m_nNumberOfLoadedSprites;
	char tmp[10];
	sprintf(tmp,"%%%d", (int)(((float)m_nNumberOfLoadedSprites / m_nNumberOfSprites) * 100));
	m_pLabelPercent->setString(tmp);

	if (m_nNumberOfLoadedSprites == m_nNumberOfSprites)
	{
		this->removeChild(m_pLabelLoading, true);
		this->removeChild(m_pLabelPercent, true);
		addSprite();
	}
}

void TextureCacheTest::addSprite()
{
	CCSize size = CCDirector::sharedDirector()->getWinSize();

	// create sprites

	CCSprite *bg = CCSprite::spriteWithFile("Images/HelloWorld.png");
	bg->setPosition(CCPointMake(size.width / 2, size.height / 2));

	CCSprite *s1 = CCSprite::spriteWithFile("Images/grossini.png");
	CCSprite *s2 = CCSprite::spriteWithFile("Images/grossini_dance_01.png");
	CCSprite *s3 = CCSprite::spriteWithFile("Images/grossini_dance_02.png");
	CCSprite *s4 = CCSprite::spriteWithFile("Images/grossini_dance_03.png");
	CCSprite *s5 = CCSprite::spriteWithFile("Images/grossini_dance_04.png");
	CCSprite *s6 = CCSprite::spriteWithFile("Images/grossini_dance_05.png");
	CCSprite *s7 = CCSprite::spriteWithFile("Images/grossini_dance_06.png");
	CCSprite *s8 = CCSprite::spriteWithFile("Images/grossini_dance_07.png");
	CCSprite *s9 = CCSprite::spriteWithFile("Images/grossini_dance_08.png");
	CCSprite *s10 = CCSprite::spriteWithFile("Images/grossini_dance_09.png");
	CCSprite *s11 = CCSprite::spriteWithFile("Images/grossini_dance_10.png");
	CCSprite *s12 = CCSprite::spriteWithFile("Images/grossini_dance_11.png");
	CCSprite *s13 = CCSprite::spriteWithFile("Images/grossini_dance_12.png");
	CCSprite *s14 = CCSprite::spriteWithFile("Images/grossini_dance_13.png");
	CCSprite *s15 = CCSprite::spriteWithFile("Images/grossini_dance_14.png");

	// just loading textures to slow down
	CCSprite *s16 = CCSprite::spriteWithFile("Images/background1.png");
	CCSprite *s17 = CCSprite::spriteWithFile("Images/background2.png");
	CCSprite *s18 = CCSprite::spriteWithFile("Images/background3.png");
	CCSprite *s19 = CCSprite::spriteWithFile("Images/blocks.png");

	s1->setPosition(CCPointMake(50, 50));
	s2->setPosition(CCPointMake(60, 50));
	s3->setPosition(CCPointMake(70, 50));
	s4->setPosition(CCPointMake(80, 50));
	s5->setPosition(CCPointMake(90, 50));
	s6->setPosition(CCPointMake(100, 50));

	s7->setPosition(CCPointMake(50, 180));
	s8->setPosition(CCPointMake(60, 180));
	s9->setPosition(CCPointMake(70, 180));
	s10->setPosition(CCPointMake(80, 180));
	s11->setPosition(CCPointMake(90, 180));
	s12->setPosition(CCPointMake(100, 180));

	s13->setPosition(CCPointMake(50, 270));
	s14->setPosition(CCPointMake(60, 270));
	s15->setPosition(CCPointMake(70, 270));

	this->addChild(bg);

	this->addChild(s1);
    this->addChild(s2);
	this->addChild(s3);
	this->addChild(s4);
	this->addChild(s5);
	this->addChild(s6);
	this->addChild(s7);
	this->addChild(s8);
	this->addChild(s9);
    this->addChild(s10);
	this->addChild(s11);
	this->addChild(s12);
	this->addChild(s13);
	this->addChild(s14);
	this->addChild(s15);
}

void TextureCacheTestScene::runThisTest()
{
    CCLayer* pLayer = new TextureCacheTest();
    addChild(pLayer);

    CCDirector::sharedDirector()->replaceScene(this);
    pLayer->release();
}


code:
#ifndef _TEXTURECACHE_TEST_H_
#define _TEXTURECACHE_TEST_H_

#include "cocos2d.h"
#include "../testBasic.h"
#include "platform/platform.h"

class TextureCacheTest : public CCLayer
{
public:
	TextureCacheTest();
	void addSprite();
	void loadingCallBack(cocos2d::CCObject *obj);

private:
	cocos2d::CCLabelTTF *m_pLabelLoading;
	cocos2d::CCLabelTTF *m_pLabelPercent;
	int m_nNumberOfSprites;
	int m_nNumberOfLoadedSprites;
};

class TextureCacheTestScene : public TestScene
{
public:
    virtual void runThisTest();
};

#endif // _TEXTURECACHE_TEST_H_