1 /*
2 * Copyright 2005 [ini4j] Development Team
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.ini4j;
18
19 import java.util.HashMap;
20 import java.util.Map;
21 import junit.framework.Test;
22 import junit.framework.TestSuite;
23
24
25
26 ///CLOVER:OFF
27
28 /**
29 * JUnit test of Convert class.
30 */
31 public class ConvertTest extends AbstractTestBase
32 {
33 /**
34 * Instantiate test.
35 *
36 * @param testName name of the test
37 */
38 public ConvertTest(String testName)
39 {
40 super(testName);
41 }
42
43 /**
44 * Create test suite.
45 *
46 * @return new test suite
47 */
48 public static Test suite()
49 {
50 return new TestSuite(ConvertTest.class);
51 }
52
53 /**
54 * Test of escape method.
55 *
56 * @throws Exception on error
57 */
58 public void testEscape() throws Exception
59 {
60 Map<String,String> data = new HashMap<String,String>();
61
62 data.put("simple","simple");
63 data.put("Iv\ufffdn","Iv\\ufffdn");
64 data.put("1\t2\n3\f","1\\t2\\n3\\f");
65
66 for(String from : data.keySet())
67 {
68 assertEquals(data.get(from), Convert.escape(from));
69 }
70 }
71
72 /**
73 * Test of unescape method.
74 *
75 * @throws Exception on error
76 */
77 @SuppressWarnings("empty-statement")
78 public void testUnescape() throws Exception
79 {
80 Map<String,String> data = new HashMap<String,String>();
81
82 data.put("simple","simple");
83 data.put("Iv\\ufffdn","Iv\ufffdn");
84 data.put("1\\t2\\n3\\f","1\t2\n3\f");
85 data.put("\\=", "=");
86
87 for(String from : data.keySet())
88 {
89 assertEquals(data.get(from), Convert.unescape(from));
90 }
91
92 // invalid unicode escape mean IllegalArgumentException
93 try
94 {
95 Convert.unescape("\\u98x");
96 fail();
97 }
98 catch (IllegalArgumentException x)
99 {
100 ;
101 }
102 }
103 }