1 #include "StringAccessTest.h"
2 #include "cppunit/TestCaller.h"
7 StringAccessTest::StringAccessTest(std::string name
) :
14 StringAccessTest::~StringAccessTest()
20 StringAccessTest::PerformTest(void)
22 //CountChars(), Length(), String()
24 BString
string("Something" B_UTF8_ELLIPSIS
);
25 CPPUNIT_ASSERT(string
.CountChars() == 10);
26 CPPUNIT_ASSERT((unsigned)string
.Length() == strlen(string
.String()));
29 BString
string2("ABCD");
30 CPPUNIT_ASSERT(string2
.CountChars() == 4);
31 CPPUNIT_ASSERT((unsigned)string2
.Length() == strlen(string2
.String()));
35 strcpy(s
, B_UTF8_ELLIPSIS
);
36 strcat(s
, B_UTF8_SMILING_FACE
);
38 CPPUNIT_ASSERT(string3
.CountChars() == 2);
39 CPPUNIT_ASSERT((unsigned)string3
.Length() == strlen(string3
.String()));
44 CPPUNIT_ASSERT(strcmp(empty
.String(), "") == 0);
45 CPPUNIT_ASSERT(empty
.Length() == 0);
46 CPPUNIT_ASSERT(empty
.CountChars() == 0);
48 //Truncate the string at end so we are left with an invalid
51 BString
invalid("some text with utf8 characters" B_UTF8_ELLIPSIS
);
52 invalid
.Truncate(invalid
.Length() -1);
53 CPPUNIT_ASSERT(invalid
.CountChars() == 31);
55 //LockBuffer(int32) and UnlockBuffer(int32)
57 BString
locked("a string");
58 char *ptrstr
= locked
.LockBuffer(20);
59 CPPUNIT_ASSERT(strcmp(ptrstr
, "a string") == 0);
60 strcat(ptrstr
, " to be locked");
61 locked
.UnlockBuffer();
62 CPPUNIT_ASSERT(strcmp(ptrstr
, "a string to be locked") == 0);
65 BString
locked2("some text");
66 char *ptr
= locked2
.LockBuffer(3);
67 CPPUNIT_ASSERT(strcmp(ptr
, "some text") == 0);
68 locked2
.UnlockBuffer(4);
69 CPPUNIT_ASSERT(strcmp(locked2
.String(), "some") == 0);
70 CPPUNIT_ASSERT(locked2
.Length() == 4);
74 ptr
= emptylocked
.LockBuffer(10);
75 CPPUNIT_ASSERT(strcmp(ptr
, "") == 0);
77 emptylocked
.UnlockBuffer();
78 CPPUNIT_ASSERT(strcmp(emptylocked
.String(), "pippo") == 0);
80 // LockBuffer(0) and UnlockBuffer(-1) on a zero lenght string
84 ptr
= crashesR5
.LockBuffer(0);
85 crashesR5
.UnlockBuffer(-1);
86 CPPUNIT_ASSERT(strcmp(crashesR5
.String(), "") == 0);
91 CppUnit::Test
*StringAccessTest::suite(void)
93 typedef CppUnit::TestCaller
<StringAccessTest
>
94 StringAccessTestCaller
;
96 return(new StringAccessTestCaller("BString::Access Test", &StringAccessTest::PerformTest
));