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

460 lines
12 KiB
C
Raw Normal View History

2019-11-23 20:27:39 +08:00
/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2019-11-23 20:27:39 +08:00
http://www.cocos2d-x.org
2019-11-23 20:27:39 +08:00
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
2019-11-23 20:27:39 +08:00
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
2019-11-23 20:27:39 +08:00
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef _SCHEDULER_TEST_H_
#define _SCHEDULER_TEST_H_
#include "cocos2d.h"
#include "extensions/cocos-ext.h"
#include "../BaseTest.h"
2019-11-23 20:27:39 +08:00
DEFINE_TEST_SUITE(SchedulerTests);
class SchedulerTestLayer : public TestCase
{
public:
};
class SchedulerAutoremove : public SchedulerTestLayer
{
public:
CREATE_FUNC(SchedulerAutoremove);
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
void autoremove(float dt);
void tick(float dt);
private:
float accum;
};
class SchedulerPauseResume : public SchedulerTestLayer
{
public:
CREATE_FUNC(SchedulerPauseResume);
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
void tick1(float dt);
void tick2(float dt);
using SchedulerTestLayer::pause;
void pause(float dt);
};
class SchedulerPauseResumeAll : public SchedulerTestLayer
{
public:
CREATE_FUNC(SchedulerPauseResumeAll);
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;
void tick1(float dt);
void tick2(float dt);
using SchedulerTestLayer::pause;
void pause(float dt);
using SchedulerTestLayer::resume;
void resume(float dt);
private:
std::set<void*> _pausedTargets;
};
class SchedulerPauseResumeAllUser : public SchedulerTestLayer
{
public:
CREATE_FUNC(SchedulerPauseResumeAllUser);
SchedulerPauseResumeAllUser();
virtual ~SchedulerPauseResumeAllUser();
virtual void onEnter() override;
virtual void onExit() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
void tick1(float dt);
void tick2(float dt);
using SchedulerTestLayer::pause;
void pause(float dt);
using SchedulerTestLayer::resume;
void resume(float dt);
private:
std::set<void*> _pausedTargets;
};
class SchedulerUnscheduleAll : public SchedulerTestLayer
{
public:
CREATE_FUNC(SchedulerUnscheduleAll);
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
void tick1(float dt);
void tick2(float dt);
void tick3(float dt);
void tick4(float dt);
void unscheduleAll(float dt);
};
class SchedulerUnscheduleAllHard : public SchedulerTestLayer
{
public:
CREATE_FUNC(SchedulerUnscheduleAllHard);
virtual void onEnter() override;
virtual void onExit() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
void tick1(float dt);
void tick2(float dt);
void tick3(float dt);
void tick4(float dt);
void unscheduleAll(float dt);
private:
bool _actionManagerActive;
};
class SchedulerUnscheduleAllUserLevel : public SchedulerTestLayer
{
public:
CREATE_FUNC(SchedulerUnscheduleAllUserLevel);
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
void tick1(float dt);
void tick2(float dt);
void tick3(float dt);
void tick4(float dt);
void unscheduleAll(float dt);
};
class SchedulerSchedulesAndRemove : public SchedulerTestLayer
{
public:
CREATE_FUNC(SchedulerSchedulesAndRemove);
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
void tick1(float dt);
void tick2(float dt);
void tick3(float dt);
void tick4(float dt);
void scheduleAndUnschedule(float dt);
};
class SchedulerUpdate : public SchedulerTestLayer
{
public:
CREATE_FUNC(SchedulerUpdate);
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
void removeUpdates(float dt);
};
class SchedulerUpdateAndCustom : public SchedulerTestLayer
{
public:
CREATE_FUNC(SchedulerUpdateAndCustom);
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
void update(float dt) override;
void tick(float dt);
void stopSelectors(float dt);
};
class SchedulerUpdateFromCustom : public SchedulerTestLayer
{
public:
CREATE_FUNC(SchedulerUpdateFromCustom);
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
void update(float dt) override;
void schedUpdate(float dt);
void stopUpdate(float dt);
};
class TestNode : public cocos2d::Node
{
public:
CREATE_FUNC(TestNode);
~TestNode();
void initWithString(const std::string& str, int priority);
2019-11-23 20:27:39 +08:00
virtual void update(float dt) override;
private:
std::string _string;
};
class RescheduleSelector : public SchedulerTestLayer
{
public:
CREATE_FUNC(RescheduleSelector);
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
void schedUpdate(float dt);
private:
float _interval;
int _ticks;
2019-11-23 20:27:39 +08:00
};
class SchedulerDelayAndRepeat : public SchedulerTestLayer
{
public:
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:
CREATE_FUNC(SchedulerTimeScale);
void onEnter() override;
void onExit() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
cocos2d::extension::ControlSlider* sliderCtl();
void sliderAction(cocos2d::Ref* sender, cocos2d::extension::Control::EventType controlEvent);
cocos2d::extension::ControlSlider* _sliderCtl;
};
2019-11-23 20:27:39 +08:00
class TwoSchedulers : public SchedulerTestLayer
{
public:
CREATE_FUNC(TwoSchedulers);
virtual ~TwoSchedulers();
virtual std::string title() const override;
virtual std::string subtitle() const override;
void onEnter() override;
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;
cocos2d::extension::ControlSlider* sliderCtl1;
cocos2d::extension::ControlSlider* sliderCtl2;
};
class SchedulerIssue2268 : public SchedulerTestLayer
{
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;
private:
cocos2d::Node* testNode;
};
class SchedulerIssueWithReschedule : public SchedulerTestLayer
{
public:
CREATE_FUNC(SchedulerIssueWithReschedule);
virtual std::string title() const override;
virtual std::string subtitle() const override;
void onEnter() override;
};
class ScheduleCallbackTest : public SchedulerTestLayer
{
public:
CREATE_FUNC(ScheduleCallbackTest);
2019-11-23 20:27:39 +08:00
~ScheduleCallbackTest();
virtual std::string title() const override;
virtual std::string subtitle() const override;
void onEnter() override;
2019-11-23 20:27:39 +08:00
void callback(float dt);
2019-11-23 20:27:39 +08:00
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;
2019-11-23 20:27:39 +08:00
virtual void update(float dt) override;
2019-11-23 20:27:39 +08:00
bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event);
};
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;
};
class SchedulerRemoveAllFunctionsToBePerformedInCocosThread : public SchedulerTestLayer
{
public:
CREATE_FUNC(SchedulerRemoveAllFunctionsToBePerformedInCocosThread);
2019-11-23 20:27:39 +08:00
virtual std::string title() const override;
virtual std::string subtitle() const override;
void onEnter() override;
void onExit() override;
void update(float dt) override;
2019-11-23 20:27:39 +08:00
private:
cocos2d::Sprite *_sprite;
2019-11-23 20:27:39 +08:00
};
class SchedulerIssue17149: public SchedulerTestLayer
2019-11-23 20:27:39 +08:00
{
public:
CREATE_FUNC(SchedulerIssue17149);
SchedulerIssue17149();
~SchedulerIssue17149();
2019-11-23 20:27:39 +08:00
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual void onEnter() override;
virtual void update(float dt) override;
2019-11-23 20:27:39 +08:00
private:
class ClassA
{
public:
ClassA();
2019-11-23 20:27:39 +08:00
void update(float dt);
2019-11-23 20:27:39 +08:00
int _member1;
int _member2;
int _member3;
};
2019-11-23 20:27:39 +08:00
class ClassB
{
public:
ClassB();
void update(float dt);
2019-11-23 20:27:39 +08:00
int _member1;
int _member2;
int _member3;
};
void *_memoryPool;
2019-11-23 20:27:39 +08:00
};
class SchedulerRemoveEntryWhileUpdate: public SchedulerTestLayer
2019-11-23 20:27:39 +08:00
{
public:
CREATE_FUNC(SchedulerRemoveEntryWhileUpdate);
2019-11-23 20:27:39 +08:00
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual void onEnter() override;
virtual void onExit() override;
2019-11-23 20:27:39 +08:00
private:
class TestClass
{
public:
TestClass(int index, TestClass *nextObj, cocos2d::Scheduler* scheduler);
2019-11-23 20:27:39 +08:00
void update(float dt);
private:
TestClass *_nextObj = nullptr;
int _index = 0;
cocos2d::Scheduler *_scheduler = nullptr;
bool _cleanedUp = false;
2019-11-23 20:27:39 +08:00
};
std::vector<TestClass *> _testvector;
2019-11-23 20:27:39 +08:00
};
class SchedulerRemoveSelectorDuringCall: public SchedulerTestLayer
2019-11-23 20:27:39 +08:00
{
public:
CREATE_FUNC(SchedulerRemoveSelectorDuringCall);
2019-11-23 20:27:39 +08:00
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual void onEnter() override;
virtual void onExit() override;
2019-11-23 20:27:39 +08:00
private:
void callback( float );
2019-11-23 20:27:39 +08:00
private:
bool _scheduled;
};
#endif