TEST(Reflection, Variable) { AM_DECLARE_VAR(g_instance, int, "MyInteger", 2); ASSERT_TRUE(g_instance == 2); g_instance = 3; ASSERT_TRUE(g_instance == 3); AM_ASSIGN_VAR("MyInteger", 4); ASSERT_TRUE(g_instance == 4); AM_ASSIGN_VAR_STR("MyInteger", "5"); ASSERT_TRUE(g_instance == 5); UDPWriteDesc writeDesc; writeDesc.port = 5005; writeDesc.address = "localhost"; std::string str = "MyInteger 6"; UDPSocket writeSocket; ASSERT_TRUE(writeSocket.connect(writeDesc)); ASSERT_EQ(writeSocket.write(str.c_str(), str.length()), str.length()); std::this_thread::sleep_for(std::chrono::seconds(1)); ASSERT_TRUE(g_instance == 6); GlobalVariableHandler::destroyInstance(); }
TEST(Network, UDPSocket) { UDPWriteDesc writeDesc; writeDesc.port = 5005; writeDesc.address = "localhost"; UDPSocket writeSocket; ASSERT_TRUE(writeSocket.connect(writeDesc)); std::string str = "Hello World"; UDPReadDesc readDesc; readDesc.port = 5005; char buffer[1024]; UDPSocket socket; ASSERT_TRUE(socket.connect(readDesc)); ASSERT_EQ(writeSocket.write(str.c_str(), str.length()), str.length()); ASSERT_EQ(socket.read(buffer, 1024), str.length()); ASSERT_STREQ(str.c_str(), buffer); AM_LOG_SUCCESS("%s", buffer); }