mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 22:00:47 +01:00

Bug: webrtc:10594, webrtc:7187 Change-Id: Icba3a5cf6dbe817ead427c27645b3ad7bc8819be Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/134642 Commit-Queue: Niels Moller <nisse@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Reviewed-by: Tommi <tommi@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27833}
62 lines
1.8 KiB
C++
62 lines
1.8 KiB
C++
/*
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "rtc_base/platform_thread.h"
|
|
|
|
#include "system_wrappers/include/sleep.h"
|
|
#include "test/gtest.h"
|
|
|
|
namespace rtc {
|
|
namespace {
|
|
|
|
void NullRunFunction(void* obj) {}
|
|
|
|
// Function that sets a boolean.
|
|
void SetFlagRunFunction(void* obj) {
|
|
bool* obj_as_bool = static_cast<bool*>(obj);
|
|
*obj_as_bool = true;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TEST(PlatformThreadTest, StartStop) {
|
|
PlatformThread thread(&NullRunFunction, nullptr, "PlatformThreadTest");
|
|
EXPECT_TRUE(thread.name() == "PlatformThreadTest");
|
|
EXPECT_TRUE(thread.GetThreadRef() == 0);
|
|
thread.Start();
|
|
EXPECT_TRUE(thread.GetThreadRef() != 0);
|
|
thread.Stop();
|
|
EXPECT_TRUE(thread.GetThreadRef() == 0);
|
|
}
|
|
|
|
TEST(PlatformThreadTest, StartStop2) {
|
|
PlatformThread thread1(&NullRunFunction, nullptr, "PlatformThreadTest1");
|
|
PlatformThread thread2(&NullRunFunction, nullptr, "PlatformThreadTest2");
|
|
EXPECT_TRUE(thread1.GetThreadRef() == thread2.GetThreadRef());
|
|
thread1.Start();
|
|
thread2.Start();
|
|
EXPECT_TRUE(thread1.GetThreadRef() != thread2.GetThreadRef());
|
|
thread2.Stop();
|
|
thread1.Stop();
|
|
}
|
|
|
|
TEST(PlatformThreadTest, RunFunctionIsCalled) {
|
|
bool flag = false;
|
|
PlatformThread thread(&SetFlagRunFunction, &flag, "RunFunctionIsCalled");
|
|
thread.Start();
|
|
|
|
// At this point, the flag may be either true or false.
|
|
thread.Stop();
|
|
|
|
// We expect the thread to have run at least once.
|
|
EXPECT_TRUE(flag);
|
|
}
|
|
|
|
} // namespace rtc
|