FileDocCategorySizeDatePackage
EventLogFunctionalTest.javaAPI DocAndroid 1.5 API6351Wed May 06 22:42:02 BST 2009android.util

EventLogFunctionalTest

public class EventLogFunctionalTest extends TestCase
Functional tests of EventLog.

Fields Summary
private static final String
TAG
private static final int
TAG_SIZE
private static final int
TYPE_FIELD_SIZE
private static final int
STARTING_POS_OF_PAYLOAD
private static final int
TEST_TAG
private static final int
TEST_TAG2
Constructors Summary
Methods Summary
public voiddisableTestReadCompoundEntry()

        long when = System.currentTimeMillis();
        EventLog.writeEvent(2719,
                new EventLog.List(1l, new EventLog.List("2", "three", "4"), 5));
        Log.i(TAG, "Wrote compound event at T=" + when);

        ArrayList<EventLog.Event> list = new ArrayList<EventLog.Event>();
        EventLog.readEvents(new int[] { 2719 }, list);

        boolean found = false;
        for (EventLog.Event event : list) {
            long eventTime = event.getTimeNanos() / 1000000;
            Log.i(TAG, "  Found event T=" + eventTime);
            if (eventTime > when - 100 && eventTime < when + 1000) {
                EventLog.List data = (EventLog.List) event.getData();
                assertEquals(data.getNumItems(), 3);

                EventLog.List nested = (EventLog.List) data.getItem(1);
                assertEquals(nested.getNumItems(), 3);

                assertEquals(data.getItem(0), 1l);
                assertEquals(nested.getItem(0), "2");
                assertEquals(nested.getItem(1), "three");
                assertEquals(nested.getItem(2), "4");
                assertEquals(data.getItem(2), 5);

                assertFalse(found);
                found = true;
            }
        }

        assertTrue(found);
    
public voiddisableTestReadSimpleEvent()

        long when = System.currentTimeMillis();
        EventLog.writeEvent(2718, 12345);
        Log.i(TAG, "Wrote simple event at T=" + when);

        ArrayList<EventLog.Event> list = new ArrayList<EventLog.Event>();
        EventLog.readEvents(new int[] { 2718 }, list);

        boolean found = false;
        for (EventLog.Event event : list) {
            assertEquals(event.getTag(), 2718);
            long eventTime = event.getTimeNanos() / 1000000;
            Log.i(TAG, "  Found event T=" + eventTime);
            if (eventTime > when - 100 && eventTime < when + 1000) {
                assertEquals(event.getProcessId(), Process.myPid());
                assertEquals(event.getThreadId(), Process.myTid());
                assertEquals(event.getData(), 12345);

                assertFalse(found);
                found = true;
            }
        }

        assertTrue(found);
    
public voidtestEventLargerThanInitialBufferCapacity()

        final Integer[] array = new Integer[127];
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
        }
        final EventLog.List list = new EventLog.List((Object[]) array);
        final int numBytes =  EventLog.writeEvent(TEST_TAG, list);
        Assert.assertEquals(STARTING_POS_OF_PAYLOAD + 1 + (5 * array.length) + 1, numBytes);
    
public voidtestEventLogTagsFile()

        EventLogTags tags = new EventLogTags();
        assertEquals(tags.get("answer").mTag, 42);
        assertEquals(tags.get("pi").mTag, 314);
        assertEquals(tags.get("e").mTag, 2718);
        assertEquals(tags.get(42).mName, "answer");
        assertEquals(tags.get(314).mName, "pi");
        assertEquals(tags.get(2718).mName, "e");
    
public voidtestLogOfListWithEmbeddedList()

        final EventLog.List list = new EventLog.List(
                new EventLog.List(1234, 2345, 3456));
        final int numBytes =  EventLog.writeEvent(TEST_TAG, list);
        Assert.assertEquals(STARTING_POS_OF_PAYLOAD + 2 + 1 + 1 + 4 + 1 + 4 + 1 + 4 + 1, numBytes);
    
public voidtestLogOfListWithMultipleInts()

       final EventLog.List list = new EventLog.List(1234, 2345, 3456);
        final int numBytes =  EventLog.writeEvent(TEST_TAG, list);
        Assert.assertEquals(STARTING_POS_OF_PAYLOAD + 1 + 1 + 4 + 1 + 4 + 1 + 4 + 1, numBytes);
    
public voidtestLogOfListWithOneInt()

        final EventLog.List list = new EventLog.List(1234);
        final int numBytes =  EventLog.writeEvent(TEST_TAG, list);
        Assert.assertEquals(STARTING_POS_OF_PAYLOAD + 1 + 1 + 4 + 1, numBytes);
    
public voidtestLogOfPosInt()


    //todo:  For now all we do is test the returned length.  More to come.
         
        final int numBytes =  EventLog.writeEvent(TEST_TAG, 0x01020304);
        Assert.assertEquals(STARTING_POS_OF_PAYLOAD + 4, numBytes);
    
public voidtestLogOfPosLong()

        final int numBytes =  EventLog.writeEvent(TEST_TAG2, 0x0102030405060708L);
        Assert.assertEquals(STARTING_POS_OF_PAYLOAD + 8, numBytes);
    
public voidtestLogOfString()

        final String valueStr = "foo bar baz";
        final int numBytes =  EventLog.writeEvent(TEST_TAG, valueStr);
        Assert.assertEquals(STARTING_POS_OF_PAYLOAD + 4 + valueStr.length() + 1, numBytes);