Make unittests work, new TagBroadcastReceiver
Change-Id: I5a3a1938a7fb91c8114447d24427f2c263bda5a3
This commit is contained in:
@@ -31,6 +31,12 @@
|
||||
|
||||
<activity android:name="TagSelector"></activity>
|
||||
<activity android:name="TagList"></activity>
|
||||
<receiver android:name=".TagBroadcastReceiver">
|
||||
<intent-filter>
|
||||
<action android:name= "com.trustedlogic.trustednfc.android.action.NDEF_TAG_DISCOVERED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
</application>
|
||||
<uses-permission android:name="com.trustedlogic.trustednfc.permission.NFC_NOTIFY"></uses-permission>
|
||||
<uses-permission android:name="com.trustedlogic.trustednfc.permission.NFC_RAW"></uses-permission>
|
||||
|
||||
52
apps/Tag/src/com/android/apps/tag/TagBroadcastReceiver.java
Normal file
52
apps/Tag/src/com/android/apps/tag/TagBroadcastReceiver.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.apps.tag;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.widget.Toast;
|
||||
import com.trustedlogic.trustednfc.android.NdefMessage;
|
||||
import com.trustedlogic.trustednfc.android.NdefRecord;
|
||||
import com.trustedlogic.trustednfc.android.NfcManager;
|
||||
|
||||
/**
|
||||
* This class doesn't work. Sorry. Think of this class as pseudo
|
||||
* code for now.
|
||||
*/
|
||||
public class TagBroadcastReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(NfcManager.NDEF_TAG_DISCOVERED_ACTION)) {
|
||||
NdefMessage msg = intent.getParcelableExtra(NfcManager.NDEF_MESSAGE_EXTRA);
|
||||
Toast.makeText(context, "got a new message", Toast.LENGTH_SHORT).show();
|
||||
insertIntoDb(msg);
|
||||
}
|
||||
}
|
||||
|
||||
private void insertIntoDb(NdefMessage msg) {
|
||||
for (NdefRecord record : msg.getRecords()) {
|
||||
insertIntoRecordDb(record.getType(), record.getPayload());
|
||||
}
|
||||
}
|
||||
|
||||
private void insertIntoRecordDb(byte[] type, byte[] payload) {
|
||||
// do something...
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,18 +27,17 @@ import android.view.Menu;
|
||||
import android.view.View;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SimpleCursorAdapter;
|
||||
import com.trustedlogic.trustednfc.android.NfcManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* @author nnk@google.com (Nick Kralevich)
|
||||
*/
|
||||
public class TagList extends ListActivity implements DialogInterface.OnClickListener {
|
||||
|
||||
private NfcManager mManager;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Toast.makeText(getBaseContext(), "entered method", Toast.LENGTH_SHORT).show();
|
||||
|
||||
SQLiteDatabase db = new TagDBHelper(this.getBaseContext()).getReadableDatabase();
|
||||
Cursor c = db.query("Tags", new String[] { "_id", "description" }, null, null, null, null, null);
|
||||
@@ -51,6 +50,9 @@ public class TagList extends ListActivity implements DialogInterface.OnClickList
|
||||
|
||||
setListAdapter(sca);
|
||||
registerForContextMenu(getListView());
|
||||
c.close();
|
||||
db.close();
|
||||
Toast.makeText(getBaseContext(), "exit method", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.android.apps.tag">
|
||||
package="com.android.apps.tag.tests">
|
||||
|
||||
<!-- We add an application tag here just so that we can indicate that
|
||||
this package needs to link against the android.test library,
|
||||
@@ -25,8 +25,8 @@
|
||||
</application>
|
||||
|
||||
<instrumentation android:name="android.test.InstrumentationTestRunner"
|
||||
android:targetPackage="com.example.android.helloactivity"
|
||||
android:label="HelloActivity sample tests">
|
||||
android:targetPackage="com.android.apps.tag"
|
||||
android:label="Tag tests">
|
||||
</instrumentation>
|
||||
|
||||
</manifest>
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.apps.tag;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
|
||||
/**
|
||||
* @author nnk@google.com (Nick Kralevich)
|
||||
*/
|
||||
public class TagBroadcastReceiverTest extends ActivityInstrumentationTestCase2<Tags> {
|
||||
/**
|
||||
* Creates an {@link ActivityInstrumentationTestCase2} for the {@link Tags} activity.
|
||||
*/
|
||||
public TagBroadcastReceiverTest() {
|
||||
super(Tags.class);
|
||||
}
|
||||
|
||||
public void testWrongMessage() {
|
||||
TagBroadcastReceiver receiver = new TagBroadcastReceiver();
|
||||
Intent i = new Intent().setAction("BOGUS");
|
||||
receiver.onReceive(getActivity().getBaseContext(), i);
|
||||
assertDatabaseNoChange(receiver);
|
||||
}
|
||||
|
||||
private void assertDatabaseNoChange(TagBroadcastReceiver receiver) {
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user