aboutsummaryrefslogtreecommitdiff
path: root/test/common/str.h
blob: 8b7b9669356d9495fb934a1827ec624b58501fb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <cxxtest/TestSuite.h>

#include "common/stdafx.h"
#include "common/str.h"

class StringTestSuite : public CxxTest::TestSuite
{
	public:
	void test_empty_clear( void )
	{
		Common::String str("test");
		TS_ASSERT( !str.empty() );
		str.clear();
		TS_ASSERT( str.empty() );
	}

	void test_lastChar( void )
	{
		Common::String str;
		TS_ASSERT_EQUALS( str.lastChar(), '\0' );
		str = "test";
		TS_ASSERT_EQUALS( str.lastChar(), 't' );
		Common::String str2("bar");
		TS_ASSERT_EQUALS( str2.lastChar(), 'r' );
	}

	void test_concat1( void )
	{
		Common::String str("foo");
		Common::String str2("bar");
		str += str2;
		TS_ASSERT_EQUALS( str, "foobar" );
		TS_ASSERT_EQUALS( str2, "bar" );
	}

	void test_concat2( void )
	{
		Common::String str("foo");
		str += "bar";
		TS_ASSERT_EQUALS( str, "foobar" );
	}

	void test_concat3( void )
	{
		Common::String str("foo");
		str += 'X';
		TS_ASSERT_EQUALS( str, "fooX" );
	}

	void test_refCount( void )
	{
		Common::String foo1("foo");
		Common::String foo2("foo");
		Common::String foo3(foo2);
		foo3 += 'X';
		TS_ASSERT_EQUALS( foo2, foo1 );
		TS_ASSERT_EQUALS( foo2, "foo" );
		TS_ASSERT_EQUALS( foo3, "foo""X" );
	}

	void test_refCount2( void )
	{
		Common::String foo1("fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd");
		Common::String foo2("fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd");
		Common::String foo3(foo2);
		foo3 += 'X';
		TS_ASSERT_EQUALS( foo2, foo1 );
		TS_ASSERT_EQUALS( foo2, "fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd" );
		TS_ASSERT_EQUALS( foo3, "fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd""X" );
	}

	void test_refCount3( void )
	{
		Common::String foo1("0123456789abcdefghijk");
		Common::String foo2("0123456789abcdefghijk");
		Common::String foo3(foo2);
		foo3 += "0123456789abcdefghijk";
		TS_ASSERT_EQUALS( foo2, foo1 );
		TS_ASSERT_EQUALS( foo2, "0123456789abcdefghijk" );
		TS_ASSERT_EQUALS( foo3, "0123456789abcdefghijk""0123456789abcdefghijk" );
	}

	void test_refCount4( void )
	{
		Common::String foo1("fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd");
		Common::String foo2("fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd");
		Common::String foo3(foo2);
		foo3 += "fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd";
		TS_ASSERT_EQUALS( foo2, foo1 );
		TS_ASSERT_EQUALS( foo2, "fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd" );
		TS_ASSERT_EQUALS( foo3, "fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd""fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd" );
	}

	void test_hasPrefix( void )
	{
		Common::String str("this/is/a/test, haha");
		TS_ASSERT_EQUALS( str.hasPrefix(""), true );
		TS_ASSERT_EQUALS( str.hasPrefix("this"), true );
		TS_ASSERT_EQUALS( str.hasPrefix("thit"), false );
		TS_ASSERT_EQUALS( str.hasPrefix("foo"), false );
	}

	void test_hasSuffix( void )
	{
		Common::String str("this/is/a/test, haha");
		TS_ASSERT_EQUALS( str.hasSuffix(""), true );
		TS_ASSERT_EQUALS( str.hasSuffix("haha"), true );
		TS_ASSERT_EQUALS( str.hasSuffix("hahb"), false );
		TS_ASSERT_EQUALS( str.hasSuffix("hahah"), false );
	}

	void test_toLowercase( void )
	{
		Common::String str("Test it, NOW! 42");
		str.toLowercase();
		TS_ASSERT_EQUALS( str, "test it, now! 42" );
	}

	void test_toUppercase( void )
	{
		Common::String str("Test it, NOW! 42");
		str.toUppercase();
		TS_ASSERT_EQUALS( str, "TEST IT, NOW! 42" );
	}
};