Update V8 to version 4.4.41.1 (cherry-pick).
[chromium-blink-merge.git] / base / win / enum_variant_unittest.cc
blob99645a265023ac2db889c57bda0ae7d3193470ee
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.
5 #include "base/win/enum_variant.h"
7 #include "base/win/scoped_com_initializer.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace base {
11 namespace win {
13 TEST(EnumVariantTest, EmptyEnumVariant) {
14 ScopedCOMInitializer com_initializer;
16 EnumVariant* ev = new EnumVariant(0);
17 ev->AddRef();
19 IUnknown* iunknown;
20 EXPECT_TRUE(SUCCEEDED(
21 ev->QueryInterface(IID_IUnknown, reinterpret_cast<void**>(&iunknown))));
22 iunknown->Release();
24 IEnumVARIANT* ienumvariant;
25 EXPECT_TRUE(SUCCEEDED(
26 ev->QueryInterface(IID_IEnumVARIANT,
27 reinterpret_cast<void**>(&ienumvariant))));
28 EXPECT_EQ(ev, ienumvariant);
29 ienumvariant->Release();
31 VARIANT out_element;
32 ULONG out_received = 0;
33 EXPECT_EQ(S_FALSE, ev->Next(1, &out_element, &out_received));
34 EXPECT_EQ(0, out_received);
36 EXPECT_EQ(S_FALSE, ev->Skip(1));
38 EXPECT_EQ(S_OK, ev->Reset());
40 IEnumVARIANT* ev2 = NULL;
41 EXPECT_EQ(S_OK, ev->Clone(&ev2));
43 EXPECT_NE(static_cast<IEnumVARIANT*>(NULL), ev2);
44 EXPECT_NE(ev, ev2);
45 EXPECT_EQ(S_FALSE, ev2->Skip(1));
46 EXPECT_EQ(S_OK, ev2->Reset());
48 ULONG ev2_finalrefcount = ev2->Release();
49 EXPECT_EQ(0, ev2_finalrefcount);
51 ULONG ev_finalrefcount = ev->Release();
52 EXPECT_EQ(0, ev_finalrefcount);
55 TEST(EnumVariantTest, SimpleEnumVariant) {
56 ScopedCOMInitializer com_initializer;
58 EnumVariant* ev = new EnumVariant(3);
59 ev->AddRef();
60 ev->ItemAt(0)->vt = VT_I4;
61 ev->ItemAt(0)->lVal = 10;
62 ev->ItemAt(1)->vt = VT_I4;
63 ev->ItemAt(1)->lVal = 20;
64 ev->ItemAt(2)->vt = VT_I4;
65 ev->ItemAt(2)->lVal = 30;
67 // Get elements one at a time.
68 VARIANT out_element;
69 ULONG out_received = 0;
70 EXPECT_EQ(S_OK, ev->Next(1, &out_element, &out_received));
71 EXPECT_EQ(1, out_received);
72 EXPECT_EQ(VT_I4, out_element.vt);
73 EXPECT_EQ(10, out_element.lVal);
74 EXPECT_EQ(S_OK, ev->Skip(1));
75 EXPECT_EQ(S_OK, ev->Next(1, &out_element, &out_received));
76 EXPECT_EQ(1, out_received);
77 EXPECT_EQ(VT_I4, out_element.vt);
78 EXPECT_EQ(30, out_element.lVal);
79 EXPECT_EQ(S_FALSE, ev->Next(1, &out_element, &out_received));
81 // Reset and get all elements at once.
82 VARIANT out_elements[3];
83 EXPECT_EQ(S_OK, ev->Reset());
84 EXPECT_EQ(S_OK, ev->Next(3, out_elements, &out_received));
85 EXPECT_EQ(3, out_received);
86 EXPECT_EQ(VT_I4, out_elements[0].vt);
87 EXPECT_EQ(10, out_elements[0].lVal);
88 EXPECT_EQ(VT_I4, out_elements[1].vt);
89 EXPECT_EQ(20, out_elements[1].lVal);
90 EXPECT_EQ(VT_I4, out_elements[2].vt);
91 EXPECT_EQ(30, out_elements[2].lVal);
92 EXPECT_EQ(S_FALSE, ev->Next(1, &out_element, &out_received));
94 // Clone it.
95 IEnumVARIANT* ev2 = NULL;
96 EXPECT_EQ(S_OK, ev->Clone(&ev2));
97 EXPECT_TRUE(ev2 != NULL);
98 EXPECT_EQ(S_FALSE, ev->Next(1, &out_element, &out_received));
99 EXPECT_EQ(S_OK, ev2->Reset());
100 EXPECT_EQ(S_OK, ev2->Next(3, out_elements, &out_received));
101 EXPECT_EQ(3, out_received);
102 EXPECT_EQ(VT_I4, out_elements[0].vt);
103 EXPECT_EQ(10, out_elements[0].lVal);
104 EXPECT_EQ(VT_I4, out_elements[1].vt);
105 EXPECT_EQ(20, out_elements[1].lVal);
106 EXPECT_EQ(VT_I4, out_elements[2].vt);
107 EXPECT_EQ(30, out_elements[2].lVal);
108 EXPECT_EQ(S_FALSE, ev2->Next(1, &out_element, &out_received));
110 ULONG ev2_finalrefcount = ev2->Release();
111 EXPECT_EQ(0, ev2_finalrefcount);
113 ULONG ev_finalrefcount = ev->Release();
114 EXPECT_EQ(0, ev_finalrefcount);
117 } // namespace win
118 } // namespace base