reference_unittest.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 "base/win/reference.h"
  5. #include <windows.foundation.h>
  6. #include <wrl/client.h>
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. #ifdef NTDDI_WIN10_VB // Windows 10.0.19041
  9. // Specialization templates that used to be in windows.foundation.h, removed in
  10. // the 10.0.19041.0 SDK, so placed here instead.
  11. namespace ABI {
  12. namespace Windows {
  13. namespace Foundation {
  14. template <>
  15. struct __declspec(uuid("3c00fd60-2950-5939-a21a-2d12c5a01b8a")) IReference<bool>
  16. : IReference_impl<Internal::AggregateType<bool, boolean>> {};
  17. template <>
  18. struct __declspec(uuid("548cefbd-bc8a-5fa0-8df2-957440fc8bf4")) IReference<int>
  19. : IReference_impl<int> {};
  20. } // namespace Foundation
  21. } // namespace Windows
  22. } // namespace ABI
  23. #endif
  24. namespace base {
  25. namespace win {
  26. namespace {
  27. using Microsoft::WRL::Make;
  28. } // namespace
  29. TEST(ReferenceTest, Value) {
  30. auto ref = Make<Reference<int>>(123);
  31. int value = 0;
  32. HRESULT hr = ref->get_Value(&value);
  33. EXPECT_TRUE(SUCCEEDED(hr));
  34. EXPECT_EQ(123, value);
  35. }
  36. TEST(ReferenceTest, ValueAggregate) {
  37. auto ref = Make<Reference<bool>>(true);
  38. boolean value = false;
  39. HRESULT hr = ref->get_Value(&value);
  40. EXPECT_TRUE(SUCCEEDED(hr));
  41. EXPECT_TRUE(value);
  42. }
  43. } // namespace win
  44. } // namespace base