2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-05-31 23:13:03 +08:00
|
|
|
//
|
|
|
|
// WebSocketTest.h
|
|
|
|
// TestCpp
|
|
|
|
//
|
|
|
|
// Created by James Chen on 5/31/13.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef __TestCpp__WebSocketTest__
|
|
|
|
#define __TestCpp__WebSocketTest__
|
|
|
|
|
|
|
|
#include "cocos2d.h"
|
2013-10-16 16:48:39 +08:00
|
|
|
#include "extensions/cocos-ext.h"
|
|
|
|
#include "network/WebSocket.h"
|
2015-04-03 14:31:03 +08:00
|
|
|
#include "BaseTest.h"
|
2013-05-31 23:13:03 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
DEFINE_TEST_SUITE(WebSocketTests);
|
|
|
|
|
|
|
|
class WebSocketTest : public TestCase
|
2014-01-02 16:25:35 +08:00
|
|
|
, public cocos2d::network::WebSocket::Delegate
|
2013-05-31 23:13:03 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-04-03 14:31:03 +08:00
|
|
|
CREATE_FUNC(WebSocketTest);
|
|
|
|
|
|
|
|
WebSocketTest();
|
|
|
|
virtual ~WebSocketTest();
|
2017-02-13 15:15:23 +08:00
|
|
|
|
|
|
|
virtual void onExit() override;
|
2013-05-31 23:13:03 +08:00
|
|
|
|
2015-07-15 12:04:48 +08:00
|
|
|
virtual void onOpen(cocos2d::network::WebSocket* ws)override;
|
|
|
|
virtual void onMessage(cocos2d::network::WebSocket* ws, const cocos2d::network::WebSocket::Data& data)override;
|
|
|
|
virtual void onClose(cocos2d::network::WebSocket* ws)override;
|
|
|
|
virtual void onError(cocos2d::network::WebSocket* ws, const cocos2d::network::WebSocket::ErrorCode& error)override;
|
2013-05-31 23:13:03 +08:00
|
|
|
|
|
|
|
// Menu Callbacks
|
2014-02-20 10:53:49 +08:00
|
|
|
void onMenuSendTextClicked(cocos2d::Ref *sender);
|
2015-12-31 10:42:06 +08:00
|
|
|
void onMenuSendMultipleTextClicked(cocos2d::Ref *sender);
|
2014-02-20 10:53:49 +08:00
|
|
|
void onMenuSendBinaryClicked(cocos2d::Ref *sender);
|
2013-05-31 23:13:03 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
virtual std::string title() const override { return "WebSocket Test"; }
|
2015-04-09 08:37:30 +08:00
|
|
|
void startTestCallback(cocos2d::Ref* sender);
|
2015-04-03 14:31:03 +08:00
|
|
|
|
2013-05-31 23:13:03 +08:00
|
|
|
private:
|
2014-01-02 16:25:35 +08:00
|
|
|
cocos2d::network::WebSocket* _wsiSendText;
|
|
|
|
cocos2d::network::WebSocket* _wsiSendBinary;
|
|
|
|
cocos2d::network::WebSocket* _wsiError;
|
2013-05-31 23:13:03 +08:00
|
|
|
|
2014-03-26 23:33:58 +08:00
|
|
|
cocos2d::Label* _sendTextStatus;
|
|
|
|
cocos2d::Label* _sendBinaryStatus;
|
|
|
|
cocos2d::Label* _errorStatus;
|
2015-04-03 14:31:03 +08:00
|
|
|
cocos2d::Menu* _startTestMenu;
|
2013-05-31 23:13:03 +08:00
|
|
|
|
|
|
|
int _sendTextTimes;
|
|
|
|
int _sendBinaryTimes;
|
|
|
|
};
|
|
|
|
|
2016-03-10 12:04:10 +08:00
|
|
|
class WebSocketCloseTest : public TestCase
|
|
|
|
, public cocos2d::network::WebSocket::Delegate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(WebSocketCloseTest);
|
|
|
|
|
|
|
|
virtual void onOpen(cocos2d::network::WebSocket* ws)override;
|
|
|
|
virtual void onMessage(cocos2d::network::WebSocket* ws, const cocos2d::network::WebSocket::Data& data)override;
|
|
|
|
virtual void onClose(cocos2d::network::WebSocket* ws)override;
|
|
|
|
virtual void onError(cocos2d::network::WebSocket* ws, const cocos2d::network::WebSocket::ErrorCode& error)override;
|
|
|
|
|
|
|
|
WebSocketCloseTest();
|
2016-04-25 16:22:46 +08:00
|
|
|
virtual ~WebSocketCloseTest();
|
2016-03-10 12:04:10 +08:00
|
|
|
|
|
|
|
virtual std::string title() const override { return "WebSocket close by resetDirector event Test"; }
|
|
|
|
std::string subtitle() const override { return "Click close button, Program should close without crash."; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
cocos2d::network::WebSocket* _wsiTest;
|
|
|
|
};
|
|
|
|
|
2013-05-31 23:13:03 +08:00
|
|
|
#endif /* defined(__TestCpp__WebSocketTest__) */
|