1/* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.util; 18 19import com.google.android.collect.Lists; 20 21import junit.framework.Assert; 22import junit.framework.TestCase; 23 24import java.nio.ByteBuffer; 25import java.nio.ByteOrder; 26 27/** 28 * tests for {@link EventLog} 29 */ 30 31public class EventLogTest extends TestCase { 32 private static final int TEST_TAG = 42; 33 34 public void testIllegalListTypesThrowException() throws Exception { 35 try { 36 EventLog.writeEvent(TEST_TAG, new EventLog.List(new Object())); 37 fail("Can't create List with any old Object"); 38 } catch (IllegalArgumentException e) { 39 // expected 40 } 41 try { 42 EventLog.writeEvent(TEST_TAG, new EventLog.List((byte) 1)); 43 fail("Can't create List with any old byte"); 44 } catch (IllegalArgumentException e) { 45 // expected 46 } 47 } 48 49 void assertIntInByteArrayEquals(int expected, byte[] buf, int pos) { 50 ByteBuffer computedBuf = ByteBuffer.wrap(buf).order(ByteOrder.nativeOrder()); 51 int computed = computedBuf.getInt(pos); 52 Assert.assertEquals(expected, computed); 53 } 54 55 void assertLongInByteArrayEquals(long expected, byte[] buf, int pos) { 56 ByteBuffer computedBuf = ByteBuffer.wrap(buf).order(ByteOrder.nativeOrder()); 57 long computed = computedBuf.getLong(pos); 58 Assert.assertEquals(expected, computed); 59 } 60 61 void assertStringInByteArrayEquals(String expected, byte[] buf, int pos) { 62 byte[] expectedBytes = expected.getBytes(); 63 Assert.assertTrue(expectedBytes.length <= buf.length - pos); 64 for (byte expectedByte : expectedBytes) { 65 Assert.assertEquals(expectedByte, buf[pos++]); 66 } 67 } 68} 69