Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c1d0556 authored by Chienyuan's avatar Chienyuan Committed by android-build-merger
Browse files

Add test about post/clear task from callback for handler am: 1860f94d am: 8c9443f8

am: 45d2dd57

Change-Id: Id564c2b0347ec87c65d224a53c36b5b88b81b8ae
parents 5db26992 45d2dd57
Loading
Loading
Loading
Loading
+26 −1
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ TEST_F(HandlerTest, post_task_cleared) {
    std::this_thread::sleep_for(std::chrono::milliseconds(5));
  };
  handler_->Post(std::move(closure));
  closure = []() { LOG(FATAL) << "Should not happen"; };
  closure = []() { EXPECT_EQ(0, 1) << "Should not happen"; };
  std::this_thread::sleep_for(std::chrono::milliseconds(5));
  handler_->Post(std::move(closure));
  handler_->Clear();
@@ -66,6 +66,31 @@ TEST_F(HandlerTest, post_task_cleared) {
  EXPECT_EQ(val, 1);
}

TEST_F(HandlerTest, post_task_from_callback) {
  int val = 0;
  Closure closure = [&val, this] {
    Closure inner_closure = [&val] { val++; };
    handler_->Post(inner_closure);
  };
  handler_->Post(closure);
  std::this_thread::sleep_for(std::chrono::milliseconds(10));
  EXPECT_EQ(val, 1);
}

TEST_F(HandlerTest, clear_task_from_callback) {
  int val = 0;
  Closure closure = [&val, this] {
    val++;
    handler_->Clear();
    std::this_thread::sleep_for(std::chrono::milliseconds(5));
  };
  handler_->Post(std::move(closure));
  closure = []() { EXPECT_EQ(0, 1) << "Should not happen"; };
  handler_->Post(std::move(closure));
  std::this_thread::sleep_for(std::chrono::milliseconds(10));
  EXPECT_EQ(val, 1);
}

}  // namespace
}  // namespace common
}  // namespace bluetooth