summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jimmy Chen <jimmycmchen@google.com> 2019-04-10 17:50:10 +0800
committer Jimmy Chen <jimmycmchen@google.com> 2019-04-11 11:12:27 +0800
commit1c4257ddb2e2dfd71311565fd2c7908bf7bee401 (patch)
tree6110f6fdc5ae3c60dead2b5ddc413b37e5e051de
parentb20dfbbf236c7151664bbe7e4c24db09575cce53 (diff)
p2p: unit tests for WifiP2pInfo
Bug: 130138124 Test: atest FrameworksWifiApiTest Change-Id: I7a6bec4faf81ec6e9164b8737588a51503caaaf7 Merged-In: I7a6bec4faf81ec6e9164b8737588a51503caaaf7
-rw-r--r--wifi/tests/src/android/net/wifi/p2p/WifiP2pInfoTest.java83
1 files changed, 83 insertions, 0 deletions
diff --git a/wifi/tests/src/android/net/wifi/p2p/WifiP2pInfoTest.java b/wifi/tests/src/android/net/wifi/p2p/WifiP2pInfoTest.java
new file mode 100644
index 000000000000..e207ca1f3e7a
--- /dev/null
+++ b/wifi/tests/src/android/net/wifi/p2p/WifiP2pInfoTest.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2019 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 android.net.wifi.p2p;
+
+import static org.junit.Assert.assertEquals;
+
+import android.os.Parcel;
+
+import androidx.test.filters.SmallTest;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.net.InetAddress;
+
+/**
+ * Unit test harness for {@link android.net.wifi.p2p.WifiP2pInfo}
+ */
+@SmallTest
+public class WifiP2pInfoTest {
+
+ private InetAddress mGroupOnwerIpv4Address;
+
+ @Before
+ public void setUp() throws Exception {
+ byte[] ipv4 = {(byte) 192, (byte) 168, (byte) 49, (byte) 1};
+ mGroupOnwerIpv4Address = InetAddress.getByAddress(ipv4);
+ }
+
+ /**
+ * Verifies copy constructor.
+ */
+ @Test
+ public void testCopyOperator() throws Exception {
+ WifiP2pInfo info = new WifiP2pInfo();
+ info.groupFormed = true;
+ info.isGroupOwner = true;
+ info.groupOwnerAddress = mGroupOnwerIpv4Address;
+
+ WifiP2pInfo copiedInfo = new WifiP2pInfo(info);
+
+ // no equals operator, use toString for data comparison.
+ assertEquals(info.toString(), copiedInfo.toString());
+ }
+
+ /**
+ * Verifies parcel serialization/deserialization.
+ */
+ @Test
+ public void testParcelOperation() throws Exception {
+ WifiP2pInfo info = new WifiP2pInfo();
+ info.groupFormed = true;
+ info.isGroupOwner = true;
+ info.groupOwnerAddress = mGroupOnwerIpv4Address;
+
+ Parcel parcelW = Parcel.obtain();
+ info.writeToParcel(parcelW, 0);
+ byte[] bytes = parcelW.marshall();
+ parcelW.recycle();
+
+ Parcel parcelR = Parcel.obtain();
+ parcelR.unmarshall(bytes, 0, bytes.length);
+ parcelR.setDataPosition(0);
+ WifiP2pInfo fromParcel = WifiP2pInfo.CREATOR.createFromParcel(parcelR);
+
+ // no equals operator, use toString for data comparison.
+ assertEquals(info.toString(), fromParcel.toString());
+ }
+}