[Scummvm-cvs-logs] SF.net SVN: scummvm:[48613] scummvm/trunk/test/common/tokenizer.h

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sun Apr 11 01:12:23 CEST 2010


Revision: 48613
          http://scummvm.svn.sourceforge.net/scummvm/?rev=48613&view=rev
Author:   fingolfin
Date:     2010-04-10 23:12:22 +0000 (Sat, 10 Apr 2010)

Log Message:
-----------
Part of patch #2982224: "GSoC: Added unit test and unified error message display"

Added Paths:
-----------
    scummvm/trunk/test/common/tokenizer.h

Added: scummvm/trunk/test/common/tokenizer.h
===================================================================
--- scummvm/trunk/test/common/tokenizer.h	                        (rev 0)
+++ scummvm/trunk/test/common/tokenizer.h	2010-04-10 23:12:22 UTC (rev 48613)
@@ -0,0 +1,59 @@
+#include <cxxtest/TestSuite.h>
+#include "common/util.h"
+#include "common/tokenizer.h"
+
+class TokenizerTestSuite : public CxxTest::TestSuite {
+public:
+	void test_nextToken() {
+		
+		// test Common::StringTokenizer class
+
+		// test normal behavior
+		Common::StringTokenizer strTokenizer("Now, this is a test!", " ,!");
+		Common::String tokenArray[] = {"Now", "this", "is", "a", "test"};
+
+		for (int i = 0; i < ARRAYSIZE(tokenArray); i++ ) {
+			// make sure nextToken works correctly
+			TS_ASSERT_EQUALS(tokenArray[i], strTokenizer.nextToken());
+		}
+
+		// test edgy conditions:
+	
+		// Empty String
+		Common::StringTokenizer s1("");
+		TS_ASSERT_EQUALS("", s1.nextToken());
+		
+		// Empty Delimiter
+		Common::StringTokenizer s2("test String", "");
+		TS_ASSERT_EQUALS("test String", s2.nextToken());
+		
+		// String is the delimiter
+		Common::StringTokenizer s3("abc", "abc");
+		TS_ASSERT_EQUALS("", s3.nextToken());
+		// Tokenizer should be empty
+		TS_ASSERT(s3.empty());
+		
+		// consecutive delimiters in the string
+		Common::StringTokenizer s4("strstr,after all!!", "str, !");
+		TS_ASSERT_EQUALS("af", s4.nextToken());
+	}
+
+	void test_resetAndEmpty() {	
+		Common::StringTokenizer strTokenizer("Just, another test!", " ,!");
+
+		// test reset()
+		Common::String token1 = strTokenizer.nextToken(); //Just
+		strTokenizer.reset();
+		Common::String token2 = strTokenizer.nextToken(); //Just
+
+		TS_ASSERT_EQUALS(token1,token2);
+
+		// test empty()
+		TS_ASSERT(!strTokenizer.empty()); 
+		strTokenizer.nextToken(); //another
+		strTokenizer.nextToken(); //test
+		TS_ASSERT(strTokenizer.empty()); 
+	}
+
+};
+


Property changes on: scummvm/trunk/test/common/tokenizer.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list