summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNingyuan Wang <nywang@google.com>2017-01-19 10:48:18 -0800
committerNingyuan Wang <nywang@google.com>2017-01-20 12:51:48 -0800
commitf28a486bccdfd9573f4a1c119f4cb6134bc44f27 (patch)
tree3e2bfb8bd28791512060eeb3dc0cea96c48554b2
parent3d06c9eb56bb3c46f407965a5d2478cf7fd82408 (diff)
Java side unit test for SingleScanSettings
Bug: 34281985 Change-Id: Id906fe1d86e4908238efa8d5bb5e63276543ee3a Test: compile, unit tests
-rw-r--r--tests/wifitests/src/com/android/server/wifi/wificond/SingleScanSettingsTest.java89
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/wificond/SingleScanSettingsTest.java b/tests/wifitests/src/com/android/server/wifi/wificond/SingleScanSettingsTest.java
new file mode 100644
index 000000000..1956a58d9
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/wificond/SingleScanSettingsTest.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wifi.wificond;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import android.os.Parcel;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+/**
+ * Unit tests for {@link com.android.server.wifi.wificond.SingleScanSettingsResult}.
+ */
+@SmallTest
+public class SingleScanSettingsTest {
+
+ private static final boolean TEST_IS_FULL_SCAN = true;
+ private static final byte[] TEST_SSID_1 =
+ new byte[] {'G', 'o', 'o', 'g', 'l', 'e', 'G', 'u', 'e', 's', 't'};
+ private static final byte[] TEST_SSID_2 =
+ new byte[] {'A', 'n', 'd', 'r', 'o', 'i', 'd', 'T', 'e', 's', 't'};
+ private static final int TEST_FREQUENCY_1 = 2456;
+ private static final int TEST_FREQUENCY_2 = 5215;
+
+ @Test
+ public void canSerializeAndDeserialize() throws Exception {
+ ChannelSettings channelSettings1 = new ChannelSettings();
+ channelSettings1.frequency = TEST_FREQUENCY_1;
+ ChannelSettings channelSettings2 = new ChannelSettings();
+ channelSettings2.frequency = TEST_FREQUENCY_2;
+
+ HiddenNetwork hiddenNetwork1 = new HiddenNetwork();
+ hiddenNetwork1.ssid = TEST_SSID_1;
+ HiddenNetwork hiddenNetwork2 = new HiddenNetwork();
+ hiddenNetwork2.ssid = TEST_SSID_2;
+
+ SingleScanSettings scanSettings = new SingleScanSettings();
+ scanSettings.isFullScan = TEST_IS_FULL_SCAN;
+ scanSettings.channelSettings =
+ new ArrayList(Arrays.asList(channelSettings1, channelSettings2));
+ scanSettings.hiddenNetworks = new ArrayList(Arrays.asList(hiddenNetwork1, hiddenNetwork2));
+
+ Parcel parcel = Parcel.obtain();
+ scanSettings.writeToParcel(parcel, 0);
+ // Rewind the pointer to the head of the parcel.
+ parcel.setDataPosition(0);
+ SingleScanSettings scanSettingsDeserialized =
+ SingleScanSettings.CREATOR.createFromParcel(parcel);
+
+ assertEquals(scanSettings.isFullScan,
+ scanSettingsDeserialized.isFullScan);
+ assertNotNull(scanSettingsDeserialized.channelSettings);
+ assertEquals(scanSettings.channelSettings.size(),
+ scanSettingsDeserialized.channelSettings.size());
+ assertArrayEquals(scanSettings.hiddenNetworks.get(0).ssid,
+ scanSettingsDeserialized.hiddenNetworks.get(0).ssid);
+ assertArrayEquals(scanSettings.hiddenNetworks.get(1).ssid,
+ scanSettingsDeserialized.hiddenNetworks.get(1).ssid);
+
+ assertNotNull(scanSettingsDeserialized.hiddenNetworks);
+ assertEquals(scanSettings.hiddenNetworks.size(),
+ scanSettingsDeserialized.hiddenNetworks.size());
+ assertEquals(scanSettings.channelSettings.get(0).frequency,
+ scanSettingsDeserialized.channelSettings.get(0).frequency);
+ assertEquals(scanSettings.channelSettings.get(1).frequency,
+ scanSettingsDeserialized.channelSettings.get(1).frequency);
+
+ }
+}