Sitelet https://github.com/androidx/androidx/pull/896
Skip to content

Run SavedStateTest through platform parceling via platformEncodeDecode - #896

Open
marco-schm wants to merge 1 commit into
androidx:androidx-mainfrom
marco-schm:savedstate-test-platform-encode-decode
Open

marco-schm wants to merge 1 commit into
androidx:androidx-mainfrom
marco-schm:savedstate-test-platform-encode-decode

Conversation

@marco-schm

Copy link
Copy Markdown
Contributor

Proposed Changes

  • Route every state under test in SavedStateTest through an overridable postProcessCreated hook (a no-op by default) by shadowing the top-level savedState factories inside the test class
  • Add a ParceledSavedStateTest subclass (in androidHostTest and androidDeviceTest) that overrides the hook with the existing platformEncodeDecode from SavedStateCodecTestUtils, so all 187 tests additionally run against a state that went through Parcel writing, byte marshalling, and unparceling, matching the treatment the serialization tests already get
  • Convert 8 assertions from reference equality to contentDeepEquals-based structural comparison. The parceled run uncovered that these relied on reference equality of values without structural equals (SavedState/Bundle instances, and arrays inside maps) and only passed because the reader returns the stored instances when no parceling is involved. This matches the approach already used by factory_withSavedState_hasInitialState and the codec tests

Testing

Test: ./gradlew :savedstate:savedstate:testAndroidHostTest

SavedStateTest (187 tests) and ParceledSavedStateTest (187 tests) both pass; full module host suite: 611 tests, 0 failures. The androidDeviceTest sources compile as well.

Issues Fixed

Fixes: b/402141515

The SavedState serialization tests already use platformEncodeDecode to
simulate parceling/unparceling on Android. This applies the same treatment
to SavedStateTest.

SavedStateTest now routes every state under test through an overridable
postProcessCreated hook (a no-op by default) by shadowing the top-level
savedState factories inside the test class. A new ParceledSavedStateTest
subclass (androidHostTest and androidDeviceTest) overrides the hook with
platformEncodeDecode, so all 187 tests additionally run against a state
that went through Parcel writing, byte marshalling, and unparceling.

The parceled run initially uncovered 8 tests whose assertions relied on
reference equality of values without structural equals (SavedState/Bundle
instances, and arrays inside maps), which only passed because the reader
returns the stored instances when no parceling is involved. Those
assertions now use contentDeepEquals-based structural comparison, matching
the approach already used by factory_withSavedState_hasInitialState and the
codec tests.

Test: ./gradlew :savedstate:savedstate:testAndroidHostTest
(SavedStateTest 187 tests and ParceledSavedStateTest 187 tests, all green;
full module host suite: 611 tests, 0 failures)
Fixes: b/402141515

This branch has not been deployed

No deployments
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.

1 participant