Skip to content
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

Add tests for OAVariantLib #101841

Merged
merged 11 commits into from
May 5, 2024
Merged

Conversation

huoyaoyuan
Copy link
Member

Test for #100176.

OAVariantLib.ChangeType will be called when a value is passed from native COM to managed via IDispatch (parameter in ComToClr call, or return value of ClrToCom call, or out value from byref parameter), and the type mismatches from managed signature. The calling order of current behavior is roughly:

  • OleVariant::MarshalObjectForOleVariant, marshals a default managed representation of the VARIANT. Invalid/unsupported VARIANT type will be rejected here and throws InvalidOleVariantTypeException.
  • RuntimeType.ForwardCallToInvokeMember, OleAutBinder.ChangeType in managed code, handles common cases like type already matches, primitive->enum and ref non-primitive->underlying type. It misses the case of ref primitive->underlying type and will always treat it as a type mismatch.
  • OAVariantLib.ChangeType and OAVariant_ChangeType: Convert source value and target type back to VARIANT and VARENUM. Specially handles the case when target is System.Color. Uses a custom mapping logic that's slightly different. Types rejected here will throw NotSupportedException, caught by OleAutBinder.ChangeType and rethrown as COMException(0x80020005).
  • VariantChangeTypeEx. It does the conversion with its own order. Errors will be thrown as-is, typically InvalidCastException.

This PR adds test for:

  • Supported conversions for different positions, including parameter in ComToClr call and return value of ClrToCom call.
  • Different rejected behaviors at each path, only for the return value case.

The test is not exhaustive and try not to exercise of detailed behavior of VariantChangeTypeEx.

@AaronRobinsonMSFT @jkotas

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 3, 2024
@AaronRobinsonMSFT AaronRobinsonMSFT merged commit a225c6f into dotnet:main May 5, 2024
69 checks passed
@huoyaoyuan huoyaoyuan deleted the oavariant-test branch May 5, 2024 04:08
michaelgsharp pushed a commit to michaelgsharp/runtime that referenced this pull request May 9, 2024
* Add native return test for basic supported types

---------

Co-authored-by: Aaron Robinson <arobins@microsoft.com>
Ruihan-Yin pushed a commit to Ruihan-Yin/runtime that referenced this pull request May 30, 2024
* Add native return test for basic supported types

---------

Co-authored-by: Aaron Robinson <arobins@microsoft.com>
@github-actions github-actions bot locked and limited conversation to collaborators Jun 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Interop-coreclr community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants