From 09588f64a280b98eefc22d05fd5ff7916ba9203e Mon Sep 17 00:00:00 2001 From: Nick Pelly Date: Wed, 7 Dec 2011 09:39:26 -0800 Subject: Fix BasicNfcEeTest java package. It was in com.android.nfc_extras, which caused it to get bundled with com.android.nfc_extras.jar, which caused all kinds of confusion when trying to push new versions of the test. It should be in com.android.nfc_extras.tests Also fix getContext() -> getTargetContext(). Change-Id: I1e3afa150809a3ed8c4f88531f039fe7797aca1d --- .../src/com/android/nfc_extras/BasicNfcEeTest.java | 117 --------------------- .../android/nfc_extras/tests/BasicNfcEeTest.java | 117 +++++++++++++++++++++ 2 files changed, 117 insertions(+), 117 deletions(-) delete mode 100644 nfc-extras/tests/src/com/android/nfc_extras/BasicNfcEeTest.java create mode 100644 nfc-extras/tests/src/com/android/nfc_extras/tests/BasicNfcEeTest.java (limited to 'nfc-extras') diff --git a/nfc-extras/tests/src/com/android/nfc_extras/BasicNfcEeTest.java b/nfc-extras/tests/src/com/android/nfc_extras/BasicNfcEeTest.java deleted file mode 100644 index e1025aa..0000000 --- a/nfc-extras/tests/src/com/android/nfc_extras/BasicNfcEeTest.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (C) 2011 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 com.android.nfc_extras; - -import android.content.Context; -import android.nfc.NfcAdapter; -import android.test.InstrumentationTestCase; -import android.util.Log; - -import com.android.nfc_extras.NfcAdapterExtras; -import com.android.nfc_extras.NfcAdapterExtras.CardEmulationRoute; -import com.android.nfc_extras.NfcExecutionEnvironment; - -import java.io.IOException; -import java.util.Arrays; - -public class BasicNfcEeTest extends InstrumentationTestCase { - private Context mContext; - private NfcAdapterExtras mAdapterExtras; - private NfcExecutionEnvironment mEe; - - public static final byte[] SELECT_CARD_MANAGER_COMMAND = new byte[] { - (byte)0x00, (byte)0xA4, (byte)0x04, (byte)0x00, // command - (byte)0x08, // data length - (byte)0xA0, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x03, (byte)0x00, (byte)0x00, - (byte)0x00, // card manager AID - (byte)0x00 // trailer - }; - - public static final byte[] SELECT_CARD_MANAGER_RESPONSE = new byte[] { - (byte)0x90, (byte)0x00, - }; - - @Override - protected void setUp() throws Exception { - super.setUp(); - mContext = getInstrumentation().getContext(); - mAdapterExtras = NfcAdapterExtras.get(NfcAdapter.getDefaultAdapter(mContext)); - mEe = mAdapterExtras.getEmbeddedExecutionEnvironment(); - } - - public void testSendCardManagerApdu() throws IOException { - mEe.open(); - - try { - byte[] out = mEe.transceive(SELECT_CARD_MANAGER_COMMAND); - assertTrue(out.length >= SELECT_CARD_MANAGER_RESPONSE.length); - byte[] trailing = Arrays.copyOfRange(out, - out.length - SELECT_CARD_MANAGER_RESPONSE.length, - out.length); - assertByteArrayEquals(SELECT_CARD_MANAGER_RESPONSE, trailing); - - } finally { - mEe.close(); - } - - } - - public void testSendCardManagerApduMultiple() throws IOException { - for (int i=0; i<10; i++) { - try { - mEe.open(); - - try { - byte[] out = mEe.transceive(SELECT_CARD_MANAGER_COMMAND); - byte[] trailing = Arrays.copyOfRange(out, - out.length - SELECT_CARD_MANAGER_RESPONSE.length, - out.length); - - } finally { - try {Thread.sleep(1000);} catch (InterruptedException e) {} - mEe.close(); - } - } catch (IOException e) {} - } - - testSendCardManagerApdu(); - - } - - public void testEnableEe() { - mAdapterExtras.setCardEmulationRoute( - new CardEmulationRoute(CardEmulationRoute.ROUTE_ON_WHEN_SCREEN_ON, mEe)); - CardEmulationRoute newRoute = mAdapterExtras.getCardEmulationRoute(); - assertEquals(CardEmulationRoute.ROUTE_ON_WHEN_SCREEN_ON, newRoute.route); - assertEquals(mEe, newRoute.nfcEe); - } - - public void testDisableEe() { - mAdapterExtras.setCardEmulationRoute( - new CardEmulationRoute(CardEmulationRoute.ROUTE_OFF, null)); - CardEmulationRoute newRoute = mAdapterExtras.getCardEmulationRoute(); - assertEquals(CardEmulationRoute.ROUTE_OFF, newRoute.route); - assertNull(newRoute.nfcEe); - } - - private static void assertByteArrayEquals(byte[] b1, byte[] b2) { - assertEquals(b1.length, b2.length); - for (int i = 0; i < b1.length; i++) { - assertEquals(b1[i], b2[i]); - } - } -} diff --git a/nfc-extras/tests/src/com/android/nfc_extras/tests/BasicNfcEeTest.java b/nfc-extras/tests/src/com/android/nfc_extras/tests/BasicNfcEeTest.java new file mode 100644 index 0000000..389dfbe --- /dev/null +++ b/nfc-extras/tests/src/com/android/nfc_extras/tests/BasicNfcEeTest.java @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2011 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 com.android.nfc_extras.tests; + +import android.content.Context; +import android.nfc.NfcAdapter; +import android.test.InstrumentationTestCase; +import android.util.Log; + +import com.android.nfc_extras.NfcAdapterExtras; +import com.android.nfc_extras.NfcAdapterExtras.CardEmulationRoute; +import com.android.nfc_extras.NfcExecutionEnvironment; + +import java.io.IOException; +import java.util.Arrays; + +public class BasicNfcEeTest extends InstrumentationTestCase { + private Context mContext; + private NfcAdapterExtras mAdapterExtras; + private NfcExecutionEnvironment mEe; + + public static final byte[] SELECT_CARD_MANAGER_COMMAND = new byte[] { + (byte)0x00, (byte)0xA4, (byte)0x04, (byte)0x00, // command + (byte)0x08, // data length + (byte)0xA0, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x03, (byte)0x00, (byte)0x00, + (byte)0x00, // card manager AID + (byte)0x00 // trailer + }; + + public static final byte[] SELECT_CARD_MANAGER_RESPONSE = new byte[] { + (byte)0x90, (byte)0x00, + }; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mContext = getInstrumentation().getTargetContext(); + mAdapterExtras = NfcAdapterExtras.get(NfcAdapter.getDefaultAdapter(mContext)); + mEe = mAdapterExtras.getEmbeddedExecutionEnvironment(); + } + + public void testSendCardManagerApdu() throws IOException { + mEe.open(); + + try { + byte[] out = mEe.transceive(SELECT_CARD_MANAGER_COMMAND); + assertTrue(out.length >= SELECT_CARD_MANAGER_RESPONSE.length); + byte[] trailing = Arrays.copyOfRange(out, + out.length - SELECT_CARD_MANAGER_RESPONSE.length, + out.length); + assertByteArrayEquals(SELECT_CARD_MANAGER_RESPONSE, trailing); + + } finally { + mEe.close(); + } + + } + + public void testSendCardManagerApduMultiple() throws IOException { + for (int i=0; i<10; i++) { + try { + mEe.open(); + + try { + byte[] out = mEe.transceive(SELECT_CARD_MANAGER_COMMAND); + byte[] trailing = Arrays.copyOfRange(out, + out.length - SELECT_CARD_MANAGER_RESPONSE.length, + out.length); + + } finally { + try {Thread.sleep(1000);} catch (InterruptedException e) {} + mEe.close(); + } + } catch (IOException e) {} + } + + testSendCardManagerApdu(); + + } + + public void testEnableEe() { + mAdapterExtras.setCardEmulationRoute( + new CardEmulationRoute(CardEmulationRoute.ROUTE_ON_WHEN_SCREEN_ON, mEe)); + CardEmulationRoute newRoute = mAdapterExtras.getCardEmulationRoute(); + assertEquals(CardEmulationRoute.ROUTE_ON_WHEN_SCREEN_ON, newRoute.route); + assertEquals(mEe, newRoute.nfcEe); + } + + public void testDisableEe() { + mAdapterExtras.setCardEmulationRoute( + new CardEmulationRoute(CardEmulationRoute.ROUTE_OFF, null)); + CardEmulationRoute newRoute = mAdapterExtras.getCardEmulationRoute(); + assertEquals(CardEmulationRoute.ROUTE_OFF, newRoute.route); + assertNull(newRoute.nfcEe); + } + + private static void assertByteArrayEquals(byte[] b1, byte[] b2) { + assertEquals(b1.length, b2.length); + for (int i = 0; i < b1.length; i++) { + assertEquals(b1[i], b2[i]); + } + } +} -- cgit v1.1