blob: c70799332b02ad100f9d534aa2f1585de14083b8 [file] [log] [blame]
Peter Qiue557c352016-09-29 10:44:15 -07001/*
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
17package android.net.wifi.hotspot2.pps;
18
Peter Qiua25d7172016-11-01 14:50:59 -070019import static org.junit.Assert.assertFalse;
Peter Qiue557c352016-09-29 10:44:15 -070020import static org.junit.Assert.assertTrue;
21
22import android.os.Parcel;
23import android.test.suitebuilder.annotation.SmallTest;
24
Peter Qiue557c352016-09-29 10:44:15 -070025import org.junit.Test;
26
27/**
28 * Unit tests for {@link android.net.wifi.hotspot2.pps.HomeSP}.
29 */
30@SmallTest
31public class HomeSPTest {
32 private static HomeSP createHomeSp() {
33 HomeSP homeSp = new HomeSP();
34 homeSp.fqdn = "fqdn";
35 homeSp.friendlyName = "friendly name";
36 homeSp.roamingConsortiumOIs = new long[] {0x55, 0x66};
37 return homeSp;
38 }
39
40 private static void verifyParcel(HomeSP writeHomeSp) throws Exception {
41 Parcel parcel = Parcel.obtain();
42 writeHomeSp.writeToParcel(parcel, 0);
43
44 parcel.setDataPosition(0); // Rewind data position back to the beginning for read.
45 HomeSP readHomeSp = HomeSP.CREATOR.createFromParcel(parcel);
46 assertTrue(readHomeSp.equals(writeHomeSp));
47 }
48
Peter Qiua25d7172016-11-01 14:50:59 -070049 /**
50 * Verify parcel read/write for an empty HomeSP.
51 *
52 * @throws Exception
53 */
Peter Qiue557c352016-09-29 10:44:15 -070054 @Test
55 public void verifyParcelWithEmptyHomeSP() throws Exception {
56 verifyParcel(new HomeSP());
57 }
58
Peter Qiua25d7172016-11-01 14:50:59 -070059 /**
60 * Verify parcel read/write for a valid HomeSP.
61 *
62 * @throws Exception
63 */
Peter Qiue557c352016-09-29 10:44:15 -070064 @Test
65 public void verifyParcelWithValidHomeSP() throws Exception {
66 verifyParcel(createHomeSp());
67 }
Peter Qiua25d7172016-11-01 14:50:59 -070068
69 /**
70 * Verify that a HomeSP is valid when both FQDN and Friendly Name
71 * are provided.
72 *
73 * @throws Exception
74 */
75 @Test
76 public void validateValidHomeSP() throws Exception {
77 HomeSP homeSp = new HomeSP();
78 homeSp.fqdn = "fqdn";
79 homeSp.friendlyName = "friendly name";
80 assertTrue(homeSp.validate());
81 }
82
83 /**
84 * Verify that a HomeSP is not valid when FQDN is not provided
85 *
86 * @throws Exception
87 */
88 @Test
89 public void validateHomeSpWithoutFqdn() throws Exception {
90 HomeSP homeSp = new HomeSP();
91 homeSp.friendlyName = "friendly name";
92 assertFalse(homeSp.validate());
93 }
94
95 /**
96 * Verify that a HomeSP is not valid when Friendly Name is not provided
97 *
98 * @throws Exception
99 */
100 @Test
101 public void validateHomeSpWithoutFriendlyName() throws Exception {
102 HomeSP homeSp = new HomeSP();
103 homeSp.fqdn = "fqdn";
104 assertFalse(homeSp.validate());
105 }
106
107 /**
108 * Verify that a HomeSP is valid when the optional Roaming Consortium OIs are
109 * provided.
110 *
111 * @throws Exception
112 */
113 @Test
114 public void validateHomeSpWithRoamingConsoritums() throws Exception {
115 HomeSP homeSp = new HomeSP();
116 homeSp.fqdn = "fqdn";
117 homeSp.friendlyName = "friendly name";
118 homeSp.roamingConsortiumOIs = new long[] {0x55, 0x66};
119 assertTrue(homeSp.validate());
120 }
Peter Qiua32e5092016-11-16 15:17:48 -0800121
122 /**
123 * Verify that copy constructor works when pass in a null source.
124 *
125 * @throws Exception
126 */
127 @Test
128 public void validateCopyConstructorFromNullSource() throws Exception {
129 HomeSP copySp = new HomeSP(null);
130 HomeSP defaultSp = new HomeSP();
131 assertTrue(copySp.equals(defaultSp));
132 }
133
134 /**
135 * Verify that copy constructor works when pass in a valid source.
136 *
137 * @throws Exception
138 */
139 @Test
140 public void validateCopyConstructorFromValidSource() throws Exception {
141 HomeSP sourceSp = new HomeSP();
142 sourceSp.fqdn = "fqdn";
143 sourceSp.friendlyName = "friendlyName";
144 sourceSp.roamingConsortiumOIs = new long[] {0x55, 0x66};
145 HomeSP copySp = new HomeSP(sourceSp);
146 assertTrue(copySp.equals(sourceSp));
147 }
Peter Qiue557c352016-09-29 10:44:15 -0700148}