OLD | NEW |
(Empty) | |
| 1 #include <gtest/gtest.h> |
| 2 #include "../src/plugin/PluginUtil.h" |
| 3 #include "../src/plugin/PluginDebug.h" |
| 4 |
| 5 class Util_Test |
| 6 : public ::testing::Test |
| 7 { |
| 8 }; |
| 9 |
| 10 namespace |
| 11 { |
| 12 void equal_ci_same( std::wstring a, std::wstring b ) |
| 13 { |
| 14 bool x = ABP::util::wstring_equal_ci( a, b ); |
| 15 ASSERT_TRUE( x ) << L"Strings '" << a << L"' and '" << "' should be consider
ed equal"; |
| 16 } |
| 17 |
| 18 void equal_ci_different( std::wstring a, std::wstring b ) |
| 19 { |
| 20 bool x = ABP::util::wstring_equal_ci( a, b ); |
| 21 ASSERT_FALSE( x ) << L"Strings '" << a << L"' and '" << "' should be conside
red not equal"; |
| 22 } |
| 23 } |
| 24 |
| 25 TEST( Util_Test, equal_ci_same_00 ) |
| 26 { |
| 27 equal_ci_same( L"", L"" ); |
| 28 } |
| 29 |
| 30 TEST( Util_Test, equal_ci_same_01 ) |
| 31 { |
| 32 equal_ci_same( L"same", L"same" ); |
| 33 } |
| 34 |
| 35 TEST( Util_Test, equal_ci_same_02 ) |
| 36 { |
| 37 equal_ci_same( L"Same", L"same" ); |
| 38 } |
| 39 |
| 40 TEST( Util_Test, equal_ci_same_03 ) |
| 41 { |
| 42 equal_ci_same( L"file://foo/firstrun.html", L"file://Foo/firstRun.html" ); |
| 43 } |
| 44 |
| 45 TEST( Util_Test, equal_ci_different_00 ) |
| 46 { |
| 47 equal_ci_different( L"", L" " ); |
| 48 } |
| 49 |
| 50 TEST( Util_Test, equal_ci_different_01 ) |
| 51 { |
| 52 equal_ci_different( L"Different", L"" ); |
| 53 } |
| 54 |
| 55 TEST( Util_Test, equal_ci_different_02 ) |
| 56 { |
| 57 equal_ci_different( L"Different", L"Idferrent" ); |
| 58 } |
| 59 |
| 60 TEST( Util_Test, equal_ci_different_03 ) |
| 61 { |
| 62 equal_ci_different( L"Difference", L"Diferrenc" ); |
| 63 } |
| 64 |
| 65 TEST( Util_Test, equal_ci_different_04 ) |
| 66 { |
| 67 equal_ci_different( L"Different", L"Diferrents" ); |
| 68 } |
| 69 |
| 70 TEST( Util_Test, begins_with_00 ) |
| 71 { |
| 72 ASSERT_TRUE( ABP::util::begins_with( L"", L"" ) ); |
| 73 } |
| 74 |
| 75 TEST( Util_Test, begins_with_01 ) |
| 76 { |
| 77 ASSERT_TRUE( ABP::util::begins_with( L"foo", L"" ) ); |
| 78 } |
| 79 |
| 80 TEST( Util_Test, begins_with_02 ) |
| 81 { |
| 82 ASSERT_TRUE( ABP::util::begins_with( L"foo", L"f" ) ); |
| 83 } |
| 84 |
| 85 TEST( Util_Test, begins_with_03 ) |
| 86 { |
| 87 ASSERT_FALSE( ABP::util::begins_with( L"foo", L"g" ) ); |
| 88 } |
| 89 |
| 90 //---------------------------------- |
| 91 // trim |
| 92 //---------------------------------- |
| 93 namespace { |
| 94 void trim_test( std::wstring input, std::wstring expected ) |
| 95 { |
| 96 std::wstring copy( input ); |
| 97 ABP::util::trim( copy ); |
| 98 ASSERT_EQ( expected, copy ); |
| 99 } |
| 100 } |
| 101 |
| 102 TEST( Util_Test, trim_00 ) |
| 103 { |
| 104 trim_test( L"", L"" ); |
| 105 } |
| 106 |
| 107 TEST( Util_Test, trim_01 ) |
| 108 { |
| 109 trim_test( L" ", L"" ); |
| 110 } |
| 111 |
| 112 TEST( Util_Test, trim_02 ) |
| 113 { |
| 114 trim_test( L"\n", L"" ); |
| 115 } |
| 116 |
| 117 TEST( Util_Test, trim_03 ) |
| 118 { |
| 119 trim_test( L"\r", L"" ); |
| 120 } |
| 121 |
| 122 TEST( Util_Test, trim_04 ) |
| 123 { |
| 124 trim_test( L"\t", L"" ); |
| 125 } |
| 126 |
| 127 TEST( Util_Test, trim_05 ) |
| 128 { |
| 129 trim_test( L"foo", L"foo" ); |
| 130 } |
| 131 |
| 132 TEST( Util_Test, trim_06 ) |
| 133 { |
| 134 trim_test( L" foo", L"foo" ); |
| 135 } |
| 136 |
| 137 TEST( Util_Test, trim_07 ) |
| 138 { |
| 139 trim_test( L"\r\nfoo", L"foo" ); |
| 140 } |
| 141 |
| 142 TEST( Util_Test, trim_08 ) |
| 143 { |
| 144 trim_test( L"\tfoo", L"foo" ); |
| 145 } |
| 146 |
| 147 TEST( Util_Test, trim_09 ) |
| 148 { |
| 149 trim_test( L"foo ", L"foo" ); |
| 150 } |
| 151 |
| 152 TEST( Util_Test, trim_10 ) |
| 153 { |
| 154 trim_test( L"foo\r\n", L"foo" ); |
| 155 } |
| 156 |
| 157 TEST( Util_Test, trim_11 ) |
| 158 { |
| 159 trim_test( L"foo\t", L"foo" ); |
| 160 } |
| 161 |
| 162 TEST( Util_Test, trim_12 ) |
| 163 { |
| 164 trim_test( L"foo bar", L"foo bar" ); |
| 165 } |
| 166 |
| 167 TEST( Util_Test, trim_13 ) |
| 168 { |
| 169 trim_test( L"foo bar \r\n", L"foo bar" ); |
| 170 } |
| 171 |
| 172 TEST( Util_Test, trim_14 ) |
| 173 { |
| 174 trim_test( L" foo bar \r\n", L"foo bar" ); |
| 175 } |
| 176 |
| 177 //---------------------------------- |
| 178 // trim_leading |
| 179 //---------------------------------- |
| 180 namespace { |
| 181 void trim_leading_test( std::wstring input, std::wstring expected ) |
| 182 { |
| 183 std::wstring copy( input ); |
| 184 ABP::util::trim_leading( copy ); |
| 185 ASSERT_EQ( expected, copy ); |
| 186 } |
| 187 } |
| 188 |
| 189 TEST( Util_Test, trim_leading_00 ) |
| 190 { |
| 191 trim_leading_test( L"", L"" ); |
| 192 } |
| 193 |
| 194 TEST( Util_Test, trim_leading_01 ) |
| 195 { |
| 196 trim_leading_test( L" ", L"" ); |
| 197 } |
| 198 |
| 199 TEST( Util_Test, trim_leading_02 ) |
| 200 { |
| 201 trim_leading_test( L"\n", L"" ); |
| 202 } |
| 203 |
| 204 TEST( Util_Test, trim_leading_03 ) |
| 205 { |
| 206 trim_leading_test( L"\r", L"" ); |
| 207 } |
| 208 |
| 209 TEST( Util_Test, trim_leading_04 ) |
| 210 { |
| 211 trim_leading_test( L"\t", L"" ); |
| 212 } |
| 213 |
| 214 TEST( Util_Test, trim_leading_05 ) |
| 215 { |
| 216 trim_leading_test( L"foo", L"foo" ); |
| 217 } |
| 218 |
| 219 TEST( Util_Test, trim_leading_06 ) |
| 220 { |
| 221 trim_leading_test( L" foo", L"foo" ); |
| 222 } |
| 223 |
| 224 TEST( Util_Test, trim_leading_07 ) |
| 225 { |
| 226 trim_leading_test( L"\r\nfoo", L"foo" ); |
| 227 } |
| 228 |
| 229 TEST( Util_Test, trim_leading_08 ) |
| 230 { |
| 231 trim_leading_test( L"\tfoo", L"foo" ); |
| 232 } |
| 233 |
| 234 TEST( Util_Test, trim_leading_09 ) |
| 235 { |
| 236 trim_leading_test( L"foo ", L"foo " ); |
| 237 } |
| 238 |
| 239 TEST( Util_Test, trim_leading_10 ) |
| 240 { |
| 241 trim_leading_test( L"foo\r\n", L"foo\r\n" ); |
| 242 } |
| 243 |
| 244 TEST( Util_Test, trim_leading_11 ) |
| 245 { |
| 246 trim_leading_test( L"foo\t", L"foo\t" ); |
| 247 } |
| 248 |
| 249 TEST( Util_Test, trim_leading_12 ) |
| 250 { |
| 251 trim_leading_test( L"foo bar", L"foo bar" ); |
| 252 } |
| 253 |
| 254 TEST( Util_Test, trim_leading_13 ) |
| 255 { |
| 256 trim_leading_test( L"foo bar \r\n", L"foo bar \r\n" ); |
| 257 } |
| 258 |
| 259 TEST( Util_Test, trim_leading_14 ) |
| 260 { |
| 261 trim_leading_test( L" foo bar \r\n", L"foo bar \r\n" ); |
| 262 } |
| 263 |
| 264 //---------------------------------- |
| 265 // trim_trailing |
| 266 //---------------------------------- |
| 267 namespace { |
| 268 void trim_trailing_test( std::wstring input, std::wstring expected ) |
| 269 { |
| 270 std::wstring copy( input ); |
| 271 ABP::util::trim_trailing( copy ); |
| 272 ASSERT_EQ( expected, copy ); |
| 273 } |
| 274 } |
| 275 |
| 276 TEST( Util_Test, trim_trailing_00 ) |
| 277 { |
| 278 trim_trailing_test( L"", L"" ); |
| 279 } |
| 280 |
| 281 TEST( Util_Test, trim_trailing_01 ) |
| 282 { |
| 283 trim_trailing_test( L" ", L"" ); |
| 284 } |
| 285 |
| 286 TEST( Util_Test, trim_trailing_02 ) |
| 287 { |
| 288 trim_trailing_test( L"\n", L"" ); |
| 289 } |
| 290 |
| 291 TEST( Util_Test, trim_trailing_03 ) |
| 292 { |
| 293 trim_trailing_test( L"\r", L"" ); |
| 294 } |
| 295 |
| 296 TEST( Util_Test, trim_trailing_04 ) |
| 297 { |
| 298 trim_trailing_test( L"\t", L"" ); |
| 299 } |
| 300 |
| 301 TEST( Util_Test, trim_trailing_05 ) |
| 302 { |
| 303 trim_trailing_test( L"foo", L"foo" ); |
| 304 } |
| 305 |
| 306 TEST( Util_Test, trim_trailing_06 ) |
| 307 { |
| 308 trim_trailing_test( L" foo", L" foo" ); |
| 309 } |
| 310 |
| 311 TEST( Util_Test, trim_trailing_07 ) |
| 312 { |
| 313 trim_trailing_test( L"\r\nfoo", L"\r\nfoo" ); |
| 314 } |
| 315 |
| 316 TEST( Util_Test, trim_trailing_08 ) |
| 317 { |
| 318 trim_trailing_test( L"\tfoo", L"\tfoo" ); |
| 319 } |
| 320 |
| 321 TEST( Util_Test, trim_trailing_09 ) |
| 322 { |
| 323 trim_trailing_test( L"foo ", L"foo" ); |
| 324 } |
| 325 |
| 326 TEST( Util_Test, trim_trailing_10 ) |
| 327 { |
| 328 trim_trailing_test( L"foo\r\n", L"foo" ); |
| 329 } |
| 330 |
| 331 TEST( Util_Test, trim_trailing_11 ) |
| 332 { |
| 333 trim_trailing_test( L"foo\t", L"foo" ); |
| 334 } |
| 335 |
| 336 TEST( Util_Test, trim_trailing_12 ) |
| 337 { |
| 338 trim_trailing_test( L"foo bar", L"foo bar" ); |
| 339 } |
| 340 |
| 341 TEST( Util_Test, trim_trailing_13 ) |
| 342 { |
| 343 trim_trailing_test( L"foo bar \r\n", L"foo bar" ); |
| 344 } |
| 345 |
| 346 TEST( Util_Test, trim_trailing_14 ) |
| 347 { |
| 348 trim_trailing_test( L" foo bar \r\n", L" foo bar" ); |
| 349 } |
| 350 |
| 351 //---------------------------------- |
| 352 // to_lower |
| 353 //---------------------------------- |
| 354 namespace |
| 355 { |
| 356 void to_lower_test( std::wstring input, std::wstring expected ) |
| 357 { |
| 358 ABP::util::to_lower( input ); |
| 359 ASSERT_EQ( input, expected ); |
| 360 } |
| 361 } |
| 362 |
| 363 TEST( Util_Test, to_lower_00 ) |
| 364 { |
| 365 to_lower_test( L"", L"" ); |
| 366 } |
| 367 |
| 368 TEST( Util_Test, to_lower_01 ) |
| 369 { |
| 370 to_lower_test( L"foo", L"foo" ); |
| 371 } |
| 372 |
| 373 TEST( Util_Test, to_lower_02 ) |
| 374 { |
| 375 to_lower_test( L"FOO", L"foo" ); |
| 376 } |
| 377 |
| 378 TEST( Util_Test, to_lower_03 ) |
| 379 { |
| 380 to_lower_test( L". !", L". !" ); |
| 381 } |
| 382 |
| 383 //---------------------------------- |
| 384 // extract_token |
| 385 //---------------------------------- |
| 386 namespace |
| 387 { |
| 388 /* |
| 389 * Source must consist of nothing but whitespace starting at position 'pos' |
| 390 */ |
| 391 void extract_token_test_none( const std::wstring source, size_t pos = 0 ) |
| 392 { |
| 393 std::wstring token( ABP::util::extract_token( source, pos ) ); |
| 394 ASSERT_EQ( L"", token ); |
| 395 // Scanner must eliminate all leading whitespace, therefore it should reach
the end of the string. |
| 396 ASSERT_EQ( pos, std::wstring::npos ); |
| 397 } |
| 398 |
| 399 /* |
| 400 * Source must consist of a single token "foo" at or after initial position, |
| 401 * with optional leading and trailing whitespace. |
| 402 * pos_end_1 is the position of the character following the terminating whites
pace of the token, |
| 403 * or 'npos' if the source is exhausted. |
| 404 */ |
| 405 void extract_token_test_single( const std::wstring source, const size_t pos_en
d_1, size_t pos = 0 ) |
| 406 { |
| 407 std::wstring token( ABP::util::extract_token( source, pos ) ); |
| 408 ASSERT_EQ( L"foo", token ); |
| 409 ASSERT_EQ( pos, pos_end_1 ); |
| 410 token = ABP::util::extract_token( source, pos ); |
| 411 ASSERT_EQ( L"", token ); |
| 412 ASSERT_EQ( pos, std::wstring::npos ); |
| 413 } |
| 414 |
| 415 /* |
| 416 * Source must consist of a two tokens: "foo" at or after initial position, "b
ar" following, |
| 417 * with mandatory separating whitespace and optional leading and trailing wh
itespace. |
| 418 * pos_end_1 is the position of the character following the terminating whites
pace of the first token. |
| 419 * pos_end_2 is the position of the character following the terminating whites
pace of the second token, |
| 420 * or 'npos' if the source is exhausted. |
| 421 */ |
| 422 void extract_token_test_double( const std::wstring source, const size_t pos_en
d_1, const size_t pos_end_2, size_t pos = 0 ) |
| 423 { |
| 424 std::wstring token( ABP::util::extract_token( source, pos ) ); |
| 425 ASSERT_EQ( L"foo", token ); |
| 426 ASSERT_EQ( pos, pos_end_1 ); |
| 427 token = ABP::util::extract_token( source, pos ); |
| 428 ASSERT_EQ( L"bar", token ); |
| 429 ASSERT_EQ( pos, pos_end_2 ); |
| 430 token = ABP::util::extract_token( source, pos ); |
| 431 ASSERT_EQ( L"", token ); |
| 432 ASSERT_EQ( pos, std::wstring::npos ); |
| 433 } |
| 434 } |
| 435 |
| 436 TEST( Util_Test, extract_token_00 ) |
| 437 { |
| 438 extract_token_test_none( L"" ); |
| 439 } |
| 440 |
| 441 TEST( Util_Test, extract_token_01 ) |
| 442 { |
| 443 extract_token_test_none( L" " ); |
| 444 } |
| 445 |
| 446 TEST( Util_Test, extract_token_02 ) |
| 447 { |
| 448 extract_token_test_none( L" " ); |
| 449 } |
| 450 |
| 451 TEST( Util_Test, extract_token_03 ) |
| 452 { |
| 453 extract_token_test_none( L" \r\n" ); |
| 454 } |
| 455 |
| 456 TEST( Util_Test, extract_token_04 ) |
| 457 { |
| 458 extract_token_test_none( L" ", 1 ); |
| 459 } |
| 460 |
| 461 TEST( Util_Test, extract_token_05 ) |
| 462 { |
| 463 extract_token_test_none( L" ", 1 ); |
| 464 } |
| 465 |
| 466 TEST( Util_Test, extract_token_06 ) |
| 467 { |
| 468 extract_token_test_none( L" ", 2 ); |
| 469 } |
| 470 |
| 471 TEST( Util_Test, extract_token_07 ) |
| 472 { |
| 473 extract_token_test_none( L"foo ", 3 ); // Not what a previous call would retur
n, but should still pass |
| 474 } |
| 475 |
| 476 TEST( Util_Test, extract_token_08 ) |
| 477 { |
| 478 extract_token_test_none( L"foo ", 4 ); |
| 479 } |
| 480 |
| 481 TEST( Util_Test, extract_token_09 ) |
| 482 { |
| 483 extract_token_test_none( L"foo ", 4 ); |
| 484 } |
| 485 |
| 486 TEST( Util_Test, extract_token_10 ) |
| 487 { |
| 488 extract_token_test_none( L"foo \r\n", 4 ); |
| 489 } |
| 490 |
| 491 TEST( Util_Test, extract_token_11 ) |
| 492 { |
| 493 extract_token_test_single( L"foo", std::wstring::npos ); |
| 494 } |
| 495 |
| 496 TEST( Util_Test, extract_token_12 ) |
| 497 { |
| 498 extract_token_test_single( L"foo ", std::wstring::npos ); |
| 499 } |
| 500 |
| 501 TEST( Util_Test, extract_token_13 ) |
| 502 { |
| 503 extract_token_test_single( L"foo ", 4 ); |
| 504 } |
| 505 |
| 506 TEST( Util_Test, extract_token_14 ) |
| 507 { |
| 508 extract_token_test_single( L" foo", std::wstring::npos ); |
| 509 } |
| 510 |
| 511 TEST( Util_Test, extract_token_15 ) |
| 512 { |
| 513 extract_token_test_single( L" foo ", std::wstring::npos ); |
| 514 } |
| 515 |
| 516 TEST( Util_Test, extract_token_16 ) |
| 517 { |
| 518 extract_token_test_single( L" foo ", 5 ); |
| 519 } |
| 520 |
| 521 TEST( Util_Test, extract_token_17 ) |
| 522 { |
| 523 extract_token_test_double( L"foo bar", 4, std::wstring::npos ); |
| 524 } |
| 525 |
| 526 TEST( Util_Test, extract_token_18 ) |
| 527 { |
| 528 extract_token_test_double( L"foo bar", 4, std::wstring::npos ); |
| 529 } |
| 530 |
| 531 TEST( Util_Test, extract_token_19 ) |
| 532 { |
| 533 extract_token_test_double( L"foo bar", 4, std::wstring::npos ); |
| 534 } |
| 535 |
| 536 TEST( Util_Test, extract_token_20 ) |
| 537 { |
| 538 extract_token_test_double( L"foo bar ", 4, std::wstring::npos ); |
| 539 } |
| 540 |
| 541 TEST( Util_Test, extract_token_21 ) |
| 542 { |
| 543 extract_token_test_double( L"foo bar ", 4, 9 ); |
| 544 } |
| 545 |
| 546 TEST( Util_Test, extract_token_22 ) |
| 547 { |
| 548 extract_token_test_double( L" foo bar", 5, std::wstring::npos ); |
| 549 } |
| 550 |
| 551 TEST( Util_Test, extract_token_23 ) |
| 552 { |
| 553 extract_token_test_double( L" foo bar", 5, std::wstring::npos ); |
| 554 } |
| 555 |
| 556 TEST( Util_Test, extract_token_24 ) |
| 557 { |
| 558 extract_token_test_double( L" foo bar ", 5, std::wstring::npos ); |
| 559 } |
| 560 |
| 561 TEST( Util_Test, extract_token_25 ) |
| 562 { |
| 563 extract_token_test_double( L" foo bar ", 5, 9 ); |
| 564 } |
| 565 |
| 566 |
| 567 //==============================================================================
=========== |
| 568 // Debug utilities |
| 569 //==============================================================================
=========== |
| 570 class Debug_Util_Test |
| 571 : public ::testing::Test |
| 572 { |
| 573 }; |
| 574 |
| 575 namespace |
| 576 { |
| 577 void widen_test( std::string a, std::wstring b ) |
| 578 { |
| 579 ASSERT_EQ( ABP::debug::widen( a ), b ); |
| 580 } |
| 581 |
| 582 void truncate_test( const std::wstring longer, const std::wstring shorter ) |
| 583 { |
| 584 std::wstring longer_copy( longer ); |
| 585 ABP::debug::truncate_source( longer_copy ); |
| 586 ASSERT_EQ( longer_copy, shorter ); |
| 587 } |
| 588 } |
| 589 |
| 590 TEST( Debug_Util_Test, widen_00 ) |
| 591 { |
| 592 widen_test( "", L"" ); |
| 593 } |
| 594 |
| 595 TEST( Debug_Util_Test, widen_01 ) |
| 596 { |
| 597 widen_test( "ABCDEFG", L"ABCDEFG" ); |
| 598 } |
| 599 |
| 600 |
| 601 TEST( Debug_Util_Test, truncate_00 ) |
| 602 { |
| 603 truncate_test( L"", L"" ); |
| 604 } |
| 605 |
| 606 TEST( Debug_Util_Test, truncate_01 ) |
| 607 { |
| 608 std::wstring length_one_hundred( 100, L'=' ); |
| 609 truncate_test( length_one_hundred, length_one_hundred ); |
| 610 } |
| 611 |
| 612 TEST( Debug_Util_Test, truncate_02 ) |
| 613 { |
| 614 std::wstring length_one_hundred_and_one( 101, L'=' ); |
| 615 std::wstring truncated( 67, L'=' ); |
| 616 truncated += L"..."; |
| 617 truncated += std::wstring( 30, L'=' ); |
| 618 truncate_test( length_one_hundred_and_one, truncated ); |
| 619 } |
| 620 |
OLD | NEW |