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;
24 import java.util.Arrays;
27 * Tests {@link AddressBookParsedResult}.
31 public final class AddressBookParsedResultTestCase extends Assert {
34 public void testAddressBookDocomo() {
35 doTest("MECARD:N:Sean Owen;;", null, new String[] {"Sean Owen"}, null, null, null, null, null, null, null, null);
36 doTest("MECARD:NOTE:ZXing Team;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;;",
37 null, new String[] {"Sean Owen"}, null, null, new String[] {"srowen@example.org"}, null, null,
38 "google.com", null, "ZXing Team");
42 public void testAddressBookAU() {
43 doTest("MEMORY:foo\r\nNAME1:Sean\r\nTEL1:+12125551212\r\n",
44 null, new String[] {"Sean"}, null, null, null, new String[] {"+12125551212"}, null, null, null, "foo");
48 public void testVCard() {
49 doTest("BEGIN:VCARD\r\nADR;HOME:123 Main St\r\nVERSION:2.1\r\nN:Owen;Sean\r\nEND:VCARD",
50 null, new String[] {"Sean Owen"}, null, new String[] {"123 Main St"}, null, null, null, null, null, null);
54 public void testBizcard() {
55 doTest("BIZCARD:N:Sean;X:Owen;C:Google;A:123 Main St;M:+12125551212;E:srowen@example.org;",
56 null, new String[] {"Sean Owen"}, null, new String[] {"123 Main St"}, new String[] {"srowen@example.org"},
57 new String[] {"+12125551212"}, "Google", null, null, null);
61 public void testSeveralAddresses() {
62 doTest("MECARD:N:Foo Bar;ORG:Company;TEL:5555555555;EMAIL:foo.bar@xyz.com;ADR:City, 10001;" +
63 "ADR:City, 10001;NOTE:This is the memo.;;",
64 null, new String[] {"Foo Bar"}, null, new String[] {"City, 10001", "City, 10001"},
65 new String[] {"foo.bar@xyz.com"},
66 new String[] {"5555555555" }, "Company", null, null, "This is the memo.");
70 public void testQuotedPrintable() {
71 doTest("BEGIN:VCARD\r\nADR;HOME;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;;" +
72 "=35=38=20=4C=79=6E=62=72=6F=6F=6B=0D=0A=43=\r\n" +
73 "=4F=20=36=39=39=\r\n" +
74 "=32=36;;;\r\nEND:VCARD",
75 null, null, null, new String[] {"58 Lynbrook\r\nCO 69926"},
76 null, null, null, null, null, null);
79 private static void doTest(String contents,
85 String[] phoneNumbers,
90 Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
91 ParsedResult result = ResultParser.parseResult(fakeResult);
92 assertSame(ParsedResultType.ADDRESSBOOK, result.getType());
93 AddressBookParsedResult addressResult = (AddressBookParsedResult) result;
94 assertEquals(title, addressResult.getTitle());
95 assertTrue(Arrays.equals(names, addressResult.getNames()));
96 assertEquals(pronunciation, addressResult.getPronunciation());
97 assertTrue(Arrays.equals(addresses, addressResult.getAddresses()));
98 assertTrue(Arrays.equals(emails, addressResult.getEmails()));
99 assertTrue(Arrays.equals(phoneNumbers, addressResult.getPhoneNumbers()));
100 assertEquals(org, addressResult.getOrg());
101 assertEquals(url, addressResult.getURL());
102 assertEquals(birthday, addressResult.getBirthday());
103 assertEquals(note, addressResult.getNote());