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 org.junit.Assert;
22 import org.junit.Test;
25 * Tests {@link WifiParsedResult}.
27 * @author Vikram Aggarwal
29 public final class WifiParsedResultTestCase extends Assert {
30 public void testNoPassword() {
31 doTest("WIFI:S:NoPassword;P:;T:;;", "NoPassword", "", "");
32 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.
51 * Put in checks for the length of the password for wep.
54 public void testWpa() {
55 doTest("WIFI:S:TenChars;P:wow;T:WPA;;", "TenChars", "wow", "WPA");
56 doTest("WIFI:S:TenChars;P:space is silent;T:WPA;;", "TenChars", "space is silent", "WPA");
57 doTest("WIFI:S:TenChars;P:hellothere;T:WEP;;", "TenChars", "hellothere", "WEP");
60 doTest("WIFI:S:TenChars;P:hello\\;there;T:WEP;;", "TenChars", "hello;there", "WEP");
62 doTest("WIFI:S:TenChars;P:hello\\:there;T:WEP;;", "TenChars", "hello:there", "WEP");
66 * Given the string contents for the barcode, check that it matches our expectations
68 private static void doTest(String contents,
72 Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
73 ParsedResult result = ResultParser.parseResult(fakeResult);
75 // Ensure it is a wifi code
76 assertSame(ParsedResultType.WIFI, result.getType());
77 WifiParsedResult wifiResult = (WifiParsedResult) result;
79 assertEquals(ssid, wifiResult.getSsid());
80 assertEquals(password, wifiResult.getPassword());
81 assertEquals(type, wifiResult.getNetworkEncryption());