1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18package com.android.settings.search;
19
20import android.content.Intent;
21import android.os.Parcel;
22import com.android.settings.testutils.SettingsRobolectricTestRunner;
23import com.android.settings.TestConfig;
24
25import org.junit.Test;
26import org.junit.runner.RunWith;
27
28import org.robolectric.annotation.Config;
29
30import static com.google.common.truth.Truth.assertThat;
31
32@RunWith(SettingsRobolectricTestRunner.class)
33@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
34public class ResultPayloadTest {
35    private ResultPayload mPayload;
36
37    private final String EXTRA_KEY = "key";
38    private final String EXTRA_VALUE = "value";
39
40    @Test
41    public void testParcelOrdering_StaysValid() {
42        Intent intent = new Intent();
43        intent.putExtra(EXTRA_KEY, EXTRA_VALUE);
44        Parcel parcel = Parcel.obtain();
45
46        mPayload = new ResultPayload(intent);
47        mPayload.writeToParcel(parcel, 0);
48        // Reset parcel for reading
49        parcel.setDataPosition(0);
50        ResultPayload newPayload = ResultPayload.CREATOR.createFromParcel(parcel);
51
52        String originalIntentExtra = mPayload.getIntent().getStringExtra(EXTRA_KEY);
53        String copiedIntentExtra = newPayload.getIntent().getStringExtra(EXTRA_KEY);
54        assertThat(originalIntentExtra).isEqualTo(copiedIntentExtra);
55    }
56}
57