[sword-cvs] sword/tests/cppunit swbuf_test.cpp, NONE,
1.1 Makefile.am, 1.1, 1.2 versekey_test.cpp, 1.2, 1.3
sword at www.crosswire.org
sword at www.crosswire.org
Fri Jul 16 04:03:38 MST 2004
Committed by: joachim
Update of /cvs/core/sword/tests/cppunit
In directory www:/tmp/cvs-serv20484
Modified Files:
Makefile.am versekey_test.cpp
Added Files:
swbuf_test.cpp
Log Message:
some more testcases
--- NEW FILE: swbuf_test.cpp ---
#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 < 50000; ++i) {
t.append("a");
t.append("b");
t.append("ccccc",1);
}
CPPUNIT_ASSERT( t.length() == 3*50000 );
char c = 'a';
for (int i = 0; i < 50000; ++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 < 50000; ++i) {
t.append('a');
t.append('b');
t.append('c');
}
CPPUNIT_ASSERT( t.length() == 3*50000 );
char c = 'a';
for (int i = 0; i < 50000; ++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 < 50000; ++i) {
t.insert(0, "a");
t.insert(1, "b");
t.insert(2, "ccccccc", 1); //only one c
}
CPPUNIT_ASSERT( t.length() == 3*50000+3 );
char c = 'a';
for (int i = 0; i < 50000; ++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*50000+0] == 'e');
CPPUNIT_ASSERT( t[3*50000+1] == 'n');
CPPUNIT_ASSERT( t[3*50000+2] == 'd');
}
void testInsertChar() {
SWBuf t = "end";
for (int i = 0; i < 50000; ++i) {
t.insert(0, 'a');
t.insert(1, 'b');
t.insert(2, 'c');
}
CPPUNIT_ASSERT( t.length() == 3*50000+3 );
char c = 'a';
for (int i = 0; i < 50000; ++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*50000+0] == 'e');
CPPUNIT_ASSERT( t[3*50000+1] == 'n');
CPPUNIT_ASSERT( t[3*50000+2] == 'd');
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(SWBufTest);
Index: Makefile.am
===================================================================
RCS file: /cvs/core/sword/tests/cppunit/Makefile.am,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Makefile.am 15 Jul 2004 13:10:33 -0000 1.1
+++ Makefile.am 16 Jul 2004 11:03:36 -0000 1.2
@@ -3,7 +3,7 @@
# Rules for the test code (use `make check` to execute)
TESTS = LibSword
check_PROGRAMS = $(TESTS)
-LibSword_SOURCES = main.cpp url_test.cpp versekey_test.cpp
+LibSword_SOURCES = main.cpp url_test.cpp versekey_test.cpp swbuf_test.cpp
LibSword_CXXFLAGS = $(CPPUNIT_CFLAGS)
LibSword_LDFLAGS = -lcppunit -ldl
Index: versekey_test.cpp
===================================================================
RCS file: /cvs/core/sword/tests/cppunit/versekey_test.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- versekey_test.cpp 15 Jul 2004 13:50:43 -0000 1.2
+++ versekey_test.cpp 16 Jul 2004 11:03:36 -0000 1.3
@@ -11,9 +11,20 @@
class VerseKeyTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE( VerseKeyTest );
+
CPPUNIT_TEST( testSingleKeyParsing );
CPPUNIT_TEST( testRangeKeyParsing );
CPPUNIT_TEST( testListKeyParsing );
+
+CPPUNIT_TEST( testLessThan );
+CPPUNIT_TEST( testLessEqualThan );
+CPPUNIT_TEST( testEquality );
+CPPUNIT_TEST( testGreaterEqualThan );
+CPPUNIT_TEST( testGreaterThan );
+
+CPPUNIT_TEST( testDecrement );
+CPPUNIT_TEST( testIncrement );
+
CPPUNIT_TEST_SUITE_END();
protected:
@@ -177,8 +188,93 @@
CPPUNIT_ASSERT( parseRangeKey("1Jn 1:1; 3:10", "en") == "I John 1:1; I John 3:10;");
CPPUNIT_ASSERT( parseRangeKey("1Jn 1:1 ;3:10", "en") == "I John 1:1; I John 3:10;");
CPPUNIT_ASSERT( parseRangeKey("1Jn 1:1 ; 3:10", "en") == "I John 1:1; I John 3:10;");
+ }
+
+ void testLessThan() {
+ VerseKey vk1("Luke 1:1");
+ VerseKey vk2("Luke 1:1");
+ VerseKey vk3("Luke 1:2");
+
+ CPPUNIT_ASSERT( !(vk1 < vk2) );
+ CPPUNIT_ASSERT( vk1 < vk3 );
+
+ for (int n = 0; n < 30; n++) {//some more stress :)
+ vk1 = "Luke 1:1";
+ vk3 = vk1;
+
+ for (int j = 0; j < 30; ++j) {
+ vk1--;
+ CPPUNIT_ASSERT( vk1 < vk3 );
+ CPPUNIT_ASSERT( vk1 < VerseKey("Revelation") );
+ CPPUNIT_ASSERT( !(vk1 < VerseKey("Gen")) );
+ }
+ }
+ }
+ void testLessEqualThan() {
+ VerseKey vk1("Luke 1:1");
+ VerseKey vk2("Luke 1:1");
+ VerseKey vk3("Luke 1:2");
+
+ CPPUNIT_ASSERT( vk1 <= vk2 );
+ CPPUNIT_ASSERT( vk1 <= vk3 );
+
+ for (int n = 0; n < 30; n++) { //some more stress
+ vk1 = "Luke 1:1";
+ vk3 = vk1;
+
+ for (int j = 0; j < 30; ++j) {
+ CPPUNIT_ASSERT( vk1 <= vk3 );
+ CPPUNIT_ASSERT( vk1 <= VerseKey("Revelation") );
+ CPPUNIT_ASSERT( !(vk1 <= VerseKey("Gen")) );
+
+ vk1--;
+ }
+ }
+ }
+ void testEquality() {
+ VerseKey vk1("Luke 1:1");
+ VerseKey vk2("Luke 1:1");
+ VerseKey vk3("Luke 1:2");
+
+ CPPUNIT_ASSERT( vk1 == vk2 );
+ CPPUNIT_ASSERT( !(vk1 == vk3) );
+ }
+ void testGreaterEqualThan() {
+ VerseKey vk1("Luke 1:3");
+ VerseKey vk2("Luke 1:3");
+ VerseKey vk3("Luke 1:1");
+
+ CPPUNIT_ASSERT( vk1 >= vk2 );
+ CPPUNIT_ASSERT( vk1 >= vk3 );
+ }
+ void testGreaterThan() {
+ VerseKey vk1("Luke 1:3");
+ VerseKey vk2("Luke 1:1");
+ VerseKey vk3("Luke 1:2");
+
+ CPPUNIT_ASSERT( vk1 > vk2 );
+ CPPUNIT_ASSERT( vk1 > vk3 );
+ }
+ void testDecrement() {
+ VerseKey vk("Matthew 1:1");
+ const int delta = 10;
+
+ for (int i =0; i < delta; ++i) {
+ vk--;
+ }
+ CPPUNIT_ASSERT( vk == VerseKey("Mal 3:15") );
+ }
+ void testIncrement() {
+ VerseKey vk("Mal 3:15");
+ const int delta = 10;
+
+ for (int i =0; i < delta; ++i) {
+ vk++;
+ }
+ CPPUNIT_ASSERT( vk == VerseKey("Matthew 1:1") );
}
+
};
CPPUNIT_TEST_SUITE_REGISTRATION(VerseKeyTest);
More information about the sword-cvs
mailing list