1 #include "StringPrependTest.h"
2 #include "cppunit/TestCaller.h"
3 #include <String.h>
4 #include <UTF8.h>
5
6
StringPrependTest(std::string name)7 StringPrependTest::StringPrependTest(std::string name)
8 : BTestCase(name)
9 {
10 }
11
12
~StringPrependTest()13 StringPrependTest::~StringPrependTest()
14 {
15 }
16
17
18 void
PerformTest(void)19 StringPrependTest::PerformTest(void)
20 {
21 BString *str1, *str2;
22
23 // Prepend(BString&)
24 NextSubTest();
25 str1 = new BString("a String");
26 str2 = new BString("PREPENDED");
27 str1->Prepend(*str2);
28 CPPUNIT_ASSERT(strcmp(str1->String(), "PREPENDEDa String") == 0);
29 delete str1;
30 delete str2;
31
32 // Prepend(const char*)
33 NextSubTest();
34 str1 = new BString("String");
35 str1->Prepend("PREPEND");
36 CPPUNIT_ASSERT(strcmp(str1->String(), "PREPENDString") == 0);
37 delete str1;
38
39 // Prepend(const char*) (NULL)
40 NextSubTest();
41 str1 = new BString("String");
42 str1->Prepend((char*)NULL);
43 CPPUNIT_ASSERT(strcmp(str1->String(), "String") == 0);
44 delete str1;
45
46 // Prepend(const char*, int32
47 NextSubTest();
48 str1 = new BString("String");
49 str1->Prepend("PREPENDED", 3);
50 CPPUNIT_ASSERT(strcmp(str1->String(), "PREString") == 0);
51 delete str1;
52
53 // Prepend(BString&, int32)
54 NextSubTest();
55 str1 = new BString("String");
56 str2 = new BString("PREPEND", 4);
57 str1->Prepend(*str2);
58 CPPUNIT_ASSERT(strcmp(str1->String(), "PREPString") == 0);
59 delete str1;
60 delete str2;
61
62 // Prepend(char, int32)
63 NextSubTest();
64 str1 = new BString("aString");
65 str1->Prepend('c', 4);
66 CPPUNIT_ASSERT(strcmp(str1->String(), "ccccaString") == 0);
67 delete str1;
68
69 // String was empty
70 NextSubTest();
71 str1 = new BString;
72 str1->Prepend("PREPENDED");
73 CPPUNIT_ASSERT(strcmp(str1->String(), "PREPENDED") == 0);
74 delete str1;
75
76 }
77
78
suite(void)79 CppUnit::Test *StringPrependTest::suite(void)
80 {
81 typedef CppUnit::TestCaller<StringPrependTest>
82 StringPrependTestCaller;
83
84 return(new StringPrependTestCaller("BString::Prepend Test",
85 &StringPrependTest::PerformTest));
86 }
87