01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: package org.outerj.daisy.xmlutil.test;
17:
18: import junit.framework.TestCase;
19: import org.outerj.daisy.xmlutil.XmlEncodingDetector;
20:
21: public class XmlEncodingDetectorTest extends TestCase {
22:
23: public void testEncodingDetection() throws Exception {
24: String test1 = "<abc/>";
25: assertEquals("UTF-8", XmlEncodingDetector.detectEncoding(test1
26: .getBytes("UTF-8")));
27:
28: String test2 = "<?xml encoding=\"ISO-8859-1\"?>\n<jaja/>";
29: assertEquals("ISO-8859-1", XmlEncodingDetector
30: .detectEncoding(test2.getBytes("ISO-8859-1")));
31:
32: String test3 = "<?xml encoding=\"ISO-8859-1\"?><jaja/>";
33: assertEquals("ISO-8859-1", XmlEncodingDetector
34: .detectEncoding(test3.getBytes("ISO-8859-1")));
35:
36: StringBuilder fillup = new StringBuilder(3000);
37: for (int i = 0; i < 3000; i++) {
38: fillup.append("a");
39: }
40:
41: String test4 = "<?xml encoding=\"ISO-8859-1\"?><jaja>" + fillup
42: + "</jaja>";
43: assertEquals("ISO-8859-1", XmlEncodingDetector
44: .detectEncoding(test4.getBytes("ISO-8859-1")));
45: }
46: }
|