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 junit.framework.TestCase;
20 import com.google.zxing.Result;
21 import com.google.zxing.BarcodeFormat;
23 import java.util.Arrays;
26 * Tests {@link AddressBookParsedResult}.
30 public final class AddressBookParsedResultTestCase extends TestCase {
32 public void testAddressBookDocomo() {
33 doTest("MECARD:N:Sean Owen;;", null, new String[] {"Sean Owen"}, null, null, null, null, null, null, null, null);
34 doTest("MECARD:NOTE:ZXing Team;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;;",
35 null, new String[] {"Sean Owen"}, null, null, new String[] {"srowen@example.org"}, null, null,
36 "google.com", null, "ZXing Team");
39 public void testAddressBookAU() {
40 doTest("MEMORY:foo\r\nNAME1:Sean\r\nTEL1:+12125551212\r\n",
41 null, new String[] {"Sean"}, null, null, null, new String[] {"+12125551212"}, null, null, null, "foo");
44 public void testVCard() {
45 doTest("BEGIN:VCARD\r\nADR;HOME:123 Main St\r\nVERSION:2.1\r\nN:Owen;Sean\r\nEND:VCARD",
46 null, new String[] {"Sean Owen"}, null, "123 Main St", null, null, null, null, null, null);
49 public void testBizcard() {
50 doTest("BIZCARD:N:Sean;X:Owen;C:Google;A:123 Main St;M:+12125551212;E:srowen@example.org;",
51 null, new String[] {"Sean Owen"}, null, "123 Main St", new String[] {"srowen@example.org"},
52 new String[] {"+12125551212"}, "Google", null, null, null);
55 private static void doTest(String contents,
61 String[] phoneNumbers,
66 Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
67 ParsedResult result = ResultParser.parseResult(fakeResult);
68 assertEquals(ParsedResultType.ADDRESSBOOK, result.getType());
69 AddressBookParsedResult addressResult = (AddressBookParsedResult) result;
70 assertEquals(title, addressResult.getTitle());
71 assertTrue(Arrays.equals(names, addressResult.getNames()));
72 assertEquals(pronunciation, addressResult.getPronunciation());
73 assertEquals(address, addressResult.getAddress());
74 assertTrue(Arrays.equals(emails, addressResult.getEmails()));
75 assertTrue(Arrays.equals(phoneNumbers, addressResult.getPhoneNumbers()));
76 assertEquals(org, addressResult.getOrg());
77 assertEquals(url, addressResult.getURL());
78 assertEquals(birthday, addressResult.getBirthday());
79 assertEquals(note, addressResult.getNote());