Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2008 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 package android.view.inputmethod.cts;
     17 
     18 import dalvik.annotation.TestLevel;
     19 import dalvik.annotation.TestTargetClass;
     20 import dalvik.annotation.TestTargetNew;
     21 import dalvik.annotation.TestTargets;
     22 
     23 import android.os.Parcel;
     24 import android.test.AndroidTestCase;
     25 import android.view.inputmethod.ExtractedText;
     26 
     27 @TestTargetClass(ExtractedText.class)
     28 public class ExtractedTextTest extends AndroidTestCase {
     29 
     30     @TestTargets({
     31         @TestTargetNew(
     32             level = TestLevel.COMPLETE,
     33             method = "describeContents",
     34             args = {}
     35         ),
     36         @TestTargetNew(
     37             level = TestLevel.COMPLETE,
     38             method = "writeToParcel",
     39             args = {android.os.Parcel.class, int.class}
     40         )
     41     })
     42     public void testWriteToParcel() {
     43 
     44         ExtractedText extractedText = new ExtractedText();
     45         extractedText.flags = 1;
     46         extractedText.selectionEnd = 11;
     47         extractedText.selectionStart = 2;
     48         extractedText.startOffset = 1;
     49         CharSequence text = "test";
     50         extractedText.text = text;
     51         Parcel p = Parcel.obtain();
     52         extractedText.writeToParcel(p, 0);
     53         p.setDataPosition(0);
     54         ExtractedText target = ExtractedText.CREATOR.createFromParcel(p);
     55         assertEquals(extractedText.flags, target.flags);
     56         assertEquals(extractedText.selectionEnd, target.selectionEnd);
     57         assertEquals(extractedText.selectionStart, target.selectionStart);
     58         assertEquals(extractedText.startOffset, target.startOffset);
     59         assertEquals(extractedText.partialStartOffset, target.partialStartOffset);
     60         assertEquals(extractedText.partialEndOffset, target.partialEndOffset);
     61         assertEquals(extractedText.text.toString(), target.text.toString());
     62 
     63         assertEquals(0, extractedText.describeContents());
     64     }
     65 }
     66