This repository has been archived by the owner on Dec 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for WifiConfigStore.xml parser
Added Robolectric dependency because we use Android dependency for XML parsing. Issue: #34
- Loading branch information
1 parent
24b4fbd
commit 81f5368
Showing
4 changed files
with
530 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
app/src/test/java/be/brunoparmentier/wifikeyshare/utils/WifiConfigStoreParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* WiFiKeyShare. Share Wi-Fi passwords with QR codes or NFC tags. | ||
* Copyright (C) 2018 Bruno Parmentier <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package be.brunoparmentier.wifikeyshare.utils; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.xmlpull.v1.XmlPullParserException; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import be.brunoparmentier.wifikeyshare.model.WifiAuthType; | ||
import be.brunoparmentier.wifikeyshare.model.WifiNetwork; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
@RunWith(RobolectricTestRunner.class) | ||
public class WifiConfigStoreParserTest { | ||
|
||
private final List<WifiNetwork> expectedWifiNetworks = new ArrayList<>(); | ||
|
||
@Before | ||
public void setUp() { | ||
expectedWifiNetworks.add(new WifiNetwork( | ||
"test1", WifiAuthType.OPEN, "", false)); | ||
expectedWifiNetworks.add(new WifiNetwork( | ||
"test2", WifiAuthType.WEP, "test", false)); | ||
expectedWifiNetworks.add(new WifiNetwork( | ||
"test3", WifiAuthType.WPA2_PSK, "test1234", false)); | ||
expectedWifiNetworks.add(new WifiNetwork( | ||
"test4", WifiAuthType.WPA2_PSK, "ABCDEFGHI0123456789JKLMNOP", false)); | ||
expectedWifiNetworks.add(new WifiNetwork( | ||
"test5", WifiAuthType.WPA2_PSK, "\";/\\=#}`,\\\"$4<d)=%", false)); | ||
expectedWifiNetworks.add(new WifiNetwork( | ||
"test6", WifiAuthType.WPA2_EAP, "", false)); | ||
expectedWifiNetworks.add(new WifiNetwork( | ||
"test7", WifiAuthType.WPA2_EAP, "", false)); | ||
expectedWifiNetworks.add(new WifiNetwork( | ||
"a\"=$\\o(#=>™•,k8", WifiAuthType.OPEN, "", false)); | ||
|
||
|
||
} | ||
|
||
@Test | ||
public void parse() throws XmlPullParserException, IOException { | ||
InputStream wifiConfigStoreFileStream = | ||
getClass().getClassLoader().getResourceAsStream("test_WifiConfigStore.xml"); | ||
|
||
List<WifiNetwork> parsedWifiNetworks = WifiConfigStoreParser.parse(wifiConfigStoreFileStream); | ||
assertEquals(expectedWifiNetworks.size(), parsedWifiNetworks.size()); | ||
for (int i = 0; i < expectedWifiNetworks.size(); i++) { | ||
assertEquals(expectedWifiNetworks.get(i), parsedWifiNetworks.get(i)); | ||
} | ||
} | ||
} |
Oops, something went wrong.