Skip to content

Added object identity test #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion tests/TestArtifacts/TestComponent.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] };
Expand Down Expand Up @@ -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;
}

}
10 changes: 10 additions & 0 deletions tests/WinRTTests/BasicFunctionTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
];
}

Expand Down Expand Up @@ -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.isTrue(testObject === testObjectAsSerializable);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With WinRT objects, assert.equal doesn't quite work as you'd expect. Instead do an assert.isTrue(lhs == rhs);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW it tries to do property comparison instead of pointer comparison IIRC

}
10 changes: 10 additions & 0 deletions tests/WinRTTests/windows/TestComponent/Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
10 changes: 9 additions & 1 deletion tests/WinRTTests/windows/TestComponent/TestComponent.idl
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,22 @@ namespace TestComponent
BooleanTypes Bools;
};

[contract(TestContract, 1)]
interface ISerializable
{
String Serialize();
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
};
}


// 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
Expand Down