throw new RuntimeException(e);\r
}\r
}\r
+\r
+ /**\r
+ * @return byte array of sample file content from file found in standard hssf test data dir \r
+ */\r
+ public static byte[] getTestDataFileContent(String fileName) {\r
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();\r
+\r
+ try {\r
+ InputStream fis = HSSFTestDataSamples.openSampleFileStream(fileName);\r
+\r
+ byte[] buf = new byte[512];\r
+ while (true) {\r
+ int bytesRead = fis.read(buf);\r
+ if (bytesRead < 1) {\r
+ break;\r
+ }\r
+ bos.write(buf, 0, bytesRead);\r
+ }\r
+ fis.close();\r
+ } catch (IOException e) {\r
+ throw new RuntimeException(e);\r
+ }\r
+ return bos.toByteArray();\r
+ }\r
}\r
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hssf.usermodel;
import junit.framework.Test;
result.addTestSuite(TestHSSFHeaderFooter.class);
result.addTestSuite(TestHSSFHyperlink.class);
result.addTestSuite(TestHSSFPalette.class);
+ result.addTestSuite(TestHSSFPatriarch.class);
result.addTestSuite(TestHSSFPicture.class);
result.addTestSuite(TestHSSFPictureData.class);
result.addTestSuite(TestHSSFRichTextString.class);
--- /dev/null
+/* ====================================================================\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.hssf.usermodel;\r
+\r
+import org.apache.poi.hssf.HSSFTestDataSamples;\r
+\r
+import junit.framework.AssertionFailedError;\r
+import junit.framework.TestCase;\r
+\r
+/**\r
+ * @author Josh Micich\r
+ */\r
+public final class TestHSSFPatriarch extends TestCase {\r
+\r
+ public void testBasic() {\r
+\r
+ HSSFWorkbook wb = new HSSFWorkbook();\r
+ HSSFSheet sheet = wb.createSheet();\r
+\r
+ HSSFPatriarch patr = sheet.createDrawingPatriarch();\r
+\r
+ assertNotNull(patr);\r
+\r
+ // assert something more interesting\r
+ }\r
+\r
+ // TODO - fix bug 44916 (1-May-2008)\r
+ public void DISABLED_test44916() {\r
+\r
+ HSSFWorkbook wb = new HSSFWorkbook();\r
+ HSSFSheet sheet = wb.createSheet();\r
+\r
+ // 1. Create drawing patriarch\r
+ HSSFPatriarch patr = sheet.createDrawingPatriarch();\r
+\r
+ // 2. Try to re-get the patriarch\r
+ HSSFPatriarch existingPatr;\r
+ try {\r
+ existingPatr = sheet.getDrawingPatriarch();\r
+ } catch (NullPointerException e) {\r
+ throw new AssertionFailedError("Identified bug 44916");\r
+ }\r
+\r
+ // 3. Use patriarch\r
+ HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 600, 245, (short) 1, 1, (short) 1, 2);\r
+ anchor.setAnchorType(3);\r
+ byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("logoKarmokar4.png");\r
+ int idx1 = wb.addPicture(pictureData, HSSFWorkbook.PICTURE_TYPE_PNG);\r
+ patr.createPicture(anchor, idx1);\r
+\r
+ // 4. Try to re-use patriarch later\r
+ existingPatr = sheet.getDrawingPatriarch();\r
+ assertNotNull(existingPatr);\r
+ }\r
+\r
+}\r
*/\r
package org.apache.poi.hssf.usermodel;\r
\r
-import java.io.ByteArrayOutputStream;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-\r
import junit.framework.TestCase;\r
\r
import org.apache.poi.hssf.HSSFTestDataSamples;\r
HSSFSheet sh1 = wb.createSheet();\r
HSSFPatriarch p1 = sh1.createDrawingPatriarch();\r
\r
- byte[] pictureData = getTestDataFileContent("logoKarmokar4.png");\r
+ byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("logoKarmokar4.png");\r
int idx1 = wb.addPicture( pictureData, HSSFWorkbook.PICTURE_TYPE_PNG );\r
HSSFPicture picture1 = p1.createPicture(new HSSFClientAnchor(), idx1);\r
HSSFClientAnchor anchor1 = picture1.getPreferredSize();\r
assertEquals(848, anchor1.getDx2());\r
assertEquals(240, anchor1.getDy2());\r
}\r
-\r
- /**\r
- * Copied from org.apache.poi.hssf.usermodel.examples.OfficeDrawing\r
- */\r
- private static byte[] getTestDataFileContent(String fileName) {\r
- ByteArrayOutputStream bos = new ByteArrayOutputStream();\r
-\r
- try {\r
- InputStream fis = HSSFTestDataSamples.openSampleFileStream(fileName);\r
-\r
- byte[] buf = new byte[512];\r
- while(true) {\r
- int bytesRead = fis.read(buf);\r
- if(bytesRead < 1) {\r
- break;\r
- }\r
- bos.write(buf, 0, bytesRead);\r
- }\r
- fis.close();\r
- } catch (IOException e) {\r
- throw new RuntimeException(e);\r
- }\r
- return bos.toByteArray();\r
- }\r
}\r