summaryrefslogtreecommitdiff
path: root/test/ByteArrayDiskWriterTest.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-06-09 10:06:53 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-06-09 10:06:53 +0000
commit2d522cf6b7be0a4e58d2111ed9f939d6e3019582 (patch)
tree336e44735aa3ac545bbf127fdaf61115f33bbed9 /test/ByteArrayDiskWriterTest.cc
parentc7fbedfa0aba7bd23f101d6823cb46348745c363 (diff)
2007-06-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
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.
Diffstat (limited to 'test/ByteArrayDiskWriterTest.cc')
-rw-r--r--test/ByteArrayDiskWriterTest.cc66
1 files changed, 66 insertions, 0 deletions
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 <string>
+#include <cppunit/extensions/HelperMacros.h>
+
+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));
+}