Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8d8767814240f6b19c18aaf4bf6ff25be9cab6ae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*******************************************************************************
 * Copyright (c) 2010 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.ua.tests.help.webapp;

import junit.framework.TestCase;

import org.eclipse.help.internal.webapp.data.UrlUtil;

public class HtmlCoderTest extends TestCase {
	
	public void testEncodeEmpty() {
		String encoded = UrlUtil.htmlEncode(null);
		assertNull(encoded);
	}	

	/**
	 * Verify that alpha characters are not encoded
	 */
	public void testEncodeAlpha() {
		final String letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		String encoded = UrlUtil.htmlEncode(letters);
		assertEquals(letters, encoded);
	}
	
	/**
	 * Verify that alpha characters are not encoded
	 */
	public void testEncodeNumeric() {
		final String numbers = "1234567890";
		String encoded = UrlUtil.htmlEncode(numbers);
		assertEquals(numbers, encoded);
	}
	
	/**
	 * Verify that space is not encoded
	 */
	public void testEncodeSpace() {
		final String spaces = "  ";
		String encoded = UrlUtil.htmlEncode(spaces);
		assertEquals(spaces, encoded);
	}

	/**
	 * Verify that quote is encoded
	 */
	public void testEncodeQuote() {
		final String source = "\'";
		String encoded = UrlUtil.htmlEncode(source);
		assertNotSame(source, encoded);
	}
	
	/**
	 * Verify that less than is encoded
	 */
	public void testEncodeLt() {
		final String source = "<";
		String encoded = UrlUtil.htmlEncode(source);
		assertNotSame(source, encoded);
	}	

	/**
	 * Verify that greater than is encoded
	 */
	public void testEncodeGt() {
		final String source = ">";
		String encoded = UrlUtil.htmlEncode(source);
		assertNotSame(source, encoded);
	}

	/**
	 * Verify that ampersand is encoded
	 */
	public void testEncodeAmp() {
		final String source = "&";
		String encoded = UrlUtil.htmlEncode(source);
		assertNotSame(source, encoded);
	}

	/**
	 * Verify that ampersand is encoded
	 */
	public void testEncodeBackslash() {
		final String source = "\\";
		String encoded = UrlUtil.htmlEncode(source);
		assertNotSame(source, encoded);
	}

	/**
	 * Verify that newline is encoded
	 */
	public void testEncodeNewline() {
		final String source = "\n";
		String encoded = UrlUtil.htmlEncode(source);
		assertNotSame(source, encoded);
	}

	/**
	 * Verify that CR is encoded
	 */
	public void testEncodeCarriageReturn() {
		final String source = "\r";
		String encoded = UrlUtil.htmlEncode(source);
		assertNotSame(source, encoded);
	}

	/**
	 * Verify that accented character is not encoded
	 */
	public void testNoEncodeAccented() {
		final String source = "\u00c1";
		String encoded = UrlUtil.htmlEncode(source);
		assertEquals(source, encoded);
	}
	
	/**
	 * Verify that Chinese character is not encoded
	 */
	public void testNoEncodeChinese() {
		final String source = "\u4e01";
		String encoded = UrlUtil.htmlEncode(source);
		assertEquals(source, encoded);
	}

}

Back to the top