1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
/******************************************************************************
*
* swbuf_test.cpp -
*
* $Id: swbuf_test.cpp 2833 2013-06-29 06:40:28Z chrislit $
*
* Copyright 2004-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
*/
#include <cppunit/extensions/HelperMacros.h>
#include <iostream>
#include "swbuf.h"
using namespace sword;
using namespace std;
class SWBufTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE( SWBufTest );
CPPUNIT_TEST( testEquality );
CPPUNIT_TEST( testAppendString );
CPPUNIT_TEST( testAppendChar );
CPPUNIT_TEST( testInsertString );
CPPUNIT_TEST( testInsertChar );
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {
}
void tearDown() {
}
void testEquality() {
SWBuf s1("Hi, this is a test!");
SWBuf s2("Hi, this is a test!");
CPPUNIT_ASSERT( s1 == s2 );
CPPUNIT_ASSERT( s1 == "Hi, this is a test!" );
CPPUNIT_ASSERT( !(s1 == "Hi, this is a wrong test!") );
}
void testAppendString() {
SWBuf t;
for (int i = 0; i < 5000; ++i) {
t.append("a");
t.append("b");
t.append("ccccc",1);
}
CPPUNIT_ASSERT( t.length() == 3*5000 );
char c = 'a';
for (int i = 0; i < 5000; ++i) { //check whether the append calls worked right
CPPUNIT_ASSERT( t[i] == c );
c = (c=='a') ? 'b' : ((c=='b') ? 'c' : 'a');
}
}
void testAppendChar() {
SWBuf t;
for (int i = 0; i < 5000; ++i) {
t.append('a');
t.append('b');
t.append('c');
}
CPPUNIT_ASSERT( t.length() == 3*5000 );
char c = 'a';
for (int i = 0; i < 5000; ++i) { //check whether the append calls worked right
CPPUNIT_ASSERT( t[i] == c );
c = (c=='a') ? 'b' : ((c=='b') ? 'c' : 'a');
}
}
void testInsertString() {
SWBuf t = "end";
for (int i = 0; i < 5000; ++i) {
t.insert(0, "a");
t.insert(1, "b");
t.insert(2, "ccccccc", 0, 1); //only one c
}
CPPUNIT_ASSERT( t.length() == 3*5000+3 );
char c = 'a';
for (int i = 0; i < 5000; ++i) { //check whether the append calls worked right
CPPUNIT_ASSERT( t[i] == c );
c = (c=='a') ? 'b' : ((c=='b') ? 'c' : 'a');
}
//check if end is at the end
CPPUNIT_ASSERT( t[3*5000+0] == 'e');
CPPUNIT_ASSERT( t[3*5000+1] == 'n');
CPPUNIT_ASSERT( t[3*5000+2] == 'd');
}
void testInsertChar() {
SWBuf t = "end";
for (int i = 0; i < 5000; ++i) {
t.insert(0, 'a');
t.insert(1, 'b');
t.insert(2, 'c');
}
CPPUNIT_ASSERT( t.length() == 3*5000+3 );
char c = 'a';
for (int i = 0; i < 5000; ++i) { //check whether the insert calls worked right
CPPUNIT_ASSERT( t[i] == c );
c = (c=='a') ? 'b' : ((c=='b') ? 'c' : 'a');
}
//check if end is at the end
CPPUNIT_ASSERT( t[3*5000+0] == 'e');
CPPUNIT_ASSERT( t[3*5000+1] == 'n');
CPPUNIT_ASSERT( t[3*5000+2] == 'd');
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(SWBufTest);
|