Skip to content

Add unit tests for Xamarin.Android.Tools.Aidl.CSharpCodeGenerator#11460

Open
Copilot wants to merge 3 commits into
mainfrom
copilot/add-unit-tests-for-csharpcodegenerator
Open

Add unit tests for Xamarin.Android.Tools.Aidl.CSharpCodeGenerator#11460
Copilot wants to merge 3 commits into
mainfrom
copilot/add-unit-tests-for-csharpcodegenerator

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 22, 2026

CSharpCodeGenerator had limited unit coverage — the existing 6 tests mirrored the MSBuild integration tests in AidlTest.cs, leaving several generator code paths only reachable via expensive MSBuild builds.

Changes

  • AidlCompilerTestBaseRunTest now takes an optional ParcelableHandling so generator behavior under each mode is exercisable.
  • New CSharpCodeGeneratorTests fixture targeting previously-uncovered code paths:
    • ParcelableIgnore / ParcelableStub / ParcelableError — all three ParcelableHandling branches (the StubParcelable method had no coverage).
    • MultipleInterfaces — multiple interface declarations in a single compilation unit.
    • OnewayMethodsoneway methods omit reply.WriteNoException () in OnTransact.
    • IBinderTypesIBinder parameters/returns route through WriteStrongBinder / ReadStrongBinder.
    • CharSequenceTypeCharSequence maps to Java.Lang.ICharSequence via Android.Text.TextUtils.
    • ParseErrorIsReported — invalid AIDL surfaces parser messages with null output.
  • 6 new TestData/*.txt golden files, generated via the existing GENERATE_OUTPUT workflow and inspected.

Example

[Test]
public void ParcelableStub () => RunTest (nameof (ParcelableStub), ParcelableHandling.Stub);

[Test]
public void ParcelableError ()
{
    const string input = "package com.xamarin.test;\nparcelable MyData;\n";
    var compiler = new AidlCompiler ();
    Assert.Throws<InvalidOperationException> (() =>
        compiler.Run (input, out _, parcelableHandling: ParcelableHandling.Error));
}

Note for reviewers

The OnewayMethods golden output captures a pre-existing quirk: the generated Proxy still calls __reply.ReadException () even though the stub side skips reply.WriteNoException (). The test snapshots current behavior rather than asserting correctness; worth a follow-up if intentional asymmetry is not desired.

Copilot AI and others added 2 commits May 22, 2026 22:55
…ce, oneway, IBinder, CharSequence

Agent-Logs-Url: https://github.com/dotnet/android/sessions/324cdc7a-1571-4d01-9842-9dd4c7a8ba2b

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/android/sessions/324cdc7a-1571-4d01-9842-9dd4c7a8ba2b

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copilot AI changed the title [WIP] Add unit tests for Xamarin.Android.Tools.Aidl.CSharpCodeGenerator Add unit tests for Xamarin.Android.Tools.Aidl.CSharpCodeGenerator May 22, 2026
Copilot AI requested a review from jonathanpeppers May 22, 2026 22:56
@jonathanpeppers jonathanpeppers marked this pull request as ready for review May 22, 2026 23:17
Copilot AI review requested due to automatic review settings May 22, 2026 23:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR expands unit test coverage for Xamarin.Android.Tools.Aidl.CSharpCodeGenerator by adding a focused NUnit fixture that validates previously-uncovered generator branches using golden TestData/*.txt snapshots, and by extending the shared test helper to vary ParcelableHandling.

Changes:

  • Extend AidlCompilerTestBase.RunTest to accept an optional ParcelableHandling argument.
  • Add CSharpCodeGeneratorTests covering parcelable modes, multiple interfaces, oneway methods, IBinder, CharSequence, and parse-error reporting.
  • Add golden snapshot files for the new scenarios under tests/.../TestData/.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/Xamarin.Android.Tools.Aidl-Tests/AidlCompilerTestBase.cs Adds ParcelableHandling parameter plumbing to exercise generator modes.
tests/Xamarin.Android.Tools.Aidl-Tests/CSharpCodeGeneratorTests.cs New NUnit fixture targeting specific generator code paths without MSBuild integration tests.
tests/Xamarin.Android.Tools.Aidl-Tests/TestData/ParcelableStub.txt Golden output for ParcelableHandling.Stub.
tests/Xamarin.Android.Tools.Aidl-Tests/TestData/ParcelableIgnore.txt Golden output for ParcelableHandling.Ignore.
tests/Xamarin.Android.Tools.Aidl-Tests/TestData/OnewayMethods.txt Golden output for method-level oneway generation behavior.
tests/Xamarin.Android.Tools.Aidl-Tests/TestData/MultipleInterfaces.txt Golden output for multiple interfaces in one compilation unit.
tests/Xamarin.Android.Tools.Aidl-Tests/TestData/IBinderTypes.txt Golden output for IBinder parameter/return codegen.
tests/Xamarin.Android.Tools.Aidl-Tests/TestData/CharSequenceType.txt Golden output for CharSequence mapping via Android.Text.TextUtils.

@@ -0,0 +1,56 @@
using System;
using System.IO;
[Test]
public void MultipleInterfaces () => RunTest (nameof (MultipleInterfaces));

[Test]
Comment on lines +101 to +105
__data.WriteInterfaceToken (descriptor);
__data.WriteInt (code);
remote.Transact (ITestStub.TransactionFireAndForget, __data, __reply, 0);
__reply.ReadException ();

remote.Transact (ITestStub.TransactionSetBinder, __data, __reply, 0);
__reply.ReadException ();

} finally {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Xamarin.Android.Tools.Aidl.CSharpCodeGenerator needs unit tests.

3 participants