From 2d522cf6b7be0a4e58d2111ed9f939d6e3019582 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 9 Jun 2007 10:06:53 +0000 Subject: 2007-06-09 Tatsuhiro Tsujikawa Added -j command-line option. * src/OptionHandlerFactory.cc (createOptionHandlers) * src/main.cc * src/ByteArrayDiskWriter.h, src/ByteArrayDiskWriter.cc Rewritten using stringstream. * src/TrackerUpdateCommand.h, src/TrackerUpdateCommand.cc Rewritten using stringstream. --- test/ByteArrayDiskWriterTest.cc | 66 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 test/ByteArrayDiskWriterTest.cc (limited to 'test/ByteArrayDiskWriterTest.cc') diff --git a/test/ByteArrayDiskWriterTest.cc b/test/ByteArrayDiskWriterTest.cc new file mode 100644 index 00000000..ff90db61 --- /dev/null +++ b/test/ByteArrayDiskWriterTest.cc @@ -0,0 +1,66 @@ +#include "ByteArrayDiskWriter.h" +#include +#include + +using namespace std; + +class ByteArrayDiskWriterTest:public CppUnit::TestFixture { + + CPPUNIT_TEST_SUITE(ByteArrayDiskWriterTest); + CPPUNIT_TEST(testWriteAndRead); + CPPUNIT_TEST(testWriteAndRead2); + CPPUNIT_TEST_SUITE_END(); +private: + +public: + void setUp() { + } + + void testWriteAndRead(); + void testWriteAndRead2(); +}; + + +CPPUNIT_TEST_SUITE_REGISTRATION( ByteArrayDiskWriterTest ); + +void ByteArrayDiskWriterTest::testWriteAndRead() { + ByteArrayDiskWriter bw; + + string msg1 = "Hello world!"; + bw.writeData(msg1.c_str(), msg1.size(), 0); + + char buf[100]; + int32_t c = bw.readData(buf, sizeof(buf), 0); + buf[c] = '\0'; + + CPPUNIT_ASSERT_EQUAL(msg1, string(buf)); + + // second call + memset(buf, '\0', sizeof(buf)); + + c = bw.readData(buf, sizeof(buf), 0); + buf[c] = '\0'; + + CPPUNIT_ASSERT_EQUAL(msg1, string(buf)); +} + +void ByteArrayDiskWriterTest::testWriteAndRead2() { + ByteArrayDiskWriter bw; + + string msg1 = "Hello world!"; + bw.writeData(msg1.c_str(), msg1.size(), 16); + + char buf[100]; + int32_t c = bw.readData(buf, sizeof(buf), 16); + buf[c] = '\0'; + + CPPUNIT_ASSERT_EQUAL(msg1, string(buf)); + + // second call + memset(buf, '\0', sizeof(buf)); + + c = bw.readData(buf, sizeof(buf), 16); + buf[c] = '\0'; + + CPPUNIT_ASSERT_EQUAL(msg1, string(buf)); +} -- cgit