1 /* 2 * Copyright (C) 2017 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 17 package com.android.car; 18 19 import android.test.AndroidTestCase; 20 import android.test.suitebuilder.annotation.SmallTest; 21 22 import java.util.Arrays; 23 import java.util.Map; 24 25 @SmallTest 26 public class VmsPublishersInfoTest extends AndroidTestCase { 27 public static final byte[] MOCK_INFO_0 = new byte[]{2, 3, 5, 7, 11, 13, 17}; 28 public static final byte[] SAME_MOCK_INFO_0 = new byte[]{2, 3, 5, 7, 11, 13, 17}; 29 public static final byte[] MOCK_INFO_1 = new byte[]{2, 3, 5, 7, 11, 13, 17, 19}; 30 31 private VmsPublishersInfo mVmsPublishersInfo; 32 33 @Override 34 protected void setUp() throws Exception { 35 super.setUp(); 36 mVmsPublishersInfo = new VmsPublishersInfo(); 37 } 38 39 // Test one info sanity 40 public void testSingleInfo() throws Exception { 41 int id = mVmsPublishersInfo.getIdForInfo(MOCK_INFO_0); 42 assertEquals(0, id); 43 44 byte[] info = mVmsPublishersInfo.getPublisherInfo(id); 45 assertTrue(Arrays.equals(MOCK_INFO_0, info)); 46 } 47 48 // Test one info sanity - wrong ID fails. 49 public void testSingleInfoWrongId() throws Exception { 50 int id = mVmsPublishersInfo.getIdForInfo(MOCK_INFO_0); 51 assertEquals(0, id); 52 53 try { 54 byte[] info = mVmsPublishersInfo.getPublisherInfo(id + 1); 55 } 56 catch (NullPointerException e) { 57 return; 58 } 59 fail(); 60 } 61 62 // Test two infos. 63 public void testTwoInfos() throws Exception { 64 int id0 = mVmsPublishersInfo.getIdForInfo(MOCK_INFO_0); 65 int id1 = mVmsPublishersInfo.getIdForInfo(MOCK_INFO_1); 66 assertEquals(0, id0); 67 assertEquals(1, id1); 68 69 byte[] info0 = mVmsPublishersInfo.getPublisherInfo(id0); 70 byte[] info1 = mVmsPublishersInfo.getPublisherInfo(id1); 71 assertTrue(Arrays.equals(MOCK_INFO_0, info0)); 72 assertTrue(Arrays.equals(MOCK_INFO_1, info1)); 73 } 74 75 // Test same info twice get the same ID. 76 public void testSingleInfoInsertedTwice() throws Exception { 77 int id = mVmsPublishersInfo.getIdForInfo(MOCK_INFO_0); 78 assertEquals(0, id); 79 80 int sameId = mVmsPublishersInfo.getIdForInfo(SAME_MOCK_INFO_0); 81 assertEquals(sameId, id); 82 } 83 } 84