Home | History | Annotate | Download | only in search
      1 /*
      2  * Copyright (C) 2016 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 
     18 package com.android.settings.search;
     19 
     20 import android.content.Intent;
     21 import android.os.Parcel;
     22 import com.android.settings.SettingsRobolectricTestRunner;
     23 import com.android.settings.TestConfig;
     24 import com.android.settings.search2.IntentPayload;
     25 import org.junit.Test;
     26 import org.junit.runner.RunWith;
     27 
     28 import org.robolectric.annotation.Config;
     29 
     30 import static com.google.common.truth.Truth.assertThat;
     31 
     32 @RunWith(SettingsRobolectricTestRunner.class)
     33 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
     34 public class IntentPayloadTest {
     35     private IntentPayload 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 IntentPayload(intent);
     47         mPayload.writeToParcel(parcel, 0);
     48         // Reset parcel for reading
     49         parcel.setDataPosition(0);
     50         IntentPayload newPayload = IntentPayload.CREATOR.createFromParcel(parcel);
     51 
     52         String originalIntentExtra = mPayload.intent.getStringExtra(EXTRA_KEY);
     53         String copiedIntentExtra = newPayload.intent.getStringExtra(EXTRA_KEY);
     54         assertThat(originalIntentExtra).isEqualTo(copiedIntentExtra);
     55     }
     56 }
     57