| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 if (!accepted) | 413 if (!accepted) |
| 414 return; | 414 return; |
| 415 clients_.push_back(new SocketTestClient(accepted)); | 415 clients_.push_back(new SocketTestClient(accepted)); |
| 416 } | 416 } |
| 417 | 417 |
| 418 std::unique_ptr<AsyncSocket> socket_; | 418 std::unique_ptr<AsyncSocket> socket_; |
| 419 std::vector<SocketTestClient*> clients_; | 419 std::vector<SocketTestClient*> clients_; |
| 420 }; | 420 }; |
| 421 | 421 |
| 422 /////////////////////////////////////////////////////////////////////////////// | 422 /////////////////////////////////////////////////////////////////////////////// |
| 423 // Generic Utilities | |
| 424 /////////////////////////////////////////////////////////////////////////////// | |
| 425 | |
| 426 inline bool ReadFile(const char* filename, std::string* contents) { | |
| 427 FILE* fp = fopen(filename, "rb"); | |
| 428 if (!fp) | |
| 429 return false; | |
| 430 char buffer[1024*64]; | |
| 431 size_t read; | |
| 432 contents->clear(); | |
| 433 while ((read = fread(buffer, 1, sizeof(buffer), fp))) { | |
| 434 contents->append(buffer, read); | |
| 435 } | |
| 436 bool success = (0 != feof(fp)); | |
| 437 fclose(fp); | |
| 438 return success; | |
| 439 } | |
| 440 | |
| 441 // Look in parent dir for parallel directory. | |
| 442 inline rtc::Pathname GetSiblingDirectory( | |
| 443 const std::string& parallel_dir) { | |
| 444 rtc::Pathname path = rtc::Filesystem::GetCurrentDirectory(); | |
| 445 while (!path.empty()) { | |
| 446 rtc::Pathname potential_parallel_dir = path; | |
| 447 potential_parallel_dir.AppendFolder(parallel_dir); | |
| 448 if (rtc::Filesystem::IsFolder(potential_parallel_dir)) { | |
| 449 return potential_parallel_dir; | |
| 450 } | |
| 451 | |
| 452 path.SetFolder(path.parent_folder()); | |
| 453 } | |
| 454 return path; | |
| 455 } | |
| 456 | |
| 457 inline rtc::Pathname GetGoogle3Directory() { | |
| 458 return GetSiblingDirectory("google3"); | |
| 459 } | |
| 460 | |
| 461 inline rtc::Pathname GetTalkDirectory() { | |
| 462 return GetSiblingDirectory("talk"); | |
| 463 } | |
| 464 | |
| 465 /////////////////////////////////////////////////////////////////////////////// | |
| 466 // Unittest predicates which are similar to STREQ, but for raw memory | 423 // Unittest predicates which are similar to STREQ, but for raw memory |
| 467 /////////////////////////////////////////////////////////////////////////////// | 424 /////////////////////////////////////////////////////////////////////////////// |
| 468 | 425 |
| 469 inline AssertionResult CmpHelperMemEq(const char* expected_expression, | 426 inline AssertionResult CmpHelperMemEq(const char* expected_expression, |
| 470 const char* expected_length_expression, | 427 const char* expected_length_expression, |
| 471 const char* actual_expression, | 428 const char* actual_expression, |
| 472 const char* actual_length_expression, | 429 const char* actual_length_expression, |
| 473 const void* expected, | 430 const void* expected, |
| 474 size_t expected_length, | 431 size_t expected_length, |
| 475 const void* actual, | 432 const void* actual, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 497 size_t buffer_size = expected_length * 2 + 1; | 454 size_t buffer_size = expected_length * 2 + 1; |
| 498 char* buffer = STACK_ARRAY(char, buffer_size); | 455 char* buffer = STACK_ARRAY(char, buffer_size); |
| 499 hex_encode(buffer, buffer_size, | 456 hex_encode(buffer, buffer_size, |
| 500 reinterpret_cast<const char*>(expected), expected_length); | 457 reinterpret_cast<const char*>(expected), expected_length); |
| 501 msg << "\nWhich is: " << buffer << " [" << expected_length << "]"; | 458 msg << "\nWhich is: " << buffer << " [" << expected_length << "]"; |
| 502 } | 459 } |
| 503 | 460 |
| 504 return AssertionFailure(msg); | 461 return AssertionFailure(msg); |
| 505 } | 462 } |
| 506 | 463 |
| 507 inline AssertionResult CmpHelperFileEq(const char* expected_expression, | |
| 508 const char* expected_length_expression, | |
| 509 const char* actual_filename, | |
| 510 const void* expected, | |
| 511 size_t expected_length, | |
| 512 const char* filename) | |
| 513 { | |
| 514 std::string contents; | |
| 515 if (!ReadFile(filename, &contents)) { | |
| 516 Message msg; | |
| 517 msg << "File '" << filename << "' could not be read."; | |
| 518 return AssertionFailure(msg); | |
| 519 } | |
| 520 return CmpHelperMemEq(expected_expression, expected_length_expression, | |
| 521 actual_filename, "", | |
| 522 expected, expected_length, | |
| 523 contents.c_str(), contents.size()); | |
| 524 } | |
| 525 | |
| 526 #define EXPECT_MEMEQ(expected, expected_length, actual, actual_length) \ | 464 #define EXPECT_MEMEQ(expected, expected_length, actual, actual_length) \ |
| 527 EXPECT_PRED_FORMAT4(::testing::CmpHelperMemEq, expected, expected_length, \ | 465 EXPECT_PRED_FORMAT4(::testing::CmpHelperMemEq, expected, expected_length, \ |
| 528 actual, actual_length) | 466 actual, actual_length) |
| 529 | 467 |
| 530 #define ASSERT_MEMEQ(expected, expected_length, actual, actual_length) \ | 468 #define ASSERT_MEMEQ(expected, expected_length, actual, actual_length) \ |
| 531 ASSERT_PRED_FORMAT4(::testing::CmpHelperMemEq, expected, expected_length, \ | 469 ASSERT_PRED_FORMAT4(::testing::CmpHelperMemEq, expected, expected_length, \ |
| 532 actual, actual_length) | 470 actual, actual_length) |
| 533 | 471 |
| 534 #define EXPECT_FILEEQ(expected, expected_length, filename) \ | |
| 535 EXPECT_PRED_FORMAT3(::testing::CmpHelperFileEq, expected, expected_length, \ | |
| 536 filename) | |
| 537 | |
| 538 #define ASSERT_FILEEQ(expected, expected_length, filename) \ | |
| 539 ASSERT_PRED_FORMAT3(::testing::CmpHelperFileEq, expected, expected_length, \ | |
| 540 filename) | |
| 541 | |
| 542 /////////////////////////////////////////////////////////////////////////////// | 472 /////////////////////////////////////////////////////////////////////////////// |
| 543 // Helpers for initializing constant memory with integers in a particular byte | 473 // Helpers for initializing constant memory with integers in a particular byte |
| 544 // order | 474 // order |
| 545 /////////////////////////////////////////////////////////////////////////////// | 475 /////////////////////////////////////////////////////////////////////////////// |
| 546 | 476 |
| 547 #define BYTE_CAST(x) static_cast<uint8_t>((x)&0xFF) | 477 #define BYTE_CAST(x) static_cast<uint8_t>((x)&0xFF) |
| 548 | 478 |
| 549 // Declare a N-bit integer as a little-endian sequence of bytes | 479 // Declare a N-bit integer as a little-endian sequence of bytes |
| 550 #define LE16(x) BYTE_CAST(((uint16_t)x) >> 0), BYTE_CAST(((uint16_t)x) >> 8) | 480 #define LE16(x) BYTE_CAST(((uint16_t)x) >> 0), BYTE_CAST(((uint16_t)x) >> 8) |
| 551 | 481 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 << minor_version; | 557 << minor_version; |
| 628 LOG(LS_WARNING) << "XRandr is not supported or is too old (pre 1.3)."; | 558 LOG(LS_WARNING) << "XRandr is not supported or is too old (pre 1.3)."; |
| 629 return false; | 559 return false; |
| 630 } | 560 } |
| 631 #endif | 561 #endif |
| 632 return true; | 562 return true; |
| 633 } | 563 } |
| 634 } // namespace testing | 564 } // namespace testing |
| 635 | 565 |
| 636 #endif // WEBRTC_BASE_TESTUTILS_H__ | 566 #endif // WEBRTC_BASE_TESTUTILS_H__ |
| OLD | NEW |