File: helpers-test.cpp

package info (click to toggle)
packagesearch 2.7.3
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 3,244 kB
  • sloc: cpp: 12,412; perl: 282; makefile: 69; sh: 13
file content (91 lines) | stat: -rw-r--r-- 1,788 bytes parent folder | download | duplicates (8)
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
/** Tests for functions in helpers.h */

#include <string>
#include <helpers.h>

using namespace std;

#ifdef __QT_TEST


#include <QTest>


class HelpersTest: public QObject
{
	Q_OBJECT
private slots:
	void testMakeLower()
	{
		string myString = "aBC";
		string& result = makeLower(myString);
		QCOMPARE(myString, string("abc"));
		// result and myString should point to the same object
		QCOMPARE(&result, &myString);
		
		// test German umlauts
		myString = "ÜÖÄ";
		string result1 = makeLower(myString);
		QCOMPARE(myString, string("ÜÖÄ"));

		
	}
	void testToLower()
	{
		string myString = "aBC";
		string result = toLower(myString);
		QCOMPARE(result, string("abc"));
		// no side effects expected
		QCOMPARE(myString, string("aBC"));
		// result and myString should not point to the same object
		QVERIFY(&result != &myString);
	}

};

QTEST_MAIN(HelpersTest)
#include "helpers-test.moc"

#endif	// __QT_TEST



#ifdef __UNIT_TEST_PP

#include <UnitTest++.h>
#include <QString>
#include <iostream>

using namespace std;

// std::string& makeLower(std::string& trans)
TEST(makeLower)
{
	string myString = "aBC";
	string& result = makeLower(myString);
	CHECK_EQUAL(myString, string("abc"));
	// result and myString should point to the same object
	CHECK_EQUAL(&result, &myString);
	
	// test German umlauts
// 	myString = "ÜÖÄ";
// 	string result1 = makeLower(myString);
// 	QCOMPARE(myString, string("ÜÖÄ"));

	
}

// inline std::string toLower(const std::string& in)
TEST(toLower)
{
	string myString = "aBC";
	string result = toLower(myString);
	CHECK_EQUAL(result, string("abc"));
	// no side effects expected
	CHECK_EQUAL(myString, string("aBC"));
	// result and myString should not point to the same object
	CHECK(&result != &myString);
}

#endif	// __UNIT_TEST_PP