zircon/system/ulib/async-loop/test/loop_tests.cc
// The C++ loop wrapper is one-to-one with the underlying C API so for the
// most part we will test through that interface but here we make sure that
// the C API actually exists but we don't comprehensively test what it does.
The C++ loop wrapper is one-to-one with the underlying C API so for the
most part we will test through that interface but here we make sure that
the C API actually exists but we don't comprehensively test what it does.
The C ++ loop wrapper is one - to - one with the underlying C API so for the most part we will test through that interface but here we make sure that the C API actually exists but we don ' t comprehensively test what it does .
TEST(Loop, CApiBasic) {
  async_loop_t* loop;
  ASSERT_EQ(ZX_OK, async_loop_create(&kAsyncLoopConfigNoAttachToCurrentThread, &loop), "create");
  ASSERT_NE(loop, nullptr, "loop");
  EXPECT_EQ(ASYNC_LOOP_RUNNABLE, async_loop_get_state(loop), "runnable");
  async_loop_quit(loop);
  EXPECT_EQ(ASYNC_LOOP_QUIT, async_loop_get_state(loop), "quitting");
  async_loop_run(loop, ZX_TIME_INFINITE, false);
  EXPECT_EQ(ZX_OK, async_loop_reset_quit(loop));
  thrd_t thread{};
  EXPECT_EQ(ZX_OK, async_loop_start_thread(loop, "name", &thread), "thread start");
  EXPECT_NE(thrd_t{}, thread, "thread ws initialized");
  async_loop_quit(loop);
  async_loop_join_threads(loop);
  async_loop_shutdown(loop);
  EXPECT_EQ(ASYNC_LOOP_SHUTDOWN, async_loop_get_state(loop), "shutdown");
  async_loop_destroy(loop);
}
TEST ( Loop , CApiBasic ) { async_loop_t * loop ; ASSERT_EQ ( ZX_OK , async_loop_create ( & kAsyncLoopConfigNoAttachToCurrentThread , & loop ) , " " ) ; ASSERT_NE ( loop , nullptr , " " ) ; EXPECT_EQ ( ASYNC_LOOP_RUNNABLE , async_loop_get_state ( loop ) , " " ) ; async_loop_quit ( loop ) ; EXPECT_EQ ( ASYNC_LOOP_QUIT , async_loop_get_state ( loop ) , " " ) ; async_loop_run ( loop , ZX_TIME_INFINITE , false ) ; EXPECT_EQ ( ZX_OK , async_loop_reset_quit ( loop ) ) ; thrd_t thread { } ; EXPECT_EQ ( ZX_OK , async_loop_start_thread ( loop , " " , & thread ) , " " ) ; EXPECT_NE ( thrd_t { } , thread , " " ) ; async_loop_quit ( loop ) ; async_loop_join_threads ( loop ) ; async_loop_shutdown ( loop ) ; EXPECT_EQ ( ASYNC_LOOP_SHUTDOWN , async_loop_get_state ( loop ) , " " ) ; async_loop_destroy ( loop ) ; }
The C++ loop wrapper is one-to-one with the underlying C API so for the
most part we will test through that interface but here we make sure that
the C API actually exists but we don't comprehensively test what it does.
The C ++ loop wrapper is one - to - one with the underlying C API so for the most part we will test through that interface but here we make sure that the C API actually exists but we don ' t comprehensively test what it does .