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 17 package com.android.server.wifi.hotspot2; 18 19 import static org.junit.Assert.assertEquals; 20 21 import android.test.suitebuilder.annotation.SmallTest; 22 23 import org.junit.Test; 24 25 /** 26 * Unit tests for {@link com.android.server.wifi.hotspot2.ANQPNetworkKey}. 27 */ 28 @SmallTest 29 public class ANQPNetworkKeyTest { 30 private static final String SSID = "TestSSID"; 31 private static final long BSSID = 0x123456L; 32 private static final long HESSID = 0x789012L; 33 private static final int ANQP_DOMAIN_ID = 1; 34 35 /** 36 * Verify that building a SSID based key works as expected. 37 * 38 * @throws Exception 39 */ 40 @Test 41 public void buildStandardESSKey() throws Exception { 42 ANQPNetworkKey expectedKey = new ANQPNetworkKey(SSID, 0, 0, ANQP_DOMAIN_ID); 43 ANQPNetworkKey actualKey = ANQPNetworkKey.buildKey(SSID, BSSID, 0, ANQP_DOMAIN_ID); 44 assertEquals(expectedKey, actualKey); 45 } 46 47 /** 48 * Verify that building a HESSID based key works as expected. 49 * 50 * @throws Exception 51 */ 52 @Test 53 public void buildHessidKey() throws Exception { 54 ANQPNetworkKey expectedKey = new ANQPNetworkKey(null, 0, HESSID, ANQP_DOMAIN_ID); 55 ANQPNetworkKey actualKey = ANQPNetworkKey.buildKey(SSID, BSSID, HESSID, ANQP_DOMAIN_ID); 56 assertEquals(expectedKey, actualKey); 57 } 58 59 /** 60 * Verify that building a key based on an AP (SSID + BSSID) works as expected. 61 * 62 * @throws Exception 63 */ 64 @Test 65 public void buildAPKey() throws Exception { 66 ANQPNetworkKey expectedKey = new ANQPNetworkKey(SSID, BSSID, 0, 0); 67 ANQPNetworkKey actualKey = ANQPNetworkKey.buildKey(SSID, BSSID, HESSID, 0); 68 assertEquals(expectedKey, actualKey); 69 } 70 } 71