From 6d27d675a3c405243655b13edb9011473430bdd4 Mon Sep 17 00:00:00 2001 From: Tristan Labelle Date: Sun, 14 Apr 2024 07:00:33 -0400 Subject: [PATCH] Add test for IVector being IIterable. --- tests/test_app/CollectionTests.swift | 5 +++++ tests/test_component/cpp/CollectionTester.cpp | 5 +++++ tests/test_component/cpp/CollectionTester.h | 1 + tests/test_component/cpp/CollectionTester.idl | 1 + 4 files changed, 12 insertions(+) diff --git a/tests/test_app/CollectionTests.swift b/tests/test_app/CollectionTests.swift index 497562c9..0e89d1d2 100644 --- a/tests/test_app/CollectionTests.swift +++ b/tests/test_app/CollectionTests.swift @@ -42,6 +42,10 @@ class CollectionTests : XCTestCase { XCTAssertEqual(vector2[2], "Goodnight") } + public func testArrayVectorIsIterable() throws { + XCTAssertNotNil(try CollectionTester.vectorToIterable(["a", "b", "c"].toVector())) + } + public func testVectorObject_toCallback() throws { let person = Person(firstName: "John", lastName: "Doe", age: 42) let array:[Any?] = [person, "Goodbye", 1] @@ -88,6 +92,7 @@ var collectionTests: [XCTestCaseEntry] = [ ("testVector_asInput", CollectionTests.testVector_asInput), ("testVector_asReturn", CollectionTests.testVector_asReturn), ("testVector_mutate", CollectionTests.testVector_mutate), + ("testArrayVectorIsIterable", CollectionTests.testArrayVectorIsIterable), ("testVectorObject_toCallback", CollectionTests.testVectorObject_toCallback), ]) ] diff --git a/tests/test_component/cpp/CollectionTester.cpp b/tests/test_component/cpp/CollectionTester.cpp index 51279c6f..e88d8a7a 100644 --- a/tests/test_component/cpp/CollectionTester.cpp +++ b/tests/test_component/cpp/CollectionTester.cpp @@ -40,6 +40,11 @@ namespace winrt::test_component::implementation callback(item); } + winrt::Windows::Foundation::Collections::IIterable CollectionTester::VectorAsIterable(winrt::Windows::Foundation::Collections::IVector const& value) + { + return value.as>(); + } + Windows::Foundation::Collections::IVector CollectionTester::ReturnStoredStringVector() { if (m_vector.Size() == 0) diff --git a/tests/test_component/cpp/CollectionTester.h b/tests/test_component/cpp/CollectionTester.h index 46084ed9..cb3881d2 100644 --- a/tests/test_component/cpp/CollectionTester.h +++ b/tests/test_component/cpp/CollectionTester.h @@ -14,6 +14,7 @@ namespace winrt::test_component::implementation static hstring InVector(winrt::Windows::Foundation::Collections::IVector const& value); static hstring InVectorView(winrt::Windows::Foundation::Collections::IVectorView const& value); static void GetObjectAt(winrt::Windows::Foundation::Collections::IVector const& value, uint32_t index, winrt::test_component::ObjectHandler const& callback); + static winrt::Windows::Foundation::Collections::IIterable VectorAsIterable(winrt::Windows::Foundation::Collections::IVector const& value); winrt::Windows::Foundation::Collections::IVector ReturnStoredStringVector(); winrt::Windows::Foundation::Collections::IMap ReturnMapFromStringToString(); diff --git a/tests/test_component/cpp/CollectionTester.idl b/tests/test_component/cpp/CollectionTester.idl index 2e25cb8b..8a3a4cac 100644 --- a/tests/test_component/cpp/CollectionTester.idl +++ b/tests/test_component/cpp/CollectionTester.idl @@ -14,6 +14,7 @@ namespace test_component static String InVector(Windows.Foundation.Collections.IVector value); static String InVectorView(Windows.Foundation.Collections.IVectorView value); static void GetObjectAt(Windows.Foundation.Collections.IVector value, UInt32 index, ObjectHandler callback); + static Windows.Foundation.Collections.IIterable VectorAsIterable(Windows.Foundation.Collections.IVector value); Windows.Foundation.Collections.IVector ReturnStoredStringVector(); Windows.Foundation.Collections.IMap ReturnMapFromStringToString();