1   /*
2    * Copyright 2005 The Apache Software Foundation.
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 org.apache.commons.configuration.plist;
18  
19  import java.io.Reader;
20  
21  import junit.framework.TestCase;
22  import junitx.framework.ArrayAssert;
23  
24  /***
25   * @author Emmanuel Bourg
26   * @version $Revision$, $Date$
27   */
28  public class TestPropertyListParser extends TestCase
29  {
30      private PropertyListParser parser = new PropertyListParser((Reader) null);
31  
32      public void testRemoveQuotes()
33      {
34          assertEquals("unquoted string", "abc", parser.removeQuotes("abc"));
35          assertEquals("quoted string", "abc", parser.removeQuotes("\"abc\""));
36          assertEquals("empty quotes", "", parser.removeQuotes("\"\""));
37          assertEquals("empty string", "", parser.removeQuotes(""));
38          assertEquals("null string", null, parser.removeQuotes(null));
39      }
40  
41      public void testUnescapeQuotes()
42      {
43          assertEquals("non escaped quotes", "aaa\"bbb\"ccc", parser.unescapeQuotes("aaa\"bbb\"ccc"));
44          assertEquals("escaped quotes", "aaa\"bbb\"ccc", parser.unescapeQuotes("aaa//\"bbb//\"ccc"));
45      }
46  
47      public void testFilterData() throws Exception
48      {
49          byte[] expected = new byte[] {0x20, 0x20};
50          ArrayAssert.assertEquals("null string", null, parser.filterData(null));
51          ArrayAssert.assertEquals("data with < >", expected, parser.filterData("<2020>"));
52          ArrayAssert.assertEquals("data without < >", expected, parser.filterData("2020"));
53          ArrayAssert.assertEquals("data with space", expected, parser.filterData("20 20"));
54          ArrayAssert.assertEquals("odd length", new byte[]{9, 0x20}, parser.filterData("920"));
55      }
56  }