SimpleIcsWriterTests.java revision 8d5c79fe3d792065b72edb6231d51e4301fd2bcc
1c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank/* Copyright (C) 2010 The Android Open Source Project 2c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank * 3c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank * Licensed under the Apache License, Version 2.0 (the "License"); 4c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank * you may not use this file except in compliance with the License. 5c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank * You may obtain a copy of the License at 6c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank * 7c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank * http://www.apache.org/licenses/LICENSE-2.0 8c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank * 9c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank * Unless required by applicable law or agreed to in writing, software 10c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank * distributed under the License is distributed on an "AS IS" BASIS, 11c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank * See the License for the specific language governing permissions and 13c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank * limitations under the License. 14c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank */ 15c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank 16c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blankpackage com.android.exchange.utility; 17c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank 188d5c79fe3d792065b72edb6231d51e4301fd2bccMarc Blankimport java.io.IOException; 198d5c79fe3d792065b72edb6231d51e4301fd2bccMarc Blank 20c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blankimport junit.framework.TestCase; 21c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank 22c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank/** 23c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank * Tests of EAS Calendar Utilities 24c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank * You can run this entire test case with: 25c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank * runtest -c com.android.exchange.utility.SimpleIcsWriterTests email 26c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank */ 27c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blankpublic class SimpleIcsWriterTests extends TestCase { 28c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank private final String string63Chars = 29c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789*"; 30c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank private final String string80Chars = 31c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ12345" + "67890"; 32c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank private static final String tag11Chars = "DESCRIPTION"; 33c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank 34c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank // Where our line breaks should end up 35c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank private final String expectedFirstLineBreak = 36c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank string63Chars.charAt(string63Chars.length() - 1) + SimpleIcsWriter.LINE_BREAK; 37c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank private final String expectedSecondLineBreak = 38c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank string80Chars.charAt(SimpleIcsWriter.MAX_LINE_LENGTH - 1) + SimpleIcsWriter.LINE_BREAK; 39c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank 408d5c79fe3d792065b72edb6231d51e4301fd2bccMarc Blank public void testWriter() throws IOException { 41c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank // Sanity test on constant strings 42c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank assertEquals(63, string63Chars.length()); 43c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank assertEquals(80, string80Chars.length()); 44c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank // Add 1 for the colon between the tag and the value 45c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank assertEquals(SimpleIcsWriter.MAX_LINE_LENGTH, 46c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank tag11Chars.length() + 1 + string63Chars.length()); 47c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank 48c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank SimpleIcsWriter w = new SimpleIcsWriter(); 49c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank w.writeTag(tag11Chars, string63Chars + string80Chars); 50c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank 51c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank // We should always end a tag on a new line 52c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank assertEquals(0, w.mLineCount); 53c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank 54c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank // Get the final string 55c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank String str = w.toString(); 56c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank assertEquals(SimpleIcsWriter.MAX_LINE_LENGTH-1, str.indexOf(expectedFirstLineBreak)); 57c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank assertEquals(SimpleIcsWriter.MAX_LINE_LENGTH + SimpleIcsWriter.LINE_BREAK_LENGTH + 58c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank (SimpleIcsWriter.MAX_LINE_LENGTH - 1), str.indexOf(expectedSecondLineBreak)); 59c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank } 60c8dc8009bcbb9dbf781f0028f07b2bbca600aeebMarc Blank} 61