Android Open Source - android-nfc-lib Write Geolocation Fails Tests






From Project

Back to project page android-nfc-lib.

License

The source code is released under:

MIT License

If you think the Android project android-nfc-lib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * WriteGeolocationFailsTests.java/* w w w.j  a v a  2 s .c  o m*/
 * NfcLibrary project.
 *
 * Created by : Daneo van Overloop - 17/6/2014.
 *
 * The MIT License (MIT)
 *
 * Copyright (c) 2014 AppFoundry. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 */

package be.appfoundry.nfclibrary.utilities.sync;

import android.content.Intent;
import android.nfc.FormatException;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.test.AndroidTestCase;

import be.appfoundry.nfclibrary.constants.NfcPayloadHeader;
import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
import be.appfoundry.nfclibrary.exceptions.TagNotPresentException;
import be.appfoundry.nfclibrary.utilities.TestUtilities;
import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;

/**
 * NfcLibrary by daneo
 * Created on 14/04/14.
 */
public class WriteGeolocationFailsTests extends AndroidTestCase {
    private TestUtilities mTestUtilities = new TestUtilities();

    // GeoLocation
    public void testWriteGeoLocationFailsNdef() throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
        double latitude = 0, longitude = 0;
        final String ndef = TestUtilities.NDEF;

        performWriteAndChecks(latitude, longitude, ndef,false);
    }

    public void testWriteGeoLocationReadOnlyNdef() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
        double latitude = 0, longitude = 0;
        final String ndef = TestUtilities.NDEF;
        performWriteAndChecks(latitude, longitude, ndef, true);
    }

    public void testWriteGeoLocationNdefFormatable() throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
        double latitude = 0, longitude = 0;
        final String ndefFormatable = TestUtilities.NDEF_FORMATABLE;
        performWriteAndChecks(latitude, longitude, ndefFormatable,false);
    }

    public void testWriteGeoLocationReadOnlyNdefFormatable() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
        double latitude = 0, longitude = 0;
        final String ndefFormatable = TestUtilities.NDEF_FORMATABLE;
        performWriteAndChecks(latitude, longitude, ndefFormatable, true);
    }

    private void performWriteAndChecks(double latitude, double longitude, String ndefFormatable,boolean readonly) throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
        assertFalse(writeGeoLocation(latitude, longitude, ndefFormatable, false));
        assertFalse(mTestUtilities.checkPayloadHeader(NfcPayloadHeader.CUSTOM_SCHEME));
    }

    boolean writeGeoLocation(Double latitude, Double longitude, String technology, boolean readonly) throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
        final Tag mockTag = mTestUtilities.mockTag(technology);

        final Intent intent = new Intent().putExtra(NfcAdapter.EXTRA_TAG, mockTag);
        NfcWriteUtility nfcMessageUtility = mTestUtilities.determineMockType(null);

        return (readonly ? nfcMessageUtility.makeOperationReadOnly().writeGeolocationToTagFromIntent(latitude, longitude, intent) : nfcMessageUtility.writeGeolocationToTagFromIntent(latitude, longitude, intent));
    }
}




Java Source Code List

be.appfoundry.nfclibrary.activities.NfcActivity.java
be.appfoundry.nfclibrary.constants.NfcPayloadHeader.java
be.appfoundry.nfclibrary.constants.NfcType.java
be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException.java
be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException.java
be.appfoundry.nfclibrary.exceptions.TagNotPresentException.java
be.appfoundry.nfclibrary.exceptions.TagNotWritableException.java
be.appfoundry.nfclibrary.implementation.NfcActivity.java
be.appfoundry.nfclibrary.implementation.TestEmptyFieldsNfcActivity.java
be.appfoundry.nfclibrary.implementation.TestFilledFieldsNfcActivity.java
be.appfoundry.nfclibrary.tasks.GenericTask.java
be.appfoundry.nfclibrary.tasks.interfaces.AsyncOperationCallback.java
be.appfoundry.nfclibrary.tasks.interfaces.AsyncUiCallback.java
be.appfoundry.nfclibrary.utilities.TestUtilities.java
be.appfoundry.nfclibrary.utilities.async.AbstractFailsTestsAsync.java
be.appfoundry.nfclibrary.utilities.async.AbstractNfcAsync.java
be.appfoundry.nfclibrary.utilities.async.GenericTaskTestsAsync.java
be.appfoundry.nfclibrary.utilities.async.WriteBluetoothNfcAsync.java
be.appfoundry.nfclibrary.utilities.async.WriteCallbackNfcAsync.java
be.appfoundry.nfclibrary.utilities.async.WriteEmailNfcAsync.java
be.appfoundry.nfclibrary.utilities.async.WriteGeoLocationNfcAsync.java
be.appfoundry.nfclibrary.utilities.async.WritePhoneNfcAsync.java
be.appfoundry.nfclibrary.utilities.async.WriteSmsNfcAsync.java
be.appfoundry.nfclibrary.utilities.async.WriteUriNfcAsync.java
be.appfoundry.nfclibrary.utilities.interfaces.AsyncNfcWriteOperation.java
be.appfoundry.nfclibrary.utilities.interfaces.NdefWrite.java
be.appfoundry.nfclibrary.utilities.interfaces.NfcMessageUtility.java
be.appfoundry.nfclibrary.utilities.interfaces.NfcReadUtility.java
be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility.java
be.appfoundry.nfclibrary.utilities.interfaces.WriteUtility.java
be.appfoundry.nfclibrary.utilities.sync.NdefWriteImpl.java
be.appfoundry.nfclibrary.utilities.sync.NfcMessageUtilityImpl.java
be.appfoundry.nfclibrary.utilities.sync.NfcReadUtilityImpl.java
be.appfoundry.nfclibrary.utilities.sync.NfcWriteUtilityImpl.java
be.appfoundry.nfclibrary.utilities.sync.WriteEmailFailsTests.java
be.appfoundry.nfclibrary.utilities.sync.WriteEmailSucceedsTests.java
be.appfoundry.nfclibrary.utilities.sync.WriteGeolocationFailsTests.java
be.appfoundry.nfclibrary.utilities.sync.WriteGeolocationSucceedsTests.java
be.appfoundry.nfclibrary.utilities.sync.WritePhoneFailsTests.java
be.appfoundry.nfclibrary.utilities.sync.WritePhoneSucceedsTests.java
be.appfoundry.nfclibrary.utilities.sync.WriteUriFailsTests.java
be.appfoundry.nfclibrary.utilities.sync.WriteUriSucceedsTests.java
be.appfoundry.nfclibrary.utilities.sync.WriteUtilityImpl.java