Add description support, as well as handle VEVENT line continuation. Get rid of unuse...
[zxing.git] / core / test / src / com / google / zxing / client / result / CalendarParsedResultTestCase.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 /**
24  * Tests {@link CalendarParsedResult}.
25  *
26  * @author Sean Owen
27  */
28 public final class CalendarParsedResultTestCase extends TestCase {
29
30   public void testStartEnd() {
31     doTest(
32         "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
33         "DTSTART:20080504T123456Z\r\n" +
34         "DTEND:20080505T234555Z\r\n" +
35         "END:VEVENT\r\nEND:VCALENDAR",
36         null, null, null, "20080504T123456Z", "20080505T234555Z", null);
37   }
38
39   public void testStart() {
40     doTest(
41         "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
42         "DTSTART:20080504T123456Z\r\n" +
43         "END:VEVENT\r\nEND:VCALENDAR",
44         null, null, null, "20080504T123456Z", "20080504T123456Z", null);
45   }
46
47   public void testSummary() {
48     doTest(
49         "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
50         "SUMMARY:foo\r\n" +
51         "DTSTART:20080504T123456Z\r\n" +
52         "END:VEVENT\r\nEND:VCALENDAR",
53         null, "foo", null, "20080504T123456Z", "20080504T123456Z", null);
54   }
55
56   public void testLocation() {
57     doTest(
58         "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
59         "LOCATION:Miami\r\n" +
60         "DTSTART:20080504T123456Z\r\n" +
61         "END:VEVENT\r\nEND:VCALENDAR",
62         null, null, "Miami", "20080504T123456Z", "20080504T123456Z", null);
63   }
64
65   public void testDescription() {
66     doTest(
67         "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
68         "DTSTART:20080504T123456Z\r\n" +
69         "DESCRIPTION:This is a test\r\n" +
70         "END:VEVENT\r\nEND:VCALENDAR",
71         "This is a test", null, null, "20080504T123456Z", "20080504T123456Z", null);
72     doTest(
73         "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
74         "DTSTART:20080504T123456Z\r\n" +
75         "DESCRIPTION:This is a test\r\n\t with a continuation\r\n" +        
76         "END:VEVENT\r\nEND:VCALENDAR",
77         "This is a test with a continuation", null, null, "20080504T123456Z", "20080504T123456Z", null);
78   }
79
80   private static void doTest(String contents,
81                              String description,
82                              String summary,
83                              String location,
84                              String start,
85                              String end,
86                              String attendee) {
87     Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
88     ParsedResult result = ResultParser.parseResult(fakeResult);
89     assertSame(ParsedResultType.CALENDAR, result.getType());
90     CalendarParsedResult calResult = (CalendarParsedResult) result;
91     assertEquals(description, calResult.getDescription());
92     assertEquals(summary, calResult.getSummary());
93     assertEquals(location, calResult.getLocation());
94     assertEquals(start, calResult.getStart());
95     assertEquals(end, calResult.getEnd());
96     assertEquals(attendee, calResult.getAttendee());
97   }
98
99 }