From: Nick Burch Date: Sun, 5 Feb 2006 18:37:18 +0000 (+0000) Subject: CString support X-Git-Tag: REL_3_0_ALPHA3~189 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=13a8f91ae689a380ceb07981f6ed6c4d35caa026;p=poi.git CString support git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@375075 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCString.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCString.java new file mode 100644 index 0000000000..a68e3bf1d7 --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCString.java @@ -0,0 +1,113 @@ + +/* ==================================================================== + Copyright 2002-2004 Apache Software Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + + + +package org.apache.poi.hslf.record; + + +import junit.framework.TestCase; +import java.io.ByteArrayOutputStream; + +/** + * Tests that CString works properly + * + * @author Nick Burch (nick at torchbox dot com) + */ +public class TestCString extends TestCase { + // From a real file + private byte[] data_a = new byte[] { 0, 0, 0xBA-256, 0x0f, 0x10, 0, 0, 0, + 0x48, 00, 0x6F, 00, 0x67, 00, 0x77, 00, + 0x61, 00, 0x72, 00, 0x74, 00, 0x73, 00 }; + private byte[] data_b = new byte[] { 0x10, 0, 0xBA-256, 0x0f, 0x10, 0, 0, 0, + 0x43, 00, 0x6F, 00, 0x6D, 00, 0x6D, 00, + 0x65, 00, 0x6E, 00, 0x74, 00, 0x73, 00 }; + + public void testRecordType() throws Exception { + CString ca = new CString(data_a, 0, data_a.length); + assertEquals(4026l, ca.getRecordType()); + CString cb = new CString(data_b, 0, data_a.length); + assertEquals(4026l, cb.getRecordType()); + } + public void testCount() throws Exception { + CString ca = new CString(data_a, 0, data_a.length); + assertEquals(0, ca.getCount()); + CString cb = new CString(data_b, 0, data_a.length); + assertEquals(0x10, cb.getCount()); + + ca.setCount(28); + assertEquals(28, ca.getCount()); + } + + public void testText() throws Exception { + CString ca = new CString(data_a, 0, data_a.length); + assertEquals("Hogwarts", ca.getText()); + CString cb = new CString(data_b, 0, data_a.length); + assertEquals("Comments", cb.getText()); + + ca.setText("FooBar"); + assertEquals("FooBar", ca.getText()); + } + + public void testWrite() throws Exception { + CString ca = new CString(data_a, 0, data_a.length); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ca.writeOut(baos); + byte[] b = baos.toByteArray(); + + assertEquals(data_a.length, b.length); + for(int i=0; i