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

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Mon Jun 1 00:11:06 CEST 2009


Revision: 41082
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41082&view=rev
Author:   lordhoto
Date:     2009-05-31 22:11:06 +0000 (Sun, 31 May 2009)

Log Message:
-----------
Add unit tests for Common::String operators. These test cases will for example cover tests on String instances, which will be added to itself (foo += foo). NOTE: Those fail currently.

Modified Paths:
--------------
    scummvm/trunk/test/common/str.h

Modified: scummvm/trunk/test/common/str.h
===================================================================
--- scummvm/trunk/test/common/str.h	2009-05-31 19:31:04 UTC (rev 41081)
+++ scummvm/trunk/test/common/str.h	2009-05-31 22:11:06 UTC (rev 41082)
@@ -118,6 +118,35 @@
 		TS_ASSERT_EQUALS(foo3, "fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd""fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd");
 	}
 
+	void test_self_asignment() {
+		Common::String foo1("12345678901234567890123456789012");
+		foo1 = foo1.c_str() + 2;
+		TS_ASSERT_EQUALS(foo1, "345678901234567890123456789012");
+
+		Common::String foo2("123456789012");
+		foo2 = foo2.c_str() + 2;
+		TS_ASSERT_EQUALS(foo2, "3456789012");
+
+		// "foo3" and "foo4" will be using allocated storage from construction on.
+		Common::String foo3("12345678901234567890123456789012");
+		foo3 += foo3.c_str();
+		TS_ASSERT_EQUALS(foo3, "12345678901234567890123456789012""12345678901234567890123456789012");
+
+		Common::String foo4("12345678901234567890123456789012");
+		foo4 += foo4;
+		TS_ASSERT_EQUALS(foo4, "12345678901234567890123456789012""12345678901234567890123456789012");
+
+		// Based on our current Common::String implementation "foo5" and "foo6" will first use the internal storage,
+		// and on "operator +=" they will change to allocated memory.
+		Common::String foo5("123456789012");
+		foo5 += foo5.c_str();
+		TS_ASSERT_EQUALS(foo5, "123456789012""123456789012");
+
+		Common::String foo6("123456789012");
+		foo6 += foo6;
+		TS_ASSERT_EQUALS(foo6, "123456789012""123456789012");
+	}
+
 	void test_hasPrefix() {
 		Common::String str("this/is/a/test, haha");
 		TS_ASSERT_EQUALS(str.hasPrefix(""), true);


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