axmol/tests/cpp-tests/Classes/SchedulerTest/SchedulerTest.h

409 lines
9.6 KiB
C
Raw Normal View History

2010-09-09 16:15:21 +08:00
#ifndef _SCHEDULER_TEST_H_
#define _SCHEDULER_TEST_H_
#include "cocos2d.h"
#include "extensions/cocos-ext.h"
#include "../BaseTest.h"
2010-09-09 16:15:21 +08:00
DEFINE_TEST_SUITE(SchedulerTests);
class SchedulerTestLayer : public TestCase
2010-09-09 16:15:21 +08:00
{
public:
};
class SchedulerAutoremove : public SchedulerTestLayer
{
public:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(SchedulerAutoremove);
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
2010-09-09 16:15:21 +08:00
2012-06-08 13:55:28 +08:00
void autoremove(float dt);
void tick(float dt);
2010-09-09 16:15:21 +08:00
private:
2012-06-08 13:55:28 +08:00
float accum;
2010-09-09 16:15:21 +08:00
};
class SchedulerPauseResume : public SchedulerTestLayer
{
public:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(SchedulerPauseResume);
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
2010-09-09 16:15:21 +08:00
2012-06-08 13:55:28 +08:00
void tick1(float dt);
void tick2(float dt);
2014-08-15 12:06:16 +08:00
using SchedulerTestLayer::pause;
2012-06-08 13:55:28 +08:00
void pause(float dt);
2010-09-09 16:15:21 +08:00
};
2012-06-12 18:12:45 +08:00
class SchedulerPauseResumeAll : public SchedulerTestLayer
{
public:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(SchedulerPauseResumeAll);
2012-06-12 18:12:45 +08:00
SchedulerPauseResumeAll();
virtual ~SchedulerPauseResumeAll();
virtual void onEnter() override;
virtual void onExit() override;
virtual void update(float delta) override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
2012-06-12 18:12:45 +08:00
void tick1(float dt);
void tick2(float dt);
2014-08-15 12:06:16 +08:00
using SchedulerTestLayer::pause;
2012-06-12 18:12:45 +08:00
void pause(float dt);
2014-08-15 12:06:16 +08:00
using SchedulerTestLayer::resume;
2012-06-12 18:12:45 +08:00
void resume(float dt);
private:
std::set<void*> _pausedTargets;
2012-06-12 18:12:45 +08:00
};
class SchedulerPauseResumeAllUser : public SchedulerTestLayer
{
public:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(SchedulerPauseResumeAllUser);
2012-06-12 18:12:45 +08:00
SchedulerPauseResumeAllUser();
virtual ~SchedulerPauseResumeAllUser();
virtual void onEnter() override;
virtual void onExit() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
2012-06-12 18:12:45 +08:00
void tick1(float dt);
void tick2(float dt);
2014-08-15 12:06:16 +08:00
using SchedulerTestLayer::pause;
2012-06-12 18:12:45 +08:00
void pause(float dt);
2014-08-15 12:06:16 +08:00
using SchedulerTestLayer::resume;
2012-06-12 18:12:45 +08:00
void resume(float dt);
private:
std::set<void*> _pausedTargets;
2012-06-12 18:12:45 +08:00
};
2010-09-09 16:15:21 +08:00
class SchedulerUnscheduleAll : public SchedulerTestLayer
{
public:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(SchedulerUnscheduleAll);
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
2010-09-09 16:15:21 +08:00
2012-06-08 13:55:28 +08:00
void tick1(float dt);
void tick2(float dt);
void tick3(float dt);
void tick4(float dt);
void unscheduleAll(float dt);
2010-09-09 16:15:21 +08:00
};
class SchedulerUnscheduleAllHard : public SchedulerTestLayer
{
2012-06-12 18:12:45 +08:00
public:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(SchedulerUnscheduleAllHard);
virtual void onEnter() override;
virtual void onExit() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
2012-06-12 18:12:45 +08:00
void tick1(float dt);
void tick2(float dt);
void tick3(float dt);
void tick4(float dt);
void unscheduleAll(float dt);
private:
bool _actionManagerActive;
2012-06-12 18:12:45 +08:00
};
class SchedulerUnscheduleAllUserLevel : public SchedulerTestLayer
{
2010-09-09 16:15:21 +08:00
public:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(SchedulerUnscheduleAllUserLevel);
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
2010-09-09 16:15:21 +08:00
2012-06-08 13:55:28 +08:00
void tick1(float dt);
void tick2(float dt);
void tick3(float dt);
void tick4(float dt);
void unscheduleAll(float dt);
2010-09-09 16:15:21 +08:00
};
class SchedulerSchedulesAndRemove : public SchedulerTestLayer
{
public:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(SchedulerSchedulesAndRemove);
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
2010-09-09 16:15:21 +08:00
2012-06-08 13:55:28 +08:00
void tick1(float dt);
void tick2(float dt);
void tick3(float dt);
void tick4(float dt);
void scheduleAndUnschedule(float dt);
2010-09-09 16:15:21 +08:00
};
class SchedulerUpdate : public SchedulerTestLayer
{
public:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(SchedulerUpdate);
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
2010-09-09 16:15:21 +08:00
2012-06-08 13:55:28 +08:00
void removeUpdates(float dt);
2010-09-09 16:15:21 +08:00
};
class SchedulerUpdateAndCustom : public SchedulerTestLayer
{
public:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(SchedulerUpdateAndCustom);
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
2010-09-09 16:15:21 +08:00
void update(float dt) override;
2012-06-08 13:55:28 +08:00
void tick(float dt);
void stopSelectors(float dt);
2010-09-09 16:15:21 +08:00
};
class SchedulerUpdateFromCustom : public SchedulerTestLayer
{
public:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(SchedulerUpdateFromCustom);
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
2010-09-09 16:15:21 +08:00
void update(float dt) override;
2012-06-08 13:55:28 +08:00
void schedUpdate(float dt);
void stopUpdate(float dt);
2010-09-09 16:15:21 +08:00
};
class TestNode : public cocos2d::Node
2010-09-09 16:15:21 +08:00
{
public:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(TestNode);
2010-09-09 16:15:21 +08:00
~TestNode();
2013-12-18 16:03:07 +08:00
void initWithString(const std::string& str, int priority);
virtual void update(float dt) override;
2010-09-09 16:15:21 +08:00
private:
2013-12-18 16:03:07 +08:00
std::string _string;
2010-09-09 16:15:21 +08:00
};
class RescheduleSelector : public SchedulerTestLayer
{
public:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(RescheduleSelector);
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
2012-06-08 13:55:28 +08:00
void schedUpdate(float dt);
private:
float _interval;
int _ticks;
};
class SchedulerDelayAndRepeat : public SchedulerTestLayer
{
public:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(SchedulerDelayAndRepeat);
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
void update(float dt) override;
};
class SchedulerTimeScale : public SchedulerTestLayer
{
public:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(SchedulerTimeScale);
void onEnter() override;
void onExit() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
2015-04-09 12:23:47 +08:00
cocos2d::extension::ControlSlider* sliderCtl();
void sliderAction(cocos2d::Ref* sender, cocos2d::extension::Control::EventType controlEvent);
2015-04-09 12:23:47 +08:00
cocos2d::extension::ControlSlider* _sliderCtl;
};
class TwoSchedulers : public SchedulerTestLayer
{
public:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(TwoSchedulers);
virtual ~TwoSchedulers();
virtual std::string title() const override;
virtual std::string subtitle() const override;
void onEnter() override;
2015-04-09 12:23:47 +08:00
cocos2d::extension::ControlSlider* sliderCtl();
void sliderAction(cocos2d::Ref* sender, cocos2d::extension::Control::EventType controlEvent);
cocos2d::Scheduler* sched1;
cocos2d::Scheduler* sched2;
cocos2d::ActionManager* actionManager1;
cocos2d::ActionManager* actionManager2;
2015-04-09 12:23:47 +08:00
cocos2d::extension::ControlSlider* sliderCtl1;
cocos2d::extension::ControlSlider* sliderCtl2;
};
class SchedulerIssue2268 : public SchedulerTestLayer
{
2013-11-14 07:55:36 +08:00
public:
CREATE_FUNC(SchedulerIssue2268);
~SchedulerIssue2268();
virtual std::string title() const override;
virtual std::string subtitle() const override;
void onEnter() override;
void update(float dt) override;
2013-11-14 07:55:36 +08:00
private:
cocos2d::Node* testNode;
};
class ScheduleCallbackTest : public SchedulerTestLayer
{
public:
CREATE_FUNC(ScheduleCallbackTest);
~ScheduleCallbackTest();
virtual std::string title() const override;
virtual std::string subtitle() const override;
void onEnter() override;
void callback(float dt);
private:
};
class ScheduleUpdatePriority : public SchedulerTestLayer
{
public:
CREATE_FUNC(ScheduleUpdatePriority);
virtual std::string title() const override;
virtual std::string subtitle() const override;
void onEnter() override;
void onExit() override;
virtual void update(float dt) override;
bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event);
2010-09-09 16:15:21 +08:00
};
2015-01-28 11:31:52 +08:00
class SchedulerIssue10232 : public SchedulerTestLayer
{
public:
CREATE_FUNC(SchedulerIssue10232);
virtual std::string title() const override;
virtual std::string subtitle() const override;
void onEnter() override;
void update(float dt) override;
2015-01-28 11:31:52 +08:00
};
class SchedulerRemoveAllFunctionsToBePerformedInCocosThread : public SchedulerTestLayer
{
public:
CREATE_FUNC(SchedulerRemoveAllFunctionsToBePerformedInCocosThread);
virtual std::string title() const override;
virtual std::string subtitle() const override;
void onEnter() override;
void onExit() override;
void update(float dt) override;
private:
cocos2d::Sprite *_sprite;
};
class SchedulerIssue17149: public SchedulerTestLayer
{
public:
CREATE_FUNC(SchedulerIssue17149);
SchedulerIssue17149();
~SchedulerIssue17149();
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual void onEnter() override;
virtual void update(float dt) override;
private:
class ClassA
{
public:
ClassA();
void update(float dt);
int _member1;
int _member2;
int _member3;
};
class ClassB
{
public:
ClassB();
void update(float dt);
int _member1;
int _member2;
int _member3;
};
void *_memoryPool;
};
class SchedulerRemoveEntryWhileUpdate: public SchedulerTestLayer
{
public:
CREATE_FUNC(SchedulerRemoveEntryWhileUpdate);
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual void onEnter() override;
virtual void onExit() override;
private:
class TestClass
{
public:
TestClass(int index, TestClass *nextObj, cocos2d::Scheduler* scheduler);
void update(float dt);
private:
TestClass *_nextObj;
int _index;
cocos2d::Scheduler *_scheduler;
bool _cleanedUp;
};
std::vector<TestClass *> _testvector;
};
2010-09-09 16:15:21 +08:00
#endif