View | Details | Raw Unified | Return to bug 49185
Collapse All | Expand All

(-)src/java/org/apache/poi/hssf/usermodel/HSSFName.java (-1 / +20 lines)
Lines 19-24 Link Here
19
19
20
import org.apache.poi.hssf.model.HSSFFormulaParser;
20
import org.apache.poi.hssf.model.HSSFFormulaParser;
21
import org.apache.poi.hssf.model.InternalWorkbook;
21
import org.apache.poi.hssf.model.InternalWorkbook;
22
import org.apache.poi.hssf.record.NameCommentRecord;
22
import org.apache.poi.hssf.record.NameRecord;
23
import org.apache.poi.hssf.record.NameRecord;
23
import org.apache.poi.hssf.record.formula.Ptg;
24
import org.apache.poi.hssf.record.formula.Ptg;
24
import org.apache.poi.ss.formula.FormulaType;
25
import org.apache.poi.ss.formula.FormulaType;
Lines 33-40 Link Here
33
public final class HSSFName implements Name {
34
public final class HSSFName implements Name {
34
    private HSSFWorkbook _book;
35
    private HSSFWorkbook _book;
35
    private NameRecord _definedNameRec;
36
    private NameRecord _definedNameRec;
37
    private NameCommentRecord _commentRec;
36
38
37
    /** Creates new HSSFName   - called by HSSFWorkbook to create a sheet from
39
    /** Creates new HSSFName   - called by HSSFWorkbook to create a name from
38
     * scratch.
40
     * scratch.
39
     *
41
     *
40
     * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createName()
42
     * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createName()
Lines 42-49 Link Here
42
     * @param book workbook object associated with the sheet.
44
     * @param book workbook object associated with the sheet.
43
     */
45
     */
44
    /* package */ HSSFName(HSSFWorkbook book, NameRecord name) {
46
    /* package */ HSSFName(HSSFWorkbook book, NameRecord name) {
47
      this(book, name, null);
48
    }
49
    /** Creates new HSSFName   - called by HSSFWorkbook to create a name from
50
     * scratch.
51
     *
52
     * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createName()
53
     * @param name the Name Record
54
     * @param comment the Name Comment Record, optional.
55
     * @param book workbook object associated with the sheet.
56
     */
57
    /* package */ HSSFName(final HSSFWorkbook book, final NameRecord name, final NameCommentRecord comment) {
45
        _book = book;
58
        _book = book;
46
        _definedNameRec = name;
59
        _definedNameRec = name;
60
        _commentRec = comment;
47
    }
61
    }
48
62
49
    /** Get the sheets name which this named range is referenced to
63
    /** Get the sheets name which this named range is referenced to
Lines 231-242 Link Here
231
     * @return the user comment for this named range
245
     * @return the user comment for this named range
232
     */
246
     */
233
    public String getComment(){
247
    public String getComment(){
248
        if (_definedNameRec.getDescriptionText() == null || _definedNameRec.getDescriptionText().length() == 0) {
249
            return _commentRec == null ? null : _commentRec.getCommentText();
250
        }
234
        return _definedNameRec.getDescriptionText();
251
        return _definedNameRec.getDescriptionText();
235
    }
252
    }
236
253
237
    /**
254
    /**
238
     * Sets the comment the user provided when the name was created.
255
     * Sets the comment the user provided when the name was created.
239
     *
256
     *
257
     * NB. This sets the description text field of the {@link NameRecord}, not a seperate {@link NameCommentRecord}.
258
     *
240
     * @param comment the user comment for this named range
259
     * @param comment the user comment for this named range
241
     */
260
     */
242
    public void setComment(String comment){
261
    public void setComment(String comment){
(-)src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (-3 / +3 lines)
Lines 67-73 Link Here
67
import org.apache.poi.poifs.filesystem.DirectoryNode;
67
import org.apache.poi.poifs.filesystem.DirectoryNode;
68
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
68
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
69
import org.apache.poi.ss.usermodel.CreationHelper;
69
import org.apache.poi.ss.usermodel.CreationHelper;
70
import org.apache.poi.ss.usermodel.PictureData;
71
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
70
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
72
import org.apache.poi.ss.formula.FormulaType;
71
import org.apache.poi.ss.formula.FormulaType;
73
import org.apache.poi.util.POILogFactory;
72
import org.apache.poi.util.POILogFactory;
Lines 276-282 Link Here
276
        }
275
        }
277
276
278
        for (int i = 0 ; i < workbook.getNumNames() ; ++i){
277
        for (int i = 0 ; i < workbook.getNumNames() ; ++i){
279
            HSSFName name = new HSSFName(this, workbook.getNameRecord(i));
278
            NameRecord nameRecord = workbook.getNameRecord(i);
279
            HSSFName name = new HSSFName(this, nameRecord, workbook.getNameCommentRecord(nameRecord));
280
            names.add(name);
280
            names.add(name);
281
        }
281
        }
282
    }
282
    }
Lines 970-976 Link Here
970
970
971
        if (isNewRecord)
971
        if (isNewRecord)
972
        {
972
        {
973
            HSSFName newName = new HSSFName(this, nameRecord);
973
            HSSFName newName = new HSSFName(this, nameRecord, nameRecord.isBuiltInName() ? null : workbook.getNameCommentRecord(nameRecord));
974
            names.add(newName);
974
            names.add(newName);
975
        }
975
        }
976
976
(-)src/java/org/apache/poi/hssf/model/LinkTable.java (-4 / +18 lines)
Lines 20-31 Link Here
20
import java.util.ArrayList;
20
import java.util.ArrayList;
21
import java.util.Iterator;
21
import java.util.Iterator;
22
import java.util.List;
22
import java.util.List;
23
import java.util.Map;
23
24
24
import org.apache.poi.hssf.record.CRNCountRecord;
25
import org.apache.poi.hssf.record.CRNCountRecord;
25
import org.apache.poi.hssf.record.CRNRecord;
26
import org.apache.poi.hssf.record.CRNRecord;
26
import org.apache.poi.hssf.record.CountryRecord;
27
import org.apache.poi.hssf.record.CountryRecord;
27
import org.apache.poi.hssf.record.ExternSheetRecord;
28
import org.apache.poi.hssf.record.ExternSheetRecord;
28
import org.apache.poi.hssf.record.ExternalNameRecord;
29
import org.apache.poi.hssf.record.ExternalNameRecord;
30
import org.apache.poi.hssf.record.NameCommentRecord;
29
import org.apache.poi.hssf.record.NameRecord;
31
import org.apache.poi.hssf.record.NameRecord;
30
import org.apache.poi.hssf.record.Record;
32
import org.apache.poi.hssf.record.Record;
31
import org.apache.poi.hssf.record.SupBookRecord;
33
import org.apache.poi.hssf.record.SupBookRecord;
Lines 149-155 Link Here
149
	private final int _recordCount;
151
	private final int _recordCount;
150
	private final WorkbookRecordList _workbookRecordList; // TODO - would be nice to remove this
152
	private final WorkbookRecordList _workbookRecordList; // TODO - would be nice to remove this
151
153
152
	public LinkTable(List inputList, int startIndex, WorkbookRecordList workbookRecordList) {
154
	public LinkTable(List inputList, int startIndex, WorkbookRecordList workbookRecordList, Map<String, NameCommentRecord> commentRecords) {
153
155
154
		_workbookRecordList = workbookRecordList;
156
		_workbookRecordList = workbookRecordList;
155
		RecordStream rs = new RecordStream(inputList, startIndex);
157
		RecordStream rs = new RecordStream(inputList, startIndex);
Lines 177-185 Link Here
177
179
178
		_definedNames = new ArrayList<NameRecord>();
180
		_definedNames = new ArrayList<NameRecord>();
179
		// collect zero or more DEFINEDNAMEs id=0x18
181
		// collect zero or more DEFINEDNAMEs id=0x18
180
		while(rs.peekNextClass() == NameRecord.class) {
182
		while(true) {
181
			NameRecord nr = (NameRecord)rs.getNext();
183
		  Class nextClass = rs.peekNextClass();
182
			_definedNames.add(nr);
184
		  if (nextClass == NameRecord.class) {
185
		    NameRecord nr = (NameRecord)rs.getNext();
186
		    _definedNames.add(nr);
187
		  }
188
189
		  else if (nextClass == NameCommentRecord.class) {
190
		    NameCommentRecord ncr = (NameCommentRecord)rs.getNext();
191
		    commentRecords.put(ncr.getNameText(), ncr);
192
		  }
193
194
		  else {
195
		    break;
196
		  }
183
		}
197
		}
184
198
185
		_recordCount = rs.getCountRead();
199
		_recordCount = rs.getCountRead();
(-)src/java/org/apache/poi/hssf/model/InternalWorkbook.java (-1 / +25 lines)
Lines 20-27 Link Here
20
import java.security.AccessControlException;
20
import java.security.AccessControlException;
21
import java.util.ArrayList;
21
import java.util.ArrayList;
22
import java.util.Iterator;
22
import java.util.Iterator;
23
import java.util.LinkedHashMap;
23
import java.util.List;
24
import java.util.List;
24
import java.util.Locale;
25
import java.util.Locale;
26
import java.util.Map;
25
27
26
import org.apache.poi.ddf.EscherBSERecord;
28
import org.apache.poi.ddf.EscherBSERecord;
27
import org.apache.poi.ddf.EscherBoolProperty;
29
import org.apache.poi.ddf.EscherBoolProperty;
Lines 57-62 Link Here
57
import org.apache.poi.hssf.record.InterfaceEndRecord;
59
import org.apache.poi.hssf.record.InterfaceEndRecord;
58
import org.apache.poi.hssf.record.InterfaceHdrRecord;
60
import org.apache.poi.hssf.record.InterfaceHdrRecord;
59
import org.apache.poi.hssf.record.MMSRecord;
61
import org.apache.poi.hssf.record.MMSRecord;
62
import org.apache.poi.hssf.record.NameCommentRecord;
60
import org.apache.poi.hssf.record.NameRecord;
63
import org.apache.poi.hssf.record.NameRecord;
61
import org.apache.poi.hssf.record.PaletteRecord;
64
import org.apache.poi.hssf.record.PaletteRecord;
62
import org.apache.poi.hssf.record.PasswordRecord;
65
import org.apache.poi.hssf.record.PasswordRecord;
Lines 165-170 Link Here
165
    private WriteAccessRecord writeAccess;
168
    private WriteAccessRecord writeAccess;
166
    private WriteProtectRecord writeProtect;
169
    private WriteProtectRecord writeProtect;
167
170
171
    /**
172
     * Hold the {@link NameCommentRecord}s indexed by the name of the {@link NameRecord} to which they apply.
173
     */
174
    private final Map<String, NameCommentRecord> commentRecords;
175
168
    private InternalWorkbook() {
176
    private InternalWorkbook() {
169
    	records     = new WorkbookRecordList();
177
    	records     = new WorkbookRecordList();
170
178
Lines 176-181 Link Here
176
		maxformatid = -1;
184
		maxformatid = -1;
177
		uses1904datewindowing = false;
185
		uses1904datewindowing = false;
178
		escherBSERecords = new ArrayList<EscherBSERecord>();
186
		escherBSERecords = new ArrayList<EscherBSERecord>();
187
		commentRecords = new LinkedHashMap<String, NameCommentRecord>();
179
    }
188
    }
180
189
181
    /**
190
    /**
Lines 261-267 Link Here
261
                    // LinkTable can start with either of these
270
                    // LinkTable can start with either of these
262
                    if (log.check( POILogger.DEBUG ))
271
                    if (log.check( POILogger.DEBUG ))
263
                        log.log(DEBUG, "found SupBook record at " + k);
272
                        log.log(DEBUG, "found SupBook record at " + k);
264
                    retval.linkTable = new LinkTable(recs, k, retval.records);
273
                    retval.linkTable = new LinkTable(recs, k, retval.records, retval.commentRecords);
265
                    k+=retval.linkTable.getRecordCount() - 1;
274
                    k+=retval.linkTable.getRecordCount() - 1;
266
                    continue;
275
                    continue;
267
                case FormatRecord.sid :
276
                case FormatRecord.sid :
Lines 299-304 Link Here
299
                    if (log.check( POILogger.DEBUG ))
308
                    if (log.check( POILogger.DEBUG ))
300
                        log.log(DEBUG, "found FileSharing at " + k);
309
                        log.log(DEBUG, "found FileSharing at " + k);
301
                    retval.fileShare = (FileSharingRecord) rec;
310
                    retval.fileShare = (FileSharingRecord) rec;
311
                    break;
312
313
                case NameCommentRecord.sid:
314
                    final NameCommentRecord ncr = (NameCommentRecord) rec;
315
                    if (log.check( POILogger.DEBUG ))
316
                        log.log(DEBUG, "found NameComment at " + k);
317
                    retval.commentRecords.put(ncr.getNameText(), ncr);
302
                default :
318
                default :
303
            }
319
            }
304
            records.add(rec);
320
            records.add(rec);
Lines 1823-1828 Link Here
1823
        return linkTable.getNameRecord(index);
1839
        return linkTable.getNameRecord(index);
1824
    }
1840
    }
1825
1841
1842
    /** gets the name comment record
1843
     * @param nameRecord name record who's comment is required.
1844
     * @return name comment record or <code>null</code> if there isn't one for the given name.
1845
     */
1846
    public NameCommentRecord getNameCommentRecord(final NameRecord nameRecord){
1847
        return commentRecords.get(nameRecord.getNameText());
1848
    }
1849
1826
    /** creates new name
1850
    /** creates new name
1827
     * @return new name record
1851
     * @return new name record
1828
     */
1852
     */
(-)src/java/org/apache/poi/hssf/dev/BiffViewer.java (+1 lines)
Lines 197-202 Link Here
197
			case MulBlankRecord.sid:       return new MulBlankRecord(in);
197
			case MulBlankRecord.sid:       return new MulBlankRecord(in);
198
			case MulRKRecord.sid:          return new MulRKRecord(in);
198
			case MulRKRecord.sid:          return new MulRKRecord(in);
199
			case NameRecord.sid:           return new NameRecord(in);
199
			case NameRecord.sid:           return new NameRecord(in);
200
			case NameCommentRecord.sid:    return new NameCommentRecord(in);
200
			case NoteRecord.sid:           return new NoteRecord(in);
201
			case NoteRecord.sid:           return new NoteRecord(in);
201
			case NumberRecord.sid:         return new NumberRecord(in);
202
			case NumberRecord.sid:         return new NumberRecord(in);
202
			case ObjRecord.sid:            return new ObjRecord(in);
203
			case ObjRecord.sid:            return new ObjRecord(in);
(-)src/java/org/apache/poi/hssf/record/NameCommentRecord.java (+138 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.hssf.record;
19
20
import org.apache.poi.util.HexDump;
21
import org.apache.poi.util.LittleEndianInput;
22
import org.apache.poi.util.LittleEndianOutput;
23
import org.apache.poi.util.StringUtil;
24
25
/**
26
 * Title: NAMECMT Record (0x0894)
27
 * <p/>
28
 * Description: Defines a comment associated with a specified name.
29
 * <P>
30
 * REFERENCE:
31
 * <P>
32
 *
33
 * @author Andrew Shirley (aks at corefiling.co.uk)
34
 */
35
public final class NameCommentRecord extends StandardRecord {
36
  public final static short sid = 0x0894;
37
38
  private final short field_1_record_type;
39
  private final short field_2_frt_cell_ref_flag;
40
  private final long field_3_reserved;
41
  //private short             field_4_name_length;
42
  //private short             field_5_comment_length;
43
  private final String field_6_name_text;
44
  private final String field_7_comment_text;
45
46
  public NameCommentRecord(final String name, final String comment) {
47
    field_1_record_type = 0;
48
    field_2_frt_cell_ref_flag = 0;
49
    field_3_reserved = 0;
50
    field_6_name_text = name;
51
    field_7_comment_text = comment;
52
  }
53
54
  @Override
55
  public void serialize(final LittleEndianOutput out) {
56
    final int field_4_name_length = field_6_name_text.length();
57
    final int field_5_comment_length = field_7_comment_text.length();
58
59
    out.writeShort(field_1_record_type);
60
    out.writeShort(field_2_frt_cell_ref_flag);
61
    out.writeLong(field_3_reserved);
62
    out.writeShort(field_4_name_length);
63
    out.writeShort(field_5_comment_length);
64
65
    out.writeByte(0);
66
    out.write(field_6_name_text.getBytes());
67
    out.writeByte(0);
68
    out.write(field_7_comment_text.getBytes());
69
  }
70
71
  @Override
72
  protected int getDataSize() {
73
    return 18 // 4 shorts + 1 long + 2 spurious 'nul's
74
         + field_6_name_text.length()
75
         + field_7_comment_text.length();
76
  }
77
78
  /**
79
   * @param ris the RecordInputstream to read the record from
80
   */
81
  public NameCommentRecord(final RecordInputStream ris) {
82
    final LittleEndianInput in = ris;
83
    field_1_record_type = in.readShort();
84
    field_2_frt_cell_ref_flag = in.readShort();
85
    field_3_reserved = in.readLong();
86
    final int field_4_name_length = in.readShort();
87
    final int field_5_comment_length = in.readShort();
88
89
    in.readByte(); //spurious NUL
90
    field_6_name_text = StringUtil.readCompressedUnicode(in, field_4_name_length);
91
    in.readByte(); //spurious NUL
92
    field_7_comment_text = StringUtil.readCompressedUnicode(in, field_5_comment_length);
93
  }
94
95
  /**
96
   * return the non static version of the id for this record.
97
   */
98
  @Override
99
  public short getSid() {
100
    return sid;
101
  }
102
103
  @Override
104
  public String toString() {
105
    final StringBuffer sb = new StringBuffer();
106
107
    sb.append("[NAMECMT]\n");
108
    sb.append("    .record type            = ").append(HexDump.shortToHex(field_1_record_type)).append("\n");
109
    sb.append("    .frt cell ref flag      = ").append(HexDump.byteToHex(field_2_frt_cell_ref_flag)).append("\n");
110
    sb.append("    .reserved               = ").append(field_3_reserved).append("\n");
111
    sb.append("    .name length            = ").append(field_6_name_text.length()).append("\n");
112
    sb.append("    .comment length         = ").append(field_7_comment_text.length()).append("\n");
113
    sb.append("    .name                   = ").append(field_6_name_text).append("\n");
114
    sb.append("    .comment                = ").append(field_7_comment_text).append("\n");
115
    sb.append("[/NAMECMT]\n");
116
117
    return sb.toString();
118
  }
119
120
  /**
121
   * @return the name of the NameRecord to which this comment applies.
122
   */
123
  public String getNameText() {
124
    return field_6_name_text;
125
  }
126
127
  /**
128
   * @return the text of the comment.
129
   */
130
  public String getCommentText() {
131
    return field_7_comment_text;
132
  }
133
134
  public short getRecordType() {
135
    return field_1_record_type;
136
  }
137
138
}
(-)src/java/org/apache/poi/hssf/record/RecordFactory.java (+1 lines)
Lines 173-178 Link Here
173
		MulBlankRecord.class,
173
		MulBlankRecord.class,
174
		MulRKRecord.class,
174
		MulRKRecord.class,
175
		NameRecord.class,
175
		NameRecord.class,
176
		NameCommentRecord.class,
176
		NoteRecord.class,
177
		NoteRecord.class,
177
		NumberRecord.class,
178
		NumberRecord.class,
178
		ObjectProtectRecord.class,
179
		ObjectProtectRecord.class,
(-)src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (+6 lines)
Lines 1734-1737 Link Here
1734
       assertEquals(234.0, row.getCell(1).getNumericCellValue());
1734
       assertEquals(234.0, row.getCell(1).getNumericCellValue());
1735
}
1735
}
1736
    }
1736
    }
1737
    
1738
    public void test49185() throws Exception {
1739
      final HSSFWorkbook wb = openSample("49185.xls");
1740
      final Name name = wb.getName("foobarName");
1741
      assertEquals("This is a comment", name.getComment());
1742
    }
1737
}
1743
}
(-)src/testcases/org/apache/poi/hssf/model/TestLinkTable.java (-1 / +32 lines)
Lines 18-29 Link Here
18
package org.apache.poi.hssf.model;
18
package org.apache.poi.hssf.model;
19
19
20
import java.util.Arrays;
20
import java.util.Arrays;
21
import java.util.Collections;
22
import java.util.LinkedHashMap;
21
import java.util.List;
23
import java.util.List;
24
import java.util.Map;
22
25
23
import junit.framework.AssertionFailedError;
26
import junit.framework.AssertionFailedError;
24
import junit.framework.TestCase;
27
import junit.framework.TestCase;
25
28
26
import org.apache.poi.hssf.HSSFTestDataSamples;
29
import org.apache.poi.hssf.HSSFTestDataSamples;
30
import org.apache.poi.hssf.record.NameCommentRecord;
31
import org.apache.poi.hssf.record.NameRecord;
27
import org.apache.poi.hssf.record.Record;
32
import org.apache.poi.hssf.record.Record;
28
import org.apache.poi.hssf.record.SSTRecord;
33
import org.apache.poi.hssf.record.SSTRecord;
29
import org.apache.poi.hssf.record.SupBookRecord;
34
import org.apache.poi.hssf.record.SupBookRecord;
Lines 138-144 Link Here
138
		
143
		
139
		LinkTable lt;
144
		LinkTable lt;
140
		try {
145
		try {
141
			lt = new LinkTable(recList, 0, wrl);
146
			lt = new LinkTable(recList, 0, wrl, Collections.<String, NameCommentRecord>emptyMap());
142
		} catch (RuntimeException e) {
147
		} catch (RuntimeException e) {
143
			if (e.getMessage().equals("Expected an EXTERNSHEET record but got (org.apache.poi.hssf.record.SSTRecord)")) {
148
			if (e.getMessage().equals("Expected an EXTERNSHEET record but got (org.apache.poi.hssf.record.SSTRecord)")) {
144
				throw new AssertionFailedError("Identified bug 47001b");
149
				throw new AssertionFailedError("Identified bug 47001b");
Lines 148-151 Link Here
148
		}
153
		}
149
		assertNotNull(lt);
154
		assertNotNull(lt);
150
	}	
155
	}	
156
157
	/**
158
	 *
159
	 */
160
	public void testNameCommentRecordBetweenNameRecords() {
161
162
		final Record[] recs = {
163
        new NameRecord(),
164
        new NameCommentRecord("name1", "comment1"),
165
        new NameRecord(),
166
        new NameCommentRecord("name2", "comment2"),
167
168
		};
169
		final List<Record> recList = Arrays.asList(recs);
170
		final WorkbookRecordList wrl = new WorkbookRecordList();
171
		final Map<String, NameCommentRecord> commentRecords = new LinkedHashMap<String, NameCommentRecord>();
172
173
		final LinkTable	lt = new LinkTable(recList, 0, wrl, commentRecords);
174
		assertNotNull(lt);
175
176
		assertEquals(2, commentRecords.size());
177
    assertTrue(recs[1] == commentRecords.get("name1")); //== is intentionally not .equals()!
178
    assertTrue(recs[3] == commentRecords.get("name2")); //== is intentionally not .equals()!
179
180
    assertEquals(2, lt.getNumNames());
181
	}
151
}
182
}
(-)src/testcases/org/apache/poi/hssf/record/TestNameCommentRecord.java (+42 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.hssf.record;
19
20
import junit.framework.TestCase;
21
22
import org.apache.poi.util.HexRead;
23
24
/**
25
 * Tests the NameCommentRecord serializes/deserializes correctly
26
 *
27
 * @author Andrew Shirley (aks at corefiling.co.uk)
28
 */
29
public final class TestNameCommentRecord extends TestCase {
30
	public void testReserialize() {
31
		final byte[] data = HexRead
32
				.readFromString(""
33
						+ "94 08 00 00 00 00 00 00 00 00 00 00 04 00 07 00 00 6E 61 6D 65 00 63 6F 6D 6D 65 6E 74]");
34
		final RecordInputStream in = TestcaseRecordInputStream.create(NameCommentRecord.sid, data);
35
		final NameCommentRecord ncr = new NameCommentRecord(in);
36
		assertEquals(0x0894, ncr.getRecordType());
37
		assertEquals("name", ncr.getNameText());
38
		assertEquals("comment", ncr.getCommentText());
39
		final byte[] data2 = ncr.serialize();
40
		TestcaseRecordInputStream.confirmRecordEncoding(NameCommentRecord.sid, data, data2);
41
	}
42
}

Return to bug 49185