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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
|
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#include <BALL/CONCEPT/classTest.h>
///////////////////////////
#include <BALL/DATATYPE/string.h>
#include <cstring>
#include <string>
///////////////////////////
START_TEST(String)
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
using namespace BALL;
using std::string;
String* s;
String* s2;
String halloh("Halloh");
CHECK(String(unsigned short us) throw())
s2 = new String((unsigned short)7);
TEST_EQUAL(*s2, "7")
delete s2;
s2 = new String((unsigned short)0);
TEST_EQUAL(*s2, "0")
delete s2;
RESULT
CHECK(String(int i) throw())
s2 = new String((int)7);
TEST_EQUAL(*s2, "7")
delete s2;
s2 = new String((int)-8);
TEST_EQUAL(*s2, "-8")
delete s2;
RESULT
CHECK(String(unsigned int ui) throw())
s2 = new String((unsigned int)7);
TEST_EQUAL(*s2, "7")
delete s2;
s2 = new String((unsigned int)0);
TEST_EQUAL(*s2, "0")
delete s2;
RESULT
CHECK(String(unsigned long) throw())
s2 = new String((unsigned long)7);
TEST_EQUAL(*s2, "7")
delete s2;
s2 = new String((unsigned long)0);
TEST_EQUAL(*s2, "0")
delete s2;
RESULT
CHECK(String(long l) throw())
s2 = new String((long)7);
TEST_EQUAL(*s2, "7")
delete s2;
s2 = new String((long)-8);
TEST_EQUAL(*s2, "-8")
delete s2;
RESULT
CHECK(String(float f) throw())
s2 = new String((float)0.0);
TEST_REAL_EQUAL(atof(s2->c_str()), 0);
delete s2;
s2 = new String((float)-1.2);
TEST_REAL_EQUAL(atof(s2->c_str()), -1.2)
delete s2;
RESULT
CHECK(String(double d) throw())
s2 = new String((double)0.0);
TEST_REAL_EQUAL(atof(s2->c_str()), 0);
delete s2;
s2 = new String((double)-1.2);
TEST_REAL_EQUAL(atof(s2->c_str()), -1.2)
delete s2;
RESULT
CHECK(void destroy() throw())
s2 = new String("hallo");
s2->destroy();
TEST_EQUAL(*s2, "")
RESULT
delete s2;
const String abcdef = "abcdef";
const String ABCDEF = "ABCDEF";
Substring empty_sub;
const Substring abcdef_sub(abcdef, 0, 6);
const Substring ABCDEF_sub(ABCDEF, 0, 6);
Substring test_sub1(ABCDEF, 0, 6);
Substring test_sub2;
String test_string;
CHECK(void set(const String& string, Index from = 0, Size len = EndPos))
s2 = new String("AAAA");
s2->set(halloh);
TEST_EQUAL(*s2, halloh)
s2->set(halloh, 1);
TEST_EQUAL(*s2, "alloh")
s2->set(halloh, -2);
TEST_EQUAL(*s2, "oh")
s2->set(halloh, -2, 0);
TEST_EQUAL(*s2, "");
s2->set(halloh, 1, 2);
TEST_EQUAL(*s2, "al")
TEST_EXCEPTION(Exception::IndexUnderflow, s2->set(halloh, -10, 3))
TEST_EXCEPTION(Exception::IndexOverflow, s2->set(halloh, 0, 10))
RESULT
delete s2;
CHECK(void set(const char* char_ptr, Index from = 0, Size len = EndPos))
s2 = new String("AAAA");
s2->set("halloh");
TEST_EQUAL(*s2, "halloh")
s2->set("halloh", 1);
TEST_EQUAL(*s2, "alloh")
s2->set("halloh", -2);
TEST_EQUAL(*s2, "oh")
s2->set("halloh", -2, 0);
TEST_EQUAL(*s2, "");
s2->set("halloh", 1, 2);
TEST_EQUAL(*s2, "al")
TEST_EXCEPTION(Exception::IndexUnderflow, s2->set("halloh", -10, 3))
TEST_EXCEPTION(Exception::IndexOverflow, s2->set("halloh", 0, 10))
RESULT
delete s2;
CHECK(void set(Size buffer_size, const char *format, ...))
s2 = new String;
s2->set(15, "%s", "halloh");
TEST_EQUAL(*s2, "halloh")
s2->set(2, "%s", "halloh");
TEST_EQUAL(*s2, "h")
s2->set(15, "%3.1f", 1.2);
TEST_EQUAL(*s2, "1.2")
TEST_EXCEPTION(Exception::IndexUnderflow, s2->set(0, "%s", "Halloh"))
TEST_EXCEPTION(Exception::NullPointer, s2->set(15, (char*)0, "Halloh", 1.5, 1.2))
RESULT
delete s2;
CHECK(void set(std::stringstream& s) throw())
std::stringstream instream("ABC DEF GHI jkl mno");
s2 = new String;
s2->set(instream);
TEST_EQUAL(*s2, "ABC")
s2->set(instream);
TEST_EQUAL(*s2, "DEF")
delete s2;
RESULT
CHECK(void set(std::strstream& s) throw())
// tested above
RESULT
s2 = new String;
CHECK(void set(char c, Size len = 1) throw())
s2->set('A');
TEST_EQUAL(*s2, "A")
s2->set('B', (Size)2);
TEST_EQUAL(*s2, "BB");
s2->set('C', (Size)0);
TEST_EQUAL(*s2, "")
RESULT
CHECK(void set(unsigned char uc) throw())
s2->set((unsigned char)'b');
TEST_EQUAL(*s2, "b")
RESULT
CHECK(void set(short s) throw())
s2->set((short)7);
TEST_EQUAL(*s2, "7")
s2->set((short)-8);
TEST_EQUAL(*s2, "-8")
RESULT
CHECK(void set(unsigned short us) throw())
s2->set((unsigned short)7);
TEST_EQUAL(*s2, "7")
s2->set((unsigned short)0);
TEST_EQUAL(*s2, "0")
RESULT
CHECK(void set(int i) throw())
s2->set((int)7);
TEST_EQUAL(*s2, "7")
s2->set((int)-8);
TEST_EQUAL(*s2, "-8")
RESULT
CHECK(void set(unsigned int ui) throw())
s2->set((unsigned int)7);
TEST_EQUAL(*s2, "7")
s2->set((unsigned int)0);
TEST_EQUAL(*s2, "0")
RESULT
CHECK(void set(unsigned long ul) throw())
s2->set((unsigned long)7);
TEST_EQUAL(*s2, "7")
s2->set((unsigned long)0);
TEST_EQUAL(*s2, "0")
RESULT
CHECK(void set(long l) throw())
s2->set((long)7);
TEST_EQUAL(*s2, "7")
s2->set((long)-8);
TEST_EQUAL(*s2, "-8")
RESULT
CHECK(void set(float f) throw())
s2->set((float)0.0);
TEST_REAL_EQUAL(atof(s2->c_str()), 0);
s2->set((float)-1.2);
TEST_REAL_EQUAL(atof(s2->c_str()), -1.2)
RESULT
CHECK(void set(double d) throw())
s2->set((double)0.0);
TEST_REAL_EQUAL(atof(s2->c_str()), 0);
s2->set((double)-1.2);
TEST_REAL_EQUAL(atof(s2->c_str()), -1.2)
RESULT
CHECK(void get(char* char_ptr, Index from = 0, Size len = EndPos) const)
char test_string[15];
s2->set("TEST");
s2->get(test_string);
TEST_EQUAL(strlen(test_string), 4);
TEST_EQUAL(strcmp(test_string, "TEST"), 0)
s2->get(test_string, 1);
TEST_EQUAL(strcmp(test_string, "EST"), 0)
s2->get(test_string, -2);
TEST_EQUAL(strcmp(test_string, "ST"), 0)
s2->get(test_string, 0, 1);
TEST_EQUAL(strcmp(test_string, "T"), 0)
s2->get(test_string, 1, 1);
TEST_EQUAL(strcmp(test_string, "E"), 0)
s2->get(test_string, 2, 2);
TEST_EQUAL(strcmp(test_string, "ST"), 0)
RESULT
delete s2;
String s4;
CHECK(const String& operator = (const String& s) throw())
String s5("Hallo");
s4 = s5;
TEST_EQUAL(s4, s5)
s5.set("");
s4 = s5;
TEST_EQUAL(s4, s5)
String s6;
s4 = s6;
TEST_EQUAL(s4, s6)
RESULT
CHECK(const String& operator = (const char* pc))
s4 = "TestTestTestTest";
TEST_EQUAL(s4, "TestTestTestTest")
s4 = "";
TEST_EQUAL(s4, "");
RESULT
CHECK(const String& operator = (std::stringstream& s) throw())
std::stringstream instream("ABC DEF GHI jkl mni");
s2 = new String;
*s2 = instream;
TEST_EQUAL(*s2, "ABC")
*s2 = instream;
TEST_EQUAL(*s2, "DEF")
delete s2;
RESULT
CHECK(const String& operator = (std::strstream& s) throw())
// tested above
RESULT
CHECK(const String& operator = (char c) throw())
s4 = 'a';
TEST_EQUAL(s4, "a");
RESULT
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
END_TEST
|