Skip to main content
summaryrefslogtreecommitdiffstats
blob: a91ff0cffe578a0497ab7a8caec051fedc3df8ff (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
/*******************************************************************************
 * Copyright (c) 2004 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.wst.xml.tests.encoding.properties;

import junit.framework.TestCase;

import org.eclipse.wst.sse.core.internal.encoding.CommonCharsetNames;

public class TestCommonNames extends TestCase {

	private static final boolean DEBUG = false;

	public void testCommonNames() {
		String[] names = CommonCharsetNames.getCommonCharsetNames();
		assertTrue("common charset names could not be loaded", names != null && names.length > 0);
		if (DEBUG) {
			for (int i = 0; i < names.length; i++) {
				String name = names[i];
				String displayName = CommonCharsetNames.getDisplayString(name);
				System.out.println( name + "    " + displayName);
			}
		}
	}
	
	public void doTestDefaultIanaNames(String stringToCheck, String defaultName, String expected) {
		String actual = CommonCharsetNames.getPreferredDefaultIanaName(stringToCheck, defaultName);
		assertEquals("default IANA name test failed for " + stringToCheck, expected, actual);
	}

	public void testASCII() {
		doTestDefaultIanaNames("ASCII", "UTF-8", "US-ASCII");
	}
	
	public void testCp1252() {
		doTestDefaultIanaNames("Cp1252", "UTF-8", "ISO-8859-1");
	}
	
	public void testMS950() {
		doTestDefaultIanaNames("MS950", "UTF-8", "BIG5");
	}
	
	public void testCp1256() {
		doTestDefaultIanaNames("Cp1256", "UTF-8", "windows-1256");
	}
	
	public void testMS949() {
		doTestDefaultIanaNames("MS949", "UTF-8", "EUC-KR");
	}
	
	public void testEUC_JP() {
		doTestDefaultIanaNames("EUC-JP", "UTF-8", "EUC-JP");
	}
	
	public void testTotallyFake() {
		doTestDefaultIanaNames("totallyFake", "UTF-8", "UTF-8");
	}
	
	public void testSystemEncoding() {
		String systemEnc = System.getProperty("file.encoding");
		if (systemEnc != null) {
			String actual = CommonCharsetNames.getPreferredDefaultIanaName(systemEnc, "UTF-8");
			assertNotNull("default IANA name test failed for system encoding " + systemEnc, actual);
		}
	}
}

Back to the top