Debian Codegraph @

tests/test_bytevectorstream.cpp

raw symbols SCIP
1 /***************************************************************************
2 copyright : (C) 2011 by Lukas Lalinsky
3 email : [email protected]
4 ***************************************************************************/
5
6 /***************************************************************************
7 * This library is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU Lesser General Public License version *
9 * 2.1 as published by the Free Software Foundation. *
10 * *
11 * This library is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the Free Software *
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
19 * 02110-1301 USA *
20 * *
21 * Alternatively, this file is available under the Mozilla Public *
22 * License Version 1.1. You may obtain a copy of the License at *
23 * http://www.mozilla.org/MPL/ *
24 ***************************************************************************/
25
26 #include "tbytevectorstream.h"
27 #include <cppunit/extensions/HelperMacros.h>
28
29 using namespace std;
30 using namespace TagLib;
31
32 class TestByteVectorStream : public CppUnit::TestFixture
33 {
34 CPPUNIT_TEST_SUITE(TestByteVectorStream);
35 CPPUNIT_TEST(testInitialData);
36 CPPUNIT_TEST(testWriteBlock);
37 CPPUNIT_TEST(testWriteBlockResize);
38 CPPUNIT_TEST(testReadBlock);
39 CPPUNIT_TEST(testRemoveBlock);
40 CPPUNIT_TEST(testInsert);
41 CPPUNIT_TEST(testSeekEnd);
42 CPPUNIT_TEST_SUITE_END();
43
44 public:
45
46 void testInitialData()
47 {
48 ByteVector v("abcd");
49 ByteVectorStream stream(v);
50
51 CPPUNIT_ASSERT_EQUAL(ByteVector("abcd"), *stream.data());
52 }
53
54 void testWriteBlock()
55 {
56 ByteVector v("abcd");
57 ByteVectorStream stream(v);
58
59 stream.seek(1);
60 stream.writeBlock(ByteVector("xx"));
61 CPPUNIT_ASSERT_EQUAL(ByteVector("axxd"), *stream.data());
62 }
63
64 void testWriteBlockResize()
65 {
66 ByteVector v("abcd");
67 ByteVectorStream stream(v);
68
69 stream.seek(3);
70 stream.writeBlock(ByteVector("xx"));
71 CPPUNIT_ASSERT_EQUAL(ByteVector("abcxx"), *stream.data());
72 stream.seek(5);
73 stream.writeBlock(ByteVector("yy"));
74 CPPUNIT_ASSERT_EQUAL(ByteVector("abcxxyy"), *stream.data());
75 }
76
77 void testReadBlock()
78 {
79 ByteVector v("abcd");
80 ByteVectorStream stream(v);
81
82 CPPUNIT_ASSERT_EQUAL(ByteVector("a"), stream.readBlock(1));
83 CPPUNIT_ASSERT_EQUAL(ByteVector("bc"), stream.readBlock(2));
84 CPPUNIT_ASSERT_EQUAL(ByteVector("d"), stream.readBlock(3));
85 CPPUNIT_ASSERT_EQUAL(ByteVector(""), stream.readBlock(3));
86 }
87
88 void testRemoveBlock()
89 {
90 ByteVector v("abcd");
91 ByteVectorStream stream(v);
92
93 stream.removeBlock(1, 1);
94 CPPUNIT_ASSERT_EQUAL(ByteVector("acd"), *stream.data());
95 stream.removeBlock(0, 2);
96 CPPUNIT_ASSERT_EQUAL(ByteVector("d"), *stream.data());
97 stream.removeBlock(0, 2);
98 CPPUNIT_ASSERT_EQUAL(ByteVector(""), *stream.data());
99 }
100
101 void testInsert()
102 {
103 ByteVector v("abcd");
104 ByteVectorStream stream(v);
105
106 stream.insert(ByteVector("xx"), 1, 1);
107 CPPUNIT_ASSERT_EQUAL(ByteVector("axxcd"), *stream.data());
108 stream.insert(ByteVector("yy"), 0, 2);
109 CPPUNIT_ASSERT_EQUAL(ByteVector("yyxcd"), *stream.data());
110 stream.insert(ByteVector("foa"), 3, 2);
111 CPPUNIT_ASSERT_EQUAL(ByteVector("yyxfoa"), *stream.data());
112 stream.insert(ByteVector("123"), 3, 0);
113 CPPUNIT_ASSERT_EQUAL(ByteVector("yyx123foa"), *stream.data());
114 }
115
116 void testSeekEnd()
117 {
118 ByteVector v("abcdefghijklmnopqrstuvwxyz");
119 ByteVectorStream stream(v);
120 CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(26), stream.length());
121
122 stream.seek(-4, IOStream::End);
123 CPPUNIT_ASSERT_EQUAL(ByteVector("w"), stream.readBlock(1));
124
125 stream.seek(-25, IOStream::End);
126 CPPUNIT_ASSERT_EQUAL(ByteVector("b"), stream.readBlock(1));
127 }
128
129 };
130
131 CPPUNIT_TEST_SUITE_REGISTRATION(TestByteVectorStream);