[sword-cvs] sword/tests/cppunit versekey_test.cpp,1.1,1.2

sword at www.crosswire.org sword at www.crosswire.org
Thu Jul 15 06:50:45 MST 2004


Committed by: joachim

Update of /cvs/core/sword/tests/cppunit
In directory www:/tmp/cvs-serv10329

Modified Files:
	versekey_test.cpp 
Log Message:
enhanced verse tests

Index: versekey_test.cpp
===================================================================
RCS file: /cvs/core/sword/tests/cppunit/versekey_test.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- versekey_test.cpp	15 Jul 2004 13:10:33 -0000	1.1
+++ versekey_test.cpp	15 Jul 2004 13:50:43 -0000	1.2
@@ -2,28 +2,21 @@
 
 #include <iostream>
 
+#include "localemgr.h"
 #include "swbuf.h"
 #include "versekey.h"
 
 using namespace sword;
+using namespace std;
 
 class VerseKeyTest : public CppUnit::TestFixture  {
 CPPUNIT_TEST_SUITE( VerseKeyTest );
 CPPUNIT_TEST( testSingleKeyParsing );
+CPPUNIT_TEST( testRangeKeyParsing );
+CPPUNIT_TEST( testListKeyParsing );
 CPPUNIT_TEST_SUITE_END();
 
-private:
-	sword::VerseKey* m_vk1;
-	sword::VerseKey* m_vk2;
-	sword::VerseKey* m_vk3;
-	
 protected:
-	void setLocaleToAll(const char* name) {
-		m_vk1->setLocale(name);
-		m_vk2->setLocale(name);
-		m_vk3->setLocale(name);
-	};
-	
 	SWBuf parseKey(const char* keyValue, const char* locale) {
 		sword::VerseKey vk;
 		vk.setLocale(locale);
@@ -33,19 +26,53 @@
 		//std::cout << ret.c_str();
 		return ret;
 	};
-	
+
+	SWBuf parseRangeKey(const char* keyValue, const char* locale) {
+		const char* oldLocale = LocaleMgr::getSystemLocaleMgr()->getDefaultLocaleName();
+		LocaleMgr::getSystemLocaleMgr()->setDefaultLocaleName(locale);
+
+		SWBuf ret;
+		
+		VerseKey DefaultVSKey;
+        	DefaultVSKey = "jas3:1";
+
+        	ListKey verses = DefaultVSKey.ParseVerseList(keyValue, DefaultVSKey, true);
+
+		for (int i = 0; i < verses.Count(); i++) {
+			VerseKey *element = dynamic_cast<VerseKey *>(verses.GetElement(i));
+			if (element) {
+				if (ret.length()) {
+					ret.append(" ");
+				}
+				
+				ret.appendFormatted( "%s - %s;", (const char*)element->LowerBound(), (const char*)element->UpperBound() );
+			}
+			else {
+				if (ret.length()) {
+					ret.append(" ");
+				}
+				
+				ret.appendFormatted("%s;", (const char *)*verses.GetElement(i));
+			}
+		}
+		
+// 		cout << ret.c_str() << endl;
+		LocaleMgr::getSystemLocaleMgr()->setDefaultLocaleName(oldLocale);
+		return ret;
+	};
+		
 public:
 	void setUp() {
-		m_vk1 = new sword::VerseKey();
+/*		m_vk1 = new sword::VerseKey();
 		m_vk2 = new sword::VerseKey();
 		m_vk3 = new sword::VerseKey();
 		
-		setLocaleToAll("en");
+		setLocaleToAll("en");*/
 	}	
 	void tearDown()  {
-		delete m_vk1;
+/*		delete m_vk1;
 		delete m_vk2;
-		delete m_vk3;
+		delete m_vk3;*/
 	}
 	
 	void testSingleKeyParsing() {
@@ -119,6 +146,39 @@
 		CPPUNIT_ASSERT( parseKey("I. jn 2:3", "de") 	== "1. Johannes 2:3");	
 	}
 
+	void testRangeKeyParsing() {
+		//some range tests with the english locale
+		CPPUNIT_ASSERT( parseRangeKey("I. jn 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;");
+		CPPUNIT_ASSERT( parseRangeKey("1Jn 1:1- 3:10", "en") 		== "I John 1:1 - I John 3:10;");
+		CPPUNIT_ASSERT( parseRangeKey("1Jn 1- 3:10", "en") 		== "I John 1:1 - I John 3:10;");
+		CPPUNIT_ASSERT( parseRangeKey("1Jn 1 -3:10", "en") 		== "I John 1:1 - I John 3:10;");
+		CPPUNIT_ASSERT( parseRangeKey("1Jn 1:1 -3:10; 1Jn 3:11", "en") 		== "I John 1:1 - I John 3:10; I John 3:11;");
+
+		//some range tests with german locale
+		CPPUNIT_ASSERT( parseRangeKey("I. jn 1:1 - 3:10", "de") 			== "1. Johannes 1:1 - 1. Johannes 3:10;");	
+		CPPUNIT_ASSERT( parseRangeKey("1. Joh 1:1 - 3:10", "de") 			== "1. Johannes 1:1 - 1. Johannes 3:10;");	
+		CPPUNIT_ASSERT( parseRangeKey("1. Johannes 1:1- 3:10", "de") 	== "1. Johannes 1:1 - 1. Johannes 3:10;");	
+		CPPUNIT_ASSERT( parseRangeKey("1. Joh 1:1- 3:10", "de") 			== "1. Johannes 1:1 - 1. Johannes 3:10;");	
+		CPPUNIT_ASSERT( parseRangeKey("1. Johannes 1:1 -3:10", "de") 	== "1. Johannes 1:1 - 1. Johannes 3:10;");	
+		CPPUNIT_ASSERT( parseRangeKey("1. Joh 1:1 -3:10", "de") 			== "1. Johannes 1:1 - 1. Johannes 3:10;");
+	}
+
+	void testListKeyParsing() {
+		//some range tests with the english locale
+		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;"); 
+		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;");
+		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;");
+		CPPUNIT_ASSERT( parseRangeKey("1Jn 1:1 ; 3:10", "en") 	== "I John 1:1; I John 3:10;");
+
+	}
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(VerseKeyTest);



More information about the sword-cvs mailing list