Exemplo n.º 1
0
 void test_empty()
 {
     Bytes bytes;
     CPPUNIT_ASSERT(bytes.capacity() >= 0);
     CPPUNIT_ASSERT_EQUAL(0, bytes.size());
     CPPUNIT_ASSERT_EQUAL(string(""), bytes.to_string());
 }
Exemplo n.º 2
0
    void test_assign()
    {
        int const size = m_hello_world_bytes.size();
        Bytes bytes;
        bytes.assign(&m_hello_world_bytes[0], size);
        CPPUNIT_ASSERT(bytes.capacity() >= size);
        CPPUNIT_ASSERT_EQUAL(size, bytes.size());
        CPPUNIT_ASSERT_EQUAL(string("Hello, world!"), bytes.to_string());

        // Shrink the array
        bytes.assign(&m_hello_world_bytes[0], size/2);
        CPPUNIT_ASSERT(bytes.capacity() >= size/2);
        CPPUNIT_ASSERT_EQUAL(size/2, bytes.size());
        CPPUNIT_ASSERT_EQUAL(string("Hello,"), bytes.to_string());

        // Expand the array
        bytes.assign(&m_hello_world_bytes[0], size);
        CPPUNIT_ASSERT(bytes.capacity() >= size);
        CPPUNIT_ASSERT_EQUAL(size, bytes.size());
        CPPUNIT_ASSERT_EQUAL(string("Hello, world!"), bytes.to_string());
    }