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 17package com.android.server.wifi.hotspot2.anqp; 18 19import static org.junit.Assert.assertEquals; 20 21import android.support.test.filters.SmallTest; 22 23import org.junit.Test; 24 25import java.nio.BufferUnderflowException; 26import java.nio.ByteBuffer; 27 28/** 29 * Unit tests for {@link com.android.server.wifi.hotspot2.anqp.IconInfo}. 30 */ 31@SmallTest 32public class IconInfoTest { 33 /** 34 * Verify that BufferUnderflowException will be thrown when parsing an empty buffer. 35 * @throws Exception 36 */ 37 @Test(expected = BufferUnderflowException.class) 38 public void parseEmptyBuffer() throws Exception { 39 IconInfo.parse(ByteBuffer.allocate(0)); 40 } 41 42 /** 43 * Verify that BufferUnderflowException will be thrown when parsing a truncated buffer 44 * (missing a byte at the end). 45 * 46 * @throws Exception 47 */ 48 @Test(expected = BufferUnderflowException.class) 49 public void parseTruncatedBuffer() throws Exception { 50 ByteBuffer buffer = ByteBuffer.wrap(IconInfoTestUtil.TEST_ICON_INFO_RAW_BYTES); 51 buffer.limit(buffer.remaining() - 1); 52 IconInfo.parse(buffer); 53 } 54 55 /** 56 * Verify that an expected {@link IconInfo} will be returned when parsing a buffer containing 57 * pre-defined test data. 58 * 59 * @throws Exception 60 */ 61 @Test 62 public void parseBufferWithTestData() throws Exception { 63 ByteBuffer buffer = ByteBuffer.wrap(IconInfoTestUtil.TEST_ICON_INFO_RAW_BYTES); 64 assertEquals(IconInfoTestUtil.TEST_ICON_INFO, IconInfo.parse(buffer)); 65 } 66} 67