Peter Qiu | e557c35 | 2016-09-29 10:44:15 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.net.wifi.hotspot2.pps; |
| 18 | |
Peter Qiu | a25d717 | 2016-11-01 14:50:59 -0700 | [diff] [blame] | 19 | import static org.junit.Assert.assertFalse; |
Peter Qiu | e557c35 | 2016-09-29 10:44:15 -0700 | [diff] [blame] | 20 | import static org.junit.Assert.assertTrue; |
| 21 | |
| 22 | import android.os.Parcel; |
| 23 | import android.test.suitebuilder.annotation.SmallTest; |
| 24 | |
Peter Qiu | e557c35 | 2016-09-29 10:44:15 -0700 | [diff] [blame] | 25 | import org.junit.Test; |
| 26 | |
| 27 | /** |
| 28 | * Unit tests for {@link android.net.wifi.hotspot2.pps.HomeSP}. |
| 29 | */ |
| 30 | @SmallTest |
| 31 | public 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 Qiu | a25d717 | 2016-11-01 14:50:59 -0700 | [diff] [blame] | 49 | /** |
| 50 | * Verify parcel read/write for an empty HomeSP. |
| 51 | * |
| 52 | * @throws Exception |
| 53 | */ |
Peter Qiu | e557c35 | 2016-09-29 10:44:15 -0700 | [diff] [blame] | 54 | @Test |
| 55 | public void verifyParcelWithEmptyHomeSP() throws Exception { |
| 56 | verifyParcel(new HomeSP()); |
| 57 | } |
| 58 | |
Peter Qiu | a25d717 | 2016-11-01 14:50:59 -0700 | [diff] [blame] | 59 | /** |
| 60 | * Verify parcel read/write for a valid HomeSP. |
| 61 | * |
| 62 | * @throws Exception |
| 63 | */ |
Peter Qiu | e557c35 | 2016-09-29 10:44:15 -0700 | [diff] [blame] | 64 | @Test |
| 65 | public void verifyParcelWithValidHomeSP() throws Exception { |
| 66 | verifyParcel(createHomeSp()); |
| 67 | } |
Peter Qiu | a25d717 | 2016-11-01 14:50:59 -0700 | [diff] [blame] | 68 | |
| 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 Qiu | a32e509 | 2016-11-16 15:17:48 -0800 | [diff] [blame] | 121 | |
| 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 Qiu | e557c35 | 2016-09-29 10:44:15 -0700 | [diff] [blame] | 148 | } |