blob: 2a9e9cdc7a2d9ba75981cbbf83875e86185a53c3 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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 {
Dan Egnor62136d32010-01-05 19:09:08 -080036 EventLog.writeEvent(TEST_TAG, new Object[]{new Object()});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037 fail("Can't create List with any old Object");
38 } catch (IllegalArgumentException e) {
39 // expected
40 }
41 try {
Dan Egnor62136d32010-01-05 19:09:08 -080042 EventLog.writeEvent(TEST_TAG, new Object[]{(byte) 1});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043 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}