2012-04-19 14:35:52 +08:00
|
|
|
#include "ExtensionsTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
#include "NotificationCenterTest/NotificationCenterTest.h"
|
|
|
|
#include "ControlExtensionTest/CCControlSceneManager.h"
|
2012-05-03 12:17:28 +08:00
|
|
|
#include "CocosBuilderTest/CocosBuilderTest.h"
|
2014-03-22 21:15:18 +08:00
|
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_EMSCRIPTEN) && (CC_TARGET_PLATFORM != CC_PLATFORM_NACL) && (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
|
2012-08-09 10:45:11 +08:00
|
|
|
#include "NetworkTest/HttpClientTest.h"
|
2013-05-08 08:25:39 +08:00
|
|
|
#endif
|
2012-09-09 22:34:32 +08:00
|
|
|
#include "TableViewTest/TableViewTestScene.h"
|
2013-09-10 09:53:15 +08:00
|
|
|
|
|
|
|
#include "CocoStudioArmatureTest/ArmatureScene.h"
|
|
|
|
#include "CocoStudioComponentsTest/ComponentsTestScene.h"
|
|
|
|
#include "CocoStudioSceneTest/SceneEditorTest.h"
|
2014-03-04 16:51:35 +08:00
|
|
|
#include "CocoStudioGUITest/CocoStudioGUITest.h"
|
2012-09-09 22:34:32 +08:00
|
|
|
|
2013-08-28 14:49:04 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
2013-05-31 23:13:03 +08:00
|
|
|
#include "NetworkTest/WebSocketTest.h"
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
#include "NetworkTest/SocketIOTest.h"
|
2013-05-31 23:13:03 +08:00
|
|
|
#endif
|
|
|
|
|
2013-05-26 19:40:13 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN)
|
2012-08-15 14:33:56 +08:00
|
|
|
#include "EditBoxTest/EditBoxTest.h"
|
|
|
|
#endif
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-11 14:07:14 +08:00
|
|
|
#include "Scale9SpriteTest/Scale9SpriteTest.h"
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
LINE_SPACE = 40,
|
|
|
|
kItemTagBasic = 1000,
|
|
|
|
};
|
|
|
|
|
2013-06-08 08:21:11 +08:00
|
|
|
static struct {
|
|
|
|
const char *name;
|
2014-02-20 10:53:49 +08:00
|
|
|
std::function<void(Ref* sender)> callback;
|
2013-06-08 08:21:11 +08:00
|
|
|
} g_extensionsTests[] = {
|
2014-02-20 10:53:49 +08:00
|
|
|
{ "NotificationCenterTest", [](Ref* sender) { runNotificationCenterTest(); }
|
2013-06-08 08:21:11 +08:00
|
|
|
},
|
2014-02-20 10:53:49 +08:00
|
|
|
{ "Scale9SpriteTest", [](Ref* sender) {
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = new S9SpriteTestScene();
|
2013-07-23 08:25:44 +08:00
|
|
|
if (scene)
|
2013-07-11 14:07:14 +08:00
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
scene->runThisTest();
|
|
|
|
scene->release();
|
2013-07-11 14:07:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2014-02-20 10:53:49 +08:00
|
|
|
{ "CCControlButtonTest", [](Ref *sender){
|
2013-06-20 14:17:10 +08:00
|
|
|
ControlSceneManager* pManager = ControlSceneManager::sharedControlSceneManager();
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = pManager->currentControlScene();
|
2013-07-23 08:25:44 +08:00
|
|
|
Director::getInstance()->replaceScene(scene);
|
2013-06-08 08:21:11 +08:00
|
|
|
}},
|
2014-02-20 10:53:49 +08:00
|
|
|
{ "CocosBuilderTest", [](Ref *sender) {
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = new CocosBuilderTestScene();
|
2013-07-23 08:25:44 +08:00
|
|
|
if (scene)
|
2013-06-08 08:21:11 +08:00
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
scene->runThisTest();
|
|
|
|
scene->release();
|
2013-06-08 08:21:11 +08:00
|
|
|
}
|
|
|
|
}},
|
2014-03-22 21:15:18 +08:00
|
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_EMSCRIPTEN) && (CC_TARGET_PLATFORM != CC_PLATFORM_NACL) && (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
|
2014-02-20 10:53:49 +08:00
|
|
|
{ "HttpClientTest", [](Ref *sender){ runHttpClientTest();}
|
2013-06-08 08:21:11 +08:00
|
|
|
},
|
2013-05-08 08:25:39 +08:00
|
|
|
#endif
|
2013-08-28 14:49:04 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
2014-02-20 10:53:49 +08:00
|
|
|
{ "WebSocketTest", [](Ref *sender){ runWebSocketTest();}
|
2013-06-08 08:21:11 +08:00
|
|
|
},
|
2014-02-20 10:53:49 +08:00
|
|
|
{ "SocketIOTest", [](Ref *sender){ runSocketIOTest();}
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
},
|
2013-05-31 23:13:03 +08:00
|
|
|
#endif
|
2013-05-26 19:40:13 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN)
|
2014-02-20 10:53:49 +08:00
|
|
|
{ "EditBoxTest", [](Ref *sender){ runEditBoxTest();}
|
2013-06-08 08:21:11 +08:00
|
|
|
},
|
2012-08-15 14:33:56 +08:00
|
|
|
#endif
|
2014-02-20 10:53:49 +08:00
|
|
|
{ "TableViewTest", [](Ref *sender){ runTableViewTest();}
|
2013-06-08 08:21:11 +08:00
|
|
|
},
|
2014-02-20 10:53:49 +08:00
|
|
|
{ "CocoStudioArmatureTest", [](Ref *sender) { ArmatureTestScene *scene = new ArmatureTestScene();
|
2013-09-10 09:53:15 +08:00
|
|
|
scene->runThisTest();
|
|
|
|
scene->release();
|
|
|
|
}
|
|
|
|
},
|
2014-02-20 10:53:49 +08:00
|
|
|
{ "CocoStudioComponentsTest", [](Ref *sender) { runComponentsTestLayerTest(); }
|
2013-06-14 14:34:50 +08:00
|
|
|
},
|
2014-02-20 10:53:49 +08:00
|
|
|
{ "CocoStudioSceneTest", [](Ref *sender) { SceneEditorTestScene *scene = new SceneEditorTestScene();
|
2014-01-03 01:42:14 +08:00
|
|
|
scene->runThisTest();
|
|
|
|
scene->release();
|
|
|
|
}
|
2013-09-16 20:54:13 +08:00
|
|
|
},
|
2014-02-20 10:53:49 +08:00
|
|
|
{ "CocoStudioGUITest", [](Ref *sender)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
2014-03-04 16:51:35 +08:00
|
|
|
CocoStudioGUITestScene* pScene = new CocoStudioGUITestScene();
|
2013-09-16 20:54:13 +08:00
|
|
|
pScene->runThisTest();
|
|
|
|
pScene->release();
|
|
|
|
}
|
|
|
|
},
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2013-06-08 08:21:11 +08:00
|
|
|
static const int g_maxTests = sizeof(g_extensionsTests) / sizeof(g_extensionsTests[0]);
|
|
|
|
|
2013-07-12 14:47:36 +08:00
|
|
|
static Point s_tCurPos = Point::ZERO;
|
2013-07-09 04:20:24 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// ExtensionsMainLayer
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void ExtensionsMainLayer::onEnter()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::onEnter();
|
2013-06-14 14:34:50 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2013-06-14 14:34:50 +08:00
|
|
|
|
2013-07-09 04:20:24 +08:00
|
|
|
_itemMenu = Menu::create();
|
2013-07-12 14:47:36 +08:00
|
|
|
_itemMenu->setPosition( Point::ZERO );
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontName("Arial");
|
|
|
|
MenuItemFont::setFontSize(24);
|
2013-06-08 08:21:11 +08:00
|
|
|
for (int i = 0; i < g_maxTests; ++i)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto pItem = MenuItemFont::create(g_extensionsTests[i].name, g_extensionsTests[i].callback);
|
2013-07-12 14:11:55 +08:00
|
|
|
pItem->setPosition(Point(s.width / 2, s.height - (i + 1) * LINE_SPACE));
|
2013-07-09 04:20:24 +08:00
|
|
|
_itemMenu->addChild(pItem, kItemTagBasic + i);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-07-09 04:20:24 +08:00
|
|
|
|
2013-10-23 16:14:03 +08:00
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesBegan = CC_CALLBACK_2(ExtensionsMainLayer::onTouchesBegan, this);
|
|
|
|
listener->onTouchesMoved = CC_CALLBACK_2(ExtensionsMainLayer::onTouchesMoved, this);
|
|
|
|
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2013-06-14 14:34:50 +08:00
|
|
|
|
2013-12-16 17:40:34 +08:00
|
|
|
auto mouseListener = EventListenerMouse::create();
|
|
|
|
mouseListener->onMouseScroll = CC_CALLBACK_1(ExtensionsMainLayer::onMouseScroll, this);
|
|
|
|
|
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(mouseListener, this);
|
|
|
|
|
2013-07-09 04:20:24 +08:00
|
|
|
addChild(_itemMenu);
|
|
|
|
}
|
|
|
|
|
2013-12-16 17:40:34 +08:00
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void ExtensionsMainLayer::onTouchesBegan(const std::vector<Touch*>& touches, Event *event)
|
2013-07-09 04:20:24 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
auto touch = static_cast<Touch*>(touches[0]);
|
2013-07-09 04:20:24 +08:00
|
|
|
|
|
|
|
_beginPos = touch->getLocation();
|
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void ExtensionsMainLayer::onTouchesMoved(const std::vector<Touch*>& touches, Event *event)
|
2013-07-09 04:20:24 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
auto touch = static_cast<Touch*>(touches[0]);
|
2013-07-09 04:20:24 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto touchLocation = touch->getLocation();
|
2013-07-09 04:20:24 +08:00
|
|
|
float nMoveY = touchLocation.y - _beginPos.y;
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto curPos = _itemMenu->getPosition();
|
|
|
|
auto nextPos = Point(curPos.x, curPos.y + nMoveY);
|
2013-07-09 04:20:24 +08:00
|
|
|
|
|
|
|
if (nextPos.y < 0.0f)
|
|
|
|
{
|
2013-07-12 14:47:36 +08:00
|
|
|
_itemMenu->setPosition(Point::ZERO);
|
2013-07-09 04:20:24 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nextPos.y > ((g_maxTests + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height))
|
|
|
|
{
|
2013-07-12 14:11:55 +08:00
|
|
|
_itemMenu->setPosition(Point(0, ((g_maxTests + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)));
|
2013-07-09 04:20:24 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_itemMenu->setPosition(nextPos);
|
|
|
|
_beginPos = touchLocation;
|
|
|
|
s_tCurPos = nextPos;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-16 17:40:34 +08:00
|
|
|
void ExtensionsMainLayer::onMouseScroll(Event* event)
|
|
|
|
{
|
|
|
|
auto mouseEvent = static_cast<EventMouse*>(event);
|
|
|
|
float nMoveY = mouseEvent->getScrollY() * 6;
|
|
|
|
|
|
|
|
auto curPos = _itemMenu->getPosition();
|
|
|
|
auto nextPos = Point(curPos.x, curPos.y + nMoveY);
|
|
|
|
|
|
|
|
if (nextPos.y < 0.0f)
|
|
|
|
{
|
|
|
|
_itemMenu->setPosition(Point::ZERO);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nextPos.y > ((g_maxTests + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height))
|
|
|
|
{
|
|
|
|
_itemMenu->setPosition(Point(0, ((g_maxTests + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_itemMenu->setPosition(nextPos);
|
|
|
|
s_tCurPos = nextPos;
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// ExtensionsTestScene
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void ExtensionsTestScene::runThisTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = new ExtensionsMainLayer();
|
2013-07-23 08:25:44 +08:00
|
|
|
addChild(layer);
|
|
|
|
layer->release();
|
2013-06-14 14:34:50 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-07-09 04:20:24 +08:00
|
|
|
|
|
|
|
|