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 static org.junit.Assert.assertEquals; 20import static org.junit.Assert.assertNotNull; 21 22import android.os.Parcel; 23import android.test.suitebuilder.annotation.SmallTest; 24 25import org.junit.Test; 26 27import java.util.ArrayList; 28import java.util.Arrays; 29 30/** 31 * Unit tests for {@link com.android.server.wifi.wificond.PnoSettingsResult}. 32 */ 33@SmallTest 34public class PnoSettingsTest { 35 36 private static final byte[] TEST_SSID_1 = 37 new byte[] {'G', 'o', 'o', 'g', 'l', 'e', 'G', 'u', 'e', 's', 't'}; 38 private static final byte[] TEST_SSID_2 = 39 new byte[] {'A', 'n', 'd', 'r', 'o', 'i', 'd', 'T', 'e', 's', 't'}; 40 private static final int TEST_INTERVAL_MS = 30000; 41 private static final int TEST_MIN_2G_RSSI = -60; 42 private static final int TEST_MIN_5G_RSSI = -65; 43 44 /** 45 * PnoSettings object can be serialized and deserialized, while keeping the 46 * values unchanged. 47 */ 48 @Test 49 public void canSerializeAndDeserialize() throws Exception { 50 51 PnoSettings pnoSettings = new PnoSettings(); 52 53 PnoNetwork pnoNetwork1 = new PnoNetwork(); 54 pnoNetwork1.ssid = TEST_SSID_1; 55 pnoNetwork1.isHidden = true; 56 57 PnoNetwork pnoNetwork2 = new PnoNetwork(); 58 pnoNetwork2.ssid = TEST_SSID_2; 59 pnoNetwork2.isHidden = false; 60 61 pnoSettings.pnoNetworks = new ArrayList(Arrays.asList(pnoNetwork1, pnoNetwork2)); 62 63 pnoSettings.intervalMs = TEST_INTERVAL_MS; 64 pnoSettings.min2gRssi = TEST_MIN_2G_RSSI; 65 pnoSettings.min5gRssi = TEST_MIN_5G_RSSI; 66 67 Parcel parcel = Parcel.obtain(); 68 pnoSettings.writeToParcel(parcel, 0); 69 // Rewind the pointer to the head of the parcel. 70 parcel.setDataPosition(0); 71 PnoSettings pnoSettingsDeserialized = 72 pnoSettings.CREATOR.createFromParcel(parcel); 73 74 assertNotNull(pnoSettingsDeserialized); 75 assertEquals(pnoSettings, pnoSettingsDeserialized); 76 } 77} 78