1/* 2 * Copyright (C) 2016 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.test.suitebuilder.annotation.SmallTest; 22 23import org.junit.Test; 24 25import java.nio.ByteBuffer; 26 27/** 28 * Unit tests for {@link com.android.server.wifi.hotspot2.anqp.RawByteElement}. 29 */ 30@SmallTest 31public class RawByteElementTest { 32 private static final Constants.ANQPElementType TEST_ELEMENT_ID = 33 Constants.ANQPElementType.HSOSUProviders; 34 35 /** 36 * Verify that a RawByteElement with an empty payload will be returned when parsing 37 * an empty buffer. 38 * 39 * @throws Exception 40 */ 41 @Test 42 public void parseEmptyBuffer() throws Exception { 43 byte[] data = new byte[0]; 44 RawByteElement actual = RawByteElement.parse(TEST_ELEMENT_ID, ByteBuffer.wrap(data)); 45 RawByteElement expected = new RawByteElement(TEST_ELEMENT_ID, data); 46 assertEquals(expected, actual); 47 } 48 49 /** 50 * Verify that the expected RawByteElement will be returned when parsing a non-empty 51 * buffer. 52 * 53 * @throws Exception 54 */ 55 @Test 56 public void parseNonEmptyBuffer() throws Exception { 57 byte[] data = new byte[10]; 58 RawByteElement actual = RawByteElement.parse(TEST_ELEMENT_ID, ByteBuffer.wrap(data)); 59 RawByteElement expected = new RawByteElement(TEST_ELEMENT_ID, data); 60 assertEquals(expected, actual); 61 } 62} 63