2 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <gtest/gtest.h>
22 #include <gmock/gmock.h>
24 #include "tizen-shared-queue/shared-queue.hpp"
32 void Do() { done_ = true; }
33 bool Done() const { return done_; }
41 TEST(SharedQueueTest, PushAndWaitAndPop) {
42 tizen_base::SharedQueue<Job> queue;
43 std::thread thread([&] {
44 auto job = queue.WaitAndPop();
46 queue.Push(std::move(job));
50 auto job = queue.WaitAndPop();
53 EXPECT_TRUE(job.Done());
56 TEST(SharedQueueTest, TryAndPop) {
57 tizen_base::SharedQueue<Job> queue;
59 EXPECT_FALSE(queue.TryAndPop(job));
61 EXPECT_TRUE(queue.TryAndPop(job));
64 TEST(SharedQueueTest, WaitAndPopFor) {
65 tizen_base::SharedQueue<Job> queue;
67 std::chrono::steady_clock::time_point begin =
68 std::chrono::steady_clock::now();
69 EXPECT_FALSE(queue.WaitAndPopFor(job, 110));
70 std::chrono::steady_clock::time_point end =
71 std::chrono::steady_clock::now();
72 auto elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(
74 EXPECT_TRUE(elapsed_time > 100);
77 begin = std::chrono::steady_clock::now();
78 EXPECT_TRUE(queue.WaitAndPopFor(job, 100));
79 end = std::chrono::steady_clock::now();
80 elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(
82 EXPECT_TRUE(elapsed_time < 100);
85 TEST(SharedQueueTest, IsEmpty) {
86 tizen_base::SharedQueue<Job> queue;
87 EXPECT_TRUE(queue.IsEmpty());
89 EXPECT_FALSE(queue.IsEmpty());
92 TEST(SharedQueueTest, Size) {
93 tizen_base::SharedQueue<Job> queue;
94 EXPECT_EQ(queue.Size(), 0);
96 EXPECT_EQ(queue.Size(), 1);