Flutter Engine
The Flutter Engine
enum_variant_unittest.cc
Go to the documentation of this file.
1// Copyright (c) 2011 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
6
7#include <wrl/client.h>
8#include <wrl/implements.h>
9
10#include "base/win/scoped_com_initializer.h"
12#include "testing/gtest/include/gtest/gtest.h"
13
14namespace base {
15namespace win {
16
17TEST(EnumVariantTest, EmptyEnumVariant) {
18 ScopedCOMInitializer com_initializer;
19
20 Microsoft::WRL::ComPtr<EnumVariant> ev = Microsoft::WRL::Make<EnumVariant>(0);
21 Microsoft::WRL::ComPtr<IEnumVARIANT> ienumvariant;
22 ASSERT_TRUE(SUCCEEDED(ev->QueryInterface(IID_PPV_ARGS(&ienumvariant))));
23
24 {
25 base::win::ScopedVariant out_element;
26 ULONG out_received = 0;
27 EXPECT_EQ(S_FALSE, ev->Next(1, out_element.Receive(), &out_received));
28 EXPECT_EQ(0u, out_received);
29 }
30
31 EXPECT_EQ(S_FALSE, ev->Skip(1));
32
33 EXPECT_EQ(S_OK, ev->Reset());
34
35 Microsoft::WRL::ComPtr<IEnumVARIANT> ev2;
36 EXPECT_EQ(S_OK, ev->Clone(&ev2));
37
38 EXPECT_NE(nullptr, ev2);
39 EXPECT_NE(ev, ev2);
40 EXPECT_EQ(S_FALSE, ev2->Skip(1));
41 EXPECT_EQ(S_OK, ev2->Reset());
42}
43
44TEST(EnumVariantTest, SimpleEnumVariant) {
45 ScopedCOMInitializer com_initializer;
46
47 Microsoft::WRL::ComPtr<EnumVariant> ev = Microsoft::WRL::Make<EnumVariant>(3);
48 ev->ItemAt(0)->vt = VT_I4;
49 ev->ItemAt(0)->lVal = 10;
50 ev->ItemAt(1)->vt = VT_I4;
51 ev->ItemAt(1)->lVal = 20;
52 ev->ItemAt(2)->vt = VT_I4;
53 ev->ItemAt(2)->lVal = 30;
54
55 // Get elements one at a time from index 0 and 2.
56 base::win::ScopedVariant out_element_0;
57 ULONG out_received_0 = 0;
58 EXPECT_EQ(S_OK, ev->Next(1, out_element_0.Receive(), &out_received_0));
59 EXPECT_EQ(1u, out_received_0);
60 EXPECT_EQ(VT_I4, out_element_0.ptr()->vt);
61 EXPECT_EQ(10, out_element_0.ptr()->lVal);
62
63 EXPECT_EQ(S_OK, ev->Skip(1));
64
65 base::win::ScopedVariant out_element_2;
66 ULONG out_received_2 = 0;
67 EXPECT_EQ(S_OK, ev->Next(1, out_element_2.Receive(), &out_received_2));
68 EXPECT_EQ(1u, out_received_2);
69 EXPECT_EQ(VT_I4, out_element_2.ptr()->vt);
70 EXPECT_EQ(30, out_element_2.ptr()->lVal);
71
72 base::win::ScopedVariant placeholder_variant;
73 EXPECT_EQ(S_FALSE, ev->Next(1, placeholder_variant.Receive(), nullptr));
74
75 // Verify the reset works for the next step.
76 ASSERT_EQ(S_OK, ev->Reset());
77
78 // Get all elements at once.
79 VARIANT out_elements[3];
80 ULONG out_received_multiple;
81 for (int i = 0; i < 3; ++i)
82 ::VariantInit(&out_elements[i]);
83 EXPECT_EQ(S_OK, ev->Next(3, out_elements, &out_received_multiple));
84 EXPECT_EQ(3u, out_received_multiple);
85 EXPECT_EQ(VT_I4, out_elements[0].vt);
86 EXPECT_EQ(10, out_elements[0].lVal);
87 EXPECT_EQ(VT_I4, out_elements[1].vt);
88 EXPECT_EQ(20, out_elements[1].lVal);
89 EXPECT_EQ(VT_I4, out_elements[2].vt);
90 EXPECT_EQ(30, out_elements[2].lVal);
91 for (int i = 0; i < 3; ++i)
92 ::VariantClear(&out_elements[i]);
93
94 base::win::ScopedVariant placeholder_variant_multiple;
95 EXPECT_EQ(S_FALSE,
96 ev->Next(1, placeholder_variant_multiple.Receive(), nullptr));
97}
98
99TEST(EnumVariantTest, Clone) {
100 ScopedCOMInitializer com_initializer;
101
102 Microsoft::WRL::ComPtr<EnumVariant> ev = Microsoft::WRL::Make<EnumVariant>(3);
103 ev->ItemAt(0)->vt = VT_I4;
104 ev->ItemAt(0)->lVal = 10;
105 ev->ItemAt(1)->vt = VT_I4;
106 ev->ItemAt(1)->lVal = 20;
107 ev->ItemAt(2)->vt = VT_I4;
108 ev->ItemAt(2)->lVal = 30;
109
110 // Clone it.
111 Microsoft::WRL::ComPtr<IEnumVARIANT> ev2;
112 EXPECT_EQ(S_OK, ev->Clone(&ev2));
113 EXPECT_TRUE(ev2 != nullptr);
114
115 VARIANT out_elements[3];
116 for (int i = 0; i < 3; ++i)
117 ::VariantInit(&out_elements[i]);
118 EXPECT_EQ(S_OK, ev2->Next(3, out_elements, nullptr));
119 EXPECT_EQ(VT_I4, out_elements[0].vt);
120 EXPECT_EQ(10, out_elements[0].lVal);
121 EXPECT_EQ(VT_I4, out_elements[1].vt);
122 EXPECT_EQ(20, out_elements[1].lVal);
123 EXPECT_EQ(VT_I4, out_elements[2].vt);
124 EXPECT_EQ(30, out_elements[2].lVal);
125 for (int i = 0; i < 3; ++i)
126 ::VariantClear(&out_elements[i]);
127}
128
129} // namespace win
130} // namespace base
const VARIANT * ptr() const
TEST(Display, ScaleFactorToFloat)
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678
#define SUCCEEDED(hr)
DWORD ULONG
Definition: windows_types.h:40