Flutter Engine
The Flutter Engine
variant_vector_unittest.cc
Go to the documentation of this file.
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
6
7#include <windows.foundation.h>
8#include <wrl/client.h>
9
10#include <cstddef>
11
12#include "base/stl_util.h"
16#include "testing/gtest/include/gtest/gtest.h"
17
19
20namespace base {
21namespace win {
22
23TEST(VariantVectorTest, InitiallyEmpty) {
24 VariantVector vector;
25 EXPECT_EQ(vector.Type(), VT_EMPTY);
26 EXPECT_EQ(vector.Size(), 0U);
27 EXPECT_TRUE(vector.Empty());
28}
29
30TEST(VariantVectorTest, MoveConstructor) {
31 VariantVector vector1;
32 Microsoft::WRL::ComPtr<IDispatch> dispatch =
33 Microsoft::WRL::Make<DispatchStub>();
34 vector1.Insert<VT_DISPATCH>(dispatch.Get());
35 EXPECT_EQ(vector1.Type(), VT_DISPATCH);
36 EXPECT_EQ(vector1.Size(), 1U);
37
38 VariantVector vector2(std::move(vector1));
39 EXPECT_EQ(vector1.Type(), VT_EMPTY);
40 EXPECT_EQ(vector1.Size(), 0U);
41 EXPECT_EQ(vector2.Type(), VT_DISPATCH);
42 EXPECT_EQ(vector2.Size(), 1U);
43 // |dispatch| should have been transferred to |vector2|.
44 EXPECT_EQ(dispatch.Reset(), 1U);
45}
46
47TEST(VariantVectorTest, MoveAssignOperator) {
48 VariantVector vector1, vector2;
49 Microsoft::WRL::ComPtr<IDispatch> dispatch1 =
50 Microsoft::WRL::Make<DispatchStub>();
51 Microsoft::WRL::ComPtr<IDispatch> dispatch2 =
52 Microsoft::WRL::Make<DispatchStub>();
53 vector1.Insert<VT_DISPATCH>(dispatch1.Get());
54 vector2.Insert<VT_UNKNOWN>(dispatch2.Get());
55 EXPECT_EQ(vector1.Type(), VT_DISPATCH);
56 EXPECT_EQ(vector1.Size(), 1U);
57 EXPECT_EQ(vector2.Type(), VT_UNKNOWN);
58 EXPECT_EQ(vector2.Size(), 1U);
59 vector1 = std::move(vector2);
60 EXPECT_EQ(vector1.Type(), VT_UNKNOWN);
61 EXPECT_EQ(vector1.Size(), 1U);
62 EXPECT_EQ(vector2.Type(), VT_EMPTY);
63 EXPECT_EQ(vector2.Size(), 0U);
64 // |dispatch1| should have been released during the move.
65 EXPECT_EQ(dispatch1.Reset(), 0U);
66 // |dispatch2| should have been transferred to |vector1|.
67 EXPECT_EQ(dispatch2.Reset(), 1U);
68
69 // Indirectly move |vector1| into itself.
70 VariantVector& reference_to_vector1 = vector1;
71 EXPECT_DCHECK_DEATH(vector1 = std::move(reference_to_vector1));
72}
73
74TEST(VariantVectorTest, Insert) {
75 VariantVector vector;
76 vector.Insert<VT_I4>(123);
77 EXPECT_EQ(vector.Type(), VT_I4);
78 // The first insert sets the type to VT_I4, and attempting to insert
79 // unrelated types will silently fail in release builds but DCHECKs
80 // in debug builds.
81 EXPECT_DCHECK_DEATH(vector.Insert<VT_UI4>(1U));
82 EXPECT_DCHECK_DEATH(vector.Insert<VT_R8>(100.0));
83 EXPECT_EQ(vector.Type(), VT_I4);
84 EXPECT_EQ(vector.Size(), 1U);
85 EXPECT_FALSE(vector.Empty());
86}
87
88TEST(VariantVectorTest, InsertCanUpcastDispatchToUnknown) {
89 Microsoft::WRL::ComPtr<IDispatch> dispatch =
90 Microsoft::WRL::Make<DispatchStub>();
91 Microsoft::WRL::ComPtr<IDispatch> unknown;
92 dispatch.CopyTo(&unknown);
93
94 VariantVector vector;
95 vector.Insert<VT_UNKNOWN>(unknown.Get());
96 vector.Insert<VT_UNKNOWN>(dispatch.Get());
97 vector.Insert<VT_DISPATCH>(dispatch.Get());
98 EXPECT_EQ(vector.Type(), VT_UNKNOWN);
99 EXPECT_EQ(vector.Size(), 3U);
100}
101
102TEST(VariantVectorTest, InsertCannotDowncastUnknownToDispatch) {
103 Microsoft::WRL::ComPtr<IDispatch> dispatch =
104 Microsoft::WRL::Make<DispatchStub>();
105 Microsoft::WRL::ComPtr<IDispatch> unknown;
106 dispatch.CopyTo(&unknown);
107
108 VariantVector vector;
109 vector.Insert<VT_DISPATCH>(dispatch.Get());
110 // The first insert sets the type to VT_DISPATCH, and attempting to
111 // explicitly insert VT_UNKNOWN will silently fail in release builds
112 // but DCHECKs in debug builds.
113 EXPECT_DCHECK_DEATH(vector.Insert<VT_UNKNOWN>(unknown.Get()));
114 EXPECT_DCHECK_DEATH(vector.Insert<VT_UNKNOWN>(dispatch.Get()));
115 EXPECT_EQ(vector.Type(), VT_DISPATCH);
116 EXPECT_EQ(vector.Size(), 1U);
117}
118
119TEST(VariantVectorTest, Reset) {
120 VariantVector vector;
121 EXPECT_EQ(vector.Type(), VT_EMPTY);
122 EXPECT_EQ(vector.Size(), 0U);
123 vector.Insert<VT_I4>(123);
124 vector.Insert<VT_I4>(456);
125 EXPECT_EQ(vector.Type(), VT_I4);
126 EXPECT_EQ(vector.Size(), 2U);
127 vector.Reset();
128 EXPECT_EQ(vector.Type(), VT_EMPTY);
129 EXPECT_EQ(vector.Size(), 0U);
130}
131
132TEST(VariantVectorTest, ResetWithManagedContents) {
133 VariantVector vector;
134 // Test that managed contents are released when cleared.
135 Microsoft::WRL::ComPtr<IUnknown> unknown1 =
136 Microsoft::WRL::Make<DispatchStub>();
137 Microsoft::WRL::ComPtr<IUnknown> unknown2;
138 unknown1.CopyTo(&unknown2);
139 vector.Insert<VT_UNKNOWN>(unknown1.Get());
140 EXPECT_EQ(vector.Type(), VT_UNKNOWN);
141 EXPECT_EQ(vector.Size(), 1U);
142 // There are now 3 references to the value owned by |unknown1|.
143 // Remove ownership from |unknown2| should reduce the count to 2.
144 EXPECT_EQ(unknown2.Reset(), 2U);
145 // Resetting the VariantVector will reduce the count to 1.
146 vector.Reset();
147 EXPECT_EQ(vector.Type(), VT_EMPTY);
148 EXPECT_EQ(vector.Size(), 0U);
149 // Then resetting |unknown1| should reduce to 0.
150 EXPECT_EQ(unknown1.Reset(), 0U);
151}
152
153TEST(VariantVectorTest, ScopeWithManagedContents) {
154 Microsoft::WRL::ComPtr<IUnknown> unknown1 =
155 Microsoft::WRL::Make<DispatchStub>();
156 {
157 VariantVector vector;
158 vector.Insert<VT_UNKNOWN>(unknown1.Get());
159 EXPECT_EQ(vector.Type(), VT_UNKNOWN);
160 EXPECT_EQ(vector.Size(), 1U);
161
162 Microsoft::WRL::ComPtr<IUnknown> unknown2;
163 unknown1.CopyTo(&unknown2);
164 // There are now 3 references to the value owned by |unknown1|.
165 // Remove ownership from |unknown2| should reduce the count to 2.
166 EXPECT_EQ(unknown2.Reset(), 2U);
167 }
168 // The VariantVector going out of scope will reduce the count to 1.
169 // Then resetting |unknown1| should reduce to 0.
170 EXPECT_EQ(unknown1.Reset(), 0U);
171}
172
173TEST(VariantVectorTest, ReleaseAsScalarVariantEmpty) {
174 VariantVector vector;
175 ScopedVariant variant(vector.ReleaseAsScalarVariant());
176 EXPECT_EQ(variant.type(), VT_EMPTY);
177}
178
179TEST(VariantVectorTest, ReleaseAsScalarVariantSingleBool) {
180 VariantVector vector;
181 ScopedVariant expected_variant;
182
183 expected_variant.Set(true);
184 vector.Insert<VT_BOOL>(true);
185 EXPECT_EQ(vector.Type(), expected_variant.type());
186 EXPECT_EQ(vector.Size(), 1U);
187
188 ScopedVariant variant(vector.ReleaseAsScalarVariant());
189 EXPECT_EQ(vector.Type(), VT_EMPTY);
190 EXPECT_EQ(vector.Size(), 0U);
191 EXPECT_EQ(variant.Compare(expected_variant), 0);
192}
193
194TEST(VariantVectorTest, ReleaseAsScalarVariantSingleI1) {
195 VariantVector vector;
196 ScopedVariant expected_variant;
197
198 expected_variant.Set((int8_t)34);
199 vector.Insert<VT_I1>(34);
200 EXPECT_EQ(vector.Type(), expected_variant.type());
201 EXPECT_EQ(vector.Size(), 1U);
202
203 ScopedVariant variant(vector.ReleaseAsScalarVariant());
204 EXPECT_EQ(vector.Type(), VT_EMPTY);
205 EXPECT_EQ(vector.Size(), 0U);
206 EXPECT_EQ(variant.Compare(expected_variant), 0);
207}
208
209TEST(VariantVectorTest, ReleaseAsScalarVariantSingleUI1) {
210 VariantVector vector;
211 ScopedVariant expected_variant;
212
213 expected_variant.Set((uint8_t)35U);
214 vector.Insert<VT_UI1>(35U);
215 EXPECT_EQ(vector.Type(), expected_variant.type());
216 EXPECT_EQ(vector.Size(), 1U);
217
218 ScopedVariant variant(vector.ReleaseAsScalarVariant());
219 EXPECT_EQ(vector.Type(), VT_EMPTY);
220 EXPECT_EQ(vector.Size(), 0U);
221 EXPECT_EQ(variant.Compare(expected_variant), 0);
222}
223
224TEST(VariantVectorTest, ReleaseAsScalarVariantSingleI2) {
225 VariantVector vector;
226 ScopedVariant expected_variant;
227
228 expected_variant.Set((int16_t)8738);
229 vector.Insert<VT_I2>(8738);
230 EXPECT_EQ(vector.Type(), expected_variant.type());
231 EXPECT_EQ(vector.Size(), 1U);
232
233 ScopedVariant variant(vector.ReleaseAsScalarVariant());
234 EXPECT_EQ(vector.Type(), VT_EMPTY);
235 EXPECT_EQ(vector.Size(), 0U);
236 EXPECT_EQ(variant.Compare(expected_variant), 0);
237}
238
239TEST(VariantVectorTest, ReleaseAsScalarVariantSingleUI2) {
240 VariantVector vector;
241 ScopedVariant expected_variant;
242
243 expected_variant.Set((uint16_t)8739U);
244 vector.Insert<VT_UI2>(8739U);
245 EXPECT_EQ(vector.Type(), expected_variant.type());
246 EXPECT_EQ(vector.Size(), 1U);
247
248 ScopedVariant variant(vector.ReleaseAsScalarVariant());
249 EXPECT_EQ(vector.Type(), VT_EMPTY);
250 EXPECT_EQ(vector.Size(), 0U);
251 EXPECT_EQ(variant.Compare(expected_variant), 0);
252}
253
254TEST(VariantVectorTest, ReleaseAsScalarVariantSingleI4) {
255 VariantVector vector;
256 ScopedVariant expected_variant;
257
258 expected_variant.Set((int32_t)572662306);
259 vector.Insert<VT_I4>(572662306);
260 EXPECT_EQ(vector.Type(), expected_variant.type());
261 EXPECT_EQ(vector.Size(), 1U);
262
263 ScopedVariant variant(vector.ReleaseAsScalarVariant());
264 EXPECT_EQ(vector.Type(), VT_EMPTY);
265 EXPECT_EQ(vector.Size(), 0U);
266 EXPECT_EQ(variant.Compare(expected_variant), 0);
267}
268
269TEST(VariantVectorTest, ReleaseAsScalarVariantSingleUI4) {
270 VariantVector vector;
271 ScopedVariant expected_variant;
272
273 expected_variant.Set((uint32_t)572662307U);
274 vector.Insert<VT_UI4>(572662307U);
275 EXPECT_EQ(vector.Type(), expected_variant.type());
276 EXPECT_EQ(vector.Size(), 1U);
277
278 ScopedVariant variant(vector.ReleaseAsScalarVariant());
279 EXPECT_EQ(vector.Type(), VT_EMPTY);
280 EXPECT_EQ(vector.Size(), 0U);
281 EXPECT_EQ(variant.Compare(expected_variant), 0);
282}
283
284TEST(VariantVectorTest, ReleaseAsScalarVariantSingleI8) {
285 VariantVector vector;
286 ScopedVariant expected_variant;
287
288 expected_variant.Set((int64_t)2459565876494606882);
289 vector.Insert<VT_I8>(2459565876494606882);
290 EXPECT_EQ(vector.Type(), expected_variant.type());
291 EXPECT_EQ(vector.Size(), 1U);
292
293 ScopedVariant variant(vector.ReleaseAsScalarVariant());
294 EXPECT_EQ(vector.Type(), VT_EMPTY);
295 EXPECT_EQ(vector.Size(), 0U);
296 EXPECT_EQ(variant.Compare(expected_variant), 0);
297}
298
299TEST(VariantVectorTest, ReleaseAsScalarVariantSingleUI8) {
300 VariantVector vector;
301 ScopedVariant expected_variant;
302
303 expected_variant.Set((uint64_t)2459565876494606883U);
304 vector.Insert<VT_UI8>(2459565876494606883U);
305 EXPECT_EQ(vector.Type(), expected_variant.type());
306 EXPECT_EQ(vector.Size(), 1U);
307
308 ScopedVariant variant(vector.ReleaseAsScalarVariant());
309 EXPECT_EQ(vector.Type(), VT_EMPTY);
310 EXPECT_EQ(vector.Size(), 0U);
311 EXPECT_EQ(variant.Compare(expected_variant), 0);
312}
313
314TEST(VariantVectorTest, ReleaseAsScalarVariantSingleR4) {
315 VariantVector vector;
316 ScopedVariant expected_variant;
317
318 expected_variant.Set(3.14159f);
319 vector.Insert<VT_R4>(3.14159f);
320 EXPECT_EQ(vector.Type(), expected_variant.type());
321 EXPECT_EQ(vector.Size(), 1U);
322
323 ScopedVariant variant(vector.ReleaseAsScalarVariant());
324 EXPECT_EQ(vector.Type(), VT_EMPTY);
325 EXPECT_EQ(vector.Size(), 0U);
326 EXPECT_EQ(variant.Compare(expected_variant), 0);
327}
328
329TEST(VariantVectorTest, ReleaseAsScalarVariantSingleR8) {
330 VariantVector vector;
331 ScopedVariant expected_variant;
332
333 expected_variant.Set(6.28318);
334 vector.Insert<VT_R8>(6.28318);
335 EXPECT_EQ(vector.Type(), expected_variant.type());
336 EXPECT_EQ(vector.Size(), 1U);
337
338 ScopedVariant variant(vector.ReleaseAsScalarVariant());
339 EXPECT_EQ(vector.Type(), VT_EMPTY);
340 EXPECT_EQ(vector.Size(), 0U);
341 EXPECT_EQ(variant.Compare(expected_variant), 0);
342}
343
344TEST(VariantVectorTest, ReleaseAsScalarVariantSingleDate) {
345 VariantVector vector;
346 ScopedVariant expected_variant;
347
348 SYSTEMTIME sys_time;
349 ::GetSystemTime(&sys_time);
350 DATE date;
351 ::SystemTimeToVariantTime(&sys_time, &date);
352 expected_variant.SetDate(date);
353 vector.Insert<VT_DATE>(date);
354 EXPECT_EQ(vector.Type(), expected_variant.type());
355 EXPECT_EQ(vector.Size(), 1U);
356
357 ScopedVariant variant(vector.ReleaseAsScalarVariant());
358 EXPECT_EQ(vector.Type(), VT_EMPTY);
359 EXPECT_EQ(vector.Size(), 0U);
360 EXPECT_EQ(variant.Compare(expected_variant), 0);
361}
362
363TEST(VariantVectorTest, ReleaseAsScalarVariantSingleBstr) {
364 VariantVector vector;
365 ScopedVariant expected_variant;
366
367 wchar_t test_string[] = L"Test string for BSTRs.";
368 expected_variant.Set(test_string);
369 vector.Insert<VT_BSTR>(test_string);
370 EXPECT_EQ(vector.Type(), expected_variant.type());
371 EXPECT_EQ(vector.Size(), 1U);
372
373 ScopedVariant variant(vector.ReleaseAsScalarVariant());
374 EXPECT_EQ(vector.Type(), VT_EMPTY);
375 EXPECT_EQ(vector.Size(), 0U);
376 EXPECT_EQ(variant.Compare(expected_variant), 0);
377}
378
379TEST(VariantVectorTest, ReleaseAsScalarVariantSingleUnknown) {
380 VariantVector vector;
381 ScopedVariant expected_variant;
382
383 Microsoft::WRL::ComPtr<IUnknown> unknown =
384 Microsoft::WRL::Make<DispatchStub>();
385 expected_variant.Set(unknown.Get());
386 vector.Insert<VT_UNKNOWN>(unknown.Get());
387 EXPECT_EQ(vector.Type(), expected_variant.type());
388 EXPECT_EQ(vector.Size(), 1U);
389
390 ScopedVariant variant(vector.ReleaseAsScalarVariant());
391 EXPECT_EQ(vector.Type(), VT_EMPTY);
392 EXPECT_EQ(vector.Size(), 0U);
393 EXPECT_EQ(variant.Compare(expected_variant), 0);
394}
395
396TEST(VariantVectorTest, ReleaseAsScalarVariantSingleDispatch) {
397 VariantVector vector;
398 ScopedVariant expected_variant;
399
400 Microsoft::WRL::ComPtr<IDispatch> dispatch =
401 Microsoft::WRL::Make<DispatchStub>();
402 expected_variant.Set(dispatch.Get());
403 vector.Insert<VT_DISPATCH>(dispatch.Get());
404 EXPECT_EQ(vector.Type(), expected_variant.type());
405 EXPECT_EQ(vector.Size(), 1U);
406
407 ScopedVariant variant(vector.ReleaseAsScalarVariant());
408 EXPECT_EQ(vector.Type(), VT_EMPTY);
409 EXPECT_EQ(vector.Size(), 0U);
410 EXPECT_EQ(variant.Compare(expected_variant), 0);
411}
412
413TEST(VariantVectorTest, ReleaseAsScalarVariantMultipleBool) {
414 constexpr VARTYPE kVariantType = VT_BOOL;
415 VariantVector vector;
416 ScopedVariant variant;
417
418 vector.Insert<kVariantType>(true);
419 vector.Insert<kVariantType>(false);
420 EXPECT_EQ(vector.Type(), kVariantType);
421 EXPECT_EQ(vector.Size(), 2U);
423}
424
425TEST(VariantVectorTest, ReleaseAsScalarVariantMultipleI1) {
426 constexpr VARTYPE kVariantType = VT_I1;
427 VariantVector vector;
428 ScopedVariant variant;
429
430 vector.Insert<kVariantType>(34);
431 vector.Insert<kVariantType>(52);
432 EXPECT_EQ(vector.Type(), kVariantType);
433 EXPECT_EQ(vector.Size(), 2U);
435}
436
437TEST(VariantVectorTest, ReleaseAsScalarVariantMultipleUI1) {
438 constexpr VARTYPE kVariantType = VT_UI1;
439 VariantVector vector;
440 ScopedVariant variant;
441
442 vector.Insert<kVariantType>(34U);
443 vector.Insert<kVariantType>(52U);
444 EXPECT_EQ(vector.Type(), kVariantType);
445 EXPECT_EQ(vector.Size(), 2U);
447}
448
449TEST(VariantVectorTest, ReleaseAsScalarVariantMultipleI2) {
450 constexpr VARTYPE kVariantType = VT_I2;
451 VariantVector vector;
452 ScopedVariant variant;
453
454 vector.Insert<kVariantType>(8738);
455 vector.Insert<kVariantType>(8758);
456 EXPECT_EQ(vector.Type(), kVariantType);
457 EXPECT_EQ(vector.Size(), 2U);
459}
460
461TEST(VariantVectorTest, ReleaseAsScalarVariantMultipleUI2) {
462 constexpr VARTYPE kVariantType = VT_UI2;
463 VariantVector vector;
464 ScopedVariant variant;
465
466 vector.Insert<kVariantType>(8739U);
467 vector.Insert<kVariantType>(8759U);
468 EXPECT_EQ(vector.Type(), kVariantType);
469 EXPECT_EQ(vector.Size(), 2U);
471}
472
473TEST(VariantVectorTest, ReleaseAsScalarVariantMultipleI4) {
474 constexpr VARTYPE kVariantType = VT_I4;
475 VariantVector vector;
476 ScopedVariant variant;
477
478 vector.Insert<kVariantType>(572662306);
479 vector.Insert<kVariantType>(572662307);
480 EXPECT_EQ(vector.Type(), kVariantType);
481 EXPECT_EQ(vector.Size(), 2U);
483}
484
485TEST(VariantVectorTest, ReleaseAsScalarVariantMultipleUI4) {
486 constexpr VARTYPE kVariantType = VT_UI4;
487 VariantVector vector;
488 ScopedVariant variant;
489
490 vector.Insert<kVariantType>(578662306U);
491 vector.Insert<kVariantType>(578662307U);
492 EXPECT_EQ(vector.Type(), kVariantType);
493 EXPECT_EQ(vector.Size(), 2U);
495}
496
497TEST(VariantVectorTest, ReleaseAsScalarVariantMultipleI8) {
498 constexpr VARTYPE kVariantType = VT_I8;
499 VariantVector vector;
500 ScopedVariant variant;
501
502 vector.Insert<kVariantType>(2459565876494606882);
503 vector.Insert<kVariantType>(2459565876494606883);
504 EXPECT_EQ(vector.Type(), kVariantType);
505 EXPECT_EQ(vector.Size(), 2U);
507}
508
509TEST(VariantVectorTest, ReleaseAsScalarVariantMultipleUI8) {
510 constexpr VARTYPE kVariantType = VT_UI8;
511 VariantVector vector;
512 ScopedVariant variant;
513
514 vector.Insert<kVariantType>(2459565876494606883U);
515 vector.Insert<kVariantType>(2459565876494606884U);
516 EXPECT_EQ(vector.Type(), kVariantType);
517 EXPECT_EQ(vector.Size(), 2U);
519}
520
521TEST(VariantVectorTest, ReleaseAsScalarVariantMultipleR4) {
522 constexpr VARTYPE kVariantType = VT_R4;
523 VariantVector vector;
524 ScopedVariant variant;
525
526 vector.Insert<kVariantType>(3.14159f);
527 vector.Insert<kVariantType>(6.28318f);
528 EXPECT_EQ(vector.Type(), kVariantType);
529 EXPECT_EQ(vector.Size(), 2U);
531}
532
533TEST(VariantVectorTest, ReleaseAsScalarVariantMultipleR8) {
534 constexpr VARTYPE kVariantType = VT_R8;
535 VariantVector vector;
536 ScopedVariant variant;
537
538 vector.Insert<kVariantType>(6.28318);
539 vector.Insert<kVariantType>(3.14159);
540 EXPECT_EQ(vector.Type(), kVariantType);
541 EXPECT_EQ(vector.Size(), 2U);
543}
544
545TEST(VariantVectorTest, ReleaseAsScalarVariantMultipleDate) {
546 constexpr VARTYPE kVariantType = VT_DATE;
547 VariantVector vector;
548 ScopedVariant variant;
549
550 SYSTEMTIME sys_time;
551 ::GetSystemTime(&sys_time);
552 DATE date;
553 ::SystemTimeToVariantTime(&sys_time, &date);
554
555 vector.Insert<kVariantType>(date);
556 vector.Insert<kVariantType>(date);
557 EXPECT_EQ(vector.Type(), kVariantType);
558 EXPECT_EQ(vector.Size(), 2U);
560}
561
562TEST(VariantVectorTest, ReleaseAsScalarVariantMultipleBstr) {
563 constexpr VARTYPE kVariantType = VT_BSTR;
564 VariantVector vector;
565 ScopedVariant variant;
566
567 wchar_t some_text[] = L"some text";
568 wchar_t more_text[] = L"more text";
569 vector.Insert<kVariantType>(some_text);
570 vector.Insert<kVariantType>(more_text);
571 EXPECT_EQ(vector.Type(), kVariantType);
572 EXPECT_EQ(vector.Size(), 2U);
574}
575
576TEST(VariantVectorTest, ReleaseAsScalarVariantMultipleUnknown) {
577 constexpr VARTYPE kVariantType = VT_UNKNOWN;
578 VariantVector vector;
579 ScopedVariant variant;
580
581 Microsoft::WRL::ComPtr<IUnknown> unknown1 =
582 Microsoft::WRL::Make<DispatchStub>();
583 Microsoft::WRL::ComPtr<IUnknown> unknown2 =
584 Microsoft::WRL::Make<DispatchStub>();
585
586 vector.Insert<kVariantType>(unknown1.Get());
587 vector.Insert<kVariantType>(unknown2.Get());
588 EXPECT_EQ(vector.Type(), kVariantType);
589 EXPECT_EQ(vector.Size(), 2U);
591}
592
593TEST(VariantVectorTest, ReleaseAsScalarVariantMultipleDispatch) {
594 constexpr VARTYPE kVariantType = VT_DISPATCH;
595 VariantVector vector;
596 ScopedVariant variant;
597
598 Microsoft::WRL::ComPtr<IDispatch> dispatch1 =
599 Microsoft::WRL::Make<DispatchStub>();
600 Microsoft::WRL::ComPtr<IDispatch> dispatch2 =
601 Microsoft::WRL::Make<DispatchStub>();
602
603 vector.Insert<kVariantType>(dispatch1.Get());
604 vector.Insert<kVariantType>(dispatch2.Get());
605 EXPECT_EQ(vector.Type(), kVariantType);
606 EXPECT_EQ(vector.Size(), 2U);
608}
609
610TEST(VariantVectorTest, ReleaseAsSafearrayVariantEmpty) {
611 VariantVector vector;
613 EXPECT_EQ(variant.type(), VT_EMPTY);
614}
615
616TEST(VariantVectorTest, ReleaseAsSafearrayVariantSingleBool) {
617 constexpr VARTYPE kVariantType = VT_BOOL;
618 VariantVector vector;
619
620 vector.Insert<kVariantType>(true);
621 EXPECT_EQ(vector.Type(), kVariantType);
622 EXPECT_EQ(vector.Size(), 1U);
623
625 EXPECT_EQ(vector.Type(), VT_EMPTY);
626 EXPECT_EQ(vector.Size(), 0U);
627 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
628
629 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
630 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
631 safearray.CreateLockScope<kVariantType>();
632 ASSERT_TRUE(lock_scope.has_value());
633 ASSERT_EQ(lock_scope->size(), 1U);
634 EXPECT_EQ(lock_scope->at(0), VARIANT_TRUE);
635 safearray.Release();
636}
637
638TEST(VariantVectorTest, ReleaseAsSafearrayVariantSingleI1) {
639 constexpr VARTYPE kVariantType = VT_I1;
640 VariantVector vector;
641
642 vector.Insert<kVariantType>(34);
643 EXPECT_EQ(vector.Type(), kVariantType);
644 EXPECT_EQ(vector.Size(), 1U);
645
647 EXPECT_EQ(vector.Type(), VT_EMPTY);
648 EXPECT_EQ(vector.Size(), 0U);
649 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
650
651 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
652 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
653 safearray.CreateLockScope<kVariantType>();
654 ASSERT_TRUE(lock_scope.has_value());
655 ASSERT_EQ(lock_scope->size(), 1U);
656 EXPECT_EQ(lock_scope->at(0), 34);
657 safearray.Release();
658}
659
660TEST(VariantVectorTest, ReleaseAsSafearrayVariantSingleUI1) {
661 constexpr VARTYPE kVariantType = VT_UI1;
662 VariantVector vector;
663
664 vector.Insert<kVariantType>(34U);
665 EXPECT_EQ(vector.Type(), kVariantType);
666 EXPECT_EQ(vector.Size(), 1U);
667
669 EXPECT_EQ(vector.Type(), VT_EMPTY);
670 EXPECT_EQ(vector.Size(), 0U);
671 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
672
673 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
674 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
675 safearray.CreateLockScope<kVariantType>();
676 ASSERT_TRUE(lock_scope.has_value());
677 ASSERT_EQ(lock_scope->size(), 1U);
678 EXPECT_EQ(lock_scope->at(0), 34U);
679 safearray.Release();
680}
681
682TEST(VariantVectorTest, ReleaseAsSafearrayVariantSingleI2) {
683 constexpr VARTYPE kVariantType = VT_I2;
684 VariantVector vector;
685
686 vector.Insert<kVariantType>(8738);
687 EXPECT_EQ(vector.Type(), kVariantType);
688 EXPECT_EQ(vector.Size(), 1U);
689
691 EXPECT_EQ(vector.Type(), VT_EMPTY);
692 EXPECT_EQ(vector.Size(), 0U);
693 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
694
695 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
696 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
697 safearray.CreateLockScope<kVariantType>();
698 ASSERT_TRUE(lock_scope.has_value());
699 ASSERT_EQ(lock_scope->size(), 1U);
700 EXPECT_EQ(lock_scope->at(0), 8738);
701 safearray.Release();
702}
703
704TEST(VariantVectorTest, ReleaseAsSafearrayVariantSingleUI2) {
705 constexpr VARTYPE kVariantType = VT_UI2;
706 VariantVector vector;
707
708 vector.Insert<kVariantType>(8739U);
709 EXPECT_EQ(vector.Type(), kVariantType);
710 EXPECT_EQ(vector.Size(), 1U);
711
713 EXPECT_EQ(vector.Type(), VT_EMPTY);
714 EXPECT_EQ(vector.Size(), 0U);
715 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
716
717 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
718 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
719 safearray.CreateLockScope<kVariantType>();
720 ASSERT_TRUE(lock_scope.has_value());
721 ASSERT_EQ(lock_scope->size(), 1U);
722 EXPECT_EQ(lock_scope->at(0), 8739U);
723 safearray.Release();
724}
725
726TEST(VariantVectorTest, ReleaseAsSafearrayVariantSingleI4) {
727 constexpr VARTYPE kVariantType = VT_I4;
728 VariantVector vector;
729
730 vector.Insert<kVariantType>(572662306);
731 EXPECT_EQ(vector.Type(), kVariantType);
732 EXPECT_EQ(vector.Size(), 1U);
733
735 EXPECT_EQ(vector.Type(), VT_EMPTY);
736 EXPECT_EQ(vector.Size(), 0U);
737 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
738
739 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
740 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
741 safearray.CreateLockScope<kVariantType>();
742 ASSERT_TRUE(lock_scope.has_value());
743 ASSERT_EQ(lock_scope->size(), 1U);
744 EXPECT_EQ(lock_scope->at(0), 572662306);
745 safearray.Release();
746}
747
748TEST(VariantVectorTest, ReleaseAsSafearrayVariantSingleUI4) {
749 constexpr VARTYPE kVariantType = VT_UI4;
750 VariantVector vector;
751
752 vector.Insert<kVariantType>(578662306U);
753 EXPECT_EQ(vector.Type(), kVariantType);
754 EXPECT_EQ(vector.Size(), 1U);
755
757 EXPECT_EQ(vector.Type(), VT_EMPTY);
758 EXPECT_EQ(vector.Size(), 0U);
759 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
760
761 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
762 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
763 safearray.CreateLockScope<kVariantType>();
764 ASSERT_TRUE(lock_scope.has_value());
765 ASSERT_EQ(lock_scope->size(), 1U);
766 EXPECT_EQ(lock_scope->at(0), 578662306U);
767 safearray.Release();
768}
769
770TEST(VariantVectorTest, ReleaseAsSafearrayVariantSingleI8) {
771 constexpr VARTYPE kVariantType = VT_I8;
772 VariantVector vector;
773
774 vector.Insert<kVariantType>(2459565876494606882);
775 EXPECT_EQ(vector.Type(), kVariantType);
776 EXPECT_EQ(vector.Size(), 1U);
777
779 EXPECT_EQ(vector.Type(), VT_EMPTY);
780 EXPECT_EQ(vector.Size(), 0U);
781 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
782
783 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
784 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
785 safearray.CreateLockScope<kVariantType>();
786 ASSERT_TRUE(lock_scope.has_value());
787 ASSERT_EQ(lock_scope->size(), 1U);
788 EXPECT_EQ(lock_scope->at(0), 2459565876494606882);
789 safearray.Release();
790}
791
792TEST(VariantVectorTest, ReleaseAsSafearrayVariantSingleUI8) {
793 constexpr VARTYPE kVariantType = VT_UI8;
794 VariantVector vector;
795
796 vector.Insert<kVariantType>(2459565876494606883U);
797 EXPECT_EQ(vector.Type(), kVariantType);
798 EXPECT_EQ(vector.Size(), 1U);
799
801 EXPECT_EQ(vector.Type(), VT_EMPTY);
802 EXPECT_EQ(vector.Size(), 0U);
803 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
804
805 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
806 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
807 safearray.CreateLockScope<kVariantType>();
808 ASSERT_TRUE(lock_scope.has_value());
809 ASSERT_EQ(lock_scope->size(), 1U);
810 EXPECT_EQ(lock_scope->at(0), 2459565876494606883U);
811 safearray.Release();
812}
813
814TEST(VariantVectorTest, ReleaseAsSafearrayVariantSingleR4) {
815 constexpr VARTYPE kVariantType = VT_R4;
816 VariantVector vector;
817
818 vector.Insert<kVariantType>(3.14159f);
819 EXPECT_EQ(vector.Type(), kVariantType);
820 EXPECT_EQ(vector.Size(), 1U);
821
823 EXPECT_EQ(vector.Type(), VT_EMPTY);
824 EXPECT_EQ(vector.Size(), 0U);
825 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
826
827 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
828 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
829 safearray.CreateLockScope<kVariantType>();
830 ASSERT_TRUE(lock_scope.has_value());
831 ASSERT_EQ(lock_scope->size(), 1U);
832 EXPECT_EQ(lock_scope->at(0), 3.14159f);
833 safearray.Release();
834}
835
836TEST(VariantVectorTest, ReleaseAsSafearrayVariantSingleR8) {
837 constexpr VARTYPE kVariantType = VT_R8;
838 VariantVector vector;
839
840 vector.Insert<kVariantType>(6.28318);
841 EXPECT_EQ(vector.Type(), kVariantType);
842 EXPECT_EQ(vector.Size(), 1U);
843
845 EXPECT_EQ(vector.Type(), VT_EMPTY);
846 EXPECT_EQ(vector.Size(), 0U);
847 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
848
849 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
850 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
851 safearray.CreateLockScope<kVariantType>();
852 ASSERT_TRUE(lock_scope.has_value());
853 ASSERT_EQ(lock_scope->size(), 1U);
854 EXPECT_EQ(lock_scope->at(0), 6.28318);
855 safearray.Release();
856}
857
858TEST(VariantVectorTest, ReleaseAsSafearrayVariantSingleDate) {
859 constexpr VARTYPE kVariantType = VT_DATE;
860 VariantVector vector;
861
862 SYSTEMTIME sys_time;
863 ::GetSystemTime(&sys_time);
864 DATE date;
865 ::SystemTimeToVariantTime(&sys_time, &date);
866
867 vector.Insert<kVariantType>(date);
868 EXPECT_EQ(vector.Type(), kVariantType);
869 EXPECT_EQ(vector.Size(), 1U);
870
872 EXPECT_EQ(vector.Type(), VT_EMPTY);
873 EXPECT_EQ(vector.Size(), 0U);
874 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
875
876 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
877 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
878 safearray.CreateLockScope<kVariantType>();
879 ASSERT_TRUE(lock_scope.has_value());
880 ASSERT_EQ(lock_scope->size(), 1U);
881 EXPECT_EQ(lock_scope->at(0), date);
882 safearray.Release();
883}
884
885TEST(VariantVectorTest, ReleaseAsSafearrayVariantSingleBstr) {
886 constexpr VARTYPE kVariantType = VT_BSTR;
887 VariantVector vector;
888
889 wchar_t some_text[] = L"some text";
890 vector.Insert<kVariantType>(some_text);
891 EXPECT_EQ(vector.Type(), kVariantType);
892 EXPECT_EQ(vector.Size(), 1U);
893
895 EXPECT_EQ(vector.Type(), VT_EMPTY);
896 EXPECT_EQ(vector.Size(), 0U);
897 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
898
899 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
900 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
901 safearray.CreateLockScope<kVariantType>();
902 ASSERT_TRUE(lock_scope.has_value());
903 ASSERT_EQ(lock_scope->size(), 1U);
904 EXPECT_STREQ(lock_scope->at(0), some_text);
905 safearray.Release();
906}
907
908TEST(VariantVectorTest, ReleaseAsSafearrayVariantSingleUnknown) {
909 constexpr VARTYPE kVariantType = VT_UNKNOWN;
910 VariantVector vector;
911
912 Microsoft::WRL::ComPtr<IUnknown> unknown =
913 Microsoft::WRL::Make<DispatchStub>();
914
915 vector.Insert<kVariantType>(unknown.Get());
916 EXPECT_EQ(vector.Type(), kVariantType);
917 EXPECT_EQ(vector.Size(), 1U);
918
920 EXPECT_EQ(vector.Type(), VT_EMPTY);
921 EXPECT_EQ(vector.Size(), 0U);
922 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
923
924 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
925 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
926 safearray.CreateLockScope<kVariantType>();
927 ASSERT_TRUE(lock_scope.has_value());
928 ASSERT_EQ(lock_scope->size(), 1U);
929 EXPECT_EQ(lock_scope->at(0), unknown.Get());
930 safearray.Release();
931}
932
933TEST(VariantVectorTest, ReleaseAsSafearrayVariantSingleDispatch) {
934 constexpr VARTYPE kVariantType = VT_DISPATCH;
935 VariantVector vector;
936
937 Microsoft::WRL::ComPtr<IDispatch> dispatch =
938 Microsoft::WRL::Make<DispatchStub>();
939
940 vector.Insert<kVariantType>(dispatch.Get());
941 EXPECT_EQ(vector.Type(), kVariantType);
942 EXPECT_EQ(vector.Size(), 1U);
943
945 EXPECT_EQ(vector.Type(), VT_EMPTY);
946 EXPECT_EQ(vector.Size(), 0U);
947 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
948
949 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
950 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
951 safearray.CreateLockScope<kVariantType>();
952 ASSERT_TRUE(lock_scope.has_value());
953 ASSERT_EQ(lock_scope->size(), 1U);
954 EXPECT_EQ(lock_scope->at(0), dispatch.Get());
955 safearray.Release();
956}
957
958TEST(VariantVectorTest, ReleaseAsSafearrayVariantMultipleBool) {
959 constexpr VARTYPE kVariantType = VT_BOOL;
960 VariantVector vector;
961
962 vector.Insert<kVariantType>(true);
963 vector.Insert<kVariantType>(false);
964 vector.Insert<kVariantType>(true);
965 EXPECT_EQ(vector.Type(), kVariantType);
966 EXPECT_EQ(vector.Size(), 3U);
967
969 EXPECT_EQ(vector.Type(), VT_EMPTY);
970 EXPECT_EQ(vector.Size(), 0U);
971 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
972
973 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
974 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
975 safearray.CreateLockScope<kVariantType>();
976 ASSERT_TRUE(lock_scope.has_value());
977 ASSERT_EQ(lock_scope->size(), 3U);
978 EXPECT_EQ(lock_scope->at(0), VARIANT_TRUE);
979 EXPECT_EQ(lock_scope->at(1), VARIANT_FALSE);
980 EXPECT_EQ(lock_scope->at(2), VARIANT_TRUE);
981 safearray.Release();
982}
983
984TEST(VariantVectorTest, ReleaseAsSafearrayVariantMultipleI1) {
985 constexpr VARTYPE kVariantType = VT_I1;
986 VariantVector vector;
987
988 vector.Insert<kVariantType>(34);
989 vector.Insert<kVariantType>(52);
990 vector.Insert<kVariantType>(12);
991 EXPECT_EQ(vector.Type(), kVariantType);
992 EXPECT_EQ(vector.Size(), 3U);
993
995 EXPECT_EQ(vector.Type(), VT_EMPTY);
996 EXPECT_EQ(vector.Size(), 0U);
997 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
998
999 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
1000 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
1001 safearray.CreateLockScope<kVariantType>();
1002 ASSERT_TRUE(lock_scope.has_value());
1003 ASSERT_EQ(lock_scope->size(), 3U);
1004 EXPECT_EQ(lock_scope->at(0), 34);
1005 EXPECT_EQ(lock_scope->at(1), 52);
1006 EXPECT_EQ(lock_scope->at(2), 12);
1007 safearray.Release();
1008}
1009
1010TEST(VariantVectorTest, ReleaseAsSafearrayVariantMultipleUI1) {
1011 constexpr VARTYPE kVariantType = VT_UI1;
1012 VariantVector vector;
1013
1014 vector.Insert<kVariantType>(34U);
1015 vector.Insert<kVariantType>(52U);
1016 vector.Insert<kVariantType>(12U);
1017 EXPECT_EQ(vector.Type(), kVariantType);
1018 EXPECT_EQ(vector.Size(), 3U);
1019
1020 ScopedVariant variant(vector.ReleaseAsSafearrayVariant());
1021 EXPECT_EQ(vector.Type(), VT_EMPTY);
1022 EXPECT_EQ(vector.Size(), 0U);
1023 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
1024
1025 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
1026 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
1027 safearray.CreateLockScope<kVariantType>();
1028 ASSERT_TRUE(lock_scope.has_value());
1029 ASSERT_EQ(lock_scope->size(), 3U);
1030 EXPECT_EQ(lock_scope->at(0), 34U);
1031 EXPECT_EQ(lock_scope->at(1), 52U);
1032 EXPECT_EQ(lock_scope->at(2), 12U);
1033 safearray.Release();
1034}
1035
1036TEST(VariantVectorTest, ReleaseAsSafearrayVariantMultipleI2) {
1037 constexpr VARTYPE kVariantType = VT_I2;
1038 VariantVector vector;
1039
1040 vector.Insert<kVariantType>(8738);
1041 vector.Insert<kVariantType>(8758);
1042 vector.Insert<kVariantType>(42);
1043 EXPECT_EQ(vector.Type(), kVariantType);
1044 EXPECT_EQ(vector.Size(), 3U);
1045
1046 ScopedVariant variant(vector.ReleaseAsSafearrayVariant());
1047 EXPECT_EQ(vector.Type(), VT_EMPTY);
1048 EXPECT_EQ(vector.Size(), 0U);
1049 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
1050
1051 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
1052 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
1053 safearray.CreateLockScope<kVariantType>();
1054 ASSERT_TRUE(lock_scope.has_value());
1055 ASSERT_EQ(lock_scope->size(), 3U);
1056 EXPECT_EQ(lock_scope->at(0), 8738);
1057 EXPECT_EQ(lock_scope->at(1), 8758);
1058 EXPECT_EQ(lock_scope->at(2), 42);
1059 safearray.Release();
1060}
1061
1062TEST(VariantVectorTest, ReleaseAsSafearrayVariantMultipleUI2) {
1063 constexpr VARTYPE kVariantType = VT_UI2;
1064 VariantVector vector;
1065
1066 vector.Insert<kVariantType>(8739U);
1067 vector.Insert<kVariantType>(8759U);
1068 vector.Insert<kVariantType>(42U);
1069 EXPECT_EQ(vector.Type(), kVariantType);
1070 EXPECT_EQ(vector.Size(), 3U);
1071
1072 ScopedVariant variant(vector.ReleaseAsSafearrayVariant());
1073 EXPECT_EQ(vector.Type(), VT_EMPTY);
1074 EXPECT_EQ(vector.Size(), 0U);
1075 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
1076
1077 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
1078 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
1079 safearray.CreateLockScope<kVariantType>();
1080 ASSERT_TRUE(lock_scope.has_value());
1081 ASSERT_EQ(lock_scope->size(), 3U);
1082 EXPECT_EQ(lock_scope->at(0), 8739U);
1083 EXPECT_EQ(lock_scope->at(1), 8759U);
1084 EXPECT_EQ(lock_scope->at(2), 42U);
1085 safearray.Release();
1086}
1087
1088TEST(VariantVectorTest, ReleaseAsSafearrayVariantMultipleI4) {
1089 constexpr VARTYPE kVariantType = VT_I4;
1090 VariantVector vector;
1091
1092 vector.Insert<kVariantType>(572662306);
1093 vector.Insert<kVariantType>(572662307);
1094 vector.Insert<kVariantType>(572662308);
1095 EXPECT_EQ(vector.Type(), kVariantType);
1096 EXPECT_EQ(vector.Size(), 3U);
1097
1098 ScopedVariant variant(vector.ReleaseAsSafearrayVariant());
1099 EXPECT_EQ(vector.Type(), VT_EMPTY);
1100 EXPECT_EQ(vector.Size(), 0U);
1101 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
1102
1103 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
1104 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
1105 safearray.CreateLockScope<kVariantType>();
1106 ASSERT_TRUE(lock_scope.has_value());
1107 ASSERT_EQ(lock_scope->size(), 3U);
1108 EXPECT_EQ(lock_scope->at(0), 572662306);
1109 EXPECT_EQ(lock_scope->at(1), 572662307);
1110 EXPECT_EQ(lock_scope->at(2), 572662308);
1111 safearray.Release();
1112}
1113
1114TEST(VariantVectorTest, ReleaseAsSafearrayVariantMultipleUI4) {
1115 constexpr VARTYPE kVariantType = VT_UI4;
1116 VariantVector vector;
1117
1118 vector.Insert<kVariantType>(578662306U);
1119 vector.Insert<kVariantType>(578662307U);
1120 vector.Insert<kVariantType>(578662308U);
1121 EXPECT_EQ(vector.Type(), kVariantType);
1122 EXPECT_EQ(vector.Size(), 3U);
1123
1124 ScopedVariant variant(vector.ReleaseAsSafearrayVariant());
1125 EXPECT_EQ(vector.Type(), VT_EMPTY);
1126 EXPECT_EQ(vector.Size(), 0U);
1127 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
1128
1129 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
1130 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
1131 safearray.CreateLockScope<kVariantType>();
1132 ASSERT_TRUE(lock_scope.has_value());
1133 ASSERT_EQ(lock_scope->size(), 3U);
1134 EXPECT_EQ(lock_scope->at(0), 578662306U);
1135 EXPECT_EQ(lock_scope->at(1), 578662307U);
1136 EXPECT_EQ(lock_scope->at(2), 578662308U);
1137 safearray.Release();
1138}
1139
1140TEST(VariantVectorTest, ReleaseAsSafearrayVariantMultipleI8) {
1141 constexpr VARTYPE kVariantType = VT_I8;
1142 VariantVector vector;
1143
1144 vector.Insert<kVariantType>(2459565876494606882);
1145 vector.Insert<kVariantType>(2459565876494606883);
1146 vector.Insert<kVariantType>(2459565876494606884);
1147 EXPECT_EQ(vector.Type(), kVariantType);
1148 EXPECT_EQ(vector.Size(), 3U);
1149
1150 ScopedVariant variant(vector.ReleaseAsSafearrayVariant());
1151 EXPECT_EQ(vector.Type(), VT_EMPTY);
1152 EXPECT_EQ(vector.Size(), 0U);
1153 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
1154
1155 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
1156 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
1157 safearray.CreateLockScope<kVariantType>();
1158 ASSERT_TRUE(lock_scope.has_value());
1159 ASSERT_EQ(lock_scope->size(), 3U);
1160 EXPECT_EQ(lock_scope->at(0), 2459565876494606882);
1161 EXPECT_EQ(lock_scope->at(1), 2459565876494606883);
1162 EXPECT_EQ(lock_scope->at(2), 2459565876494606884);
1163 safearray.Release();
1164}
1165
1166TEST(VariantVectorTest, ReleaseAsSafearrayVariantMultipleUI8) {
1167 constexpr VARTYPE kVariantType = VT_UI8;
1168 VariantVector vector;
1169
1170 vector.Insert<kVariantType>(2459565876494606883U);
1171 vector.Insert<kVariantType>(2459565876494606884U);
1172 vector.Insert<kVariantType>(2459565876494606885U);
1173 EXPECT_EQ(vector.Type(), kVariantType);
1174 EXPECT_EQ(vector.Size(), 3U);
1175
1176 ScopedVariant variant(vector.ReleaseAsSafearrayVariant());
1177 EXPECT_EQ(vector.Type(), VT_EMPTY);
1178 EXPECT_EQ(vector.Size(), 0U);
1179 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
1180
1181 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
1182 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
1183 safearray.CreateLockScope<kVariantType>();
1184 ASSERT_TRUE(lock_scope.has_value());
1185 ASSERT_EQ(lock_scope->size(), 3U);
1186 EXPECT_EQ(lock_scope->at(0), 2459565876494606883U);
1187 EXPECT_EQ(lock_scope->at(1), 2459565876494606884U);
1188 EXPECT_EQ(lock_scope->at(2), 2459565876494606885U);
1189 safearray.Release();
1190}
1191
1192TEST(VariantVectorTest, ReleaseAsSafearrayVariantMultipleR4) {
1193 constexpr VARTYPE kVariantType = VT_R4;
1194 VariantVector vector;
1195
1196 vector.Insert<kVariantType>(3.14159f);
1197 vector.Insert<kVariantType>(6.28318f);
1198 EXPECT_EQ(vector.Type(), kVariantType);
1199 EXPECT_EQ(vector.Size(), 2U);
1200
1201 ScopedVariant variant(vector.ReleaseAsSafearrayVariant());
1202 EXPECT_EQ(vector.Type(), VT_EMPTY);
1203 EXPECT_EQ(vector.Size(), 0U);
1204 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
1205
1206 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
1207 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
1208 safearray.CreateLockScope<kVariantType>();
1209 ASSERT_TRUE(lock_scope.has_value());
1210 ASSERT_EQ(lock_scope->size(), 2U);
1211 EXPECT_EQ(lock_scope->at(0), 3.14159f);
1212 EXPECT_EQ(lock_scope->at(1), 6.28318f);
1213 safearray.Release();
1214}
1215
1216TEST(VariantVectorTest, ReleaseAsSafearrayVariantMultipleR8) {
1217 constexpr VARTYPE kVariantType = VT_R8;
1218 VariantVector vector;
1219
1220 vector.Insert<kVariantType>(6.28318);
1221 vector.Insert<kVariantType>(3.14159);
1222 EXPECT_EQ(vector.Type(), kVariantType);
1223 EXPECT_EQ(vector.Size(), 2U);
1224
1225 ScopedVariant variant(vector.ReleaseAsSafearrayVariant());
1226 EXPECT_EQ(vector.Type(), VT_EMPTY);
1227 EXPECT_EQ(vector.Size(), 0U);
1228 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
1229
1230 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
1231 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
1232 safearray.CreateLockScope<kVariantType>();
1233 ASSERT_TRUE(lock_scope.has_value());
1234 ASSERT_EQ(lock_scope->size(), 2U);
1235 EXPECT_EQ(lock_scope->at(0), 6.28318);
1236 EXPECT_EQ(lock_scope->at(1), 3.14159);
1237 safearray.Release();
1238}
1239
1240TEST(VariantVectorTest, ReleaseAsSafearrayVariantMultipleDate) {
1241 constexpr VARTYPE kVariantType = VT_DATE;
1242 VariantVector vector;
1243 SYSTEMTIME sys_time;
1244 ::GetSystemTime(&sys_time);
1245 DATE date;
1246 ::SystemTimeToVariantTime(&sys_time, &date);
1247
1248 vector.Insert<kVariantType>(date);
1249 vector.Insert<kVariantType>(date);
1250 EXPECT_EQ(vector.Type(), kVariantType);
1251 EXPECT_EQ(vector.Size(), 2U);
1252
1253 ScopedVariant variant(vector.ReleaseAsSafearrayVariant());
1254 EXPECT_EQ(vector.Type(), VT_EMPTY);
1255 EXPECT_EQ(vector.Size(), 0U);
1256 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
1257
1258 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
1259 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
1260 safearray.CreateLockScope<kVariantType>();
1261 ASSERT_TRUE(lock_scope.has_value());
1262 ASSERT_EQ(lock_scope->size(), 2U);
1263 EXPECT_EQ(lock_scope->at(0), date);
1264 EXPECT_EQ(lock_scope->at(1), date);
1265 safearray.Release();
1266}
1267
1268TEST(VariantVectorTest, ReleaseAsSafearrayVariantMultipleBstr) {
1269 constexpr VARTYPE kVariantType = VT_BSTR;
1270 VariantVector vector;
1271 wchar_t some_text[] = L"some text";
1272 wchar_t more_text[] = L"more text";
1273 vector.Insert<kVariantType>(some_text);
1274 vector.Insert<kVariantType>(more_text);
1275 EXPECT_EQ(vector.Type(), kVariantType);
1276 EXPECT_EQ(vector.Size(), 2U);
1277
1278 ScopedVariant variant(vector.ReleaseAsSafearrayVariant());
1279 EXPECT_EQ(vector.Type(), VT_EMPTY);
1280 EXPECT_EQ(vector.Size(), 0U);
1281 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
1282
1283 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
1284 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
1285 safearray.CreateLockScope<kVariantType>();
1286 ASSERT_TRUE(lock_scope.has_value());
1287 ASSERT_EQ(lock_scope->size(), 2U);
1288 EXPECT_STREQ(lock_scope->at(0), some_text);
1289 EXPECT_STREQ(lock_scope->at(1), more_text);
1290 safearray.Release();
1291}
1292
1293TEST(VariantVectorTest, ReleaseAsSafearrayVariantMultipleUnknown) {
1294 constexpr VARTYPE kVariantType = VT_UNKNOWN;
1295 VariantVector vector;
1296
1297 Microsoft::WRL::ComPtr<IUnknown> unknown1 =
1298 Microsoft::WRL::Make<DispatchStub>();
1299 Microsoft::WRL::ComPtr<IUnknown> unknown2 =
1300 Microsoft::WRL::Make<DispatchStub>();
1301
1302 vector.Insert<kVariantType>(unknown1.Get());
1303 vector.Insert<kVariantType>(unknown2.Get());
1304 EXPECT_EQ(vector.Type(), kVariantType);
1305 EXPECT_EQ(vector.Size(), 2U);
1306
1307 ScopedVariant variant(vector.ReleaseAsSafearrayVariant());
1308 EXPECT_EQ(vector.Type(), VT_EMPTY);
1309 EXPECT_EQ(vector.Size(), 0U);
1310 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
1311
1312 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
1313 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
1314 safearray.CreateLockScope<kVariantType>();
1315 ASSERT_TRUE(lock_scope.has_value());
1316 ASSERT_EQ(lock_scope->size(), 2U);
1317 EXPECT_EQ(lock_scope->at(0), unknown1.Get());
1318 EXPECT_EQ(lock_scope->at(1), unknown2.Get());
1319 safearray.Release();
1320}
1321
1322TEST(VariantVectorTest, ReleaseAsSafearrayVariantMultipleDispatch) {
1323 constexpr VARTYPE kVariantType = VT_DISPATCH;
1324 VariantVector vector;
1325
1326 Microsoft::WRL::ComPtr<IDispatch> dispatch1 =
1327 Microsoft::WRL::Make<DispatchStub>();
1328 Microsoft::WRL::ComPtr<IDispatch> dispatch2 =
1329 Microsoft::WRL::Make<DispatchStub>();
1330
1331 vector.Insert<kVariantType>(dispatch1.Get());
1332 vector.Insert<kVariantType>(dispatch2.Get());
1333 EXPECT_EQ(vector.Type(), kVariantType);
1334 EXPECT_EQ(vector.Size(), 2U);
1335
1336 ScopedVariant variant(vector.ReleaseAsSafearrayVariant());
1337 EXPECT_EQ(vector.Type(), VT_EMPTY);
1338 EXPECT_EQ(vector.Size(), 0U);
1339 EXPECT_EQ(variant.type(), VT_ARRAY | kVariantType);
1340
1341 ScopedSafearray safearray(V_ARRAY(variant.ptr()));
1342 base::Optional<ScopedSafearray::LockScope<kVariantType>> lock_scope =
1343 safearray.CreateLockScope<kVariantType>();
1344 ASSERT_TRUE(lock_scope.has_value());
1345 ASSERT_EQ(lock_scope->size(), 2U);
1346 EXPECT_EQ(lock_scope->at(0), dispatch1.Get());
1347 EXPECT_EQ(lock_scope->at(1), dispatch2.Get());
1348 safearray.Release();
1349}
1350
1351TEST(VariantVectorTest, CompareVariant) {
1352 VariantVector vector;
1353 ScopedVariant variant;
1354 EXPECT_EQ(vector.Compare(variant), 0);
1355
1356 vector.Insert<VT_I4>(123);
1357 EXPECT_EQ(vector.Type(), VT_I4);
1358 EXPECT_EQ(vector.Size(), 1U);
1359
1360 variant.Set(123);
1361 EXPECT_EQ(vector.Compare(variant), 0);
1362 variant.Set(4);
1363 EXPECT_EQ(vector.Compare(variant), 1);
1364 variant.Set(567);
1365 EXPECT_EQ(vector.Compare(variant), -1);
1366 // Because the types do not match and VT_I4 is less-than VT_R8,
1367 // |vector| compares as less-than |variant|, even though the value
1368 // in |vector| is greater.
1369 variant.Set(1.0);
1370 EXPECT_EQ(variant.type(), VT_R8);
1371 EXPECT_LT(vector.Type(), variant.type());
1372 EXPECT_EQ(vector.Compare(variant), -1);
1373
1374 vector.Insert<VT_I4>(456);
1375 EXPECT_EQ(vector.Size(), 2U);
1376
1377 // The first element of |vector| is equal to |variant|, but |vector|
1378 // has more than one element so it is greater-than |variant|.
1379 variant.Set(123);
1380 EXPECT_EQ(vector.Compare(variant), 1);
1381 // The first element of |vector| is greater-than |variant|.
1382 variant.Set(5);
1383 EXPECT_EQ(vector.Compare(variant), 1);
1384 // The first element of |vector| is less-than |variant|.
1385 variant.Set(1000);
1386 EXPECT_EQ(vector.Compare(variant), -1);
1387}
1388
1389TEST(VariantVectorTest, CompareSafearray) {
1390 VariantVector vector;
1391 vector.Insert<VT_I4>(123);
1392 vector.Insert<VT_I4>(456);
1393 EXPECT_EQ(vector.Type(), VT_I4);
1394 EXPECT_EQ(vector.Size(), 2U);
1395
1396 ScopedVariant variant(vector.ReleaseAsSafearrayVariant());
1397 EXPECT_EQ(variant.type(), VT_ARRAY | VT_I4);
1398 EXPECT_EQ(vector.Type(), VT_EMPTY);
1399 EXPECT_EQ(vector.Size(), 0U);
1400
1401 // Because |vector| is now empty, it will compare as less-than the array.
1402 EXPECT_EQ(vector.Compare(V_ARRAY(variant.ptr())), -1);
1403 EXPECT_EQ(vector.Compare(variant), -1);
1404
1405 vector.Insert<VT_I4>(123);
1406 EXPECT_EQ(vector.Type(), VT_I4);
1407 EXPECT_EQ(vector.Size(), 1U);
1408 // |vector| has fewer elements than |variant|.
1409 EXPECT_EQ(vector.Compare(V_ARRAY(variant.ptr())), -1);
1410 EXPECT_EQ(vector.Compare(variant), -1);
1411
1412 vector.Insert<VT_I4>(456);
1413 EXPECT_EQ(vector.Type(), VT_I4);
1414 EXPECT_EQ(vector.Size(), 2U);
1415 // |vector| is now equal to |variant|.
1416 EXPECT_EQ(vector.Compare(V_ARRAY(variant.ptr())), 0);
1417 EXPECT_EQ(vector.Compare(variant), 0);
1418
1419 vector.Insert<VT_I4>(789);
1420 EXPECT_EQ(vector.Type(), VT_I4);
1421 EXPECT_EQ(vector.Size(), 3U);
1422 // |vector| contains |variant| but has more elements so
1423 // |vector| is now greater-than |variant|.
1424 EXPECT_EQ(vector.Compare(V_ARRAY(variant.ptr())), 1);
1425 EXPECT_EQ(vector.Compare(variant), 1);
1426
1427 vector.Reset();
1428 vector.Insert<VT_I4>(456);
1429 EXPECT_EQ(vector.Type(), VT_I4);
1430 EXPECT_EQ(vector.Size(), 1U);
1431 // |vector| has fewer elements than |variant|, but the first element in
1432 // |vector| compares as greater-than the first element in |variant|.
1433 EXPECT_EQ(vector.Compare(V_ARRAY(variant.ptr())), 1);
1434 EXPECT_EQ(vector.Compare(variant), 1);
1435
1436 vector.Reset();
1437 vector.Insert<VT_R8>(0.0);
1438 vector.Insert<VT_R8>(0.0);
1439 EXPECT_EQ(vector.Type(), VT_R8);
1440 // Because the types do not match and VT_R8 is greater-than VT_I4,
1441 // |vector| compares as greater-than |variant|, even though the values
1442 // in |vector| are less-than the values in |variant|.
1443 EXPECT_GT(VT_R8, VT_I4);
1444 EXPECT_EQ(vector.Compare(V_ARRAY(variant.ptr())), 1);
1445 EXPECT_EQ(vector.Compare(variant), 1);
1446
1447 vector.Reset();
1448 vector.Insert<VT_I2>(1000);
1449 vector.Insert<VT_I2>(1000);
1450 EXPECT_EQ(vector.Type(), VT_I2);
1451 // Because the types do not match and VT_I2 is less-than VT_I4,
1452 // |vector| compares as less-than |variant|, even though the values
1453 // in |vector| are greater-than the values in |variant|.
1454 EXPECT_LT(VT_I2, VT_I4);
1455 EXPECT_EQ(vector.Compare(V_ARRAY(variant.ptr())), -1);
1456 EXPECT_EQ(vector.Compare(variant), -1);
1457}
1458
1459TEST(VariantVectorTest, CompareVariantVector) {
1460 VariantVector vector1, vector2;
1461 EXPECT_EQ(vector1.Compare(vector2), 0);
1462 EXPECT_EQ(vector1, vector2);
1463
1464 vector1.Insert<VT_I4>(1);
1465 EXPECT_EQ(vector1.Compare(vector2), 1);
1466 EXPECT_EQ(vector2.Compare(vector1), -1);
1467 EXPECT_NE(vector1, vector2);
1468
1469 vector2.Insert<VT_I4>(1);
1470 EXPECT_EQ(vector1.Compare(vector2), 0);
1471 EXPECT_EQ(vector2.Compare(vector1), 0);
1472 EXPECT_EQ(vector1, vector2);
1473
1474 vector1.Insert<VT_I4>(1);
1475 EXPECT_EQ(vector1.Compare(vector2), 1);
1476 EXPECT_EQ(vector2.Compare(vector1), -1);
1477 EXPECT_NE(vector1, vector2);
1478
1479 vector2.Insert<VT_I4>(2);
1480 EXPECT_EQ(vector1.Compare(vector2), -1);
1481 EXPECT_EQ(vector2.Compare(vector1), 1);
1482 EXPECT_NE(vector1, vector2);
1483
1484 vector1.Reset();
1485 vector1.Insert<VT_I4>(10);
1486 vector2.Reset();
1487 vector2.Insert<VT_R8>(5.0);
1488 // Because the types do not match and VT_I4 is less-than VT_R8,
1489 // |vector1| compares as less-than |vector2|, even though the value
1490 // in |vector1| is greater.
1491 EXPECT_LT(vector1.Type(), vector2.Type());
1492 EXPECT_EQ(vector1.Compare(vector2), -1);
1493 EXPECT_EQ(vector2.Compare(vector1), 1);
1494 EXPECT_NE(vector1, vector2);
1495}
1496
1497} // namespace win
1498} // namespace base
std::optional< LockScope< ElementVartype > > CreateLockScope() const
const VARIANT * ptr() const
void Set(const wchar_t *str)
int Compare(const VARIANT &other, bool ignore_case=false) const
void Insert(typename internal::VariantUtil< ExpectedVartype >::Type value)
int Compare(const VARIANT &other, bool ignore_case=false) const
#define EXPECT_DCHECK_DEATH(statement)
Definition: gtest_util.h:37
TEST(Display, ScaleFactorToFloat)
void Reset(SkPath *path)
Definition: path_ops.cc:40
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678