test_push.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. 
  2. #include "hello_test.h"
  3. #include "../server/WinServer.h"
  4. #include "../server/Push.h"
  5. TEST_F(HelloTest, pushSyncGlobalCommunicator)
  6. {
  7. shared_ptr<Communicator> c = getCommunicator();
  8. transGlobalCommunicator([&](Communicator *comm){
  9. testPush(comm);
  10. }, c.get());
  11. }
  12. TEST_F(HelloTest, pushSyncGlobalCommunicatorInCoroutine)
  13. {
  14. shared_ptr<Communicator> c = getCommunicator();
  15. transInCoroutineGlobalCommunicator([&](Communicator *comm){
  16. testPush(comm);
  17. }, c.get());
  18. }
  19. TEST_F(HelloTest, pushReconnectGlobalCommunicator)
  20. {
  21. shared_ptr<Communicator> c = getCommunicator();
  22. transGlobalCommunicator([&](Communicator *comm){
  23. testReconnect(comm);
  24. }, c.get());
  25. }
  26. class RegisterPushCallBack : public PushPrxCallback
  27. {
  28. public:
  29. virtual void callback_testPush(tars::Int32 ret, const std::string& msg)
  30. {
  31. _msg = msg;
  32. }
  33. string _msg;
  34. };
  35. typedef TC_AutoPtr<RegisterPushCallBack> RegisterPushCallBackPtr;
  36. TEST_F(HelloTest, push)
  37. {
  38. shared_ptr<Communicator> comm = getCommunicator();
  39. WinServer ws;
  40. startServer(ws, WIN_CONFIG());
  41. string obj = getObj(ws.getConfig(), "WinAdapter");
  42. HelloPrx prx = comm->stringToProxy<HelloPrx>(obj);
  43. RegisterPushCallBackPtr callback = new RegisterPushCallBack();
  44. prx->tars_set_push_callback(callback);
  45. string msg = TC_Common::now2str();
  46. prx->testPushRegister(msg);
  47. TC_Common::msleep(50);
  48. ASSERT_TRUE(callback->_msg == msg);
  49. stopServer(ws);
  50. }