|
Lines 45-66
Link Here
|
| 45 |
|
45 |
|
| 46 |
checkEncodedContents(ENCODING_NOTSUPPORTED, ENCODING_NOTSUPPORTED, ENCODING_UTF8); |
46 |
checkEncodedContents(ENCODING_NOTSUPPORTED, ENCODING_NOTSUPPORTED, ENCODING_UTF8); |
| 47 |
checkEncodedContents(ENCODING_NOTSUPPORTED, ENCODING_NOTSUPPORTED, ENCODING_UTF16); |
47 |
checkEncodedContents(ENCODING_NOTSUPPORTED, ENCODING_NOTSUPPORTED, ENCODING_UTF16); |
|
|
48 |
|
| 49 |
checkEncodedContents(ENCODING_UTF16, ENCODING_UTF16, ENCODING_UTF16, true); |
| 50 |
checkEncodedContents(ENCODING_UTF8, ENCODING_UTF8, ENCODING_UTF8, true); |
| 51 |
|
| 52 |
checkEncodedContents(ENCODING_UTF16, ENCODING_UTF16, ENCODING_UTF8, true); |
| 53 |
checkEncodedContents(ENCODING_UTF8, ENCODING_UTF8, ENCODING_UTF16, true); |
| 54 |
|
| 55 |
checkEncodedContents(ENCODING_NOTSUPPORTED, ENCODING_NOTSUPPORTED, ENCODING_UTF8, true); |
| 56 |
checkEncodedContents(ENCODING_NOTSUPPORTED, ENCODING_NOTSUPPORTED, ENCODING_UTF16, true); |
| 48 |
} |
57 |
} |
| 49 |
|
58 |
|
| 50 |
public void testEncodedContents2() throws Exception { |
59 |
public void testEncodedContents2() throws Exception { |
| 51 |
checkEncodedContents2(ENCODING_UTF16, ENCODING_UTF16); |
60 |
checkEncodedContents2(ENCODING_UTF16, ENCODING_UTF16); |
| 52 |
checkEncodedContents2(ENCODING_UTF8, ENCODING_UTF8); |
61 |
checkEncodedContents2(ENCODING_UTF8, ENCODING_UTF8); |
| 53 |
checkEncodedContents2(ENCODING_NOTSUPPORTED, ENCODING_NOTSUPPORTED); |
62 |
checkEncodedContents2(ENCODING_NOTSUPPORTED, ENCODING_NOTSUPPORTED); |
|
|
63 |
|
| 64 |
checkEncodedContents2(ENCODING_UTF16, ENCODING_UTF16, true); |
| 65 |
checkEncodedContents2(ENCODING_UTF8, ENCODING_UTF8, true); |
| 66 |
checkEncodedContents2(ENCODING_NOTSUPPORTED, ENCODING_NOTSUPPORTED, true); |
| 54 |
} |
67 |
} |
| 55 |
|
68 |
|
| 56 |
public void testEncodedContents3() throws Exception { |
69 |
public void testEncodedContents3() throws Exception { |
| 57 |
IContentDescription description = Platform.getContentTypeManager().getDescriptionFor(getInputStream(ENCODING_INCORRECT, ENCODING_UTF8), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET}); |
70 |
IContentDescription description = Platform.getContentTypeManager().getDescriptionFor(getInputStream(ENCODING_INCORRECT, ENCODING_UTF8, false), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET}); |
|
|
71 |
assertNull("1.0", description); |
| 72 |
|
| 73 |
description = Platform.getContentTypeManager().getDescriptionFor(getInputStream(ENCODING_INCORRECT, ENCODING_UTF16, false), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET}); |
| 74 |
assertNull("2.0", description); |
| 75 |
|
| 76 |
description = Platform.getContentTypeManager().getDescriptionFor(getReader(ENCODING_INCORRECT, false), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET}); |
| 77 |
assertNull("3.0", description); |
| 78 |
|
| 79 |
description = Platform.getContentTypeManager().getDescriptionFor(getInputStream(ENCODING_INCORRECT, ENCODING_UTF8, true), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET}); |
| 58 |
assertNull("1.0", description); |
80 |
assertNull("1.0", description); |
| 59 |
|
81 |
|
| 60 |
description = Platform.getContentTypeManager().getDescriptionFor(getInputStream(ENCODING_INCORRECT, ENCODING_UTF16), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET}); |
82 |
description = Platform.getContentTypeManager().getDescriptionFor(getInputStream(ENCODING_INCORRECT, ENCODING_UTF16, true), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET}); |
| 61 |
assertNull("2.0", description); |
83 |
assertNull("2.0", description); |
| 62 |
|
84 |
|
| 63 |
description = Platform.getContentTypeManager().getDescriptionFor(getReader(ENCODING_INCORRECT), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET}); |
85 |
description = Platform.getContentTypeManager().getDescriptionFor(getReader(ENCODING_INCORRECT, true), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET}); |
| 64 |
assertNull("3.0", description); |
86 |
assertNull("3.0", description); |
| 65 |
} |
87 |
} |
| 66 |
|
88 |
|
|
Lines 68-94
Link Here
|
| 68 |
return new TestSuite(XMLContentDescriberTest.class); |
90 |
return new TestSuite(XMLContentDescriberTest.class); |
| 69 |
} |
91 |
} |
| 70 |
|
92 |
|
| 71 |
private void checkEncodedContents(String resultEncoding, String encodingInContent, String encoding) throws Exception { |
93 |
private void checkEncodedContents(String resultEncoding, String encodingInContent, String encoding, boolean encInNewLine) throws Exception { |
| 72 |
IContentDescription description = Platform.getContentTypeManager().getDescriptionFor(getInputStream(encodingInContent, encoding), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET}); |
94 |
IContentDescription description = Platform.getContentTypeManager().getDescriptionFor(getInputStream(encodingInContent, encoding, encInNewLine), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET}); |
| 73 |
assertNotNull("1.0", description); |
95 |
assertNotNull("1.0", description); |
| 74 |
assertEquals("1.1", Platform.PI_RUNTIME + ".xml", description.getContentType().getId()); |
96 |
assertEquals("1.1", Platform.PI_RUNTIME + ".xml", description.getContentType().getId()); |
| 75 |
assertEquals("1.2", resultEncoding, description.getProperty(IContentDescription.CHARSET)); |
97 |
assertEquals("1.2", resultEncoding, description.getProperty(IContentDescription.CHARSET)); |
| 76 |
} |
98 |
} |
| 77 |
|
99 |
|
| 78 |
private void checkEncodedContents2(String resultEncoding, String encodingInContent) throws Exception { |
100 |
private void checkEncodedContents(String resultEncoding, String encodingInContent, String encoding) throws Exception { |
| 79 |
IContentDescription description = Platform.getContentTypeManager().getDescriptionFor(getReader(encodingInContent), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET}); |
101 |
checkEncodedContents(resultEncoding, encodingInContent, encoding, false); |
|
|
102 |
} |
| 103 |
|
| 104 |
private void checkEncodedContents2(String resultEncoding, String encodingInContent, boolean encInNewLine) throws Exception { |
| 105 |
IContentDescription description = Platform.getContentTypeManager().getDescriptionFor(getReader(encodingInContent, encInNewLine), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET}); |
| 80 |
assertNotNull("2.0", description); |
106 |
assertNotNull("2.0", description); |
| 81 |
assertEquals("2.1", Platform.PI_RUNTIME + ".xml", description.getContentType().getId()); |
107 |
assertEquals("2.1", Platform.PI_RUNTIME + ".xml", description.getContentType().getId()); |
| 82 |
assertEquals("2.2", resultEncoding, description.getProperty(IContentDescription.CHARSET)); |
108 |
assertEquals("2.2", resultEncoding, description.getProperty(IContentDescription.CHARSET)); |
| 83 |
} |
109 |
} |
| 84 |
|
110 |
|
| 85 |
private InputStream getInputStream(String encodingInContent, String encoding) throws UnsupportedEncodingException { |
111 |
private void checkEncodedContents2(String resultEncoding, String encodingInContent) throws Exception { |
| 86 |
String content = "<?xml version=\"1.0\" encoding=\"" + encodingInContent + "\"?><root attribute=\"" + ENCODED_TEXT + "\">"; |
112 |
checkEncodedContents2(resultEncoding, encodingInContent, false); |
|
|
113 |
} |
| 114 |
|
| 115 |
private InputStream getInputStream(String encodingInContent, String encoding, boolean encInNewLine) throws UnsupportedEncodingException { |
| 116 |
String content = "<?xml version=\"1.0\"" + (encInNewLine ? "\n" : "") + "encoding=\"" + encodingInContent + "\"?><root attribute=\"" + ENCODED_TEXT + "\">"; |
| 87 |
return new ByteArrayInputStream(content.getBytes(encoding)); |
117 |
return new ByteArrayInputStream(content.getBytes(encoding)); |
| 88 |
} |
118 |
} |
| 89 |
|
119 |
|
| 90 |
private Reader getReader(String encodingInContent) { |
120 |
private Reader getReader(String encodingInContent, boolean encInNewLine) { |
| 91 |
String content = "<?xml version=\"1.0\" encoding=\"" + encodingInContent + "\"?><root attribute=\"" + ENCODED_TEXT + "\">"; |
121 |
String content = "<?xml version=\"1.0\"" + (encInNewLine ? "\n" : "") + " encoding=\"" + encodingInContent + "\"?><root attribute=\"" + ENCODED_TEXT + "\">"; |
| 92 |
return new InputStreamReader(new ByteArrayInputStream(content.getBytes())); |
122 |
return new InputStreamReader(new ByteArrayInputStream(content.getBytes())); |
| 93 |
} |
123 |
} |
| 94 |
} |
124 |
} |