601708d8dcf5cb128fdb62f7772e33d5c3d55782
[zxing.git] / core / test / src / com / google / zxing / client / result / AddressBookParsedResultTestCase.java
1 /*
2  * Copyright 2007 ZXing authors
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.google.zxing.client.result;
18
19 import com.google.zxing.BarcodeFormat;
20 import com.google.zxing.Result;
21 import junit.framework.TestCase;
22
23 import java.util.Arrays;
24
25 /**
26  * Tests {@link AddressBookParsedResult}.
27  *
28  * @author Sean Owen
29  */
30 public final class AddressBookParsedResultTestCase extends TestCase {
31
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");
37   }
38
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");
42   }
43
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, new String[] {"123 Main St"}, null, null, null, null, null, null);
47   }
48
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, new String[] {"123 Main St"}, new String[] {"srowen@example.org"},
52         new String[] {"+12125551212"}, "Google", null, null, null);
53   }
54
55   public void testSeveralAddresses() {
56     doTest("MECARD:N:Foo Bar;ORG:Company;TEL:5555555555;EMAIL:foo.bar@xyz.com;ADR:City, 10001;" +
57            "ADR:City, 10001;NOTE:This is the memo.;;",
58            null, new String[] {"Foo Bar"}, null, new String[] {"City, 10001", "City, 10001"},
59            new String[] {"foo.bar@xyz.com"},
60            new String[] {"5555555555" }, "Company", null, null, "This is the memo.");
61   }
62
63   public void testQuotedPrintable() {
64     doTest("BEGIN:VCARD\r\nADR;HOME;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;;" +
65            "=35=38=20=4C=79=6E=62=72=6F=6F=6B=0D=0A=43=\r\n" +
66            "=4F=20=36=39=39=\r\n" +
67            "=32=36;;;\r\nEND:VCARD",
68            null, null, null, new String[] {"58 Lynbrook\r\nCO 69926"},
69            null, null, null, null, null, null);
70   }
71
72   private static void doTest(String contents,
73                              String title,
74                              String[] names,
75                              String pronunciation,
76                              String[] addresses,
77                              String[] emails,
78                              String[] phoneNumbers,
79                              String org,
80                              String url,
81                              String birthday,
82                              String note) {
83     Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
84     ParsedResult result = ResultParser.parseResult(fakeResult);
85     assertSame(ParsedResultType.ADDRESSBOOK, result.getType());
86     AddressBookParsedResult addressResult = (AddressBookParsedResult) result;
87     assertEquals(title, addressResult.getTitle());
88     assertTrue(Arrays.equals(names, addressResult.getNames()));
89     assertEquals(pronunciation, addressResult.getPronunciation());
90     assertTrue(Arrays.equals(addresses, addressResult.getAddresses()));
91     assertTrue(Arrays.equals(emails, addressResult.getEmails()));
92     assertTrue(Arrays.equals(phoneNumbers, addressResult.getPhoneNumbers()));
93     assertEquals(org, addressResult.getOrg());
94     assertEquals(url, addressResult.getURL());
95     assertEquals(birthday, addressResult.getBirthday());
96     assertEquals(note, addressResult.getNote());
97   }
98
99 }