[sword-cvs] sword/tests/cppunit url_test.cpp,1.2,1.3

sword at www.crosswire.org sword at www.crosswire.org
Tue Jul 20 02:29:25 MST 2004


Committed by: joachim

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

Modified Files:
	url_test.cpp 
Log Message:
added decode function to URL; params of an URL get decoded now; checked with cppunit before this commit

Index: url_test.cpp
===================================================================
RCS file: /cvs/core/sword/tests/cppunit/url_test.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- url_test.cpp	17 Jul 2004 16:28:04 -0000	1.2
+++ url_test.cpp	20 Jul 2004 09:29:22 -0000	1.3
@@ -4,6 +4,8 @@
 
 #include "url.h"
 
+using namespace sword;
+
 class URLTest : public CppUnit::TestFixture  {
 CPPUNIT_TEST_SUITE( URLTest );
 CPPUNIT_TEST( testProtocol );
@@ -11,6 +13,8 @@
 CPPUNIT_TEST( testPath );
 CPPUNIT_TEST( testParametersMap );
 CPPUNIT_TEST( testParameterValue );
+CPPUNIT_TEST( testEncode );
+CPPUNIT_TEST( testDecode );
 CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -21,7 +25,7 @@
 public:
 	void setUp() {
 		m_url1 = new sword::URL("http://www.crosswire.org/index.jsp?page=help&user=foo&name=bar");
-		m_url2 = new sword::URL("ftp://ftp.crosswire.org/sword/wiki/index.jsp?page=help&user=foo&name=bar");
+		m_url2 = new sword::URL("ftp://ftp.crosswire.org/sword/wiki/index.jsp?page=help&user=foo&name=foo%20bar");
 		m_url3 = new sword::URL("crosswire.org/index.jsp");
 	}	
 	void tearDown()  {
@@ -61,7 +65,7 @@
  		params = m_url2->getParameters(); //test url2 params
 		CPPUNIT_ASSERT( !strcmp(params[sword::SWBuf("page")].c_str(), "help") );
 		CPPUNIT_ASSERT( !strcmp(params[sword::SWBuf("user")].c_str(),  "foo") );
-		CPPUNIT_ASSERT( !strcmp(params[sword::SWBuf("name")].c_str(), "bar") );
+		CPPUNIT_ASSERT( !strcmp(params[sword::SWBuf("name")].c_str(), "foo bar") );
 	
  		params = m_url3->getParameters(); //test url3 params
 		CPPUNIT_ASSERT( params.size() == 0 );
@@ -75,10 +79,27 @@
 		
 		CPPUNIT_ASSERT( !strcmp(m_url2->getParamterValue("page"), "help") );
 		CPPUNIT_ASSERT( !strcmp(m_url2->getParamterValue("user"), "foo") );
-		CPPUNIT_ASSERT( !strcmp(m_url2->getParamterValue("name"), "bar") );
+		CPPUNIT_ASSERT( !strcmp(m_url2->getParamterValue("name"), "foo bar") );
 		
 		CPPUNIT_ASSERT( m_url3->getParamterValue("page") && strlen(m_url3->getParamterValue("page")) == 0 );
 	}	
+
+	void testEncode() {	
+		const char* encoded = URL::encode("this is a test");
+		CPPUNIT_ASSERT( !strcmp(encoded, "this%20is%20a%20test") || !strcmp(encoded, "this+is+a+test") );
+		
+		CPPUNIT_ASSERT( !strcmp(URL::encode("this-is-a-test"), "this-is-a-test") );
+		CPPUNIT_ASSERT( !strcmp(URL::encode(""), "") );
+	}
+	
+	void testDecode() {
+		CPPUNIT_ASSERT( !strcmp(URL::decode("this%3Eis%3Ea%3Etest"), "this>is>a>test") );
+		CPPUNIT_ASSERT( !strcmp(URL::decode("this%3Eis%3Ea%3Etest%3E"), "this>is>a>test>") );
+		CPPUNIT_ASSERT( !strcmp(URL::decode("%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%20%20%20%20%20"), ">>>>>>>>>>     ") );
+		CPPUNIT_ASSERT( !strcmp(URL::decode("nothing%20"), "nothing ") );
+		CPPUNIT_ASSERT( !strcmp(URL::decode("nothing"), "nothing") );
+		CPPUNIT_ASSERT( !strcmp(URL::decode(""), "") );
+	}
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(URLTest);



More information about the sword-cvs mailing list