You are viewing a plain text version of this content. The canonical link for it is here.
Posted to kato-commits@incubator.apache.org by sp...@apache.org on 2009/11/24 12:27:11 UTC
svn commit: r883669 [5/6] - in
/incubator/kato/trunk/org.apache.kato/kato.tck: ./ src/test/ant/
src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/kato/
src/test/java/org/apache/kato/tck/ src/test/java/org/apache/kato/tck/tests/
src/...
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageProcessTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageProcessTest.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageProcessTest.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageProcessTest.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,203 @@
+/*******************************************************************************
+ * Licensed 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.kato.tests.junit;
+
+import java.util.Iterator;
+import java.util.Properties;
+
+import javax.tools.diagnostics.image.CorruptData;
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DiagnosticException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.ImageProcess;
+import javax.tools.diagnostics.image.ImageThread;
+import javax.tools.diagnostics.runtime.ManagedRuntime;
+
+
+
+public class ImageProcessTest extends AbstractImageTestcase {
+
+ ImageProcess _proc=null;
+
+ protected void setUp() throws Exception {
+ _proc = defaultImageProcess();
+ super.setUp();
+ }
+
+ /*
+ * Test method for 'javax.tools.diagnostics.image.ImageProcess.getCommandLine()'
+ */
+ public void testGetCommandLine()
+ {
+ try {
+ assertNotNull(_proc.getCommandLine());
+ } catch (DiagnosticException e) {
+ //acceptable
+ assertTrue(true);
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageProcess.getEnvironment()'
+ *
+ * Ensures that the properties are non-null
+ */
+ public void testGetEnvironment()
+ {
+ try {
+ Properties env = _proc.getEnvironment();
+ assertNotNull(env);
+ } catch (DataUnavailable e) {
+ //acceptable
+ } catch (CorruptDataException e) {
+ //acceptable
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageProcess.getID()'
+ *
+ * Ensures that the process ID is non-null and non-empty
+ */
+ public void testGetID()
+ {
+ try {
+ String id = _proc.getID();
+ assertNotNull(id);
+ assertTrue(id.length() > 0);
+ } catch (DataUnavailable e) {
+ //acceptable
+ } catch (CorruptDataException e) {
+ //acceptable
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageProcess.getLibraries()'
+ *
+ * Make sure that the libraries iterator is non-null
+ */
+ public void testGetLibraries()
+ {
+ try {
+ assertNotNull(_proc.getLibraries());
+ } catch (DataUnavailable e) {
+ //this is considered correct
+ } catch (CorruptDataException e) {
+ //this is considered correct
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageProcess.getExecutable()'
+ *
+ * Make sure that the module is non-null
+ */
+ public void testGetExecutable()
+ {
+ try {
+ assertNotNull(_proc.getExecutable());
+ } catch (DataUnavailable e) {
+ //this will be considered a success
+ } catch (CorruptDataException e) {
+ //normally we won't be testing corrupt data so this is a failure
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageProcess.getThreads()'
+ *
+ * Ensures that there is at least one thread and it is an instance of ImageThread or CorruptData
+ */
+ public void testGetThreads()
+ {
+ Iterator threads = _proc.getThreads().iterator();
+ assertNotNull(threads);
+ assertTrue(threads.hasNext());
+ Object instance = threads.next();
+ assertTrue((instance instanceof ImageThread) || (instance instanceof CorruptData));
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageProcess.getCurrentThread()'
+ *
+ * Ensures that anything (even null) is returned or the correct exception is thrown
+ */
+ public void testGetCurrentThread()
+ {
+ try {
+ _proc.getCurrentThread();
+ } catch (CorruptDataException e) {
+ //acceptable
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageProcess.getRuntimes()'
+ *
+ * Ensures that at least one runtime is returned and that it is an instance of ManagedRuntime or CorruptData
+ */
+ public void testGetRuntimes()
+ {
+ Iterator runtimes = _proc.getRuntimes().iterator();
+ assertNotNull(runtimes);
+ assertTrue(runtimes.hasNext());
+ Object instance = runtimes.next();
+ assertTrue((instance instanceof ManagedRuntime) || (instance instanceof CorruptData));
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageProcess.getSignalNumber()'
+ *
+ * Ensures that no unexpected exceptions are thrown
+ */
+ public void testGetSignalNumber()
+ {
+ try {
+ _proc.getSignalNumber();
+ } catch (DataUnavailable e) {
+ //acceptable in the spec
+ } catch (CorruptDataException e) {
+ //acceptable in the spec
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageProcess.getSignalName()'
+ *
+ * Ensures that anything (even null) is returned or the correct exceptions are thrown
+ */
+ public void testGetSignalName()
+ {
+ try {
+ _proc.getSignalName();
+ } catch (DataUnavailable e) {
+ //acceptable
+ } catch (CorruptDataException e) {
+ //acceptable
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageProcess.getPointerSize()'
+ *
+ * This should return 31, 32, or 64
+ */
+ public void testGetPointerSize()
+ {
+ int size = _proc.getPointerSize();
+ assertTrue((31 == size) || (32 == size) || (64 == size));
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageRegisterTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageRegisterTest.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageRegisterTest.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageRegisterTest.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Licensed 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.kato.tests.junit;
+
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.ImageRegister;
+
+public class ImageRegisterTest extends AbstractImageTestcase
+{
+ private ImageRegister _testRegister;
+
+ public ImageRegister defaultImageRegister()
+ {
+ // if getRegisters() returns an empty iterator (which is valid)
+ // then defaultImageRegisters returns null
+ Iterator theR = defaultImageThread().getRegisters().iterator();
+ ImageRegister theIR = null;
+ while (theR.hasNext()){
+ theIR = (ImageRegister) theR.next();
+ }
+ return theIR;
+ }
+
+ protected void setUp() throws Exception
+ {
+ _testRegister = defaultImageRegister();
+ super.setUp();
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageRegister.getName()'
+ *
+ * Ensures that the register has a non-null non-empty name
+ */
+ public void testGetName()
+ {
+ // _testRegister == null if the registers are empty
+ // ie the iterator is empty which is valid
+ if (null != _testRegister){
+ String name = _testRegister.getName();
+ assertNotNull(name);
+ assertTrue(name.length() > 0);
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageRegister.toString()'
+ *
+ */
+ public void testToString()
+ {
+ // _testRegister == null if the registers are empty
+ // ie the iterator is empty which is valid
+ if (null != _testRegister){
+ String name = null;
+ name = _testRegister.toString();
+
+ assertNotNull(name);
+ assertTrue(name.length() > 0);
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageRegister.getValue()'
+ *
+ * Ensures that we can make the call without unexpected exceptions occurring
+ */
+ public void testGetValue()
+ {
+ // _testRegister == null if the registers are empty
+ // ie the iterator is empty which is valid
+ if (null != _testRegister){
+ try {
+ _testRegister.getValue();
+ } catch (CorruptDataException e) {
+ //accepted by spec
+ }
+ }
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageSectionTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageSectionTest.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageSectionTest.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageSectionTest.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,115 @@
+/*******************************************************************************
+ * Licensed 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.kato.tests.junit;
+
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.ImageSection;
+import javax.tools.diagnostics.runtime.java.JavaMethod;
+
+
+public class ImageSectionTest extends AbstractImageTestcase
+{
+ private ImageSection _section = null;
+
+ public ImageSection defaultImageSection()
+ {
+ //for now we will just grab a compiled method section
+ JavaMethod method = defaultJavaMethod();
+ Iterator it = method.getCompiledSections().iterator();
+ assertNotNull(it);
+ assertTrue(it.hasNext());
+ return (ImageSection) it.next();
+ }
+
+
+ protected void setUp() throws Exception
+ {
+ _section = defaultImageSection();
+ super.setUp();
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageSection.getBaseAddress()'
+ *
+ * Ensure that we get a non-null base address
+ */
+ public void testGetBaseAddress()
+ {
+ assertNotNull(_section.getBaseAddress());
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageSection.getSize()'
+ *
+ * Ensure that we get a >0 size
+ */
+ public void testGetSize()
+ {
+ assertTrue(_section.getSize() > 0);
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageSection.getName()'
+ *
+ * Ensure that we get a non-null name
+ */
+ public void testGetName()
+ {
+ assertNotNull(_section.getName());
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageSection.isExecutable()'
+ *
+ * Ensures that the method can be called
+ */
+ public void testIsExecutable()
+ {
+ try {
+ _section.isExecutable();
+ } catch (DataUnavailable e) {
+ //accepted by spec
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageSection.isReadOnly()'
+ *
+ * Ensures that the method can be called
+ */
+ public void testIsReadOnly()
+ {
+ try {
+ _section.isReadOnly();
+ } catch (DataUnavailable e) {
+ //accepted by spec
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageSection.isShared()'
+ *
+ * Ensures that the method can be called
+ */
+ public void testIsShared()
+ {
+ try {
+ _section.isShared();
+ } catch (DataUnavailable e) {
+ //accepted by spec
+ }
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageStackFrameTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageStackFrameTest.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageStackFrameTest.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageStackFrameTest.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Licensed 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.kato.tests.junit;
+
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.ImagePointer;
+import javax.tools.diagnostics.image.ImageStackFrame;
+import javax.tools.diagnostics.image.ImageThread;
+
+
+public class ImageStackFrameTest extends AbstractImageTestcase
+{
+ private ImageStackFrame _stackFrame;
+
+ public ImageStackFrame defaultStackFrame()
+ {
+// try {
+// return (ImageStackFrame) defaultImageThread().getStackFrames().next();
+// } catch (DataUnavailable e) {
+ // Try harder to find a thread with a stack.
+ Iterator it = defaultImageProcess().getThreads().iterator();
+ while (it.hasNext()) {
+ ImageThread thread = (ImageThread) it.next();
+ try {
+ if (thread.getStackFrames().isEmpty()==false) {
+ return (ImageStackFrame) thread.getStackFrames().get(0);
+ }
+ } catch (DataUnavailable e1) {
+ // Ignore
+ }
+ }
+ // although this is accepted by the spec, it has no real meaning for the test so just choose to be unimplemented
+ throw new TestNotImplementedException();
+// }
+ }
+
+ protected void setUp() throws Exception
+ {
+ _stackFrame = defaultStackFrame();
+ super.setUp();
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageStackFrame.getProcedureAddress()'
+ *
+ * Ensures that we get a non-null address
+ */
+ public void testGetProcedureAddress()
+ {
+ try {
+ ImagePointer address = _stackFrame.getProcedureAddress();
+ assertNotNull(address);
+ } catch (CorruptDataException e) {
+ //accepted
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageStackFrame.getBasePointer()'
+ *
+ * Ensures that we get a non-null base pointer
+ */
+ public void testGetBasePointer()
+ {
+ try {
+ ImagePointer address = _stackFrame.getBasePointer();
+ assertNotNull(address);
+ assertTrue(address.getAddress() != 0);
+ } catch (CorruptDataException e) {
+ //accepted
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageStackFrame.getProcedureName()'
+ *
+ * Ensures that we get a non-null, non-empty name
+ */
+ public void testGetProcedureName()
+ {
+ try {
+ String name = _stackFrame.getProcedureName();
+ assertNotNull(name);
+ assertTrue(name.length() > 0);
+ } catch (CorruptDataException e) {
+ //accepted
+ }
+ }
+
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageSymbolTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageSymbolTest.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageSymbolTest.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageSymbolTest.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Licensed 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.kato.tests.junit;
+
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.ImagePointer;
+import javax.tools.diagnostics.image.ImageSymbol;
+
+
+public class ImageSymbolTest extends AbstractImageTestcase
+{
+ private ImageSymbol _symbol;
+
+ public ImageSymbol defaultImageSymbol()
+ {
+ Iterator symbols = defaultImageModule().getSymbols().iterator();
+ if(symbols.hasNext()) {
+ return (ImageSymbol) symbols.next();
+ } else {
+ return null;
+ }
+ }
+
+ protected void setUp() throws Exception
+ {
+ _symbol = defaultImageSymbol();
+ super.setUp();
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageSymbol.getAddress()'
+ * Ensures that the address is non-null
+ */
+ public void testGetAddress()
+ {
+ ImagePointer address = _symbol.getAddress();
+ assertNotNull(address);
+ assertTrue(address.getAddress() != 0);
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageSymbol.getName()'
+ * Ensures that the name is non-null and non-empty
+ */
+ public void testGetName()
+ {
+ String name = _symbol.getName();
+ assertNotNull(name);
+ assertTrue(name.length() > 0);
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageTest.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageTest.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageTest.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,203 @@
+/*******************************************************************************
+ * Licensed 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.kato.tests.junit;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.tools.diagnostics.image.CorruptData;
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.Image;
+
+
+/**
+ *
+ * A collection of simple test-cases to make sure that the DTFJ Image Interface agrees with its documented
+ * behaviour.
+ */
+public class ImageTest extends AbstractImageTestcase
+{
+ private Image _core=null;
+ protected void setUp() throws Exception
+ {
+ try {
+ //this is required to load the core file image which is to be tested so that we don't have to load each time
+ _core = defaultTestingImage();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ fail();
+ }
+ super.setUp();
+ }
+
+
+ //now, onto the testing
+
+ /**
+ * ensure that the core has non-null address spaces and at least one
+ */
+ public void testGetAddressSpaces() {
+ List it = _core.getAddressSpaces();
+
+ assertNotNull(it);
+ assertFalse(it.isEmpty());
+ }
+
+ /**
+ * make sure that the creation time is sane (>0)
+ */
+ public void testGetCreationTime() {
+ try {
+ assertTrue(_core.getCreationTime() > 0);
+ } catch (DataUnavailable e) {
+ //spec correct
+ } catch (Throwable t) {
+ //exception fall-through
+ fail();
+ }
+ }
+
+ /**
+ * test that the installed memory is sane or not known
+ */
+ public void testGetInstalledMemory() {
+ try {
+ assertTrue(_core.getInstalledMemory() > 0);
+ } catch (DataUnavailable e) {
+ //this is considered acceptable behaviour
+ } catch (Throwable t) {
+ //exception fall-through
+ fail();
+ }
+ }
+
+ /**
+ * make sure that we get a sane number of processors or unknown
+ */
+ public void testGetProcessorCount() {
+ try {
+ assertTrue(_core.getProcessorCount() > 0);
+ } catch (DataUnavailable e) {
+ //this is considered acceptable behaviour
+ } catch (Throwable t) {
+ //exception fall-through
+ fail();
+ }
+ }
+
+ /**
+ * Make sure that the processor subtype is non-null
+ * TODO: this probably isn't the right way to test this
+ */
+ public void testGetProcessorSubtype() {
+ try {
+ assertNotNull(_core.getProcessorSubType());
+ } catch (DataUnavailable e) {
+ //accepted in spec
+ } catch (CorruptDataException e) {
+ //accepted in spec
+ } catch (Throwable t) {
+ //exception fall-through
+ fail();
+ }
+ }
+
+ /**
+ * Make sure that we get a processor name
+ */
+ public void testGetProcessorType() {
+ try {
+ assertNotNull(_core.getProcessorType());
+ } catch (DataUnavailable e) {
+ //this exception is supported by the API so it is ok
+ } catch (CorruptDataException e) {
+ //this exception is supported by the API so it is ok
+ } catch (Throwable t) {
+ //exception fall-through
+ fail();
+ }
+ }
+
+ /**
+ * Make sure that there is a system sub-type
+ * TODO: this probably isn't the right way to test this
+ */
+ public void testGetSystemSubType() {
+ try {
+ assertNotNull(_core.getSystemSubType());
+ } catch (DataUnavailable e) {
+ //accepted in spec
+ } catch (CorruptDataException e) {
+ //accepted in spec
+ } catch (Throwable t) {
+ //exception fall-through
+ fail();
+ }
+ }
+
+ /**
+ * Make sure that there is a system type
+ */
+ public void testGetSystemType() {
+ try {
+ assertNotNull(_core.getSystemType());
+ } catch (DataUnavailable e) {
+ //this exception is supported by the API so it is ok
+ } catch (CorruptDataException e) {
+ //this exception is supported by the API so it is ok
+ } catch (Throwable t) {
+ //exception fall-through
+ fail();
+ }
+ }
+
+ /**
+ * Ensures that the string is non-null and throws no unexpected exceptions
+ */
+ public void testGetHostName()
+ {
+ try {
+ assertNotNull(_core.getHostName());
+ } catch (DataUnavailable e) {
+ //this exception is supported by the API so it is ok
+ } catch (CorruptDataException e) {
+ //this exception is supported by the API so it is ok
+ } catch (Throwable t) {
+ //exception fall-through
+ fail();
+ }
+ }
+
+ /**
+ * Ensures that the iterator is non-null, throws no expected exceptions, and every member is an InetAddress
+ */
+ public void testGetIPAddresses()
+ {
+ try {
+ Iterator addresses = _core.getIPAddresses();
+ assertNotNull(addresses);
+ while (addresses.hasNext()) {
+ Object address = addresses.next();
+ assertTrue((address instanceof java.net.InetAddress)
+ || (address instanceof CorruptData));
+ }
+ } catch (DataUnavailable e) {
+ //this exception is supported by the API so it is ok
+ } catch (Throwable t) {
+ //exception fall-through
+ fail();
+ }
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageThreadTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageThreadTest.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageThreadTest.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageThreadTest.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * Licensed 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.kato.tests.junit;
+
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.CorruptData;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.ImageRegister;
+import javax.tools.diagnostics.image.ImageSection;
+import javax.tools.diagnostics.image.ImageStackFrame;
+import javax.tools.diagnostics.image.ImageThread;
+
+
+public class ImageThreadTest extends AbstractImageTestcase
+{
+ private ImageThread _thread = null;
+
+ protected void setUp() throws Exception
+ {
+ _thread = defaultImageThread();
+ assertNotNull(_thread);
+ super.setUp();
+ }
+
+ /*
+ * Test method for 'javax.tools.diagnostics.image.ImageThread.getID()'
+ */
+ public void testGetID()
+ {
+ try {
+ String id = _thread.getID();
+ assertNotNull(id);
+ Long.decode(id);
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageThread.getStackFrames()'
+ *
+ * Ensures that a non-null iterator is returned with at lzero or more elements
+ * of type ImageStackFrame or CorruptData.
+ *
+ */
+ public void testGetStackFrames()
+ {
+ try {
+ Iterator frames = _thread.getStackFrames().iterator();
+
+ assertNotNull(frames);
+ while (frames.hasNext()) {
+ Object frame = frames.next();
+ assertTrue((frame instanceof ImageStackFrame) || (frame instanceof CorruptData));
+ }
+ } catch (DataUnavailable e) {
+ //acceptable in spec
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageThread.getStackSections()'
+ *
+ * Ensures that at least one stack section exists
+ */
+ public void testGetStackSections()
+ {
+ Iterator it = _thread.getStackSections().iterator();
+ assertNotNull(it);
+ // empty iterator is a valid return from getStackFrames
+ while (it.hasNext()) {
+ Object section = it.next();
+ assertTrue((section instanceof ImageSection) || (section instanceof CorruptData));
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageThread.getRegisters()'
+ *
+ * Ensures that a non-null, non-empty iterator is returned and all instances
+ * are of type ImageRegister
+ */
+ public void testGetRegisters()
+ {
+ Iterator regs = _thread.getRegisters().iterator();
+
+ assertNotNull(regs);
+ // Empty iterator is a valid return from getRegisters
+ while (regs.hasNext()) {
+ Object reg = regs.next();
+ // if there are registers check they are valid
+ assertTrue(reg instanceof ImageRegister);
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageThread.getProperties()'
+ *
+ * Ensures that non-null properties are returned
+ */
+ public void testGetProperties()
+ {
+ assertNotNull(_thread.getProperties());
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaClassLoaderTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaClassLoaderTest.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaClassLoaderTest.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaClassLoaderTest.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Licensed 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.kato.tests.junit;
+
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.runtime.java.JavaClass;
+import javax.tools.diagnostics.runtime.java.JavaClassLoader;
+import javax.tools.diagnostics.runtime.java.JavaObject;
+
+
+public class JavaClassLoaderTest extends AbstractImageTestcase
+{
+ private JavaClassLoader _loader;
+
+ protected void setUp() throws Exception
+ {
+ _loader = defaultJavaClassLoader();
+ super.setUp();
+ }
+
+
+ /**
+ * Ensure that the classes iterator is non-null
+ */
+ public void testGetDefinedClasses()
+ {
+ Iterator iter = _loader.getDefinedClasses().iterator();
+ assertNotNull(iter);
+ }
+
+ /**
+ * Ensure that the cached classes iterator is non-null
+ */
+ public void testGetCachedClasses()
+ {
+ Iterator iter = _loader.getCachedClasses().iterator();
+ assertNotNull(iter);
+ }
+
+ /**
+ *
+ * Grab any class, then try looking up a class with that name since we know it is there
+ */
+ public void testFindClass()
+ {
+ JavaClass oneClass = (JavaClass) _loader.getDefinedClasses().get(0);
+ try {
+ String name = oneClass.getName();
+ JavaClass foundClass = _loader.findClass(name);
+ //make sure that it came out
+ assertNotNull(foundClass);
+ //classes might not be the same instance but they should be comparable to each other if they are the same entity
+ assertTrue(foundClass.equals(oneClass));
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ *
+ * Ensure that the class loader object exists and is an instance of java.lang.ClassLoader
+ * or some class that inherits from it
+ */
+ public void testGetObject()
+ {
+ try {
+ JavaObject loader = _loader.getObject();
+ boolean didMatch = false;
+ JavaClass oneClass = loader.getJavaClass();
+ while ((!didMatch) && (null != oneClass)) {
+ if (oneClass.getName().equals("java/lang/ClassLoader")) {
+ didMatch = true;
+ }
+ oneClass = oneClass.getSuperclass();
+ }
+ assertTrue(didMatch);
+ } catch (CorruptDataException e) {
+ //technically, this is valid
+ }
+
+ }
+
+ /**
+ * Verify that the equals call doesn't throw
+ */
+ public void testEquals()
+ {
+ try{
+ assertTrue(_loader.equals(_loader));
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Verify that hashCode() doesn't throw and returns non-zero (technically zero is ok but it will be
+ * flagged here to ensure that we aren't doing anything bad to create the hashcode)
+ */
+ public void testHashCode()
+ {
+ try {
+ assertTrue(0 != _loader.hashCode());
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaClassTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaClassTest.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaClassTest.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaClassTest.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,534 @@
+/*******************************************************************************
+ * Licensed 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.kato.tests.junit;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.tools.diagnostics.image.CorruptData;
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.ImagePointer;
+import javax.tools.diagnostics.image.MemoryAccessException;
+import javax.tools.diagnostics.runtime.java.JavaClass;
+import javax.tools.diagnostics.runtime.java.JavaClassLoader;
+import javax.tools.diagnostics.runtime.java.JavaField;
+import javax.tools.diagnostics.runtime.java.JavaMethod;
+import javax.tools.diagnostics.runtime.java.JavaObject;
+import javax.tools.diagnostics.runtime.java.JavaReference;
+
+import org.apache.kato.tests.scenarios.ArrayletTest;
+
+
+public class JavaClassTest extends AbstractImageTestcase
+{
+
+ public class Super {
+ int superField1 = 3;
+ String superField2 = "Ciao";
+ }
+
+ public class Sub extends Super {
+ long subField1 = 100;
+ char[] subField2 = new char[]{'c','c'};
+
+ public Sub() {
+ System.out.println("Sub instantiated");
+ }
+ }
+
+ private JavaClass _testClass;
+ private JavaObject _arrayInstance; //array classes aren't loaded like normal classes and only come into existence when an array object is created
+ private static Sub _subClassObject = null;
+ private static ArrayletTest _testDeadlock = null;
+
+ protected void setUp() throws Exception
+ {
+ try {
+ _testClass = defaultJavaClass();
+ _arrayInstance = defaultJavaObject(true);
+ super.setUp();
+ } catch (TestNotImplementedException e) {
+ throw e;
+ }
+ }
+
+ public void configureDeclareFieldsNotInherited() {
+ _subClassObject = new Sub();
+ }
+
+ public void configureArraylets() {
+ _testDeadlock = new ArrayletTest();
+ }
+
+
+ /*
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaClass.getObject()'
+ */
+ public void testGetObject()
+ {
+ try {
+ JavaObject object = _testClass.getObject();
+ assertNotNull(object);
+ /* validate that the object is an instance of java/lang/Class */
+ JavaClass javaLangClass = object.getJavaClass();
+ assertNotNull(javaLangClass);
+ assertEquals(javaLangClass.getName(), "java/lang/Class");
+
+ } catch (CorruptDataException e) {
+ //allowed by the spec
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /*
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaClass.getClassLoader()'
+ */
+ public void testGetClassLoader()
+ {
+ try {
+ JavaClassLoader loader = _testClass.getClassLoader();
+ assertNotNull(loader);
+ } catch (CorruptDataException e) {
+ //allowed by the spec
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /*
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaClass.getName()'
+ */
+ public void testGetName()
+ {
+ try {
+ String name = _testClass.getName();
+ assertNotNull(name);
+ } catch (CorruptDataException e) {
+ //allowed by the spec
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /*
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaClass.getSuperclass()'
+ */
+ public void testGetSuperclass()
+ {
+ try {
+ JavaClass superClass = _testClass.getSuperclass();
+ assertNotNull(superClass);
+ } catch (CorruptDataException e) {
+ //allowed by the spec
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /*
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaClass.getInterfaces()'
+ */
+ public void testGetInterfaces()
+ {
+ try {
+ List iter = _testClass.getInterfaces();
+ assertNotNull(iter);
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /*
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaClass.getModifiers()'
+ */
+ public void testGetModifiers()
+ {
+ try {
+ _testClass.getModifiers();
+ //fill in any checks that could be used for validity here
+ } catch (CorruptDataException e) {
+ //allowed by the spec
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /*
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaClass.isArray()'
+ */
+ public void testIsArray()
+ {
+ //any result is safe so long as it doesn't throw something unexpected
+ try {
+ _testClass.isArray();
+ } catch (CorruptDataException e) {
+ //allowed by the spec
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaClass.getComponentType()'
+ *
+ * Ensures that we get a non-null component type which has a non-null, non-empty length
+ */
+ public void testGetComponentType()
+ {
+ JavaClass arrayClass = null;
+ JavaClass component = null;
+ try {
+ arrayClass = _arrayInstance.getJavaClass();
+ component = arrayClass.getComponentType();
+ } catch (CorruptDataException e) {
+ //allowed by the spec
+ }
+ assertNotNull(component);
+ String name=null;
+ try {
+ name = component.getName();
+ } catch (CorruptDataException e) {
+ }
+ assertNotNull(name);
+ assertTrue(name.length() > 0);
+
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaClass.getDeclaredFields()'
+ *
+ * Ensures that we get a non-null iterator and anything in the iterator is an instance
+ * of JavaField or CorruptData
+ */
+ public void testGetDeclaredFields()
+ {
+ try {
+ Iterator fields = _testClass.getDeclaredFields().iterator();
+ assertNotNull(fields);
+ while (fields.hasNext()) {
+ Object element = fields.next();
+ assertTrue((element instanceof JavaField) || (element instanceof CorruptData));
+ }
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaClass.getDeclaredMethods()'
+ *
+ * Ensures that the declared methods iterator is non-null and any methods in it
+ * are either JavaMethod or CorruptData
+ */
+ public void testGetDeclaredMethods()
+ {
+ try {
+ Iterator methods = _testClass.getDeclaredMethods().iterator();
+ assertNotNull(methods);
+ while (methods.hasNext()) {
+ Object instance = methods.next();
+ assertTrue((instance instanceof JavaMethod) || (instance instanceof CorruptData));
+ }
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaClass.getConstantPoolReferences()'
+ *
+ * Ensures that the test class returns a non-null iterator and that any elements
+ * in it are either JavaObject or CorruptData
+ */
+ public void testGetConstantPoolReferences()
+ {
+ try {
+ Iterator references = _testClass.getConstantPoolReferences().iterator();
+ assertNotNull(references);
+ while (references.hasNext()) {
+ Object instance = references.next();
+ assertTrue((instance instanceof JavaObject) || (instance instanceof CorruptData));
+ if (instance instanceof JavaObject) {
+ // ensure that these are valid objects by reading the class
+ JavaObject object = (JavaObject)instance;
+ JavaClass clazz = object.getJavaClass();
+ assertNotNull(clazz);
+ }
+ }
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaClass.getID()'
+ *
+ * Ensures that the pointer is non-null and that the underlying address is non-zero
+ */
+ public void testGetID()
+ {
+ try {
+ ImagePointer id = _testClass.getID();
+ assertNotNull(id);
+ assertTrue(0 != id.getAddress());
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaClass.getReferences()'
+ *
+ * Ensures that the test class returns a non-null iterator, that any elements in it are
+ * either JavaReference or CorruptData, and that any JavaReference objects have a non-null
+ * description.
+ */
+ public void testGetReferences()
+ {
+ try {
+ Iterator references = _testClass.getReferences().iterator();
+ assertNotNull(references);
+ while (references.hasNext()) {
+ Object instance = references.next();
+ assertTrue((instance instanceof JavaReference) || (instance instanceof CorruptData));
+ if (instance instanceof JavaReference) {
+ // sniff these objects by getting the description
+ JavaReference object = (JavaReference)instance;
+ String description = object.getDescription();
+ assertNotNull(description);
+ }
+ }
+ } catch (Exception e) {
+ // if we caught anything else, this is a failure
+ fail();
+ }
+ }
+
+ /**
+ * Verify that the equals call doesn't throw
+ */
+ public void testEquals()
+ {
+ try{
+ assertTrue(_testClass.equals(_testClass));
+ } catch (Throwable t) {
+ //if we fail internally, we want to flag that as a test failure, not just an error
+ t.printStackTrace();
+ fail();
+ }
+ }
+
+ /**
+ * Verify that hashCode() doesn't throw and returns non-zero (technically zero is ok but it will be
+ * flagged here to ensure that we aren't doing anything bad to create the hashcode)
+ */
+ public void testHashCode()
+ {
+ try {
+ assertTrue(0 != _testClass.hashCode());
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ public void testDeclaredFieldsNotInherited()
+ {
+ try {
+ //search all the loaders for a class which we know we had in the address space
+ String candidateClass = this.getClass().getName()+"$Sub";
+ candidateClass = candidateClass.replace('.', '/');
+ JavaClass subclass = _findClassForName(candidateClass);
+ if (null == subclass) {
+ //not finding this testing class makes this test useless
+ //note that this can also happen if we are working with a corrupt core file
+ throw new TestNotImplementedException();
+ }
+ JavaClass superclass = null;
+ try {
+ superclass = subclass.getSuperclass();
+ } catch (CorruptDataException e) {
+ //even though this would be valid, it isn't helpful for our case
+ throw new TestNotImplementedException();
+ }
+ if (null == superclass) {
+ //not finding this testing class makes this test useless
+ throw new TestNotImplementedException();
+ }
+ //now make sure that none of the fields in subclass are in superclass
+ Iterator subfields = subclass.getDeclaredFields().iterator();
+ while (subfields.hasNext()) {
+ Object subtest = subfields.next();
+ Iterator superfields = superclass.getDeclaredFields().iterator();
+
+ while (superfields.hasNext()) {
+ Object supertest = superfields.next();
+ assertFalse(supertest.equals(subtest));
+ }
+ }
+ } catch (TestNotImplementedException t) {
+ //we wanted this exception to break the test case with error instead of failure so re-throw
+ throw t;
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ private JavaClass _findClassForName(String candidateClass)
+ {
+ Iterator allLoaders = defaultJavaRuntime().getJavaClassLoaders().iterator();
+ JavaClass subclass = null;
+ while (allLoaders.hasNext() && (null == subclass)) {
+ JavaClassLoader loader = (JavaClassLoader) allLoaders.next();
+ Iterator classes = loader.getDefinedClasses().iterator();
+ while (classes.hasNext() && (null == subclass)) {
+ JavaClass oneClass = (JavaClass) classes.next();
+ try {
+ if (oneClass.getName().equals(candidateClass)) {
+ subclass = oneClass;
+ break;
+ }
+ } catch (CorruptDataException e) {
+ //even though this would be valid, it isn't helpful for our case
+ throw new TestNotImplementedException();
+ }
+ }
+ }
+ return subclass;
+ }
+
+ /**
+ * This test should eventually be moved out to a stand-alone high-level test since it is looking for a specific
+ * field to verify that arraycopy and arraylets (in the RTJ case) work properly.
+ */
+ public void testArraylets()
+ {
+ String staticSizeName = "DTFJ_ARRAYLET_LENGTH";
+ String staticName = "DTFJ_ARRAYLET_TEST_INSTANCE";
+ JavaClass candidateClass = _findClassForName("org/apache/kato/tests/scenarios/ArrayletTest");
+
+ if (null != candidateClass) {
+ int size = 0;
+ JavaObject container = null;
+ Iterator fields = candidateClass.getDeclaredFields().iterator();
+
+ try {
+ while (fields.hasNext()) {
+ JavaField field = (JavaField) fields.next();
+ String fieldName = field.getName();
+
+ if (fieldName.equals(staticSizeName)) {
+ size = field.getInt(null);
+ } else if (fieldName.equals(staticName)) {
+ container = (JavaObject) field.get(null);
+ }
+ }
+ //now ensure that we actually have something to test with
+ if ((0 != size) && (null != container)) {
+ //now, pull apart the fields of the container
+ JavaClass containerClass = container.getJavaClass();
+ Iterator theseFields = containerClass.getDeclaredFields().iterator();
+ while (theseFields.hasNext()) {
+ JavaField oneField = (JavaField) theseFields.next();
+ if (oneField.getName().equals("DTFJ_ARRAYLET_INTS")) {
+ //run the int test
+ JavaObject array = (JavaObject) oneField.get(container);
+ int remote[] = new int[size];
+ int whole[] = new int[size];
+ for (int i = 0; i < size; i++) {
+ array.arraycopy(i, remote, i, 1);
+ assertTrue(remote[i] == (size -i));
+ }
+ array.arraycopy(0, whole, 0, size);
+ assertTrue(Arrays.equals(whole, remote));
+ } else if (oneField.getName().equals("DTFJ_ARRAYLET_BYTES")) {
+ //run the byte test
+ JavaObject array = (JavaObject) oneField.get(container);
+ byte remote[] = new byte[size];
+ byte whole[] = new byte[size];
+ for (int i = 0; i < size; i++) {
+ array.arraycopy(i, remote, i, 1);
+ assertTrue(remote[i] == ((byte)(size -i)));
+ }
+ array.arraycopy(0, whole, 0, size);
+ assertTrue(Arrays.equals(whole, remote));
+ } else if (oneField.getName().equals("DTFJ_ARRAYLET_STRINGCONTAINER")) {
+ //run the byte test
+ JavaObject array = (JavaObject) oneField.get(container);
+ JavaObject whole[] = new JavaObject[size];
+ array.arraycopy(0, whole, 0, size);
+ JavaField stringField = null;
+ Iterator iter = whole[0].getJavaClass().getDeclaredFields().iterator();
+ while(iter.hasNext()) {
+ JavaField testField = (JavaField) iter.next();
+ if (testField.getName().equals("_stringField")) {
+ //this is the field
+ stringField = testField;
+ }
+ }
+ assertNotNull(stringField);
+ //now extract the string fields
+ for (int i = 0; i < whole.length; i++) {
+ String stringContent = stringField.getString(whole[i]);
+ assertTrue(stringContent.equals(Integer.toString(size-i)));
+ }
+ }
+ }
+ } else {
+ //we are missing something required to run the test
+ throw new TestNotImplementedException();
+ }
+ } catch (CorruptDataException e) {
+ //if anything went wrong, we can't run the test
+ throw new TestNotImplementedException();
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ //if anything went wrong, we can't run the test
+ throw new TestNotImplementedException();
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ } else {
+ //the class isn't there so say we can't run the test
+ throw new TestNotImplementedException();
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaClass.toString()'
+ *
+ */
+ public void testToString()
+ {
+ String theString = _testClass.toString();
+ assertNotNull(theString);
+ assertTrue(theString.length() >= 0 );
+ }
+
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaFieldTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaFieldTest.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaFieldTest.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaFieldTest.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,286 @@
+/*******************************************************************************
+ * Licensed 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.kato.tests.junit;
+
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.MemoryAccessException;
+import javax.tools.diagnostics.runtime.java.JavaClass;
+import javax.tools.diagnostics.runtime.java.JavaClassLoader;
+import javax.tools.diagnostics.runtime.java.JavaField;
+import javax.tools.diagnostics.runtime.java.JavaObject;
+
+
+public class JavaFieldTest extends AbstractImageTestcase
+{
+ private JavaObject _testInstance;
+ private JavaField _field;
+ private JavaField _anotherField;
+
+ public static JavaField defaultJavaField(JavaClass clazz)
+ {
+ return (JavaField) clazz.getDeclaredFields().get(0);
+ }
+
+ protected void setUp() throws Exception
+ {
+ try {
+ _testInstance = defaultJavaObject(false);
+ Iterator declaredFields=_testInstance.getJavaClass().getDeclaredFields().iterator();
+ _field = (JavaField)declaredFields.next(); //guaranteed to exist - see JavaObjectTest#defaultJavaObject()
+ _anotherField=(JavaField)declaredFields.next(); //guaranteed to exist - see JavaObjectTest#defaultJavaObject()
+ super.setUp();
+ } catch (TestNotImplementedException e) {
+ throw e;
+ } catch (Throwable t) {
+ //we weren't expecting any exceptions during startup so that is a test failure
+ t.printStackTrace();
+ fail();
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaField.get(JavaObject)'
+ *
+ * This test will fail if a runtime exception is thrown (i.e. if _field does not represent a proper field of _testInstance)
+ */
+ public void testGet()
+ {
+ try {
+ Object field = _field.get(_testInstance);
+ } catch (CorruptDataException e) {
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaField.getBoolean(JavaObject)'
+ *
+ * Ensures that we succeed or get expected exceptions
+ */
+ public void testGetBoolean()
+ {
+ try {
+ _field.getBoolean(_testInstance);
+ } catch (IllegalArgumentException e) {
+ } catch (CorruptDataException e) {
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaField.getByte(JavaObject)'
+ *
+ * Ensures that we succeed or get expected exceptions
+ */
+ public void testGetByte()
+ {
+ try {
+ _field.getByte(_testInstance);
+ } catch (IllegalArgumentException e) {
+ } catch (CorruptDataException e) {
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaField.getChar(JavaObject)'
+ *
+ * Ensures that we succeed or get expected exceptions
+ */
+ public void testGetChar()
+ {
+ try {
+ _field.getChar(_testInstance);
+ } catch (IllegalArgumentException e) {
+ } catch (CorruptDataException e) {
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaField.getDouble(JavaObject)'
+ *
+ * Ensures that we succeed or get expected exceptions
+ */
+ public void testGetDouble()
+ {
+ try {
+ _field.getDouble(_testInstance);
+ } catch (IllegalArgumentException e) {
+ } catch (CorruptDataException e) {
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaField.getFloat(JavaObject)'
+ *
+ * Ensures that we succeed or get expected exceptions
+ */
+ public void testGetFloat()
+ {
+ try {
+ _field.getFloat(_testInstance);
+ } catch (IllegalArgumentException e) {
+ } catch (CorruptDataException e) {
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaField.getInt(JavaObject)'
+ *
+ * Ensures that we succeed or get expected exceptions
+ */
+ public void testGetInt()
+ {
+ try {
+ _field.getInt(_testInstance);
+ } catch (IllegalArgumentException e) {
+ } catch (CorruptDataException e) {
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaField.getLong(JavaObject)'
+ *
+ * Ensures that we succeed or get expected exceptions
+ */
+ public void testGetLong()
+ {
+ try {
+ _field.getLong(_testInstance);
+ } catch (IllegalArgumentException e) {
+ } catch (CorruptDataException e) {
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaField.getShort(JavaObject)'
+ *
+ * Ensures that we succeed or get expected exceptions
+ */
+ public void testGetShort()
+ {
+ try {
+ _field.getShort(_testInstance);
+ } catch (IllegalArgumentException e) {
+ } catch (CorruptDataException e) {
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaField.getString(JavaObject)'
+ *
+ * Ensures that we succeed or get expected exceptions
+ */
+ public void testGetString()
+ {
+ try {
+ String string = _field.getString(_testInstance);
+ assertNotNull(string);
+ } catch (IllegalArgumentException e) {
+ } catch (CorruptDataException e) {
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ }
+ }
+
+ /**
+ * Verify that the equals call doesn't throw
+ */
+ public void testEquals()
+ {
+ try{
+ assertFalse(_field.equals(_anotherField));
+ assertTrue(_field.equals(_field));
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Verify that hashCode() doesn't throw and returns non-zero (technically zero is ok but it will be
+ * flagged here to ensure that we aren't doing anything bad to create the hashcode)
+ */
+ public void testHashCode()
+ {
+ try {
+ assertTrue(0 != _testInstance.hashCode());
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * This test is to cover an issue where a static field is not parsed correctly. It is very specialized
+ * because of this interest in very special information.
+ * It looks up the PI constant on java.lang.Math and compares it to the running VM's notion of that constant
+ */
+ public void testJavaStaticFieldDouble()
+ {
+ JavaClass math = null;
+ Iterator loaders = defaultJavaRuntime().getJavaClassLoaders().iterator();
+
+ while (loaders.hasNext()) {
+ JavaClassLoader loader = (JavaClassLoader) loaders.next();
+ try {
+ for (Iterator iter = loader.getDefinedClasses().iterator(); iter.hasNext();) {
+ JavaClass clazz = (JavaClass) iter.next();
+ if (clazz.getName().equals("java/lang/Math")) {
+ math = clazz;
+ break;
+ }
+ }
+ } catch (CorruptDataException e) {
+ // Ignore.
+ }
+ }
+
+ if (null != math) {
+ Iterator fields = math.getDeclaredFields().iterator();
+ while (fields.hasNext()) {
+ JavaField field = (JavaField) fields.next();
+ try {
+ if (field.getName().equals("PI")) {
+ double pi = field.getDouble(null);
+ assertTrue(Math.PI == pi);
+ }
+ } catch (CorruptDataException e) {
+ //ignore
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ //fail
+ assertTrue(false);
+ }
+ }
+ } else {
+ throw new TestNotImplementedException();
+ }
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaHeapTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaHeapTest.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaHeapTest.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaHeapTest.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Licensed 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.kato.tests.junit;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.tools.diagnostics.runtime.java.JavaHeap;
+
+
+public class JavaHeapTest extends AbstractImageTestcase
+{
+ private JavaHeap _heap = null;
+
+ protected void setUp() throws Exception
+ {
+ _heap = defaultJavaHeap();
+ super.setUp();
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaHeap.getSections()'
+ *
+ * Ensure that the heap has at least one section
+ */
+ public void testGetSections()
+ {
+ List iter = _heap.getSections();
+ assertNotNull(iter);
+ assertFalse(iter.isEmpty());
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaHeap.getName()'
+ *
+ * Ensure that the heap has a non-empty name
+ */
+ public void testGetName()
+ {
+ String name = _heap.getName();
+ assertNotNull(name);
+ assertTrue(name.length() > 0);
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaHeap.getObjects()'
+ *
+ * Ensure that we return a non-empty iterator
+ */
+ public void testGetObjects()
+ {
+ Iterator it = _heap.getObjects().iterator();
+ assertNotNull(it);
+ assertTrue(it.hasNext());
+ }
+
+ /**
+ * Verify that the equals call doesn't throw
+ */
+ public void testEquals()
+ {
+ try{
+ assertTrue(_heap.equals(_heap));
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Verify that hashCode() doesn't throw and returns non-zero (technically zero is ok but it will be
+ * flagged here to ensure that we aren't doing anything bad to create the hashcode)
+ */
+ public void testHashCode()
+ {
+ try {
+ assertTrue(0 != _heap.hashCode());
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaLocationTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaLocationTest.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaLocationTest.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaLocationTest.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,150 @@
+/*******************************************************************************
+ * Licensed 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.kato.tests.junit;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.ImagePointer;
+import javax.tools.diagnostics.runtime.java.JavaLocation;
+import javax.tools.diagnostics.runtime.java.JavaStackFrame;
+
+public class JavaLocationTest extends AbstractImageTestcase
+{
+ private JavaLocation _location;
+
+ public JavaLocation defaultLocation()
+ {
+ try {
+ return ((JavaStackFrame)defaultJavaThread().getStackFrames().get(0)).getLocation();
+ } catch (CorruptDataException e) {
+ //XXX: how should this be handled?
+ throw new TestNotImplementedException();
+ }
+ }
+
+ protected void setUp() throws Exception
+ {
+ _location = defaultLocation();
+ super.setUp();
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaLocation.getAddress()'
+ *
+ * Ensures that the address is non-null
+ */
+ public void testGetAddress()
+ {
+ try {
+ ImagePointer address = _location.getAddress();
+ assertNotNull(address);
+ } catch (CorruptDataException e) {
+ //acceptable
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaLocation.getLineNumber()'
+ *
+ * Ensures that the line number is >0
+ */
+ public void testGetLineNumber()
+ {
+ try {
+ assertTrue(_location.getLineNumber() > 0);
+ } catch (DataUnavailable e) {
+ //acceptable
+ } catch (CorruptDataException e) {
+ //acceptable
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaLocation.getFilename()'
+ *
+ * Ensures that the filename is non-null and non-empty
+ */
+ public void testGetFilename()
+ {
+ try {
+ String filename = _location.getFilename();
+ assertNotNull(filename);
+ assertTrue(filename.length() > 0);
+ } catch (DataUnavailable e) {
+ //acceptable
+ } catch (CorruptDataException e) {
+ //acceptable
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaLocation.getCompilationLevel()'
+ *
+ * Ensures that the call succeeds
+ */
+ public void testGetCompilationLevel()
+ {
+ try {
+ _location.getCompilationLevel();
+ } catch (CorruptDataException e) {
+ //acceptable
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaLocation.getMethod()'
+ *
+ * Ensures that a non-null method is returned
+ */
+ public void testGetMethod()
+ {
+ try {
+ assertNotNull(_location.getMethod());
+ } catch (CorruptDataException e) {
+ //acceptable
+ }
+ }
+
+ /**
+ * Verify that the equals call doesn't throw
+ */
+ public void testEquals()
+ {
+ try{
+ assertTrue(_location.equals(_location));
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Verify that hashCode() doesn't throw and returns non-zero (technically zero is ok but it will be
+ * flagged here to ensure that we aren't doing anything bad to create the hashcode)
+ */
+ public void testHashCode()
+ {
+ try {
+ assertTrue(0 != _location.hashCode());
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ public void testToString()
+ {
+ String theString = _location.toString();
+ assertNotNull(theString);
+ assertTrue(theString.length() >= 0 );
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaMethodTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaMethodTest.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaMethodTest.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaMethodTest.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Licensed 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.kato.tests.junit;
+
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.ImageSection;
+import javax.tools.diagnostics.runtime.java.JavaField;
+import javax.tools.diagnostics.runtime.java.JavaMethod;
+
+
+public class JavaMethodTest extends AbstractImageTestcase
+{
+ private JavaMethod _method = null;
+
+ protected void setUp() throws Exception
+ {
+ _method = defaultJavaMethod();
+ super.setUp();
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaMethod.getBytecodeSections()'
+ *
+ * Ensures that a non-null iterator is returned and every element of the iterator is ImageSection.
+ * (note that the iterator can be empty in the case of natives)
+ */
+ public void testGetBytecodeSections()
+ {
+ Iterator it = _method.getBytecodeSections().iterator();
+ assertNotNull(it);
+ while (it.hasNext()) {
+ assertTrue(it.next() instanceof ImageSection);
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaMethod.getCompiledSections()'
+ *
+ * Ensures that a non-null, non-empty iterator is returned
+ */
+ public void testGetCompiledSections()
+ {
+ Iterator it = _method.getCompiledSections().iterator();
+ assertNotNull(it);
+ assertTrue(it.hasNext());
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaMember.getModifiers()'
+ *
+ * Ensures that the call succeeds
+ */
+ public void testGetModifiers()
+ {
+ try {
+ _method.getModifiers();
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaMember.getDeclaringClass()'
+ *
+ * Ensures that the class has a non-null address
+ */
+ public void testGetDeclaringClass()
+ {
+ try {
+ assertTrue(0 != _method.getDeclaringClass().getID().getAddress());
+ } catch (CorruptDataException e) {
+ } catch (DataUnavailable e) {
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaMember.getName()'
+ *
+ * Ensure that the method has a non-empty name
+ */
+ public void testGetName()
+ {
+ try {
+ assertTrue(_method.getName().length() > 0);
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaMember.getSignature()'
+ *
+ * Ensure that the signature is non-empty
+ */
+ public void testGetSignature()
+ {
+ try {
+ assertTrue(_method.getSignature().length() > 0);
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ * Verify that the equals call doesn't throw
+ */
+ public void testEquals()
+ {
+ try{
+ assertTrue(_method.equals(_method));
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Verify that hashCode() doesn't throw and returns non-zero (technically zero is ok but it will be
+ * flagged here to ensure that we aren't doing anything bad to create the hashcode)
+ */
+ public void testHashCode()
+ {
+ try {
+ assertTrue(0 != _method.hashCode());
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ public void testToString()
+ {
+ String theString=_method.toString();
+ assertNotNull(theString);
+ assertTrue(theString.length() >= 0 );
+ }
+
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaMonitorTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaMonitorTest.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaMonitorTest.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/JavaMonitorTest.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,172 @@
+/*******************************************************************************
+ * Licensed 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.kato.tests.junit;
+
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.CorruptData;
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.runtime.java.JavaMonitor;
+import javax.tools.diagnostics.runtime.java.JavaThread;
+
+
+public class JavaMonitorTest extends AbstractImageTestcase
+{
+ private JavaMonitor _monitor = null;
+
+ public JavaMonitor defaultJavaMonitor()
+ {
+ Iterator it = defaultJavaRuntime().getMonitors().iterator();
+ assertNotNull(it);
+ assertTrue(it.hasNext());
+ return (JavaMonitor) it.next();
+ }
+
+ protected void setUp() throws Exception
+ {
+ _monitor = defaultJavaMonitor();
+ super.setUp();
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaMonitor.getObject()'
+ *
+ * Ensures that no unexpected exceptions are thrown
+ */
+ public void testGetObject()
+ {
+ _monitor.getObject();
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaMonitor.getName()'
+ *
+ * Ensures that a non-null name is returned
+ */
+ public void testGetName()
+ {
+ try {
+ String name = _monitor.getName();
+ assertNotNull(name);
+ } catch (CorruptDataException e) {
+ //this is technically allowed
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaMonitor.getOwner()'
+ *
+ * Ensures that no unexpected exceptions are thrown
+ */
+ public void testGetOwner()
+ {
+ try {
+ _monitor.getOwner();
+ } catch (CorruptDataException e) {
+ //this is technically allowed
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaMonitor.getEnterWaiters()'
+ *
+ * Ensures that either an empty iterator is returned, or a non-empty iterator where all the
+ * elements are JavaThread of CorruptData is returned.
+ */
+ public void testGetEnterWaiters()
+ {
+ Iterator iter = _monitor.getEnterWaiters().iterator();
+ assertNotNull(iter);
+ while (iter.hasNext()) {
+ Object element = iter.next();
+ assertTrue((element instanceof JavaThread) || (element instanceof CorruptData));
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaMonitor.getNotifyWaiters()'
+ *
+ * Ensures that either an empty iterator is returned, or a non-empty iterator where all the
+ * elements are JavaThread of CorruptData is returned.
+ */
+ public void testGetNotifyWaiters()
+ {
+ Iterator iter = _monitor.getNotifyWaiters().iterator();
+ assertNotNull(iter);
+ while (iter.hasNext()) {
+ Object element = iter.next();
+ assertTrue((element instanceof JavaThread) || (element instanceof CorruptData));
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.runtime.java.JavaMonitor.getID()'
+ *
+ * Ensures that the pointer we receive is non-null.
+ */
+ public void testGetID()
+ {
+ assertNotNull(_monitor.getID());
+ }
+
+ /**
+ * Verify that the equals call doesn't throw
+ */
+ public void testEquals()
+ {
+ try{
+ assertTrue(_monitor.equals(_monitor));
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Verify that hashCode() doesn't throw and returns non-zero (technically zero is ok but it will be
+ * flagged here to ensure that we aren't doing anything bad to create the hashcode)
+ */
+ public void testHashCode()
+ {
+ try {
+ assertTrue(0 != _monitor.hashCode());
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Ensure that all the monitors we find which have owners have valid owners.
+ *
+ * Note: This test may have to be removed or further qualified in the future if we want to restrict this test suite to only deal
+ * with spec behaviour (which would allow getOwner() to throw CorruptDataException) or to test corner cases and past bugs in the
+ * (since this test suite currently addresses both needs).
+ */
+ public void testAllMonitorOwners()
+ {
+ try {
+ Iterator it = defaultJavaRuntime().getMonitors().iterator();
+
+ while (it.hasNext()) {
+ JavaMonitor monitor = (JavaMonitor) it.next();
+ JavaThread owner = monitor.getOwner();
+
+ if (null != owner) {
+ assertNotNull(owner.getName());
+ }
+ }
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+}