/hg/rhino-tests: Added new test case src/org/RhinoTests/Invocabl...
ptisnovs at icedtea.classpath.org
ptisnovs at icedtea.classpath.org
Tue Sep 11 07:59:45 PDT 2012
changeset 1909ce4c5896 in /hg/rhino-tests
details: http://icedtea.classpath.org/hg/rhino-tests?cmd=changeset;node=1909ce4c5896
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Tue Sep 11 17:02:20 2012 +0200
Added new test case src/org/RhinoTests/InvocableClassTest.java with 20 tests.
diffstat:
ChangeLog | 7 +
Makefile | 2 +
src/org/RhinoTests/InvocableClassTest.java | 347 +++++++++++++++++++++++++++++
3 files changed, 356 insertions(+), 0 deletions(-)
diffs (384 lines):
diff -r d649db1c7d07 -r 1909ce4c5896 ChangeLog
--- a/ChangeLog Mon Sep 10 10:31:55 2012 +0200
+++ b/ChangeLog Tue Sep 11 17:02:20 2012 +0200
@@ -1,3 +1,10 @@
+2012-09-11 Pavel Tisnovsky <ptisnovs at redhat.com>
+
+ * src/org/RhinoTests/InvocableClassTest.java:
+ Added new test case with 20 tests.
+ * Makefile:
+ Added new class to compile and new test to run.
+
2012-09-10 Pavel Tisnovsky <ptisnovs at redhat.com>
* src/org/RhinoTests/CompiledScriptTest.java:
diff -r d649db1c7d07 -r 1909ce4c5896 Makefile
--- a/Makefile Mon Sep 10 10:31:55 2012 +0200
+++ b/Makefile Tue Sep 11 17:02:20 2012 +0200
@@ -62,6 +62,7 @@
CompiledScriptTest \
CompiledScriptClassTest \
InvocableTest \
+ InvocableClassTest \
ScriptContextTest \
ScriptContextClassTest \
ScriptExceptionTest \
@@ -90,6 +91,7 @@
$(BUILD_DIR)/$(TEST_PACKAGE)/CompiledScriptTest.class \
$(BUILD_DIR)/$(TEST_PACKAGE)/CompiledScriptClassTest.class \
$(BUILD_DIR)/$(TEST_PACKAGE)/InvocableTest.class \
+ $(BUILD_DIR)/$(TEST_PACKAGE)/InvocableClassTest.class \
$(BUILD_DIR)/$(TEST_PACKAGE)/JavaScriptsTest.class \
$(BUILD_DIR)/$(TEST_PACKAGE)/ScriptContextTest.class \
$(BUILD_DIR)/$(TEST_PACKAGE)/ScriptContextClassTest.class \
diff -r d649db1c7d07 -r 1909ce4c5896 src/org/RhinoTests/InvocableClassTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/RhinoTests/InvocableClassTest.java Tue Sep 11 17:02:20 2012 +0200
@@ -0,0 +1,347 @@
+/*
+ Rhino test framework
+
+ Copyright (C) 2011, 2012 Red Hat
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+IcedTea is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version.
+*/
+
+package org.RhinoTests;
+
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.List;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import javax.script.Invocable;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptEngine;
+
+
+
+/**
+ * Set of tests which check the API of Invocable interface using
+ * Java reflection API.
+ *
+ * @author Pavel Tisnovsky
+ */
+public class InvocableClassTest extends BaseRhinoTest {
+
+ /**
+ * Object that represents the type of Invocable.
+ */
+ Class invocableClass = null;
+
+ @Override
+ protected void setUp(String[] args) {
+ // setup attribute used by tests
+ this.invocableClass = Invocable.class;
+ }
+
+ @Override
+ protected void tearDown() {
+ // this block could be empty
+ return;
+ }
+
+ /**
+ * Test for method javax.script.Invocable.getClass().isAssignableFrom()
+ */
+ protected void testIsAssignableFrom() {
+ assertTrue(this.invocableClass.isAssignableFrom(Invocable.class),
+ "Method Invocable.getClass().isAssignableFrom() returns wrong value");
+ }
+
+ /**
+ * Test for method javax.script.Invocable.getClass().isInstance()
+ */
+ protected void testIsInstance() {
+ assertTrue(this.invocableClass.isInstance((Invocable)(new ScriptEngineManager().getEngineByName(Constants.EngineNames.ENGINE_NAME_JavaScript))),
+ "Method Invocable.getClass().isInstance() returns wrong value");
+ }
+
+ /**
+ * Test for method javax.script.Invocable.getClass().isInterface()
+ */
+ protected void testIsInterface() {
+ assertTrue(this.invocableClass.isInterface(),
+ "Method Invocable.getClass().isInterface() returns wrong value");
+ }
+
+ /**
+ * Test for method javax.script.Invocable.getClass().isLocalClass()
+ */
+ protected void testIsLocalClass() {
+ assertFalse(this.invocableClass.isLocalClass(),
+ "Method Invocable.getClass().isLocalClass() returns wrong value");
+ }
+
+ /**
+ * Test for method javax.script.Invocable.getClass().isMemberClass()
+ */
+ protected void testIsMemberClass() {
+ assertFalse(this.invocableClass.isMemberClass(),
+ "Method Invocable.getClass().isMemberClass() returns wrong value");
+ }
+
+ /**
+ * Test for method javax.script.Invocable.getClass().isPrimitive()
+ */
+ protected void testIsPrimitive() {
+ assertFalse(this.invocableClass.isPrimitive(),
+ "Method Invocable.getClass().isPrimitive() returns wrong value");
+ }
+
+ /**
+ * Test for method javax.script.Invocable.getClass().isSynthetic()
+ */
+ protected void testIsSynthetic() {
+ assertFalse(this.invocableClass.isSynthetic(),
+ "Method Invocable.getClass().isSynthetic() returns wrong value");
+ }
+
+ /**
+ * Test for method javax.script.Invocable.getClass().getInterfaces()
+ */
+ protected void testGetInterfaces() {
+ List interfaces = Arrays.asList(this.invocableClass.getInterfaces());
+ assertTrue(interfaces.isEmpty(),
+ "list of implemented interfaces should be empty");
+ }
+
+ /**
+ * Test for method javax.script.Invocable.getClass().getModifiers()
+ */
+ protected void testGetModifiers() {
+ int modifiers = this.invocableClass.getModifiers();
+ assertTrue(Modifier.isPublic(modifiers),
+ "Method Invocable.getClass().getModifiers() - isPublic modifier is set to a wrong value");
+ assertFalse(Modifier.isPrivate(modifiers),
+ "Method Invocable.getClass().getModifiers() - isPrivate modifier is set to a wrong value");
+ assertFalse(Modifier.isProtected(modifiers),
+ "Method Invocable.getClass().getModifiers() - isProtected modifier is set to a wrong value");
+ assertTrue(Modifier.isAbstract(modifiers),
+ "Method Invocable.getClass().getModifiers() - isAbstract modifier is set to a wrong value");
+ assertFalse(Modifier.isFinal(modifiers),
+ "Method Invocable.getClass().getModifiers() - isFinal modifier is set to a wrong value");
+ assertTrue(Modifier.isInterface(modifiers),
+ "Method Invocable.getClass().getModifiers() - isInterface modifier is set to a wrong value");
+ assertFalse(Modifier.isNative(modifiers),
+ "Method Invocable.getClass().getModifiers() - isNative modifier is set to a wrong value");
+ assertFalse(Modifier.isStatic(modifiers),
+ "Method Invocable.getClass().getModifiers() - isStatic modifier is set to a wrong value");
+ assertFalse(Modifier.isStrict(modifiers),
+ "Method Invocable.getClass().getModifiers() - isStrict modifier is set to a wrong value");
+ assertFalse(Modifier.isSynchronized(modifiers),
+ "Method Invocable.getClass().getModifiers() - isSynchronized modifier is set to a wrong value");
+ assertFalse(Modifier.isTransient(modifiers),
+ "Method Invocable.getClass().getModifiers() - isTransient modifier is set to a wrong value");
+ assertFalse(Modifier.isVolatile(modifiers),
+ "Method Invocable.getClass().getModifiers() - isVolatile modifier is set to a wrong value");
+ }
+
+ /**
+ * Test for method javax.script.Invocable.getClass().getName()
+ */
+ protected void testGetName() {
+ String name = this.invocableClass.getName();
+ assertEquals(name, "javax.script.Invocable",
+ "Method Invocable.getClass().getName() returns wrong value " + name);
+ }
+
+ /**
+ * Test for method javax.script.Invocable.getClass().getPackage()
+ */
+ protected void testGetPackage() {
+ Package p = this.invocableClass.getPackage();
+ String packageName = p.getName();
+ assertEquals(packageName, "javax.script",
+ "Method Invocable.getClass().getPackage().getName() returns wrong value " + packageName);
+ }
+
+ /**
+ * Test for method javax.script.Invocable.getClass().getSimpleName()
+ */
+ protected void testGetSimpleName() {
+ String simpleName = this.invocableClass.getSimpleName();
+ assertEquals(simpleName, "Invocable",
+ "Method Invocable.getClass().getSimpleName() returns wrong value " + simpleName);
+ }
+
+ /**
+ * Test for method javax.script.Invocable.getClass().getSuperclass()
+ */
+ protected void testGetSuperclass() {
+ Class superClass = this.invocableClass.getSuperclass();
+ assertNull(superClass,
+ "Method Invocable.getClass().getSuperclass() does not return null");
+ }
+
+ /**
+ * Test for method javax.script.Invocable.getClass().getConstructors()
+ */
+ protected void testGetConstructors() {
+ Constructor[] constructors = this.invocableClass.getConstructors();
+ assertEquals(constructors.length, 0, "no constructors should be set");
+ }
+
+ /**
+ * Test for method javax.script.Invocable.getClass().getDeclaredConstructors()
+ */
+ protected void testGetDeclaredConstructors() {
+ Constructor[] constructors = this.invocableClass.getDeclaredConstructors();
+ assertEquals(constructors.length, 0, "no constructors should be set");
+ }
+
+ /**
+ * Test for method javax.script.Invocable.getClass().getFields()
+ */
+ protected void testGetFields() {
+ // following fields should exists
+ final String[] fieldsThatShouldExists = {
+ };
+ // get all fields
+ Field[] fields = this.invocableClass.getFields();
+ // and transform the array into a list of field names
+ List<String> fieldsAsString = new ArrayList<String>();
+ for (Field field : fields) {
+ fieldsAsString.add(field.toString());
+ }
+ // check if all required fields really exists
+ for (String fieldThatShouldExists : fieldsThatShouldExists) {
+ assertTrue(fieldsAsString.contains(fieldThatShouldExists),
+ "field " + fieldThatShouldExists + " not found");
+ }
+ }
+
+ /**
+ * Test for method javax.script.Invocable.getClass().getDeclaredFields()
+ */
+ protected void testGetDeclaredFields() {
+ // following fields should be declared
+ final String[] fieldsThatShouldExists = {
+ };
+ // get all declared fields
+ Field[] declaredFields = this.invocableClass.getDeclaredFields();
+ // and transform the array into a list of field names
+ List<String> declaredFieldsAsString = new ArrayList<String>();
+ for (Field field : declaredFields) {
+ declaredFieldsAsString.add(field.toString());
+ }
+ // check if all required fields really exists
+ for (String fieldThatShouldExists : fieldsThatShouldExists) {
+ assertTrue(declaredFieldsAsString.contains(fieldThatShouldExists),
+ "field " + fieldThatShouldExists + " not found");
+ }
+ }
+
+ /**
+ * Test for method javax.script.Invocable.getClass().getMethods()
+ */
+ protected void testGetMethods() {
+ // following methods should be inherited
+ final String[] methodsThatShouldExists = {
+ "public abstract java.lang.Object javax.script.Invocable.getInterface(java.lang.Class)",
+ "public abstract java.lang.Object javax.script.Invocable.getInterface(java.lang.Object,java.lang.Class)",
+ "public abstract java.lang.Object javax.script.Invocable.invokeFunction(java.lang.String,java.lang.Object[]) throws javax.script.ScriptException,java.lang.NoSuchMethodException",
+ "public abstract java.lang.Object javax.script.Invocable.invokeMethod(java.lang.Object,java.lang.String,java.lang.Object[]) throws javax.script.ScriptException,java.lang.NoSuchMethodException",
+ };
+ // get all inherited methods
+ Method[] methods = this.invocableClass.getMethods();
+ // and transform the array into a list of method names
+ List<String> methodsAsString = new ArrayList<String>();
+ for (Method method : methods) {
+ methodsAsString.add(method.toString());
+ }
+ // check if all required methods really exists
+ for (String methodThatShouldExists : methodsThatShouldExists) {
+ assertTrue(methodsAsString.contains(methodThatShouldExists),
+ "method " + methodThatShouldExists + " not found");
+ }
+ }
+
+ /**
+ * Test for method javax.script.Invocable.getClass().getDeclaredMethods()
+ */
+ protected void testGetDeclaredMethods() {
+ // following methods should be declared
+ final String[] declaredMethodsThatShouldExists = {
+ "public abstract java.lang.Object javax.script.Invocable.getInterface(java.lang.Class)",
+ "public abstract java.lang.Object javax.script.Invocable.getInterface(java.lang.Object,java.lang.Class)",
+ "public abstract java.lang.Object javax.script.Invocable.invokeFunction(java.lang.String,java.lang.Object[]) throws javax.script.ScriptException,java.lang.NoSuchMethodException",
+ "public abstract java.lang.Object javax.script.Invocable.invokeMethod(java.lang.Object,java.lang.String,java.lang.Object[]) throws javax.script.ScriptException,java.lang.NoSuchMethodException",
+ };
+ // get all declared methods
+ Method[] declaredMethods = this.invocableClass.getDeclaredMethods();
+ // and transform the array into a list of method names
+ List<String> methodsAsString = new ArrayList<String>();
+ for (Method method : declaredMethods) {
+ methodsAsString.add(method.toString());
+ }
+ // check if all required methods really exists
+ for (String methodThatShouldExists : declaredMethodsThatShouldExists) {
+ assertTrue(methodsAsString.contains(methodThatShouldExists),
+ "declared method " + methodThatShouldExists + " not found");
+ }
+ }
+
+ /**
+ * Test for instanceof operator applied to a class javax.script.Invocable
+ */
+ protected void testInstanceOf() {
+ // tested object
+ Object o = (Invocable)(new ScriptEngineManager().getEngineByName(Constants.EngineNames.ENGINE_NAME_JavaScript));
+
+ // basic check of instanceof operator
+ assertTrue(o instanceof Invocable, "instanceof Invocable is wrongly evaluated to false");
+
+ // check operator instanceof against all superclasses
+ assertTrue(o instanceof Object, "instanceof Object is wrongly evaluated to false");
+ }
+
+ /**
+ * Entry point to this test case.
+ *
+ * @param args parameters passed from command line
+ */
+ public static void main(String[] args) {
+ new InvocableClassTest().doTests(args);
+ }
+}
+
More information about the distro-pkg-dev
mailing list