Skip to content

Commit 997a460

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

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
String content = "text with an Unicode emoji \uD83D\uDE42";
38+
OdfTableCell cell = document.getSpreadsheetTables().get(0).getCellByPosition(0, 0);
39+
cell.setStringValue(content);
40+
File destination =
41+
File.createTempFile("gh137-test-emoji", ".ods", ResourceUtilities.getTempTestDirectory());
42+
document.save(destination);
43+
44+
OdfSpreadsheetDocument loadedDocument = OdfSpreadsheetDocument.loadDocument(destination);
45+
OdfTableCell loadedCell = loadedDocument.getSpreadsheetTables().get(0).getCellByPosition(0, 0);
46+
Assert.assertEquals(content, loadedCell.getStringValue());
47+
}
48+
49+
@Test
50+
public void testSaveAndLoadDocumentWithPlainAscii() throws Exception {
51+
OdfSpreadsheetDocument document = OdfSpreadsheetDocument.newSpreadsheetDocument();
52+
String content = "simple ASCII text";
53+
OdfTableCell cell = document.getSpreadsheetTables().get(0).getCellByPosition(0, 0);
54+
cell.setStringValue(content);
55+
File destination =
56+
File.createTempFile("gh137-test-ascii", ".ods", ResourceUtilities.getTempTestDirectory());
57+
document.save(destination);
58+
59+
OdfSpreadsheetDocument loadedDocument = OdfSpreadsheetDocument.loadDocument(destination);
60+
OdfTableCell loadedCell = loadedDocument.getSpreadsheetTables().get(0).getCellByPosition(0, 0);
61+
Assert.assertEquals(content, loadedCell.getStringValue());
62+
}
63+
}

0 commit comments

Comments
 (0)