2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2014-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-10-06 18:47:07 +08:00
|
|
|
Copyright (c) 2021 Bytedance Inc.
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-10-06 18:47:07 +08:00
|
|
|
https://adxe.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:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "platform/CCPlatformConfig.h"
|
|
|
|
|
|
|
|
#ifndef __NEWAUDIOENGINE_TEST_H_
|
2021-12-28 21:27:32 +08:00
|
|
|
# define __NEWAUDIOENGINE_TEST_H_
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-28 21:27:32 +08:00
|
|
|
# include "cocos2d.h"
|
|
|
|
# include "../BaseTest.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-28 21:27:32 +08:00
|
|
|
# include "audio/include/AudioEngine.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
DEFINE_TEST_SUITE(AudioEngineTests);
|
|
|
|
|
|
|
|
class AudioEngineTestDemo : public TestCase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AudioEngineTestDemo();
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onExit() override;
|
|
|
|
|
|
|
|
virtual void onBackCallback(cocos2d::Ref* sender) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::shared_ptr<bool> _isDestroyed;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioControlTest : public AudioEngineTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(AudioControlTest);
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~AudioControlTest();
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual bool init() override;
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void update(float dt) override;
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual std::string title() const override;
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
private:
|
|
|
|
int _audioID;
|
|
|
|
bool _loopEnabled;
|
|
|
|
float _volume;
|
|
|
|
float _duration;
|
|
|
|
float _timeRatio;
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
void* _playItem;
|
|
|
|
void* _timeSlider;
|
|
|
|
bool _updateTimeSlider;
|
|
|
|
bool _isStopped;
|
|
|
|
cocos2d::Label* _playOverLabel;
|
|
|
|
};
|
|
|
|
|
2020-08-01 19:25:39 +08:00
|
|
|
class AudioWavTest : public AudioEngineTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(AudioWavTest);
|
|
|
|
|
|
|
|
virtual ~AudioWavTest();
|
|
|
|
|
|
|
|
virtual bool init() override;
|
|
|
|
|
|
|
|
void onEnter() override;
|
|
|
|
|
|
|
|
virtual std::string title() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
int _audioID = -1;
|
|
|
|
|
|
|
|
int _curIndex = -1;
|
|
|
|
std::vector<std::string> _wavFiles;
|
|
|
|
|
|
|
|
cocos2d::Label* _stateLabel = nullptr;
|
|
|
|
};
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
class PlaySimultaneouslyTest : public AudioEngineTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(PlaySimultaneouslyTest);
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~PlaySimultaneouslyTest();
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual bool init() override;
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual std::string title() const override;
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
private:
|
|
|
|
static const int TEST_COUNT = 10;
|
|
|
|
std::string _files[TEST_COUNT];
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
void* _playItem;
|
|
|
|
int _playingcount;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioProfileTest : public AudioEngineTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(AudioProfileTest);
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~AudioProfileTest();
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual bool init() override;
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void update(float dt) override;
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
private:
|
|
|
|
static const int FILE_COUNT = 2;
|
|
|
|
std::string _files[FILE_COUNT];
|
|
|
|
cocos2d::AudioProfile _audioProfile;
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
int _audioCount;
|
|
|
|
cocos2d::Label* _showLabel;
|
|
|
|
float _time;
|
|
|
|
float _minDelay;
|
|
|
|
void* _timeSlider;
|
|
|
|
};
|
|
|
|
|
|
|
|
class InvalidAudioFileTest : public AudioEngineTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(InvalidAudioFileTest);
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~InvalidAudioFileTest();
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual bool init() override;
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
private:
|
|
|
|
};
|
|
|
|
|
|
|
|
class LargeAudioFileTest : public AudioEngineTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(LargeAudioFileTest);
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~LargeAudioFileTest();
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual bool init() override;
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual std::string title() const override;
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
private:
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioLoadTest : public AudioEngineTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(AudioLoadTest);
|
|
|
|
|
|
|
|
virtual bool init() override;
|
|
|
|
|
|
|
|
virtual std::string title() const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioIssue18597Test : public AudioEngineTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(AudioIssue18597Test);
|
|
|
|
|
|
|
|
float _time;
|
|
|
|
|
|
|
|
virtual bool init() override;
|
|
|
|
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioIssue11143Test : public AudioEngineTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(AudioIssue11143Test);
|
|
|
|
|
|
|
|
virtual bool init() override;
|
|
|
|
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioPerformanceTest : public AudioEngineTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(AudioPerformanceTest);
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual bool init() override;
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioSwitchStateTest : public AudioEngineTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(AudioSwitchStateTest);
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2021-10-06 11:24:39 +08:00
|
|
|
void onEnter() override;
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioSmallFileTest : public AudioEngineTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(AudioSmallFileTest);
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2021-10-06 11:24:39 +08:00
|
|
|
void onEnter() override;
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioSmallFile2Test : public AudioEngineTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(AudioSmallFile2Test);
|
|
|
|
|
|
|
|
virtual void onEnter() override;
|
|
|
|
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioSmallFile3Test : public AudioEngineTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(AudioSmallFile3Test);
|
|
|
|
|
|
|
|
virtual void onEnter() override;
|
|
|
|
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioPauseResumeAfterPlay : public AudioEngineTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(AudioPauseResumeAfterPlay);
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void onEnter() override;
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioIssue16938Test : public AudioEngineTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(AudioIssue16938Test);
|
|
|
|
|
|
|
|
virtual void onEnter() override;
|
|
|
|
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioPreloadSameFileMultipleTimes : public AudioEngineTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(AudioPreloadSameFileMultipleTimes);
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void onEnter() override;
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioPlayFileInWritablePath : public AudioEngineTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(AudioPlayFileInWritablePath);
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void onEnter() override;
|
|
|
|
virtual void onExit() override;
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
private:
|
|
|
|
std::vector<std::string> _oldSearchPaths;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioPlayInFinishedCB : public AudioEngineTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(AudioPlayInFinishedCB);
|
|
|
|
|
|
|
|
virtual void onEnter() override;
|
|
|
|
virtual void onExit() override;
|
|
|
|
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
|
|
|
|
private:
|
2021-12-28 21:27:32 +08:00
|
|
|
void doPlay(std::string_view filename);
|
|
|
|
void playMusic(std::string_view filename);
|
2019-11-23 20:27:39 +08:00
|
|
|
std::list<std::string> _playList;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioUncacheInFinishedCB : public AudioEngineTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(AudioUncacheInFinishedCB);
|
|
|
|
|
|
|
|
virtual void onEnter() override;
|
|
|
|
virtual void onExit() override;
|
|
|
|
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* defined(__NEWAUDIOENGINE_TEST_H_) */
|