scoped_service_publisher_unittest.cc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2020 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 "base/fuchsia/scoped_service_publisher.h"
  5. #include <lib/fidl/cpp/binding_set.h>
  6. #include "base/fuchsia/service_directory_test_base.h"
  7. #include "base/run_loop.h"
  8. #include "testing/gtest/include/gtest/gtest.h"
  9. namespace base {
  10. class ScopedServicePublisherTest : public ServiceDirectoryTestBase {};
  11. TEST_F(ScopedServicePublisherTest, ConstructorPublishesService) {
  12. // Remove the default service binding.
  13. service_binding_.reset();
  14. // Create bindings and register using a publisher instance.
  15. fidl::BindingSet<testfidl::TestInterface> bindings;
  16. ScopedServicePublisher<testfidl::TestInterface> publisher(
  17. outgoing_directory_.get(), bindings.GetHandler(&test_service_));
  18. auto client = public_service_directory_->Connect<testfidl::TestInterface>();
  19. VerifyTestInterface(&client, ZX_OK);
  20. }
  21. TEST_F(ScopedServicePublisherTest, DestructorRemovesService) {
  22. // Remove the default service binding.
  23. service_binding_.reset();
  24. fidl::BindingSet<testfidl::TestInterface> bindings;
  25. {
  26. ScopedServicePublisher<testfidl::TestInterface> publisher(
  27. outgoing_directory_.get(), bindings.GetHandler(&test_service_));
  28. }
  29. // Once the publisher leaves scope, the service shouldn't be available.
  30. auto new_client =
  31. public_service_directory_->Connect<testfidl::TestInterface>();
  32. VerifyTestInterface(&new_client, ZX_ERR_PEER_CLOSED);
  33. }
  34. } // namespace base