1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.ini4j.spi;
17
18 import org.ini4j.Ini4jCase;
19
20 import static org.junit.Assert.assertEquals;
21
22 import org.junit.Before;
23 import org.junit.Test;
24
25 public class WinEscapeToolTest extends Ini4jCase
26 {
27 public static final String VALUE1 = "simple";
28 public static final String ESCAPE1 = "simple";
29 public static final String VALUE2 = "Iván";
30 public static final String ESCAPE2 = "Iv\\xe1n";
31 public static final String VALUE3 = "1\t2\n3\f4\b5\r6";
32 public static final String ESCAPE3 = "1\\t2\\n3\\f4\\b5\\r6";
33 public static final String VALUE4 = "Iv\u0017n";
34 public static final String ESCAPE4 = "Iv\\x17n";
35 public static final String VALUE5 = "Árvíztrtükörfúrógép";
36 public static final String ESCAPE5 = "\\xc1rv\\xedztrt\\xfck\\xf6rf\\xfar\\xf3g\\xe9p";
37 private static final String INVALID_HEX = "\\x1_";
38 private static final String INVALID_OCT = "\\o19_";
39 protected WinEscapeTool instance;
40
41 @Before @Override public void setUp() throws Exception
42 {
43 super.setUp();
44 instance = WinEscapeTool.getInstance();
45 }
46
47 @Test public void testEscape() throws Exception
48 {
49 assertEquals(ESCAPE1, instance.escape(VALUE1));
50 assertEquals(ESCAPE2, instance.escape(VALUE2));
51 assertEquals(ESCAPE3, instance.escape(VALUE3));
52 assertEquals(ESCAPE4, instance.escape(VALUE4));
53 assertEquals(ESCAPE5, instance.escape(VALUE5));
54 }
55
56 @Test public void testInvalidHex()
57 {
58 try
59 {
60 instance.unescape(INVALID_HEX);
61 missing(IllegalArgumentException.class);
62 }
63 catch (IllegalArgumentException x)
64 {
65
66 }
67 }
68
69 @Test public void testInvalidOctal()
70 {
71 try
72 {
73 instance.unescape(INVALID_OCT);
74 missing(IllegalArgumentException.class);
75 }
76 catch (IllegalArgumentException x)
77 {
78
79 }
80 }
81
82 @Test public void testSingleton() throws Exception
83 {
84 assertEquals(WinEscapeTool.class, WinEscapeTool.getInstance().getClass());
85 }
86
87 @Test public void testUnescape() throws Exception
88 {
89 assertEquals(VALUE1, instance.unescape(ESCAPE1));
90 assertEquals(VALUE2, instance.unescape(ESCAPE2));
91 assertEquals(VALUE3, instance.unescape(ESCAPE3));
92 assertEquals(VALUE4, instance.unescape(ESCAPE4));
93 assertEquals(VALUE5, instance.unescape(ESCAPE5));
94 assertEquals("=", instance.unescape("\\="));
95 assertEquals("xAx", instance.unescape("x\\o101x"));
96 }
97 }