run_all_unittests.cc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <stdio.h>
  5. #include <memory>
  6. #include "base/bind.h"
  7. #include "base/logging.h"
  8. #include "base/message_loop/message_pump_type.h"
  9. #include "base/test/launcher/unit_test_launcher.h"
  10. #include "base/test/test_suite.h"
  11. #include "base/threading/thread.h"
  12. #include "mojo/core/embedder/embedder.h"
  13. #include "mojo/core/embedder/scoped_ipc_support.h"
  14. #include "testing/gtest/include/gtest/gtest.h"
  15. class MojoEnabledTestEnvironment final : public testing::Environment {
  16. public:
  17. MojoEnabledTestEnvironment() : mojo_ipc_thread_("MojoIpcThread") {}
  18. ~MojoEnabledTestEnvironment() final = default;
  19. void SetUp() final {
  20. mojo::core::Init();
  21. mojo_ipc_thread_.StartWithOptions(
  22. base::Thread::Options(base::MessagePumpType::IO, 0));
  23. mojo_ipc_support_ = std::make_unique<mojo::core::ScopedIPCSupport>(
  24. mojo_ipc_thread_.task_runner(),
  25. mojo::core::ScopedIPCSupport::ShutdownPolicy::FAST);
  26. VLOG(1) << "Mojo initialized";
  27. }
  28. void TearDown() final {
  29. mojo_ipc_support_.reset();
  30. VLOG(1) << "Mojo IPC tear down";
  31. }
  32. private:
  33. base::Thread mojo_ipc_thread_;
  34. std::unique_ptr<mojo::core::ScopedIPCSupport> mojo_ipc_support_;
  35. };
  36. int main(int argc, char* argv[]) {
  37. base::TestSuite test_suite(argc, argv);
  38. testing::AddGlobalTestEnvironment(new MojoEnabledTestEnvironment());
  39. return base::LaunchUnitTests(
  40. argc, argv,
  41. base::BindOnce(&base::TestSuite::Run, base::Unretained(&test_suite)));
  42. }