blob: e9c3058a7bf28494fdc05a220a139205eb840fd2 [file] [log] [blame]
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.view.inputmethod.cts;
import android.os.Bundle;
import android.os.LocaleList;
import android.os.Parcel;
import android.test.AndroidTestCase;
import android.text.TextUtils;
import android.util.Printer;
import android.view.inputmethod.EditorInfo;
public class EditorInfoTest extends AndroidTestCase {
public void testEditorInfo() {
EditorInfo info = new EditorInfo();
info.actionId = 1;
info.actionLabel = "actionLabel";
info.fieldId = 2;
info.fieldName = "fieldName";
info.hintText = "hintText";
info.imeOptions = EditorInfo.IME_FLAG_NO_ENTER_ACTION;
info.initialCapsMode = TextUtils.CAP_MODE_CHARACTERS;
info.initialSelEnd = 10;
info.initialSelStart = 0;
info.inputType = EditorInfo.TYPE_MASK_CLASS;
info.label = "label";
info.packageName = "android.view.cts";
info.privateImeOptions = "privateIme";
Bundle b = new Bundle();
String key = "bundleKey";
String value = "bundleValue";
b.putString(key, value);
info.extras = b;
info.hintLocales = LocaleList.forLanguageTags("en-PH,en-US");
assertEquals(0, info.describeContents());
Parcel p = Parcel.obtain();
info.writeToParcel(p, 0);
p.setDataPosition(0);
EditorInfo targetInfo = EditorInfo.CREATOR.createFromParcel(p);
p.recycle();
assertEquals(info.actionId, targetInfo.actionId);
assertEquals(info.fieldId, targetInfo.fieldId);
assertEquals(info.fieldName, targetInfo.fieldName);
assertEquals(info.imeOptions, targetInfo.imeOptions);
assertEquals(info.initialCapsMode, targetInfo.initialCapsMode);
assertEquals(info.initialSelEnd, targetInfo.initialSelEnd);
assertEquals(info.initialSelStart, targetInfo.initialSelStart);
assertEquals(info.inputType, targetInfo.inputType);
assertEquals(info.packageName, targetInfo.packageName);
assertEquals(info.privateImeOptions, targetInfo.privateImeOptions);
assertEquals(info.hintText.toString(), targetInfo.hintText.toString());
assertEquals(info.actionLabel.toString(), targetInfo.actionLabel.toString());
assertEquals(info.label.toString(), targetInfo.label.toString());
assertEquals(info.extras.getString(key), targetInfo.extras.getString(key));
assertEquals(info.hintLocales, targetInfo.hintLocales);
TestPrinter printer = new TestPrinter();
String prefix = "TestEditorInfo";
info.dump(printer, prefix);
assertTrue(printer.isPrintlnCalled);
}
public void testNullHintLocals() {
EditorInfo info = new EditorInfo();
info.hintLocales = null;
Parcel p = Parcel.obtain();
info.writeToParcel(p, 0);
p.setDataPosition(0);
EditorInfo targetInfo = EditorInfo.CREATOR.createFromParcel(p);
p.recycle();
assertNull(targetInfo.hintLocales);
}
private class TestPrinter implements Printer {
public boolean isPrintlnCalled;
public void println(String x) {
isPrintlnCalled = true;
}
}
}