49599 - Correct writing of NoteRecord author text when switching between ASCII and Unicode

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@964800 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2010-07-16 13:57:17 +00:00
parent 8c763967ab
commit 6d93fb9d5d
3 changed files with 35 additions and 0 deletions

View File

@ -34,6 +34,7 @@
<changes>
<release version="3.7-beta2" date="2010-??-??">
<action dev="POI-DEVELOPERS" type="fix">49599 - Correct writing of NoteRecord author text when switching between ASCII and Unicode</action>
<action dev="POI-DEVELOPERS" type="fix">HWPF: Improve reading of auto-saved ("complex") documents</action>
<action dev="POI-DEVELOPERS" type="add">Paragraph level as well as whole-file text extraction for Word 6/95 files through HWPF</action>
<action dev="POI-DEVELOPERS" type="add">Text Extraction support for older Word 6 and Word 95 files via HWPF</action>

View File

@ -191,6 +191,13 @@ public final class NoteRecord extends StandardRecord {
field_3_flags = flags;
}
/**
* For unit testing only!
*/
protected boolean authorIsMultibyte() {
return field_5_hasMultibyte;
}
/**
* Object id for OBJ record that contains the comment
*/
@ -221,6 +228,7 @@ public final class NoteRecord extends StandardRecord {
*/
public void setAuthor(String author) {
field_6_author = author;
field_5_hasMultibyte = StringUtil.hasMultibyte(author);
}
public Object clone() {

View File

@ -102,8 +102,34 @@ public final class TestNoteRecord extends TestCase {
throw new AssertionFailedError("Identified bug in reading note with unicode author");
}
assertEquals("\u30A2\u30D1\u30C3\u30C1\u65CF", nr.getAuthor());
assertTrue(nr.authorIsMultibyte());
byte[] ser = nr.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(NoteRecord.sid, data, ser);
// Re-check
in = TestcaseRecordInputStream.create(ser);
nr = new NoteRecord(in);
assertEquals("\u30A2\u30D1\u30C3\u30C1\u65CF", nr.getAuthor());
assertTrue(nr.authorIsMultibyte());
// Change to a non unicode author, will stop being unicode
nr.setAuthor("Simple");
ser = nr.serialize();
in = TestcaseRecordInputStream.create(ser);
nr = new NoteRecord(in);
assertEquals("Simple", nr.getAuthor());
assertFalse(nr.authorIsMultibyte());
// Now set it back again
nr.setAuthor("Unicode\u1234");
ser = nr.serialize();
in = TestcaseRecordInputStream.create(ser);
nr = new NoteRecord(in);
assertEquals("Unicode\u1234", nr.getAuthor());
assertTrue(nr.authorIsMultibyte());
}
}