From 55b0b3755421c7b795d78cf5836677078423a27f Mon Sep 17 00:00:00 2001 From: deadbeef Date: Thu, 28 Jul 2016 10:51:10 -0700 Subject: [PATCH] Use a better method to generate a random ID in IvfFileWriterTest. It was generating a random ID using the test case's "this" pointer and the current time. However, the current time may be imprecise. And the "this" pointer may have repeatable values. BUG=webrtc:5898 Review-Url: https://codereview.webrtc.org/2190533004 Cr-Commit-Position: refs/heads/master@{#13560} --- .../video_coding/utility/ivf_file_writer_unittest.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/webrtc/modules/video_coding/utility/ivf_file_writer_unittest.cc b/webrtc/modules/video_coding/utility/ivf_file_writer_unittest.cc index ae1283b78d..f22aff78cd 100644 --- a/webrtc/modules/video_coding/utility/ivf_file_writer_unittest.cc +++ b/webrtc/modules/video_coding/utility/ivf_file_writer_unittest.cc @@ -13,6 +13,7 @@ #include #include "testing/gtest/include/gtest/gtest.h" +#include "webrtc/base/helpers.h" #include "webrtc/base/logging.h" #include "webrtc/base/thread.h" #include "webrtc/base/timeutils.h" @@ -31,15 +32,14 @@ static const int kMaxFileRetries = 5; class IvfFileWriterTest : public ::testing::Test { protected: void SetUp() override { - const int64_t start_id = - reinterpret_cast(this) ^ rtc::TimeMicros(); - int64_t id = start_id; + const uint64_t start_id = rtc::CreateRandomId64(); + uint64_t id = start_id; do { std::ostringstream oss; oss << test::OutputPath() << "ivf_test_file_" << id++ << ".ivf"; file_name_ = oss.str(); - } while (id < start_id + 100 && FileExists(false)); - ASSERT_LT(id, start_id + 100); + } while ((id - start_id) < 100u && FileExists(false)); + ASSERT_LT(id - start_id, 100u); } bool WriteDummyTestFrames(int width,