poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1516314 - /poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
Date Wed, 21 Aug 2013 22:19:59 GMT
Author: centic
Date: Wed Aug 21 22:19:58 2013
New Revision: 1516314

URL: http://svn.apache.org/r1516314
Log:
Adjust test for Bug 50298 to not leave a temporary file behind and
enhance the test with some more cases of moving/changing/removing sheet
order/names

Modified:
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java?rev=1516314&r1=1516313&r2=1516314&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java Wed Aug 21
22:19:58 2013
@@ -897,15 +897,67 @@ public final class TestHSSFWorkbook exte
 	public void testBug50298() throws Exception {
 		HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("50298.xls");
 
+		assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received");
+
+		HSSFSheet sheet = wb.cloneSheet(0);
+		
+		assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received", "Invoice
(2)");
+
+		wb.setSheetName(wb.getSheetIndex(sheet), "copy");
+
+		assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received", "copy");
+
+		wb.setSheetOrder("copy", 0);
+
+		assertSheetOrder(wb, "copy", "Invoice", "Invoice1", "Digest", "Deferred", "Received");
+
+		wb.removeSheetAt(0);
+		
+		assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received");
+
+		// check that the overall workbook serializes with its correct size
+		int expected = wb.getWorkbook().getSize();
+		int written = wb.getWorkbook().serialize(0, new byte[expected*2]);
+		
+		assertEquals("Did not have the expected size when writing the workbook: written: " + written
+ ", but expected: " + expected,
+				expected, written);
+		
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		wb.write(out);
 		
+		HSSFWorkbook read = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+		assertSheetOrder(read, "Invoice", "Invoice1", "Digest", "Deferred", "Received");
+	}
+
+	public void testBug50298a() throws Exception {
+		HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("50298.xls");
+
+		assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received");
+
 		HSSFSheet sheet = wb.cloneSheet(0);
+		
+		assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received", "Invoice
(2)");
 
 		wb.setSheetName(wb.getSheetIndex(sheet), "copy");
 
+		assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received", "copy");
+
 		wb.setSheetOrder("copy", 0);
 
+		assertSheetOrder(wb, "copy", "Invoice", "Invoice1", "Digest", "Deferred", "Received");
+
 		wb.removeSheetAt(0);
 		
+		assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received");
+
+		wb.removeSheetAt(1);
+		
+		assertSheetOrder(wb, "Invoice", "Digest", "Deferred", "Received");
+		
+		wb.setSheetOrder("Digest", 3);
+
+		assertSheetOrder(wb, "Invoice", "Deferred", "Received", "Digest");
+		
 		// check that the overall workbook serializes with its correct size
 		int expected = wb.getWorkbook().getSize();
 		int written = wb.getWorkbook().serialize(0, new byte[expected*2]);
@@ -913,11 +965,23 @@ public final class TestHSSFWorkbook exte
 		assertEquals("Did not have the expected size when writing the workbook: written: " + written
+ ", but expected: " + expected,
 				expected, written);
 		
-		FileOutputStream fileOut = new FileOutputStream("/tmp/workbook.xls");
-		try {
-			wb.write(fileOut);
-		} finally {
-			fileOut.close();
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		wb.write(out);
+		
+		HSSFWorkbook read = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+		assertSheetOrder(wb, "Invoice", "Deferred", "Received", "Digest");
+	}
+	
+	private void assertSheetOrder(HSSFWorkbook wb, String... sheets) {
+		StringBuilder sheetNames = new StringBuilder();
+		for(int i = 0;i < wb.getNumberOfSheets();i++) {
+			sheetNames.append(wb.getSheetAt(i).getSheetName()).append(",");
+		}
+		assertEquals("Had: " + sheetNames.toString(), 
+				sheets.length, wb.getNumberOfSheets());
+		for(int i = 0;i < wb.getNumberOfSheets();i++) {
+			assertEquals("Had: " + sheetNames.toString(), 
+					sheets[i], wb.getSheetAt(i).getSheetName());
 		}
 	}
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message