From 20eea4a87296f105f61db75ce017cea9b3ae2e32 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Sat, 5 Mar 2011 15:37:24 +0000 Subject: [PATCH] Refactor the HMEF contents checks to use a superclass, and stub out the Rtf Message body tests (disabled as there looks to be a padding issue still to solve) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1078304 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hmef/HMEFTest.java | 46 +++++++++++++++++++ .../org/apache/poi/hmef/TestAttachments.java | 24 +--------- .../apache/poi/hmef/TestCompressedRTF.java | 24 ++++++++-- .../org/apache/poi/hmef/TestHMEFMessage.java | 31 ++++++++++--- 4 files changed, 93 insertions(+), 32 deletions(-) create mode 100644 src/scratchpad/testcases/org/apache/poi/hmef/HMEFTest.java diff --git a/src/scratchpad/testcases/org/apache/poi/hmef/HMEFTest.java b/src/scratchpad/testcases/org/apache/poi/hmef/HMEFTest.java new file mode 100644 index 000000000..8c68b6820 --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hmef/HMEFTest.java @@ -0,0 +1,46 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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.hmef; + +import java.io.IOException; + +import junit.framework.TestCase; + +import org.apache.poi.POIDataSamples; +import org.apache.poi.util.IOUtils; + +public abstract class HMEFTest extends TestCase { + protected static final POIDataSamples _samples = POIDataSamples.getHMEFInstance(); + + protected void assertContents(String filename, Attachment attachment) + throws IOException { + assertEquals(filename, attachment.getLongFilename()); + assertContents(filename, attachment.getContents()); + } + protected void assertContents(String filename, byte[] actual) + throws IOException { + byte[] expected = IOUtils.toByteArray( + _samples.openResourceAsStream("quick-contents/" + filename) + ); + + assertEquals(expected.length, actual.length); + for(int i=0; i