test_tc_clientsocket.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "util/tc_common.h"
  2. #include "util/tc_clientsocket.h"
  3. #include "gtest/gtest.h"
  4. #include <iostream>
  5. #include <vector>
  6. using namespace std;
  7. using namespace tars;
  8. class UtilClientSocketTest : public testing::Test
  9. {
  10. public:
  11. //添加日志
  12. static void SetUpTestCase()
  13. {
  14. }
  15. static void TearDownTestCase()
  16. {
  17. }
  18. virtual void SetUp() //TEST跑之前会执行SetUp
  19. {
  20. }
  21. virtual void TearDown() //TEST跑完之后会执行TearDown
  22. {
  23. }
  24. };
  25. TEST_F(UtilClientSocketTest, testParseEndpoint)
  26. {
  27. TC_Endpoint ep;
  28. ep.parse("tcp -h 127.0.0.1 -p 17890 -t 3000:");
  29. ASSERT_TRUE(ep.isTcp());
  30. ASSERT_TRUE(ep.getHost() == "127.0.0.1");
  31. ASSERT_TRUE(ep.getPort() == 3000);
  32. }
  33. TEST_F(UtilClientSocketTest, testSepEndpointOK)
  34. {
  35. vector<string> v = TC_Endpoint::sepEndpoint("tcp -h 127.0.0.1 -p 17890 -t 3000:tcp -h 127.0.0.1 -p 17890 -t 3001");
  36. LOG_CONSOLE_DEBUG << v.size() << ", " << TC_Common::tostr(v.begin(), v.end(), ", ") << endl;
  37. ASSERT_TRUE(v.size() == 2);
  38. ASSERT_TRUE(v[0] == "tcp -h 127.0.0.1 -p 17890 -t 3000");
  39. ASSERT_TRUE(v[1] == "tcp -h 127.0.0.1 -p 17890 -t 3001");
  40. }
  41. TEST_F(UtilClientSocketTest, testSepEndpoint1)
  42. {
  43. vector<string> v = TC_Endpoint::sepEndpoint("tcp -h 127.0.0.1 -p 17890 -t 3000:");
  44. // LOG_CONSOLE_DEBUG << v.size() << ", " << TC_Common::tostr(v.begin(), v.end(), ", ") << endl;
  45. ASSERT_TRUE(v.size() == 1);
  46. ASSERT_TRUE(v[0] == "tcp -h 127.0.0.1 -p 17890 -t 3000");
  47. }
  48. TEST_F(UtilClientSocketTest, testSepEndpoint2)
  49. {
  50. vector<string> v = TC_Endpoint::sepEndpoint("tcp -h 127.0.0.1 -p 17890 -t 3000:tcp -h 127.0.0.1 -p 17890 -t 3001:");
  51. // LOG_CONSOLE_DEBUG << v.size() << ", " << TC_Common::tostr(v.begin(), v.end(), ", ") << endl;
  52. ASSERT_TRUE(v.size() == 2);
  53. ASSERT_TRUE(v[0] == "tcp -h 127.0.0.1 -p 17890 -t 3000");
  54. ASSERT_TRUE(v[1] == "tcp -h 127.0.0.1 -p 17890 -t 3001");
  55. }