xref: /haiku/src/tests/kits/support/bstring/StringFormatAppendTest.cpp (revision 1e60bdeab63fa7a57bc9a55b032052e95a18bd2c)
1 #include "StringFormatAppendTest.h"
2 #include "cppunit/TestCaller.h"
3 #include <String.h>
4 
5 
6 StringFormatAppendTest::StringFormatAppendTest(std::string name)
7 		: BTestCase(name)
8 {
9 }
10 
11 
12 StringFormatAppendTest::~StringFormatAppendTest()
13 {
14 }
15 
16 
17 void
18 StringFormatAppendTest::PerformTest(void)
19 {
20 	BString *string, *string2;
21 
22 	// operator<<(const char *);
23 	NextSubTest();
24 	string = new BString("some");
25 	*string << " ";
26 	*string << "text";
27 	CPPUNIT_ASSERT(strcmp(string->String(), "some text") == 0);
28 	delete string;
29 
30 	// operator<<(const BString &);
31 	NextSubTest();
32 	string = new BString("some ");
33 	string2 = new BString("text");
34 	*string << *string2;
35 	CPPUNIT_ASSERT(strcmp(string->String(), "some text") == 0);
36 	delete string;
37 	delete string2;
38 
39 	// operator<<(char);
40 	NextSubTest();
41 	string = new BString("str");
42 	*string << 'i' << 'n' << 'g';
43 	CPPUNIT_ASSERT(strcmp(string->String(), "string") == 0);
44 	delete string;
45 
46 	// operator<<(int);
47 	NextSubTest();
48 	string = new BString("level ");
49 	*string << (int)42;
50 	CPPUNIT_ASSERT(strcmp(string->String(), "level 42") == 0);
51 	delete string;
52 
53 	NextSubTest();
54 	string = new BString("error ");
55 	*string << (int)-1;
56 	CPPUNIT_ASSERT(strcmp(string->String(), "error -1") == 0);
57 	delete string;
58 
59 	// operator<<(unsigned int);
60 	NextSubTest();
61 	string = new BString("number ");
62 	*string << (unsigned int)296;
63 	CPPUNIT_ASSERT(strcmp(string->String(), "number 296") == 0);
64 	delete string;
65 
66 	// operator<<(uint32);
67 	NextSubTest();
68 	string = new BString;
69 	*string << (uint32)102456;
70 	CPPUNIT_ASSERT(strcmp(string->String(), "102456") == 0);
71 	delete string;
72 
73 	// operator<<(int32);
74 	NextSubTest();
75 	string = new BString;
76 	*string << (int32)112456;
77 	CPPUNIT_ASSERT(strcmp(string->String(), "112456") == 0);
78 	delete string;
79 
80 	NextSubTest();
81 	string = new BString;
82 	*string << (int32)-112475;
83 	CPPUNIT_ASSERT(strcmp(string->String(), "-112475") == 0);
84 	delete string;
85 
86 	// operator<<(uint64);
87 	NextSubTest();
88 	string = new BString;
89 	*string << (uint64)1145267987;
90 	CPPUNIT_ASSERT(strcmp(string->String(), "1145267987") == 0);
91 	delete string;
92 
93 	// operator<<(int64);
94 	NextSubTest();
95 	string = new BString;
96 	*string << (int64)112456;
97 	CPPUNIT_ASSERT(strcmp(string->String(), "112456") == 0);
98 	delete string;
99 
100 	NextSubTest();
101 	string = new BString;
102 	*string << (int64)-112475;
103 	CPPUNIT_ASSERT(strcmp(string->String(), "-112475") == 0);
104 	delete string;
105 
106 	// operator<<(float);
107 	NextSubTest();
108 	string = new BString;
109 	*string << (float)34.542;
110 	CPPUNIT_ASSERT(strcmp(string->String(), "34.54") == 0);
111 	delete string;
112 
113 	// Misc test
114 	NextSubTest();
115 	BString s;
116 	s << "This" << ' ' << "is" << ' ' << 'a' << ' ' << "test"
117 		<< ' ' << "sentence";
118 	CPPUNIT_ASSERT(strcmp(s.String(), "This is a test sentence") == 0);
119 }
120 
121 
122 CppUnit::Test *StringFormatAppendTest::suite(void)
123 {
124 	typedef CppUnit::TestCaller<StringFormatAppendTest>
125 		StringFormatAppendTestCaller;
126 
127 	return(new StringFormatAppendTestCaller("BString::FormatAppend Test",
128 		&StringFormatAppendTest::PerformTest));
129 }
130