diff options
author | Thomas Watson | 2009-08-05 21:20:04 +0000 |
---|---|---|
committer | Thomas Watson | 2009-08-05 21:20:04 +0000 |
commit | 253b5eb592ae85e1dd67afb448dfd41932a86960 (patch) | |
tree | 389938b96750416556c52ba66ac09fd2f458ab4e | |
parent | 1a1b13d16a0784cd511c5ed858b1852700375743 (diff) | |
download | rt.equinox.framework-253b5eb592ae85e1dd67afb448dfd41932a86960.tar.gz rt.equinox.framework-253b5eb592ae85e1dd67afb448dfd41932a86960.tar.xz rt.equinox.framework-253b5eb592ae85e1dd67afb448dfd41932a86960.zip |
Bug 285292 Trace fails to determine class/method/line number when using a tracing class
2 files changed, 56 insertions, 4 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/debugoptions/DebugOptionsTestCase.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/debugoptions/DebugOptionsTestCase.java index 47722f259..6c1a27543 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/debugoptions/DebugOptionsTestCase.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/debugoptions/DebugOptionsTestCase.java @@ -14,6 +14,7 @@ package org.eclipse.osgi.tests.debugoptions; import java.util.*; import java.util.Map.Entry; import junit.framework.*; +import org.eclipse.osgi.framework.debug.FrameworkDebugTraceEntry; import org.eclipse.osgi.service.debug.DebugOptions; import org.eclipse.osgi.service.debug.DebugOptionsListener; import org.eclipse.osgi.tests.OSGiTestsActivator; @@ -45,6 +46,7 @@ public class DebugOptionsTestCase extends TestCase { protected void tearDown() throws Exception { if (debugOptions == null) return; + debugOptions.setDebugEnabled(false); debugOptions = null; OSGiTestsActivator.getContext().ungetService(ref); if (reg != null) @@ -55,6 +57,59 @@ public class DebugOptionsTestCase extends TestCase { assertTrue("Listener did not get called", listener.gotCalled()); //$NON-NLS-1$ } + /** + * Test that a new {@link FrameworkDebugTraceEntry} object created without a trace class + * has 'org.eclipse.osgi.tests.debugoptions.DebugOptionsTestCase' as the class name and + * 'testTracingEntry01' as the method name that it determined as the caller of it. + * + * This test mimics the tracing framework to ensure that the correct class name and method name + * are returned and written to the trace file. + */ + public void testTracingEntry01() { + + String bundleName = OSGiTestsActivator.getContext().getBundle().getSymbolicName(); + String optionPath = "/debug"; //$NON-NLS-1$ + String message = "Test message"; //$NON-NLS-1$ + FrameworkDebugTraceEntry traceEntry = new FrameworkDebugTraceEntry(bundleName, optionPath, message, null); + String correctClassName = "org.eclipse.osgi.tests.debugoptions.DebugOptionsTestCase"; //$NON-NLS-1$ + String correctMethodName = "testTracingEntry01"; //$NON-NLS-1$ + assertEquals("The class calling the trace API does not match the expected value.", correctClassName, traceEntry.getClassName()); //$NON-NLS-1$ + assertEquals("The method calling the trace API does not match the expected value.", correctMethodName, traceEntry.getMethodName()); //$NON-NLS-1$ + } + + /** + * Test that a new {@link FrameworkDebugTraceEntry} object created with a trace class + * of 'org.eclipse.osgi.tests.debugoptions.DebugOptionsTestCase' has the correct class name and + * method name of the caller. + * + * This test mimics the tracing framework to ensure that the correct class name and method name + * are returned and written to the trace file. + */ + public void testTracingEntry02() { + + String correctClassName = Runner1.class.getName(); + String correctMethodName = "run"; //$NON-NLS-1$ + FrameworkDebugTraceEntry traceEntry = new Runner1().run(); + assertEquals("The class calling the trace API does not match the expected value.", correctClassName, traceEntry.getClassName()); //$NON-NLS-1$ + assertEquals("The method calling the trace API does not match the expected value.", correctMethodName, traceEntry.getMethodName()); //$NON-NLS-1$ + } + + static class Runner1 { + public FrameworkDebugTraceEntry run() { + return new Runner2().run(); + } + } + + static class Runner2 { + public FrameworkDebugTraceEntry run() { + String bundleName = OSGiTestsActivator.getContext().getBundle().getSymbolicName(); + String optionPath = "/debug"; //$NON-NLS-1$ + String message = "Test message"; //$NON-NLS-1$ + Class tracingClass = this.getClass(); + return new FrameworkDebugTraceEntry(bundleName, optionPath, message, tracingClass); + } + } + public void testDyanmicEnablement01() { listener.clear(); if (debugOptions.isDebugEnabled()) @@ -67,7 +122,6 @@ public class DebugOptionsTestCase extends TestCase { debugOptions.setOption(getName() + "/debug", "true"); //$NON-NLS-1$ //$NON-NLS-2$ assertTrue("Listener did not get called", listener.gotCalled()); //$NON-NLS-1$ assertNull("Found bad value: " + listener.getIncorrectValue(), listener.getIncorrectValue()); //$NON-NLS-1$ - debugOptions.setDebugEnabled(false); } public void testDyanmicEnablement02() { @@ -82,7 +136,6 @@ public class DebugOptionsTestCase extends TestCase { debugOptions.setOption(getName() + "/debug", "true"); //$NON-NLS-1$ //$NON-NLS-2$ assertTrue("Listener did not get called", listener.gotCalled()); //$NON-NLS-1$ assertNotNull("Should find bad value: " + listener.getIncorrectValue(), listener.getIncorrectValue()); //$NON-NLS-1$ - debugOptions.setDebugEnabled(false); } public void testDyanmicEnablement03() { @@ -120,7 +173,6 @@ public class DebugOptionsTestCase extends TestCase { assertTrue("Listener did not get called", listener.gotCalled()); //$NON-NLS-1$ assertTrue("Another listener did not get called", anotherListener.gotCalled()); //$NON-NLS-1$ - debugOptions.setDebugEnabled(false); anotherReg.unregister(); } diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugTraceEntry.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugTraceEntry.java index a05793239..0703fefa8 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugTraceEntry.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugTraceEntry.java @@ -126,8 +126,8 @@ public class FrameworkDebugTraceEntry { determineClassName = stackElements[i].getClassName(); determineMethodName = stackElements[i].getMethodName(); determineLineNumber = stackElements[i].getLineNumber(); + break; // only break when the right stack element has been found; Otherwise keep trying } - break; } i++; } |