aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2015-06-21 19:06:32 +0000
committerAndreas Beeker <kiwiwings@apache.org>2015-06-21 19:06:32 +0000
commite90b9dd5e1e28b9f44f5e393b49d3679ca361b56 (patch)
treee8558761ee6348dd5f281b611571d5ab550ee2a3 /src/testcases/org/apache
parent230990a630f7959f95d1d37b25b3b7c207c12f6c (diff)
downloadpoi-e90b9dd5e1e28b9f44f5e393b49d3679ca361b56.tar.gz
poi-e90b9dd5e1e28b9f44f5e393b49d3679ca361b56.zip
Bug 58040 - Log Forging
and marked POILogger/POILogFactory internal git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1686748 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache')
-rw-r--r--src/testcases/org/apache/poi/util/AllPOIUtilTests.java41
-rw-r--r--src/testcases/org/apache/poi/util/TestPOILogger.java71
2 files changed, 78 insertions, 34 deletions
diff --git a/src/testcases/org/apache/poi/util/AllPOIUtilTests.java b/src/testcases/org/apache/poi/util/AllPOIUtilTests.java
index de6739bb7f..34ad0f4bd3 100644
--- a/src/testcases/org/apache/poi/util/AllPOIUtilTests.java
+++ b/src/testcases/org/apache/poi/util/AllPOIUtilTests.java
@@ -17,30 +17,29 @@
package org.apache.poi.util;
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
/**
* Test suite for all sub-packages of org.apache.poi.util<br/>
*/
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ TestArrayUtil.class
+ , TestBinaryTree.class
+ , TestBitField.class
+ , TestByteField.class
+ , TestHexDump.class
+ , TestIntegerField.class
+ , TestIntList.class
+ , TestLittleEndian.class
+ , TestLongField.class
+ , TestPOILogFactory.class
+ , TestPOILogger.class
+ , TestShortField.class
+ , TestShortList.class
+ , TestStringUtil.class
+ , TestTempFile.class
+})
public final class AllPOIUtilTests {
- public static Test suite() {
- TestSuite result = new TestSuite(AllPOIUtilTests.class.getName());
- result.addTestSuite(TestArrayUtil.class);
- result.addTestSuite(TestBinaryTree.class);
- result.addTestSuite(TestBitField.class);
- result.addTestSuite(TestByteField.class);
- result.addTestSuite(TestHexDump.class);
- result.addTestSuite(TestIntegerField.class);
- result.addTestSuite(TestIntList.class);
- result.addTestSuite(TestLittleEndian.class);
- result.addTestSuite(TestLongField.class);
- result.addTestSuite(TestPOILogFactory.class);
- result.addTestSuite(TestPOILogger.class);
- result.addTestSuite(TestShortField.class);
- result.addTestSuite(TestShortList.class);
- result.addTestSuite(TestStringUtil.class);
- result.addTestSuite(TestTempFile.class);
- return result;
- }
}
diff --git a/src/testcases/org/apache/poi/util/TestPOILogger.java b/src/testcases/org/apache/poi/util/TestPOILogger.java
index a3d34fac17..7fc5824d45 100644
--- a/src/testcases/org/apache/poi/util/TestPOILogger.java
+++ b/src/testcases/org/apache/poi/util/TestPOILogger.java
@@ -18,7 +18,13 @@
package org.apache.poi.util;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.Field;
+
+import org.junit.Test;
/**
* Tests the log class.
@@ -27,23 +33,62 @@ import junit.framework.TestCase;
* @author Marc Johnson (mjohnson at apache dot org)
* @author Nicola Ken Barozzi (nicolaken at apache.org)
*/
-public final class TestPOILogger extends TestCase {
-
+public final class TestPOILogger extends POILogger {
+ private String lastLog = "";
+ private Throwable lastEx = null;
+
/**
* Test different types of log output.
*/
- public void testVariousLogTypes() {
- //NKB Testing only that logging classes use gives no exception
- // Since logging can be disabled, no checking of logging
- // output is done.
+ @Test
+ public void testVariousLogTypes() throws Exception {
+ Field f = POILogFactory.class.getDeclaredField("_loggerClassName");
+ f.setAccessible(true);
+ String oldLCN = (String)f.get(null);
+ try {
+ f.set(null, TestPOILogger.class.getName());
+ POILogger log = POILogFactory.getLogger( "foo" );
+ assertTrue(log instanceof TestPOILogger);
+
+ TestPOILogger tlog = (TestPOILogger)log;
+
+ log.log(POILogger.WARN, "Test = ", 1);
+ assertEquals("Test = 1", tlog.lastLog);
+
+ log.logFormatted(POILogger.ERROR, "Test param 1 = %, param 2 = %d", "2", 3 );
+ assertEquals("Test param 1 = 2, param 2 = 3", tlog.lastLog);
+
+ log.logFormatted(POILogger.ERROR, "Test param 1 = %d, param 2 = %", new int[]{4, 5} );
+ assertEquals("Test param 1 = 4, param 2 = 5", tlog.lastLog);
+
+ log.logFormatted(POILogger.ERROR, "Test param 1 = %1.1, param 2 = %0.1", new double[]{4, 5.23} );
+ assertEquals("Test param 1 = 4, param 2 = 5.2", tlog.lastLog);
- POILogger log = POILogFactory.getLogger( "foo" );
+ log.log(POILogger.ERROR, "Test ", 1,2,new Exception("bla"));
+ assertEquals("Test 12", tlog.lastLog);
+ assertNotNull(tlog.lastEx);
+
+ log.log(POILogger.ERROR, "log\nforging", "\nevil","\nlog");
+ assertEquals("log forging evil log", tlog.lastLog);
+ } finally {
+ f.set(null, oldLCN);
+ }
+ }
- log.log( POILogger.WARN, "Test = ", Integer.valueOf( 1 ) );
- log.logFormatted( POILogger.ERROR, "Test param 1 = %, param 2 = %", "2", Integer.valueOf( 3 ) );
- log.logFormatted( POILogger.ERROR, "Test param 1 = %, param 2 = %", new int[]{4, 5} );
- log.logFormatted( POILogger.ERROR,
- "Test param 1 = %1.1, param 2 = %0.1", new double[]{4, 5.23} );
+ public void initialize(String cat) {
+ }
+
+ public void log(int level, Object obj1) {
+ lastLog = (obj1 == null) ? "" : obj1.toString();
+ lastEx = null;
+ }
+
+ public void log(int level, Object obj1, Throwable exception) {
+ lastLog = (obj1 == null) ? "" : obj1.toString();
+ lastEx = exception;
+ }
+ public boolean check(int level) {
+ return true;
}
}