From: Nick Burch Date: Sun, 26 Feb 2006 20:10:29 +0000 (+0000) Subject: Tests for Atom for 2000/XP style comments X-Git-Tag: REL_3_0_ALPHA3~172 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7a31899934d2bc32a5a646a3a13874e0d4f506f7;p=poi.git Tests for Atom for 2000/XP style comments git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@381153 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000Atom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000Atom.java new file mode 100644 index 0000000000..cc91249fba --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000Atom.java @@ -0,0 +1,131 @@ + +/* ==================================================================== + 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; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * Tests that Comment2000Atom works properly. + * + * @author Nick Burch (nick at torchbox dot com) + */ +public class TestComment2000Atom extends TestCase { + // From a real file + private byte[] data_a = new byte[] { + 00, 00, 0xE1-256, 0x2E, 0x1C, 00, 00, 00, + 01, 00, 00, 00, 0xD6-256, 07, 01, 00, + 02, 00, 0x18, 00, 0x0A, 00, 0x1A, 00, + 0x0F, 00, 0xCD-256, 00, 0x92-256, 00, + 00, 00, 0x92-256, 00, 00, 00 + }; + private byte[] data_b = new byte[] { + 00, 00, 0xE1-256, 0x2E, 0x1C, 00, 00, 00, + 05, 00, 00, 00, 0xD6-256, 0x07, 01, 00, + 02, 00, 0x18, 00, 0x0A, 00, 0x19, 00, 03, + 00, 0xD5-256, 02, 0x0A, 00, 00, 00, + 0x0E, 00, 00, 00 + }; + + private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS"); + + public void testRecordType() throws Exception { + Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length); + assertEquals(12002l, ca.getRecordType()); + } + + public void testGetDate() throws Exception { + Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length); + Comment2000Atom cb = new Comment2000Atom(data_b, 0, data_b.length); + + // A is 2006-01-24 (2nd day of week) 22:26:15.205 + Date exp_a = sdf.parse("2006-01-24 22:26:15.205"); + // B is 2006-01-24 (2nd day of week) 22:25:03.725 + Date exp_b = sdf.parse("2006-01-24 22:25:03.725"); + + assertEquals(exp_a, ca.getDate()); + assertEquals(exp_b, cb.getDate()); + } + + public void testGetNums() throws Exception { + Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length); + Comment2000Atom cb = new Comment2000Atom(data_b, 0, data_b.length); + + // A is number 1 + assertEquals(1, ca.getNumber()); + // B is number 5 + assertEquals(5, cb.getNumber()); + } + + public void testGetPos() throws Exception { + Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length); + Comment2000Atom cb = new Comment2000Atom(data_b, 0, data_b.length); + + // A is at 0x92, 0x92 + assertEquals(0x92, ca.getXOffset()); + assertEquals(0x92, ca.getYOffset()); + + // B is at 0x0A, 0x0E + assertEquals(0x0A, cb.getXOffset()); + assertEquals(0x0E, cb.getYOffset()); + } + + public void testWrite() throws Exception { + Comment2000Atom ca = new Comment2000Atom(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