Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2009 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 package android.view.inputmethod.cts;
     18 
     19 import static org.junit.Assert.assertEquals;
     20 import static org.junit.Assert.assertNull;
     21 import static org.mockito.Matchers.anyString;
     22 import static org.mockito.Mockito.atLeastOnce;
     23 import static org.mockito.Mockito.mock;
     24 import static org.mockito.Mockito.verify;
     25 
     26 import android.os.Bundle;
     27 import android.os.LocaleList;
     28 import android.os.Parcel;
     29 import android.support.test.filters.SmallTest;
     30 import android.support.test.runner.AndroidJUnit4;
     31 import android.test.MoreAsserts;
     32 import android.text.TextUtils;
     33 import android.util.Printer;
     34 import android.view.inputmethod.EditorInfo;
     35 
     36 import org.junit.Test;
     37 import org.junit.runner.RunWith;
     38 
     39 @SmallTest
     40 @RunWith(AndroidJUnit4.class)
     41 public class EditorInfoTest {
     42     @Test
     43     public void testEditorInfo() {
     44         EditorInfo info = new EditorInfo();
     45 
     46         info.actionId = 1;
     47         info.actionLabel = "actionLabel";
     48         info.fieldId = 2;
     49         info.fieldName = "fieldName";
     50         info.hintText = "hintText";
     51         info.imeOptions = EditorInfo.IME_FLAG_NO_ENTER_ACTION;
     52         info.initialCapsMode = TextUtils.CAP_MODE_CHARACTERS;
     53         info.initialSelEnd = 10;
     54         info.initialSelStart = 0;
     55         info.inputType = EditorInfo.TYPE_MASK_CLASS;
     56         info.label = "label";
     57         info.packageName = "android.view.cts";
     58         info.privateImeOptions = "privateIme";
     59         Bundle b = new Bundle();
     60         String key = "bundleKey";
     61         String value = "bundleValue";
     62         b.putString(key, value);
     63         info.extras = b;
     64         info.hintLocales = LocaleList.forLanguageTags("en-PH,en-US");
     65         info.contentMimeTypes = new String[]{"image/gif", "image/png"};
     66 
     67         assertEquals(0, info.describeContents());
     68 
     69         Parcel p = Parcel.obtain();
     70         info.writeToParcel(p, 0);
     71         p.setDataPosition(0);
     72         EditorInfo targetInfo = EditorInfo.CREATOR.createFromParcel(p);
     73         p.recycle();
     74         assertEquals(info.actionId, targetInfo.actionId);
     75         assertEquals(info.fieldId, targetInfo.fieldId);
     76         assertEquals(info.fieldName, targetInfo.fieldName);
     77         assertEquals(info.imeOptions, targetInfo.imeOptions);
     78         assertEquals(info.initialCapsMode, targetInfo.initialCapsMode);
     79         assertEquals(info.initialSelEnd, targetInfo.initialSelEnd);
     80         assertEquals(info.initialSelStart, targetInfo.initialSelStart);
     81         assertEquals(info.inputType, targetInfo.inputType);
     82         assertEquals(info.packageName, targetInfo.packageName);
     83         assertEquals(info.privateImeOptions, targetInfo.privateImeOptions);
     84         assertEquals(info.hintText.toString(), targetInfo.hintText.toString());
     85         assertEquals(info.actionLabel.toString(), targetInfo.actionLabel.toString());
     86         assertEquals(info.label.toString(), targetInfo.label.toString());
     87         assertEquals(info.extras.getString(key), targetInfo.extras.getString(key));
     88         assertEquals(info.hintLocales, targetInfo.hintLocales);
     89         MoreAsserts.assertEquals(info.contentMimeTypes, targetInfo.contentMimeTypes);
     90 
     91         Printer printer = mock(Printer.class);
     92         String prefix = "TestEditorInfo";
     93         info.dump(printer, prefix);
     94         verify(printer, atLeastOnce()).println(anyString());
     95     }
     96 
     97     @Test
     98     public void testNullHintLocals() {
     99         EditorInfo info = new EditorInfo();
    100         info.hintLocales = null;
    101         Parcel p = Parcel.obtain();
    102         info.writeToParcel(p, 0);
    103         p.setDataPosition(0);
    104         EditorInfo targetInfo = EditorInfo.CREATOR.createFromParcel(p);
    105         p.recycle();
    106         assertNull(targetInfo.hintLocales);
    107     }
    108 }
    109