Skip to content

Commit 0cddb21

Browse files
committed
Add unit test for Unicode XML serialization bug
See: GH-137
1 parent 86da4be commit 0cddb21

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
package org.odftoolkit.odfdom.doc;
20+
21+
import java.io.File;
22+
import org.junit.Assert;
23+
import org.junit.Test;
24+
import org.odftoolkit.odfdom.doc.table.OdfTableCell;
25+
import org.odftoolkit.odfdom.utils.ResourceUtilities;
26+
27+
/**
28+
* Test for Unicode astral character XML serialization bug.
29+
*
30+
* @see <a href="https://github.com/tdf/odftoolkit/issues/137">GH-137</a>
31+
* @author Daniel Gerhardt
32+
*/
33+
public class UnicodeSerializationGh137Test {
34+
@Test
35+
public void testSaveAndLoadDocumentWithUnicodeEmojiCharacter() throws Exception {
36+
OdfSpreadsheetDocument document = OdfSpreadsheetDocument.newSpreadsheetDocument();
37+
// content contains 🙂 emoji
38+
String content = "text with an Unicode emoji \uD83D\uDE42";
39+
OdfTableCell cell = document.getSpreadsheetTables().get(0).getCellByPosition(0, 0);
40+
cell.setStringValue(content);
41+
File destination =
42+
File.createTempFile("gh137-test-emoji", ".ods", ResourceUtilities.getTempTestDirectory());
43+
document.save(destination);
44+
45+
OdfSpreadsheetDocument loadedDocument = OdfSpreadsheetDocument.loadDocument(destination);
46+
OdfTableCell loadedCell = loadedDocument.getSpreadsheetTables().get(0).getCellByPosition(0, 0);
47+
Assert.assertEquals(content, loadedCell.getStringValue());
48+
}
49+
50+
@Test
51+
public void testSaveAndLoadDocumentWithGreekCharacter() throws Exception {
52+
OdfSpreadsheetDocument document = OdfSpreadsheetDocument.newSpreadsheetDocument();
53+
// content contains Greek 𝜈 (Nu) character
54+
String content = "text with a Greek character \uD835\uDF08";
55+
OdfTableCell cell = document.getSpreadsheetTables().get(0).getCellByPosition(0, 0);
56+
cell.setStringValue(content);
57+
File destination =
58+
File.createTempFile("gh137-test-greek", ".ods", ResourceUtilities.getTempTestDirectory());
59+
document.save(destination);
60+
61+
OdfSpreadsheetDocument loadedDocument = OdfSpreadsheetDocument.loadDocument(destination);
62+
OdfTableCell loadedCell = loadedDocument.getSpreadsheetTables().get(0).getCellByPosition(0, 0);
63+
Assert.assertEquals(content, loadedCell.getStringValue());
64+
}
65+
66+
@Test
67+
public void testSaveAndLoadDocumentWithPlainAscii() throws Exception {
68+
OdfSpreadsheetDocument document = OdfSpreadsheetDocument.newSpreadsheetDocument();
69+
String content = "simple ASCII text";
70+
OdfTableCell cell = document.getSpreadsheetTables().get(0).getCellByPosition(0, 0);
71+
cell.setStringValue(content);
72+
File destination =
73+
File.createTempFile("gh137-test-ascii", ".ods", ResourceUtilities.getTempTestDirectory());
74+
document.save(destination);
75+
76+
OdfSpreadsheetDocument loadedDocument = OdfSpreadsheetDocument.loadDocument(destination);
77+
OdfTableCell loadedCell = loadedDocument.getSpreadsheetTables().get(0).getCellByPosition(0, 0);
78+
Assert.assertEquals(content, loadedCell.getStringValue());
79+
}
80+
}

0 commit comments

Comments
 (0)