Loading tests/src/com/android/server/telecom/tests/unit/PhoneAccountRegistrarTest.java +56 −6 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Parcel; import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; import android.test.AndroidTestCase; Loading @@ -39,9 +40,11 @@ import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.util.Arrays; public class PhoneAccountRegistrarTest extends AndroidTestCase { private static final int MAX_VERSION = Integer.MAX_VALUE; private static final String FILE_NAME = "phone-account-registrar-test.xml"; private PhoneAccountRegistrar mRegistrar; Loading @@ -58,12 +61,12 @@ public class PhoneAccountRegistrarTest extends AndroidTestCase { public void testPhoneAccountHandle() throws Exception { PhoneAccountHandle input = new PhoneAccountHandle(new ComponentName("pkg0", "cls0"), "id0"); PhoneAccountHandle result = roundTrip(this, input, PhoneAccountHandle result = roundTripXml(this, input, PhoneAccountRegistrar.sPhoneAccountHandleXml, mContext); assertPhoneAccountHandleEquals(input, result); PhoneAccountHandle inputN = new PhoneAccountHandle(new ComponentName("pkg0", "cls0"), null); PhoneAccountHandle resultN = roundTrip(this, inputN, PhoneAccountHandle resultN = roundTripXml(this, inputN, PhoneAccountRegistrar.sPhoneAccountHandleXml, mContext); Log.i(this, "inputN = %s, resultN = %s", inputN, resultN); assertPhoneAccountHandleEquals(inputN, resultN); Loading @@ -74,14 +77,15 @@ public class PhoneAccountRegistrarTest extends AndroidTestCase { .addSupportedUriScheme(PhoneAccount.SCHEME_TEL) .addSupportedUriScheme(PhoneAccount.SCHEME_VOICEMAIL) .build(); PhoneAccount result = roundTrip(this, input, PhoneAccountRegistrar.sPhoneAccountXml, PhoneAccount result = roundTripXml(this, input, PhoneAccountRegistrar.sPhoneAccountXml, mContext); assertPhoneAccountEquals(input, result); } public void testState() throws Exception { PhoneAccountRegistrar.State input = makeQuickState(); PhoneAccountRegistrar.State result = roundTrip(this, input, PhoneAccountRegistrar.sStateXml, PhoneAccountRegistrar.State result = roundTripXml(this, input, PhoneAccountRegistrar.sStateXml, mContext); assertStateEquals(input, result); } Loading Loading @@ -184,6 +188,38 @@ public class PhoneAccountRegistrarTest extends AndroidTestCase { assertNull(mRegistrar.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL)); } public void testPhoneAccountParceling() throws Exception { PhoneAccountHandle handle = makeQuickAccountHandle("foo"); roundTripPhoneAccount(new PhoneAccount.Builder(handle, null).build()); roundTripPhoneAccount(new PhoneAccount.Builder(handle, "foo").build()); roundTripPhoneAccount( new PhoneAccount.Builder(handle, "foo") .setAddress(Uri.parse("tel:123456")) .setCapabilities(23) .setHighlightColor(0xf0f0f0) .setIcon( "com.android.server.telecom.tests", R.drawable.stat_sys_phone_call, 0xfefefe) .setShortDescription("short description") .setSubscriptionAddress(Uri.parse("tel:2345678")) .setSupportedUriSchemes(Arrays.asList("tel", "sip")) .build()); roundTripPhoneAccount( new PhoneAccount.Builder(handle, "foo") .setAddress(Uri.parse("tel:123456")) .setCapabilities(23) .setHighlightColor(0xf0f0f0) .setIcon( BitmapFactory.decodeResource( getContext().getResources(), R.drawable.stat_sys_phone_call)) .setShortDescription("short description") .setSubscriptionAddress(Uri.parse("tel:2345678")) .setSupportedUriSchemes(Arrays.asList("tel", "sip")) .build()); } private static PhoneAccountHandle makeQuickAccountHandle(String id) { return new PhoneAccountHandle( new ComponentName( Loading @@ -209,7 +245,21 @@ public class PhoneAccountRegistrarTest extends AndroidTestCase { .build(); } private static <T> T roundTrip( private static void roundTripPhoneAccount(PhoneAccount original) throws Exception { PhoneAccount copy = null; { Parcel parcel = Parcel.obtain(); parcel.writeParcelable(original, 0); parcel.setDataPosition(0); copy = parcel.readParcelable(PhoneAccountRegistrarTest.class.getClassLoader()); parcel.recycle(); } assertPhoneAccountEquals(original, copy); } private static <T> T roundTripXml( Object self, T input, PhoneAccountRegistrar.XmlSerialization<T> xml, Loading @@ -234,7 +284,7 @@ public class PhoneAccountRegistrarTest extends AndroidTestCase { XmlPullParser parser = Xml.newPullParser(); parser.setInput(new BufferedInputStream(new ByteArrayInputStream(data)), null); parser.nextTag(); result = xml.readFromXml(parser, 0, context); result = xml.readFromXml(parser, MAX_VERSION, context); } Log.d(self, "result = " + result); Loading Loading
tests/src/com/android/server/telecom/tests/unit/PhoneAccountRegistrarTest.java +56 −6 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Parcel; import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; import android.test.AndroidTestCase; Loading @@ -39,9 +40,11 @@ import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.util.Arrays; public class PhoneAccountRegistrarTest extends AndroidTestCase { private static final int MAX_VERSION = Integer.MAX_VALUE; private static final String FILE_NAME = "phone-account-registrar-test.xml"; private PhoneAccountRegistrar mRegistrar; Loading @@ -58,12 +61,12 @@ public class PhoneAccountRegistrarTest extends AndroidTestCase { public void testPhoneAccountHandle() throws Exception { PhoneAccountHandle input = new PhoneAccountHandle(new ComponentName("pkg0", "cls0"), "id0"); PhoneAccountHandle result = roundTrip(this, input, PhoneAccountHandle result = roundTripXml(this, input, PhoneAccountRegistrar.sPhoneAccountHandleXml, mContext); assertPhoneAccountHandleEquals(input, result); PhoneAccountHandle inputN = new PhoneAccountHandle(new ComponentName("pkg0", "cls0"), null); PhoneAccountHandle resultN = roundTrip(this, inputN, PhoneAccountHandle resultN = roundTripXml(this, inputN, PhoneAccountRegistrar.sPhoneAccountHandleXml, mContext); Log.i(this, "inputN = %s, resultN = %s", inputN, resultN); assertPhoneAccountHandleEquals(inputN, resultN); Loading @@ -74,14 +77,15 @@ public class PhoneAccountRegistrarTest extends AndroidTestCase { .addSupportedUriScheme(PhoneAccount.SCHEME_TEL) .addSupportedUriScheme(PhoneAccount.SCHEME_VOICEMAIL) .build(); PhoneAccount result = roundTrip(this, input, PhoneAccountRegistrar.sPhoneAccountXml, PhoneAccount result = roundTripXml(this, input, PhoneAccountRegistrar.sPhoneAccountXml, mContext); assertPhoneAccountEquals(input, result); } public void testState() throws Exception { PhoneAccountRegistrar.State input = makeQuickState(); PhoneAccountRegistrar.State result = roundTrip(this, input, PhoneAccountRegistrar.sStateXml, PhoneAccountRegistrar.State result = roundTripXml(this, input, PhoneAccountRegistrar.sStateXml, mContext); assertStateEquals(input, result); } Loading Loading @@ -184,6 +188,38 @@ public class PhoneAccountRegistrarTest extends AndroidTestCase { assertNull(mRegistrar.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL)); } public void testPhoneAccountParceling() throws Exception { PhoneAccountHandle handle = makeQuickAccountHandle("foo"); roundTripPhoneAccount(new PhoneAccount.Builder(handle, null).build()); roundTripPhoneAccount(new PhoneAccount.Builder(handle, "foo").build()); roundTripPhoneAccount( new PhoneAccount.Builder(handle, "foo") .setAddress(Uri.parse("tel:123456")) .setCapabilities(23) .setHighlightColor(0xf0f0f0) .setIcon( "com.android.server.telecom.tests", R.drawable.stat_sys_phone_call, 0xfefefe) .setShortDescription("short description") .setSubscriptionAddress(Uri.parse("tel:2345678")) .setSupportedUriSchemes(Arrays.asList("tel", "sip")) .build()); roundTripPhoneAccount( new PhoneAccount.Builder(handle, "foo") .setAddress(Uri.parse("tel:123456")) .setCapabilities(23) .setHighlightColor(0xf0f0f0) .setIcon( BitmapFactory.decodeResource( getContext().getResources(), R.drawable.stat_sys_phone_call)) .setShortDescription("short description") .setSubscriptionAddress(Uri.parse("tel:2345678")) .setSupportedUriSchemes(Arrays.asList("tel", "sip")) .build()); } private static PhoneAccountHandle makeQuickAccountHandle(String id) { return new PhoneAccountHandle( new ComponentName( Loading @@ -209,7 +245,21 @@ public class PhoneAccountRegistrarTest extends AndroidTestCase { .build(); } private static <T> T roundTrip( private static void roundTripPhoneAccount(PhoneAccount original) throws Exception { PhoneAccount copy = null; { Parcel parcel = Parcel.obtain(); parcel.writeParcelable(original, 0); parcel.setDataPosition(0); copy = parcel.readParcelable(PhoneAccountRegistrarTest.class.getClassLoader()); parcel.recycle(); } assertPhoneAccountEquals(original, copy); } private static <T> T roundTripXml( Object self, T input, PhoneAccountRegistrar.XmlSerialization<T> xml, Loading @@ -234,7 +284,7 @@ public class PhoneAccountRegistrarTest extends AndroidTestCase { XmlPullParser parser = Xml.newPullParser(); parser.setInput(new BufferedInputStream(new ByteArrayInputStream(data)), null); parser.nextTag(); result = xml.readFromXml(parser, 0, context); result = xml.readFromXml(parser, MAX_VERSION, context); } Log.d(self, "result = " + result); Loading