vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / support / bstring / StringEscapeTest.cpp
blob1722982a3a25bb96ec16b87e2898988a5ae4fe48
1 #include "StringEscapeTest.h"
2 #include "cppunit/TestCaller.h"
3 #include <String.h>
5 StringEscapeTest::StringEscapeTest(std::string name) :
6 BTestCase(name)
12 StringEscapeTest::~StringEscapeTest()
17 void
18 StringEscapeTest::PerformTest(void)
20 BString *string1;
22 //CharacterEscape(char*, char)
23 NextSubTest();
24 string1 = new BString("abcdefghi");
25 string1->CharacterEscape("acf", '/');
26 CPPUNIT_ASSERT(strcmp(string1->String(), "/ab/cde/fghi") == 0);
27 delete string1;
29 //BString is null
30 NextSubTest();
31 string1 = new BString;
32 string1->CharacterEscape("abc", '/');
33 CPPUNIT_ASSERT(strcmp(string1->String(), "") == 0);
34 delete string1;
36 //BString doesn't contain wanted characters
37 NextSubTest();
38 string1 = new BString("abcdefghi");
39 string1->CharacterEscape("z34", 'z');
40 CPPUNIT_ASSERT(strcmp(string1->String(), "abcdefghi") == 0);
41 delete string1;
43 //CharacterEscape(char *, char*, char)
44 NextSubTest();
45 string1 = new BString("something");
46 string1->CharacterEscape("newstring", "esi", '0');
47 CPPUNIT_ASSERT(strcmp(string1->String(), "n0ew0str0ing") == 0);
48 delete string1;
50 #ifndef TEST_R5
51 //assigned string is NULL
52 //it crashes r5 implementation, but not ours :)
53 NextSubTest();
54 string1 = new BString("something");
55 string1->CharacterEscape((char*)NULL, "ei", '-');
56 CPPUNIT_ASSERT(strcmp(string1->String(), "") == 0);
57 delete string1;
58 #endif
60 //String was empty
61 NextSubTest();
62 string1 = new BString;
63 string1->CharacterEscape("newstring", "esi", '0');
64 CPPUNIT_ASSERT(strcmp(string1->String(), "n0ew0str0ing") == 0);
65 delete string1;
67 //CharacterDeescape(char)
68 NextSubTest();
69 string1 = new BString("/a/nh/g/bhhgy/fgtuhjkb/");
70 string1->CharacterDeescape('/');
71 CPPUNIT_ASSERT(strcmp(string1->String(), "anhgbhhgyfgtuhjkb") == 0);
72 delete string1;
74 //String was empty
75 NextSubTest();
76 string1 = new BString;
77 string1->CharacterDeescape('/');
78 CPPUNIT_ASSERT(strcmp(string1->String(), "") == 0);
79 delete string1;
81 //String doesn't contain character to escape
82 NextSubTest();
83 string1 = new BString("/a/nh/g/bhhgy/fgtuhjkb/");
84 string1->CharacterDeescape('-');
85 CPPUNIT_ASSERT(strcmp(string1->String(), "/a/nh/g/bhhgy/fgtuhjkb/") == 0);
86 delete string1;
88 //CharacterDeescape(char* original, char)
89 NextSubTest();
90 string1 = new BString("oldString");
91 string1->CharacterDeescape("-ne-ws-tri-ng-", '-');
92 CPPUNIT_ASSERT(strcmp(string1->String(), "newstring") == 0);
93 delete string1;
95 //String was empty
96 NextSubTest();
97 string1 = new BString;
98 string1->CharacterDeescape("new/str/ing", '/');
99 CPPUNIT_ASSERT(strcmp(string1->String(), "newstring") == 0);
100 delete string1;
102 #ifndef TEST_R5
103 //assigned string is empty
104 //it crashes r5 implementation, but not ours :)
105 NextSubTest();
106 string1 = new BString("pippo");
107 string1->CharacterDeescape((char*)NULL, '/');
108 CPPUNIT_ASSERT(strcmp(string1->String(), "") == 0);
109 delete string1;
110 #endif
112 //String doesn't contain character to escape
113 NextSubTest();
114 string1 = new BString("Old");
115 string1->CharacterDeescape("/a/nh/g/bhhgy/fgtuhjkb/", '-');
116 CPPUNIT_ASSERT(strcmp(string1->String(), "/a/nh/g/bhhgy/fgtuhjkb/") == 0);
117 delete string1;
121 CppUnit::Test *StringEscapeTest::suite(void)
123 typedef CppUnit::TestCaller<StringEscapeTest>
124 StringEscapeTestCaller;
126 return(new StringEscapeTestCaller("BString::Escape Test", &StringEscapeTest::PerformTest));