Add NDEF smoke tests.

Change-Id: I00009c29fb297f7fe6c9d290ac295078ce67ece5
diff --git a/CtsTestCaseList.mk b/CtsTestCaseList.mk
index 9e3f0a5..60e6858 100644
--- a/CtsTestCaseList.mk
+++ b/CtsTestCaseList.mk
@@ -44,6 +44,7 @@
 	CtsJniTestCases \
 	CtsLocationTestCases \
 	CtsMediaTestCases \
+	CtsNdefTestCases \
 	CtsOsTestCases \
 	CtsPermissionTestCases \
 	CtsPermission2TestCases \
diff --git a/tests/tests/ndef/Android.mk b/tests/tests/ndef/Android.mk
new file mode 100644
index 0000000..4cb0b78
--- /dev/null
+++ b/tests/tests/ndef/Android.mk
@@ -0,0 +1,34 @@
+# 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.
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_PACKAGE_NAME := CtsNdefTestCases
+
+# Don't include this package in any target.
+LOCAL_MODULE_TAGS := optional
+
+# When built, explicitly put it in the data partition.
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+# All tests should include android.test.runner.
+LOCAL_JAVA_LIBRARIES := android.test.runner
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_PACKAGE)
diff --git a/tests/tests/ndef/AndroidManifest.xml b/tests/tests/ndef/AndroidManifest.xml
new file mode 100644
index 0000000..4a65818
--- /dev/null
+++ b/tests/tests/ndef/AndroidManifest.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.android.cts.ndef">
+
+    <application>
+        <uses-library android:name="android.test.runner" />
+    </application>
+
+    <!-- This is a self-instrumenting test package. -->
+    <instrumentation android:name="android.test.InstrumentationTestRunner"
+                     android:targetPackage="com.android.cts.ndef"
+                     android:label="CTS tests of NDEF data classes"/>
+
+</manifest>
+
diff --git a/tests/tests/ndef/src/android/ndef/cts/BasicNdefTest.java b/tests/tests/ndef/src/android/ndef/cts/BasicNdefTest.java
new file mode 100644
index 0000000..6e2ac3c
--- /dev/null
+++ b/tests/tests/ndef/src/android/ndef/cts/BasicNdefTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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 android.ndef.cts;
+
+import android.nfc.NdefMessage;
+import android.nfc.NdefRecord;
+import android.nfc.FormatException;
+
+import junit.framework.TestCase;
+
+public class BasicNdefTest extends TestCase {
+    /**
+     * A Smart Poster containing a URL and no text.
+     */
+    public static final byte[] SMART_POSTER_URL_NO_TEXT = new byte[] {
+            (byte) 0xd1, (byte) 0x02, (byte) 0x0f, (byte) 0x53, (byte) 0x70, (byte) 0xd1,
+            (byte) 0x01, (byte) 0x0b, (byte) 0x55, (byte) 0x01, (byte) 0x67, (byte) 0x6f,
+            (byte) 0x6f, (byte) 0x67, (byte) 0x6c, (byte) 0x65, (byte) 0x2e, (byte) 0x63,
+            (byte) 0x6f, (byte) 0x6d
+    };
+
+    public void test_parseSmartPoster() throws FormatException {
+        NdefMessage msg = new NdefMessage(SMART_POSTER_URL_NO_TEXT);
+        NdefRecord[] records = msg.getRecords();
+
+        assertEquals(1, records.length);
+
+        assertEquals(0, records[0].getId().length);
+
+        assertEquals(NdefRecord.TNF_WELL_KNOWN, records[0].getTnf());
+
+        assertByteArrayEquals(NdefRecord.RTD_SMART_POSTER, records[0].getType());
+
+        assertByteArrayEquals(new byte[] {
+                (byte) 0xd1, (byte) 0x01, (byte) 0x0b, (byte) 0x55, (byte) 0x01,
+                (byte) 0x67, (byte) 0x6f, (byte) 0x6f, (byte) 0x67, (byte) 0x6c,
+                (byte) 0x65, (byte) 0x2e, (byte) 0x63, (byte) 0x6f, (byte) 0x6d},
+                records[0].getPayload());
+    }
+
+    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]);
+        }
+    }
+}