Skip to content

Commit

Permalink
Full coverage of data stream operators for basic types
Browse files Browse the repository at this point in the history
  • Loading branch information
ropez committed Mar 6, 2010
1 parent aea7be5 commit f0f0f7b
Showing 1 changed file with 41 additions and 7 deletions.
48 changes: 41 additions & 7 deletions src/test/test_data_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,18 @@ CPPUNIT_TEST_SUITE_REGISTRATION(TestDataStreamReadBytes);
class TestDataStreamOnBuffer : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestDataStreamOnBuffer);
CPPUNIT_TEST(testInt);
CPPUNIT_TEST(testReal);
CPPUNIT_TEST(testBool);
CPPUNIT_TEST(testChar);
CPPUNIT_TEST(testShort);
CPPUNIT_TEST(testInt);
CPPUNIT_TEST(testLong);
CPPUNIT_TEST(testFloat);
CPPUNIT_TEST(testDouble);
CPPUNIT_TEST(testByteArray);
CPPUNIT_TEST(testValueList);
CPPUNIT_TEST(testPropertyList);
CPPUNIT_TEST(testStdString);
CPPUNIT_TEST(testCStringToStdString);
CPPUNIT_TEST(testRandomTypes);
CPPUNIT_TEST_SUITE_END();

Expand Down Expand Up @@ -331,16 +336,35 @@ class TestDataStreamOnBuffer : public CppUnit::TestFixture
t = 0;
}

void testBool() {
test(true, false, true);
}

void testChar() {
unsigned char uc = '\n';
test('a', uc, '\0');
}

void testShort() {
short v1 = 42, v2 = 0;
unsigned short v3 = 0xffffu;
test(v1, v2, v3);
}

void testInt() {
test(42, 0xffffffff, 0);
test(42, 0xffffffffu, 0);
}

void testReal() {
test(3.14, 3.14, 1e-8);
void testLong() {
test(42l, ~0ul, 0l);
}

void testChar() {
test('a', '\n', '\0');
void testFloat() {
test(3.14f, 3.14159f, 1e-8f);
}

void testDouble() {
test(3.14, 3.14159, 1e-8);
}

void testByteArray() {
Expand Down Expand Up @@ -371,6 +395,16 @@ class TestDataStreamOnBuffer : public CppUnit::TestFixture
test(v1, v2, v3);
}

void testCStringToStdString() {
DataStream ds(t.get());
write(ds, "foo");
write(ds, "");
write(ds, "\tfoo\tbar\n");
read(ds, std::string("foo"));
read(ds, std::string(""));
read(ds, std::string("\tfoo\tbar\n"));
}

void testRandomTypes() {
test(42, ByteArray(), '\0');
test(3.14, std::string("foo"), 0xffffffff);
Expand Down

0 comments on commit f0f0f7b

Please sign in to comment.