2 * Copyright 2007 ZXing authors
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.google.zxing.client.result;
19 import com.google.zxing.BarcodeFormat;
20 import com.google.zxing.Result;
21 import junit.framework.TestCase;
23 import java.util.Arrays;
26 * Tests {@link WifiParsedResult}.
28 * @author Vikram Aggarwal
30 public final class WifiParsedResultTestCase extends TestCase {
31 public void testNoPassword() {
32 doTest("WIFI:S:NoPassword;P:;T:;;", "NoPassword", "", "");
33 doTest("WIFI:S:No Password;P:;T:;;", "No Password", "", "");
36 public void testWep() {
37 doTest("WIFI:S:TenChars;P:0123456789;T:WEP;;", "TenChars", "0123456789", "WEP");
38 doTest("WIFI:S:TenChars;P:abcde56789;T:WEP;;", "TenChars", "abcde56789", "WEP");
39 // Non hex should not fail at this level
40 doTest("WIFI:S:TenChars;P:hellothere;T:WEP;;", "TenChars", "hellothere", "WEP");
43 doTest("WIFI:S:Ten\\;\\;Chars;P:0123456789;T:WEP;;", "Ten;;Chars", "0123456789", "WEP");
45 doTest("WIFI:S:Ten\\:\\:Chars;P:0123456789;T:WEP;;", "Ten::Chars", "0123456789", "WEP");
47 // TODO(vikrama) Need a test for SB as well.
50 // Put in checks for the length of the password for wep.
51 public void testWpa() {
52 doTest("WIFI:S:TenChars;P:wow;T:WPA;;", "TenChars", "wow", "WPA");
53 doTest("WIFI:S:TenChars;P:space is silent;T:WPA;;", "TenChars", "space is silent", "WPA");
54 doTest("WIFI:S:TenChars;P:hellothere;T:WEP;;", "TenChars", "hellothere", "WEP");
57 doTest("WIFI:S:TenChars;P:hello\\;there;T:WEP;;", "TenChars", "hello;there", "WEP");
59 doTest("WIFI:S:TenChars;P:hello\\:there;T:WEP;;", "TenChars", "hello:there", "WEP");
62 // Given the string contents for the barcode, check that it matches
64 private static void doTest(String contents,
68 Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
69 ParsedResult result = ResultParser.parseResult(fakeResult);
71 // Ensure it is a wifi code
72 assertSame(ParsedResultType.WIFI, result.getType());
73 WifiParsedResult wifiResult = (WifiParsedResult) result;
75 assertEquals(ssid, wifiResult.getSsid());
76 assertEquals(password, wifiResult.getPassword());
77 assertEquals(type, wifiResult.getNetworkEncryption());