| 26 | CPPUNIT_TEST_SUITE_REGISTRATION(DHTConnectionImplTest); |
| 27 | |
| 28 | void DHTConnectionImplTest::testWriteAndReadData() |
| 29 | { |
| 30 | try { |
| 31 | DHTConnectionImpl con1(AF_INET); |
| 32 | uint16_t con1port = 0; |
| 33 | CPPUNIT_ASSERT(con1.bind(con1port, A2STR::NIL)); |
| 34 | |
| 35 | DHTConnectionImpl con2(AF_INET); |
| 36 | uint16_t con2port = 0; |
| 37 | CPPUNIT_ASSERT(con2.bind(con2port, A2STR::NIL)); |
| 38 | |
| 39 | std::string message1 = "hello world."; |
| 40 | // hostname should be "localhost", not 127.0.0.1. Test failed on Mac OSX10.5 |
| 41 | con1.sendMessage(reinterpret_cast<const unsigned char*>(message1.c_str()), |
| 42 | message1.size(), "localhost", con2port); |
| 43 | |
| 44 | unsigned char readbuffer[100]; |
| 45 | std::string remoteHost; |
| 46 | uint16_t remotePort; |
| 47 | { |
| 48 | while (!con2.getSocket()->isReadable(0)) |
| 49 | ; |
| 50 | ssize_t rlength = con2.receiveMessage(readbuffer, sizeof(readbuffer), |
| 51 | remoteHost, remotePort); |
| 52 | CPPUNIT_ASSERT_EQUAL((ssize_t)message1.size(), rlength); |
| 53 | CPPUNIT_ASSERT_EQUAL(message1, |
| 54 | std::string(&readbuffer[0], &readbuffer[rlength])); |
| 55 | } |
| 56 | } |
| 57 | catch (Exception& e) { |
| 58 | CPPUNIT_FAIL(e.stackTrace()); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | } // namespace aria2 |
nothing calls this directly
no test coverage detected