001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hpsf.basic;
019:
020: import junit.framework.Assert;
021: import junit.framework.TestCase;
022:
023: import org.apache.poi.hpsf.ClassID;
024: import org.apache.poi.hpsf.DocumentSummaryInformation;
025: import org.apache.poi.hpsf.PropertySet;
026: import org.apache.poi.hpsf.SummaryInformation;
027:
028: /**
029: * <p>Tests ClassID structure.</p>
030: *
031: * @author Michael Zalewski (zalewski@optonline.net)
032: */
033: public class TestClassID extends TestCase {
034: /**
035: * <p>Constructor</p>
036: *
037: * @param name the test case's name
038: */
039: public TestClassID(final String name) {
040: super (name);
041: }
042:
043: /**
044: * Various tests of overridden .equals()
045: */
046: public void testEquals() {
047: ClassID clsidTest1 = new ClassID(new byte[] { 0x01, 0x02, 0x03,
048: 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c,
049: 0x0d, 0x0e, 0x0f, 0x10 }, 0);
050: ClassID clsidTest2 = new ClassID(new byte[] { 0x01, 0x02, 0x03,
051: 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c,
052: 0x0d, 0x0e, 0x0f, 0x10 }, 0);
053: ClassID clsidTest3 = new ClassID(new byte[] { 0x01, 0x02, 0x03,
054: 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c,
055: 0x0d, 0x0e, 0x0f, 0x11 }, 0);
056: Assert.assertEquals(clsidTest1, clsidTest1);
057: Assert.assertEquals(clsidTest1, clsidTest2);
058: Assert.assertFalse(clsidTest1.equals(clsidTest3));
059: Assert.assertFalse(clsidTest1.equals(null));
060: }
061:
062: /**
063: * Try to write to a buffer that is too small. This should
064: * throw an Exception
065: */
066: public void testWriteArrayStoreException() {
067: ClassID clsidTest = new ClassID(new byte[] { 0x01, 0x02, 0x03,
068: 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c,
069: 0x0d, 0x0e, 0x0f, 0x10 }, 0);
070: boolean bExceptionOccurred = false;
071: try {
072: clsidTest.write(new byte[15], 0);
073: } catch (Exception e) {
074: bExceptionOccurred = true;
075: }
076: Assert.assertTrue(bExceptionOccurred);
077:
078: bExceptionOccurred = false;
079: try {
080: clsidTest.write(new byte[16], 1);
081: } catch (Exception e) {
082: bExceptionOccurred = true;
083: }
084: Assert.assertTrue(bExceptionOccurred);
085:
086: // These should work without throwing an Exception
087: bExceptionOccurred = false;
088: try {
089: clsidTest.write(new byte[16], 0);
090: clsidTest.write(new byte[17], 1);
091: } catch (Exception e) {
092: bExceptionOccurred = true;
093: }
094: Assert.assertFalse(bExceptionOccurred);
095: }
096:
097: /**
098: * <p>Tests the {@link PropertySet} methods. The test file has two
099: * property set: the first one is a {@link SummaryInformation},
100: * the second one is a {@link DocumentSummaryInformation}.</p>
101: */
102: public void testClassID() {
103: ClassID clsidTest = new ClassID(new byte[] { 0x01, 0x02, 0x03,
104: 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c,
105: 0x0d, 0x0e, 0x0f, 0x10 }, 0);
106: Assert.assertEquals(clsidTest.toString().toUpperCase(),
107: "{04030201-0605-0807-090A-0B0C0D0E0F10}");
108: }
109:
110: /**
111: * <p>Runs the test cases stand-alone.</p>
112: *
113: * @param args Command-line parameters (ignored)
114: */
115: public static void main(final String[] args) {
116: System.setProperty("HPSF.testdata.path",
117: "./src/testcases/org/apache/poi/hpsf/data");
118: junit.textui.TestRunner.run(TestClassID.class);
119: }
120:
121: }
|