From db26615d27e2b742e50edb0960639e4f7c8daeca Mon Sep 17 00:00:00 2001 From: UJJWAL CHADHA Date: Wed, 28 Apr 2021 15:59:37 -0700 Subject: [PATCH 1/3] Added object identity test --- tests/WinRTTests/BasicFunctionTests.js | 10 ++++++++++ tests/WinRTTests/windows/TestComponent/Test.h | 10 ++++++++++ .../WinRTTests/windows/TestComponent/TestComponent.idl | 10 +++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/WinRTTests/BasicFunctionTests.js b/tests/WinRTTests/BasicFunctionTests.js index a251f74..1f347b2 100644 --- a/tests/WinRTTests/BasicFunctionTests.js +++ b/tests/WinRTTests/BasicFunctionTests.js @@ -81,6 +81,8 @@ export function makeBasicFunctionTestScenarios(pThis) { //Static methods for non activable classes new TestScenario('StaticOnlyTest::CopyString', runStaticMethodForNonActivableMethod.bind(pThis)), + + new TestScenario('Object Identity', runObjectIdentityTest.bind(pThis)), ]; } @@ -672,4 +674,12 @@ function runStaticMethodForNonActivableMethod(scenario) { this.runSync(scenario, () => { assert.equal("Hello", TestComponent.StaticOnlyTest.copyString("Hello")); }); +} + +function runObjectIdentityTest(scenario) { + this.runSync(scenario, () => { + const testObject = new TestComponent.TestObject(2); + const testObjectAsSerializable = testObject.asSerializable(); + assert.equal(testObject, testObjectAsSerializable); + }); } \ No newline at end of file diff --git a/tests/WinRTTests/windows/TestComponent/Test.h b/tests/WinRTTests/windows/TestComponent/Test.h index 60d18b8..09c3a25 100644 --- a/tests/WinRTTests/windows/TestComponent/Test.h +++ b/tests/WinRTTests/windows/TestComponent/Test.h @@ -16,6 +16,16 @@ namespace winrt::TestComponent::implementation return m_value; } + winrt::hstring Serialize() + { + return L"TestObject:::" + winrt::to_hstring(m_value); + } + + ISerializable AsSerializable() + { + return *this; + } + private: int32_t m_value; }; diff --git a/tests/WinRTTests/windows/TestComponent/TestComponent.idl b/tests/WinRTTests/windows/TestComponent/TestComponent.idl index 09593aa..3662271 100644 --- a/tests/WinRTTests/windows/TestComponent/TestComponent.idl +++ b/tests/WinRTTests/windows/TestComponent/TestComponent.idl @@ -59,14 +59,22 @@ namespace TestComponent BooleanTypes Bools; }; + [contract(TestContract, 1)] + interface ISerializable + { + String Serialize(); + }; + // Used in places where we want to validate returning/accepting/etc. types of an object type [contract(TestContract, 1)] - runtimeclass TestObject + runtimeclass TestObject : ISerializable { // This is purposefully not no-arg constructible so that we get compilation errors if the code gen gets this wrong TestObject(Int32 val); Int32 Value{ get; }; + + ISerializable AsSerializable(); } // Delegates From 1678453ab4d34bbb11f8f9f7ac51809e8ba460e5 Mon Sep 17 00:00:00 2001 From: UJJWAL CHADHA Date: Wed, 28 Apr 2021 16:02:05 -0700 Subject: [PATCH 2/3] Added generated typescript --- tests/TestArtifacts/TestComponent.d.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/TestArtifacts/TestComponent.d.ts b/tests/TestArtifacts/TestComponent.d.ts index ed5a12c..72920ce 100644 --- a/tests/TestArtifacts/TestComponent.d.ts +++ b/tests/TestArtifacts/TestComponent.d.ts @@ -58,6 +58,10 @@ declare namespace TestComponent { overloadedHierarchyBaseMethod(param1: string, param2: string): string; } + interface ISerializable { + serialize(): string; + } + type InterwovenDelegate = (inBool: boolean, inNumeric: number, inArray: number[]) => { outBool: boolean; outNumeric: number; outArray: number[]; fillArray: number[]; returnValue: number }; type NumericArrayDelegate = (values: number[]) => { subset: number[]; outValue: number[]; returnValue: number[] }; @@ -450,9 +454,11 @@ declare namespace TestComponent { fourth, } - class TestObject { + class TestObject implements TestComponent.ISerializable { readonly value: number; constructor(val: number); + asSerializable(): TestComponent.ISerializable; + serialize(): string; } } \ No newline at end of file From d8df863abcbc5ac34037338a92e7cb7645b78376 Mon Sep 17 00:00:00 2001 From: UJJWAL CHADHA Date: Wed, 28 Apr 2021 17:23:51 -0700 Subject: [PATCH 3/3] Assertion fix --- tests/WinRTTests/BasicFunctionTests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/WinRTTests/BasicFunctionTests.js b/tests/WinRTTests/BasicFunctionTests.js index 1f347b2..78e5c81 100644 --- a/tests/WinRTTests/BasicFunctionTests.js +++ b/tests/WinRTTests/BasicFunctionTests.js @@ -680,6 +680,6 @@ function runObjectIdentityTest(scenario) { this.runSync(scenario, () => { const testObject = new TestComponent.TestObject(2); const testObjectAsSerializable = testObject.asSerializable(); - assert.equal(testObject, testObjectAsSerializable); + assert.isTrue(testObject === testObjectAsSerializable); }); } \ No newline at end of file