10ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze/* 23746d9e25f2805b16b69eb7420a629fc66f6a788Matthew Fritze * Copyright (C) 2017 The Android Open Source Project 30ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze * 40ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze * Licensed under the Apache License, Version 2.0 (the "License"); 50ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze * you may not use this file except in compliance with the License. 60ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze * You may obtain a copy of the License at 70ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze * 80ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze * http://www.apache.org/licenses/LICENSE-2.0 90ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze * 100ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze * Unless required by applicable law or agreed to in writing, software 110ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze * distributed under the License is distributed on an "AS IS" BASIS, 120ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze * See the License for the specific language governing permissions and 140ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze * limitations under the License. 150ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze * 160ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze */ 170ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze 182078bc2358031ef3a191900d9036daf4251911c1Matthew Fritzepackage com.android.settings.search; 190ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze 2022a39c2b93bc66db71238274a7683d329232d124James Lemieuximport static com.google.common.truth.Truth.assertThat; 2122a39c2b93bc66db71238274a7683d329232d124James Lemieux 220ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritzeimport android.content.Intent; 230ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritzeimport android.os.Parcel; 2422a39c2b93bc66db71238274a7683d329232d124James Lemieux 259f1e911759dc6fedaac9fa65afb79f6a93022bf4Andrew Sappersteinimport com.android.settings.testutils.SettingsRobolectricTestRunner; 269f1e911759dc6fedaac9fa65afb79f6a93022bf4Andrew Sapperstein 270ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritzeimport org.junit.Test; 280ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritzeimport org.junit.runner.RunWith; 290ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze 300ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze@RunWith(SettingsRobolectricTestRunner.class) 313746d9e25f2805b16b69eb7420a629fc66f6a788Matthew Fritzepublic class ResultPayloadTest { 320ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze 3322a39c2b93bc66db71238274a7683d329232d124James Lemieux private static final String EXTRA_KEY = "key"; 3422a39c2b93bc66db71238274a7683d329232d124James Lemieux private static final String EXTRA_VALUE = "value"; 350ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze 360ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze @Test 370ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze public void testParcelOrdering_StaysValid() { 380ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze Intent intent = new Intent(); 390ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze intent.putExtra(EXTRA_KEY, EXTRA_VALUE); 400ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze Parcel parcel = Parcel.obtain(); 410ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze 4222a39c2b93bc66db71238274a7683d329232d124James Lemieux final ResultPayload payload = new ResultPayload(intent); 4322a39c2b93bc66db71238274a7683d329232d124James Lemieux payload.writeToParcel(parcel, 0); 440ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze // Reset parcel for reading 450ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze parcel.setDataPosition(0); 463746d9e25f2805b16b69eb7420a629fc66f6a788Matthew Fritze ResultPayload newPayload = ResultPayload.CREATOR.createFromParcel(parcel); 470ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze 4822a39c2b93bc66db71238274a7683d329232d124James Lemieux String originalIntentExtra = payload.getIntent().getStringExtra(EXTRA_KEY); 493746d9e25f2805b16b69eb7420a629fc66f6a788Matthew Fritze String copiedIntentExtra = newPayload.getIntent().getStringExtra(EXTRA_KEY); 500ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze assertThat(originalIntentExtra).isEqualTo(copiedIntentExtra); 510ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze } 520ed37c351333429f58e1561fcb8e6af9c2041507Matthew Fritze} 53