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.wificond; 18 19import android.net.wifi.IWifiScannerImpl; 20 21import static org.junit.Assert.assertEquals; 22import static org.junit.Assert.assertNotNull; 23 24import android.os.Parcel; 25import android.support.test.filters.SmallTest; 26 27import org.junit.Test; 28 29import java.util.ArrayList; 30import java.util.Arrays; 31 32/** 33 * Unit tests for {@link com.android.server.wifi.wificond.SingleScanSettingsResult}. 34 */ 35@SmallTest 36public class SingleScanSettingsTest { 37 38 private static final byte[] TEST_SSID_1 = 39 new byte[] {'G', 'o', 'o', 'g', 'l', 'e', 'G', 'u', 'e', 's', 't'}; 40 private static final byte[] TEST_SSID_2 = 41 new byte[] {'A', 'n', 'd', 'r', 'o', 'i', 'd', 'T', 'e', 's', 't'}; 42 private static final int TEST_FREQUENCY_1 = 2456; 43 private static final int TEST_FREQUENCY_2 = 5215; 44 45 /** 46 * SingleScanSettings object can be serialized and deserialized, while keeping the 47 * values unchanged. 48 */ 49 @Test 50 public void canSerializeAndDeserialize() throws Exception { 51 ChannelSettings channelSettings1 = new ChannelSettings(); 52 channelSettings1.frequency = TEST_FREQUENCY_1; 53 ChannelSettings channelSettings2 = new ChannelSettings(); 54 channelSettings2.frequency = TEST_FREQUENCY_2; 55 56 HiddenNetwork hiddenNetwork1 = new HiddenNetwork(); 57 hiddenNetwork1.ssid = TEST_SSID_1; 58 HiddenNetwork hiddenNetwork2 = new HiddenNetwork(); 59 hiddenNetwork2.ssid = TEST_SSID_2; 60 61 SingleScanSettings scanSettings = new SingleScanSettings(); 62 scanSettings.scanType = IWifiScannerImpl.SCAN_TYPE_HIGH_ACCURACY; 63 64 scanSettings.channelSettings = 65 new ArrayList(Arrays.asList(channelSettings1, channelSettings2)); 66 scanSettings.hiddenNetworks = new ArrayList(Arrays.asList(hiddenNetwork1, hiddenNetwork2)); 67 68 Parcel parcel = Parcel.obtain(); 69 scanSettings.writeToParcel(parcel, 0); 70 // Rewind the pointer to the head of the parcel. 71 parcel.setDataPosition(0); 72 SingleScanSettings scanSettingsDeserialized = 73 SingleScanSettings.CREATOR.createFromParcel(parcel); 74 75 assertNotNull(scanSettingsDeserialized); 76 assertEquals(scanSettings, scanSettingsDeserialized); 77 } 78} 79