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 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
|
/***************************************************************************
copyright : (C) 2007 by Lukas Lalinsky
email : lukas@oxygene.sk
***************************************************************************/
/***************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License version *
* 2.1 as published by the Free Software Foundation. *
* *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
* 02110-1301 USA *
* *
* Alternatively, this file is available under the Mozilla Public *
* License Version 1.1. You may obtain a copy of the License at *
* http://www.mozilla.org/MPL/ *
***************************************************************************/
#include <string>
#include <cstring>
#include "tstring.h"
#include "tstringlist.h"
#include "tbytevector.h"
#include "tutils.h"
#include <cppunit/extensions/HelperMacros.h>
using namespace std;
using namespace TagLib;
class TestString : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestString);
CPPUNIT_TEST(testString);
CPPUNIT_TEST(testRfind);
CPPUNIT_TEST(testUTF16Encode);
CPPUNIT_TEST(testUTF16Decode);
CPPUNIT_TEST(testUTF16DecodeInvalidBOM);
CPPUNIT_TEST(testUTF16DecodeEmptyWithBOM);
CPPUNIT_TEST(testSurrogatePair);
CPPUNIT_TEST(testAppendCharDetach);
CPPUNIT_TEST(testAppendStringDetach);
CPPUNIT_TEST(testToInt);
CPPUNIT_TEST(testFromInt);
CPPUNIT_TEST(testSubstr);
CPPUNIT_TEST(testNewline);
CPPUNIT_TEST(testUpper);
CPPUNIT_TEST(testEncodeNonLatin1);
CPPUNIT_TEST(testEncodeEmpty);
CPPUNIT_TEST(testEncodeNonBMP);
CPPUNIT_TEST(testIterator);
CPPUNIT_TEST(testInvalidUTF8);
CPPUNIT_TEST(testEmpty);
CPPUNIT_TEST_SUITE_END();
public:
void testString()
{
String s = "taglib string";
ByteVector v = "taglib string";
CPPUNIT_ASSERT(v == s.data(String::Latin1));
char str[] = "taglib string";
CPPUNIT_ASSERT(strcmp(s.toCString(), str) == 0);
CPPUNIT_ASSERT(s == "taglib string");
CPPUNIT_ASSERT(s != "taglib STRING");
CPPUNIT_ASSERT(s != "taglib");
CPPUNIT_ASSERT(s != "taglib string taglib");
CPPUNIT_ASSERT(s == L"taglib string");
CPPUNIT_ASSERT(s != L"taglib STRING");
CPPUNIT_ASSERT(s != L"taglib");
CPPUNIT_ASSERT(s != L"taglib string taglib");
s.clear();
CPPUNIT_ASSERT(s.isEmpty());
String unicode("José Carlos", String::UTF8);
CPPUNIT_ASSERT(strcmp(unicode.toCString(), "Jos\xe9 Carlos") == 0);
String latin = "Jos\xe9 Carlos";
CPPUNIT_ASSERT(strcmp(latin.toCString(true), "José Carlos") == 0);
String c = "1";
CPPUNIT_ASSERT(c == L"1");
c = L'\u4E00';
CPPUNIT_ASSERT(c == L"\u4E00");
String unicode2(unicode.to8Bit(true), String::UTF8);
CPPUNIT_ASSERT(unicode == unicode2);
String unicode3(L"\u65E5\u672C\u8A9E");
CPPUNIT_ASSERT(*(unicode3.toCWString() + 1) == L'\u672C');
constexpr wchar_t wcSystemOrder[] = {L'\u65E5', L'\u672C', L'\u8A9E', 0};
constexpr wchar_t wcSwappedOrder[] = {L'\uE565', L'\u2C67', L'\u9E8A', 0};
const std::wstring wsSystemOrder = L"\u65e5\u672c\u8a9e";
const std::wstring wsSwappedOrder = L"\ue565\u2c67\u9e8a";
const bool isLe = Utils::systemByteOrder() == Utils::LittleEndian;
String unicode4(isLe ? wcSwappedOrder : wcSystemOrder, String::UTF16BE);
CPPUNIT_ASSERT(unicode4[1] == L'\u672c');
String unicode5(isLe ? wcSystemOrder : wcSwappedOrder, String::UTF16LE);
CPPUNIT_ASSERT(unicode5[1] == L'\u672c');
String unicode6(isLe ? wsSwappedOrder : wsSystemOrder, String::UTF16BE);
CPPUNIT_ASSERT(unicode6[1] == L'\u672c');
String unicode7(isLe ? wsSystemOrder : wsSwappedOrder, String::UTF16LE);
CPPUNIT_ASSERT(unicode7[1] == L'\u672c');
CPPUNIT_ASSERT(String(" foo ").stripWhiteSpace() == String("foo"));
CPPUNIT_ASSERT(String("foo ").stripWhiteSpace() == String("foo"));
CPPUNIT_ASSERT(String(" foo").stripWhiteSpace() == String("foo"));
CPPUNIT_ASSERT(String("foo").stripWhiteSpace() == String("foo"));
CPPUNIT_ASSERT(String("f o o").stripWhiteSpace() == String("f o o"));
CPPUNIT_ASSERT(String(" f o o ").stripWhiteSpace() == String("f o o"));
CPPUNIT_ASSERT(memcmp(String("foo").data(String::Latin1).data(), "foo", 3) == 0);
CPPUNIT_ASSERT(memcmp(String("f").data(String::Latin1).data(), "f", 1) == 0);
}
void testUTF16Encode()
{
String a("foo");
ByteVector b("\0f\0o\0o", 6);
ByteVector c("f\0o\0o\0", 6);
ByteVector d("\377\376f\0o\0o\0", 8);
CPPUNIT_ASSERT(a.data(String::UTF16BE) != a.data(String::UTF16LE));
CPPUNIT_ASSERT(b == a.data(String::UTF16BE));
CPPUNIT_ASSERT(c == a.data(String::UTF16LE));
CPPUNIT_ASSERT_EQUAL(d, a.data(String::UTF16));
}
void testUTF16Decode()
{
String a("foo");
ByteVector b("\0f\0o\0o", 6);
ByteVector c("f\0o\0o\0", 6);
ByteVector d("\377\376f\0o\0o\0", 8);
CPPUNIT_ASSERT_EQUAL(a, String(b, String::UTF16BE));
CPPUNIT_ASSERT_EQUAL(a, String(c, String::UTF16LE));
CPPUNIT_ASSERT_EQUAL(a, String(d, String::UTF16));
}
// this test is expected to print "TagLib: String::prepare() -
// Invalid UTF16 string." on the console 3 times
void testUTF16DecodeInvalidBOM()
{
ByteVector b(" ", 1);
ByteVector c(" ", 2);
ByteVector d(" \0f\0o\0o", 8);
CPPUNIT_ASSERT_EQUAL(String(), String(b, String::UTF16));
CPPUNIT_ASSERT_EQUAL(String(), String(c, String::UTF16));
CPPUNIT_ASSERT_EQUAL(String(), String(d, String::UTF16));
}
void testUTF16DecodeEmptyWithBOM()
{
ByteVector a("\377\376", 2);
ByteVector b("\376\377", 2);
CPPUNIT_ASSERT_EQUAL(String(), String(a, String::UTF16));
CPPUNIT_ASSERT_EQUAL(String(), String(b, String::UTF16));
}
void testSurrogatePair()
{
// Make sure that a surrogate pair is converted into single UTF-8 char
// and vice versa.
const ByteVector v1("\xff\xfe\x42\xd8\xb7\xdf\xce\x91\x4b\x5c");
const ByteVector v2("\xf0\xa0\xae\xb7\xe9\x87\x8e\xe5\xb1\x8b");
const String s1(v1, String::UTF16);
CPPUNIT_ASSERT_EQUAL(s1.data(String::UTF8), v2);
const String s2(v2, String::UTF8);
CPPUNIT_ASSERT_EQUAL(s2.data(String::UTF16), v1);
const ByteVector v3("\xfe\xff\xd8\x01\x30\x42");
CPPUNIT_ASSERT(String(v3, String::UTF16).data(String::UTF8).isEmpty());
const ByteVector v4("\xfe\xff\x30\x42\xdc\x01");
CPPUNIT_ASSERT(String(v4, String::UTF16).data(String::UTF8).isEmpty());
const ByteVector v5("\xfe\xff\xdc\x01\xd8\x01");
CPPUNIT_ASSERT(String(v5, String::UTF16).data(String::UTF8).isEmpty());
}
void testAppendStringDetach()
{
String a("a");
String b = a;
a += "b";
CPPUNIT_ASSERT_EQUAL(String("ab"), a);
CPPUNIT_ASSERT_EQUAL(String("a"), b);
}
void testAppendCharDetach()
{
String a("a");
String b = a;
a += 'b';
CPPUNIT_ASSERT_EQUAL(String("ab"), a);
CPPUNIT_ASSERT_EQUAL(String("a"), b);
}
void testRfind()
{
CPPUNIT_ASSERT_EQUAL(-1, String("foo.bar").rfind(".", 0));
CPPUNIT_ASSERT_EQUAL(-1, String("foo.bar").rfind(".", 1));
CPPUNIT_ASSERT_EQUAL(-1, String("foo.bar").rfind(".", 2));
CPPUNIT_ASSERT_EQUAL(3, String("foo.bar").rfind(".", 3));
CPPUNIT_ASSERT_EQUAL(3, String("foo.bar").rfind(".", 4));
CPPUNIT_ASSERT_EQUAL(3, String("foo.bar").rfind(".", 5));
CPPUNIT_ASSERT_EQUAL(3, String("foo.bar").rfind(".", 6));
CPPUNIT_ASSERT_EQUAL(3, String("foo.bar").rfind(".", 7));
CPPUNIT_ASSERT_EQUAL(3, String("foo.bar").rfind("."));
}
void testToInt()
{
bool ok;
CPPUNIT_ASSERT_EQUAL(String("123").toInt(&ok), 123);
CPPUNIT_ASSERT_EQUAL(ok, true);
CPPUNIT_ASSERT_EQUAL(String("-123").toInt(&ok), -123);
CPPUNIT_ASSERT_EQUAL(ok, true);
CPPUNIT_ASSERT_EQUAL(String("abc").toInt(&ok), 0);
CPPUNIT_ASSERT_EQUAL(ok, false);
CPPUNIT_ASSERT_EQUAL(String("1x").toInt(&ok), 1);
CPPUNIT_ASSERT_EQUAL(ok, false);
CPPUNIT_ASSERT_EQUAL(String("").toInt(&ok), 0);
CPPUNIT_ASSERT_EQUAL(ok, false);
CPPUNIT_ASSERT_EQUAL(String("-").toInt(&ok), 0);
CPPUNIT_ASSERT_EQUAL(ok, false);
CPPUNIT_ASSERT_EQUAL(String("123").toInt(), 123);
CPPUNIT_ASSERT_EQUAL(String("-123").toInt(), -123);
CPPUNIT_ASSERT_EQUAL(String("123aa").toInt(), 123);
CPPUNIT_ASSERT_EQUAL(String("-123aa").toInt(), -123);
CPPUNIT_ASSERT_EQUAL(String("0000").toInt(), 0);
CPPUNIT_ASSERT_EQUAL(String("0001").toInt(), 1);
String("2147483648").toInt(&ok);
CPPUNIT_ASSERT_EQUAL(ok, false);
String("-2147483649").toInt(&ok);
CPPUNIT_ASSERT_EQUAL(ok, false);
}
void testFromInt()
{
CPPUNIT_ASSERT_EQUAL(String::number(0), String("0"));
CPPUNIT_ASSERT_EQUAL(String::number(12345678), String("12345678"));
CPPUNIT_ASSERT_EQUAL(String::number(-12345678), String("-12345678"));
}
void testSubstr()
{
CPPUNIT_ASSERT_EQUAL(String("01"), String("0123456").substr(0, 2));
CPPUNIT_ASSERT_EQUAL(String("12"), String("0123456").substr(1, 2));
CPPUNIT_ASSERT_EQUAL(String("123456"), String("0123456").substr(1, 200));
CPPUNIT_ASSERT_EQUAL(String("0123456"), String("0123456").substr(0, 7));
CPPUNIT_ASSERT_EQUAL(String("0123456"), String("0123456").substr(0, 200));
}
void testNewline()
{
ByteVector cr("abc\x0dxyz", 7);
ByteVector lf("abc\x0axyz", 7);
ByteVector crlf("abc\x0d\x0axyz", 8);
CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(7), String(cr).size());
CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(7), String(lf).size());
CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(8), String(crlf).size());
CPPUNIT_ASSERT(L'\x0d' == String(cr)[3]);
CPPUNIT_ASSERT(L'\x0a' == String(lf)[3]);
CPPUNIT_ASSERT(L'\x0d' == String(crlf)[3]);
CPPUNIT_ASSERT(L'\x0a' == String(crlf)[4]);
}
void testUpper()
{
String s1 = "tagLIB 012 strING";
String s2 = s1.upper();
CPPUNIT_ASSERT_EQUAL(String("tagLIB 012 strING"), s1);
CPPUNIT_ASSERT_EQUAL(String("TAGLIB 012 STRING"), s2);
}
void testEncodeNonLatin1()
{
const String jpn(L"\u65E5\u672C\u8A9E");
CPPUNIT_ASSERT_EQUAL(ByteVector("\xE5\x2C\x9E"), jpn.data(String::Latin1));
CPPUNIT_ASSERT_EQUAL(ByteVector("\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E"), jpn.data(String::UTF8));
CPPUNIT_ASSERT_EQUAL(ByteVector("\xFF\xFE\xE5\x65\x2C\x67\x9E\x8A"), jpn.data(String::UTF16));
CPPUNIT_ASSERT_EQUAL(ByteVector("\xE5\x65\x2C\x67\x9E\x8A"), jpn.data(String::UTF16LE));
CPPUNIT_ASSERT_EQUAL(ByteVector("\x65\xE5\x67\x2C\x8A\x9E"), jpn.data(String::UTF16BE));
CPPUNIT_ASSERT_EQUAL(std::string("\xE5\x2C\x9E"), jpn.to8Bit(false));
CPPUNIT_ASSERT_EQUAL(std::string("\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E"), jpn.to8Bit(true));
}
void testEncodeEmpty()
{
const String empty;
CPPUNIT_ASSERT(empty.data(String::Latin1).isEmpty());
CPPUNIT_ASSERT(empty.data(String::UTF8).isEmpty());
CPPUNIT_ASSERT_EQUAL(ByteVector("\xFF\xFE"), empty.data(String::UTF16));
CPPUNIT_ASSERT(empty.data(String::UTF16LE).isEmpty());
CPPUNIT_ASSERT(empty.data(String::UTF16BE).isEmpty());
CPPUNIT_ASSERT(empty.to8Bit(false).empty());
CPPUNIT_ASSERT(empty.to8Bit(true).empty());
}
void testEncodeNonBMP()
{
const ByteVector a("\xFF\xFE\x3C\xD8\x50\xDD\x40\xD8\xF5\xDC\x3C\xD8\x00\xDE", 14);
const ByteVector b("\xF0\x9F\x85\x90\xF0\xA0\x83\xB5\xF0\x9F\x88\x80");
CPPUNIT_ASSERT_EQUAL(b, String(a, String::UTF16).data(String::UTF8));
}
void testIterator()
{
String s1 = "taglib string";
String s2 = s1;
String::Iterator it1 = s1.begin();
String::Iterator it2 = s2.begin();
CPPUNIT_ASSERT(L't' == *it1);
CPPUNIT_ASSERT(L't' == *it2);
std::advance(it1, 4);
std::advance(it2, 4);
*it2 = L'I';
CPPUNIT_ASSERT(L'i' == *it1);
CPPUNIT_ASSERT(L'I' == *it2);
}
void testInvalidUTF8()
{
CPPUNIT_ASSERT_EQUAL(String("/"), String(ByteVector("\x2F"), String::UTF8));
CPPUNIT_ASSERT(String(ByteVector("\xC0\xAF"), String::UTF8).isEmpty());
CPPUNIT_ASSERT(String(ByteVector("\xE0\x80\xAF"), String::UTF8).isEmpty());
CPPUNIT_ASSERT(String(ByteVector("\xF0\x80\x80\xAF"), String::UTF8).isEmpty());
CPPUNIT_ASSERT(String(ByteVector("\xF8\x80\x80\x80\x80"), String::UTF8).isEmpty());
CPPUNIT_ASSERT(String(ByteVector("\xFC\x80\x80\x80\x80\x80"), String::UTF8).isEmpty());
CPPUNIT_ASSERT(String(ByteVector("\xC2"), String::UTF8).isEmpty());
CPPUNIT_ASSERT(String(ByteVector("\xE0\x80"), String::UTF8).isEmpty());
CPPUNIT_ASSERT(String(ByteVector("\xF0\x80\x80"), String::UTF8).isEmpty());
CPPUNIT_ASSERT(String(ByteVector("\xF8\x80\x80\x80"), String::UTF8).isEmpty());
CPPUNIT_ASSERT(String(ByteVector("\xFC\x80\x80\x80\x80"), String::UTF8).isEmpty());
CPPUNIT_ASSERT(String('\x80', String::UTF8).isEmpty());
CPPUNIT_ASSERT(String(ByteVector("\xED\xA0\x80\xED\xB0\x80"), String::UTF8).isEmpty());
CPPUNIT_ASSERT(String(ByteVector("\xED\xB0\x80\xED\xA0\x80"), String::UTF8).isEmpty());
}
void testEmpty()
{
const String empty;
const String notEmpty("A");
String mutEmpty;
CPPUNIT_ASSERT_EQUAL(empty, String(""));
CPPUNIT_ASSERT_EQUAL(empty, String(std::wstring()));
CPPUNIT_ASSERT_EQUAL(empty, String(static_cast<const wchar_t *>(nullptr)));
CPPUNIT_ASSERT(empty != String('\0'));
CPPUNIT_ASSERT_EQUAL(empty, String(L'\0'));
CPPUNIT_ASSERT_EQUAL(empty, String(static_cast<const char *>(nullptr)));
CPPUNIT_ASSERT_EQUAL(empty, String(ByteVector()));
CPPUNIT_ASSERT_EQUAL(empty.to8Bit(), std::string());
CPPUNIT_ASSERT_EQUAL(empty.toWString(), std::wstring());
CPPUNIT_ASSERT_EQUAL(::strlen(empty.toCString()), (size_t)0);
CPPUNIT_ASSERT_EQUAL(::wcslen(empty.toCWString()), (size_t)0);
CPPUNIT_ASSERT(empty.begin() == empty.end());
CPPUNIT_ASSERT(empty.cbegin() == empty.cend());
CPPUNIT_ASSERT(mutEmpty.begin() == mutEmpty.end());
CPPUNIT_ASSERT_EQUAL(empty.find(mutEmpty), 0);
CPPUNIT_ASSERT_EQUAL(empty.find(notEmpty), -1);
CPPUNIT_ASSERT_EQUAL(notEmpty.find(empty), 0);
CPPUNIT_ASSERT_EQUAL(empty.rfind(mutEmpty), 0);
CPPUNIT_ASSERT_EQUAL(empty.rfind(notEmpty), -1);
CPPUNIT_ASSERT_EQUAL(notEmpty.rfind(empty), 1);
CPPUNIT_ASSERT_EQUAL(empty.split(), StringList(empty));
CPPUNIT_ASSERT_EQUAL(empty.startsWith(mutEmpty), true);
CPPUNIT_ASSERT_EQUAL(empty.startsWith(notEmpty), false);
CPPUNIT_ASSERT_EQUAL(notEmpty.startsWith(empty), true);
CPPUNIT_ASSERT_EQUAL(empty.substr(0), empty);
CPPUNIT_ASSERT_EQUAL(mutEmpty.append(empty), empty);
CPPUNIT_ASSERT_EQUAL(mutEmpty.append(notEmpty), notEmpty);
mutEmpty.clear();
CPPUNIT_ASSERT_EQUAL(mutEmpty, empty);
CPPUNIT_ASSERT_EQUAL(String(notEmpty).append(empty), notEmpty);
CPPUNIT_ASSERT_EQUAL(empty.upper(), empty);
CPPUNIT_ASSERT_EQUAL(empty.size(), 0U);
CPPUNIT_ASSERT_EQUAL(empty.length(), 0U);
CPPUNIT_ASSERT_EQUAL(empty.isEmpty(), true);
CPPUNIT_ASSERT_EQUAL(empty.data(String::Latin1), ByteVector());
CPPUNIT_ASSERT_EQUAL(empty.data(String::UTF16LE), ByteVector());
bool ok;
empty.toInt(&ok);
CPPUNIT_ASSERT(!ok);
CPPUNIT_ASSERT_EQUAL(empty.stripWhiteSpace(), empty);
CPPUNIT_ASSERT_EQUAL(empty.isLatin1(), true);
CPPUNIT_ASSERT_EQUAL(empty.isAscii(), true);
CPPUNIT_ASSERT(empty == mutEmpty);
CPPUNIT_ASSERT(empty != notEmpty);
CPPUNIT_ASSERT(empty == "");
CPPUNIT_ASSERT(empty != " ");
CPPUNIT_ASSERT(empty == L"");
CPPUNIT_ASSERT(empty != L" ");
CPPUNIT_ASSERT(empty == static_cast<const char *>(nullptr));
CPPUNIT_ASSERT(!(empty != static_cast<const char *>(nullptr)));
CPPUNIT_ASSERT(empty == static_cast<const wchar_t *>(nullptr));
CPPUNIT_ASSERT(!(empty != static_cast<const wchar_t *>(nullptr)));
CPPUNIT_ASSERT_EQUAL(mutEmpty += empty, empty);
CPPUNIT_ASSERT_EQUAL(mutEmpty += notEmpty, notEmpty);
mutEmpty.clear();
CPPUNIT_ASSERT_EQUAL(mutEmpty += static_cast<const char *>(nullptr), empty);
CPPUNIT_ASSERT_EQUAL(mutEmpty += static_cast<const wchar_t *>(nullptr), empty);
CPPUNIT_ASSERT_EQUAL(mutEmpty = static_cast<const char *>(nullptr), empty);
CPPUNIT_ASSERT_EQUAL(mutEmpty = static_cast<const wchar_t *>(nullptr), empty);
String tmp;
mutEmpty.swap(tmp);
CPPUNIT_ASSERT_EQUAL(mutEmpty, empty);
CPPUNIT_ASSERT_EQUAL(empty < notEmpty, true);
CPPUNIT_ASSERT_EQUAL(empty + mutEmpty, empty);
CPPUNIT_ASSERT_EQUAL(empty + notEmpty, notEmpty);
CPPUNIT_ASSERT_EQUAL(empty + static_cast<const char *>(nullptr), empty);
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestString);
|