001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.commons.configuration.plist; 019 020 import static org.junit.Assert.assertEquals; 021 022 import java.io.Reader; 023 import java.util.Calendar; 024 import java.util.SimpleTimeZone; 025 026 import junitx.framework.ArrayAssert; 027 028 import org.junit.Test; 029 030 /** 031 * @author Emmanuel Bourg 032 * @version $Id: TestPropertyListParser.java 1225903 2011-12-30 19:49:15Z oheger $ 033 */ 034 public class TestPropertyListParser 035 { 036 private PropertyListParser parser = new PropertyListParser((Reader) null); 037 038 @Test 039 public void testRemoveQuotes() 040 { 041 assertEquals("unquoted string", "abc", parser.removeQuotes("abc")); 042 assertEquals("quoted string", "abc", parser.removeQuotes("\"abc\"")); 043 assertEquals("empty quotes", "", parser.removeQuotes("\"\"")); 044 assertEquals("empty string", "", parser.removeQuotes("")); 045 assertEquals("null string", null, parser.removeQuotes(null)); 046 } 047 048 @Test 049 public void testUnescapeQuotes() 050 { 051 assertEquals("non escaped quotes", "aaa\"bbb\"ccc", parser.unescapeQuotes("aaa\"bbb\"ccc")); 052 assertEquals("escaped quotes", "aaa\"bbb\"ccc", parser.unescapeQuotes("aaa\\\"bbb\\\"ccc")); 053 } 054 055 @Test 056 public void testParseDate() throws Exception 057 { 058 Calendar calendar = Calendar.getInstance(); 059 calendar.set(Calendar.YEAR, 2002); 060 calendar.set(Calendar.MONTH, Calendar.MARCH); 061 calendar.set(Calendar.DAY_OF_MONTH, 22); 062 calendar.set(Calendar.HOUR_OF_DAY, 11); 063 calendar.set(Calendar.MINUTE, 30); 064 calendar.set(Calendar.SECOND, 0); 065 calendar.set(Calendar.MILLISECOND, 0); 066 calendar.setTimeZone(new SimpleTimeZone(60 * 60 * 1000, "Apache/Jakarta")); 067 068 assertEquals("parsed date", calendar.getTime(), parser.parseDate("<*D2002-03-22 11:30:00 +0100>")); 069 } 070 071 @Test 072 public void testFilterData() throws Exception 073 { 074 byte[] expected = new byte[] {0x20, 0x20}; 075 ArrayAssert.assertEquals("null string", null, parser.filterData(null)); 076 ArrayAssert.assertEquals("data with < >", expected, parser.filterData("<2020>")); 077 ArrayAssert.assertEquals("data without < >", expected, parser.filterData("2020")); 078 ArrayAssert.assertEquals("data with space", expected, parser.filterData("20 20")); 079 ArrayAssert.assertEquals("odd length", new byte[]{9, 0x20}, parser.filterData("920")); 080 } 081 }