xref: /aosp_15_r20/external/cronet/base/win/reference_unittest.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2018 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/win/reference.h"
6 
7 #include <windows.foundation.h>
8 #include <wrl/client.h>
9 
10 #include "testing/gtest/include/gtest/gtest.h"
11 
12 #ifdef NTDDI_WIN10_VB  // Windows 10.0.19041
13 // Specialization templates that used to be in windows.foundation.h, removed in
14 // the 10.0.19041.0 SDK, so placed here instead.
15 namespace ABI {
16 namespace Windows {
17 namespace Foundation {
18 template <>
19 struct __declspec(uuid("3c00fd60-2950-5939-a21a-2d12c5a01b8a")) IReference<bool>
20     : IReference_impl<Internal::AggregateType<bool, boolean>> {};
21 
22 template <>
23 struct __declspec(uuid("548cefbd-bc8a-5fa0-8df2-957440fc8bf4")) IReference<int>
24     : IReference_impl<int> {};
25 }  // namespace Foundation
26 }  // namespace Windows
27 }  // namespace ABI
28 #endif
29 
30 namespace base {
31 namespace win {
32 
33 namespace {
34 
35 using Microsoft::WRL::Make;
36 
37 }  // namespace
38 
TEST(ReferenceTest,Value)39 TEST(ReferenceTest, Value) {
40   auto ref = Make<Reference<int>>(123);
41   int value = 0;
42   HRESULT hr = ref->get_Value(&value);
43   EXPECT_TRUE(SUCCEEDED(hr));
44   EXPECT_EQ(123, value);
45 }
46 
TEST(ReferenceTest,ValueAggregate)47 TEST(ReferenceTest, ValueAggregate) {
48   auto ref = Make<Reference<bool>>(true);
49   boolean value = false;
50   HRESULT hr = ref->get_Value(&value);
51   EXPECT_TRUE(SUCCEEDED(hr));
52   EXPECT_TRUE(value);
53 }
54 
55 }  // namespace win
56 }  // namespace base
57