FileDocCategorySizeDatePackage
TestCad.javaAPI DocphoneME MR2 API (J2ME)3378Wed May 02 18:00:36 BST 2007com.sun.midp.io.j2me.apdu

TestCad

public class TestCad extends com.sun.midp.i3test.TestCase
This test case tests basic com.sun.midp.io.j2me.apdu.Cad class functionality.

Fields Summary
Constructors Summary
Methods Summary
public voidassertNotEmpty(java.lang.String message, byte[] arr)
Tests if array arr is not empty.

param
message Message to say if array is empty.
param
arr Array to test.


        boolean is_null = true;
        
        if (arr != null) {
            for (int i = 0; i < arr.length; i++) {
                if (arr[i] != (byte)0) {
                    is_null = false;
                }
            }
        }
        assertFalse(message, is_null);
    
public voidrunTests()
Run tests.

        try {
            declare("testCad");
            testCad();

        }
        catch (Throwable t) {
            fail("" + t);
        }
    
private voidtestCad()
Test class creation and initialization.


        boolean stub_flag = false;
        
        try {
            SlotFactory.init();
        } 
        catch (CardDeviceException e) {
            if (e.getMessage().equals("stub")) {
                stub_flag = true;
            } else {
                throw e;
            }
        }

        if (!stub_flag) {
            int slot = 0;
            SecurityToken token = null;
            Cad cad = new Cad(slot, token);
            byte[] request = {
                (byte)0x00, (byte)0xA4, 
                    (byte)0x04, (byte)0x00, (byte)0x08,
                (byte)0xA0, (byte)0x00, (byte)0x00, 
                (byte)0x00, (byte)0x18, (byte)0x43, 
                (byte)0x4D, (byte)0x00, (byte)0x3F};
            
            int channel = cad.selectApplication(false, request);
            assertTrue(true);
    
            byte[] atr = cad.getATR();
            assertNotEmpty("Empty ATR", atr);
        } else {
            assertTrue(true);
        }