From: Thomas Walker Lynch Date: Wed, 18 Dec 2024 16:14:18 +0000 (+0000) Subject: misc X-Git-Url: https://git.reasoningtechnology.com/style/rt_dark_doc.css?a=commitdiff_plain;h=1074c4fa0ae632faf0a1c9816544d6f3ea63c1b7;p=Mosaic misc --- diff --git "a/developer/javac\360\237\226\211/Mosaic_Dispatcher.java" "b/developer/javac\360\237\226\211/Mosaic_Dispatcher.java" index e2b9a86..530b5b7 100644 --- "a/developer/javac\360\237\226\211/Mosaic_Dispatcher.java" +++ "b/developer/javac\360\237\226\211/Mosaic_Dispatcher.java" @@ -169,27 +169,29 @@ Dispatcher instance. */ class MethodSignature_To_Handle_Map{ - private Map map; - // test facilities + // Static test messaging // - private boolean test = false; - public void test_switch(boolean test){ - if(this.test && !test){ - test_print("test messages off"); - this.test = test; + private static boolean test = false; + public static void test_switch(boolean test){ + if (MethodSignature_To_Handle_Map.test && !test){ + test_print("MethodSignature_To_Handle_Map:: test messages off"); } - if( !this.test && test){ - this.test = test; - test_print("test messages on"); + if (!MethodSignature_To_Handle_Map.test && test){ + test_print("MethodSignature_To_Handle_Map:: test messages on"); } + MethodSignature_To_Handle_Map.test = test; } - private void test_print(String message){ - if(test){ - System.out.println("MethodSignature_To_Handle_Map::" + message); + private static void test_print(String message){ + if (test){ + System.out.println(message); } } + // instance data + // + private Map map; + // field access and strings // @@ -204,22 +206,29 @@ class MethodSignature_To_Handle_Map{ private void add_entry(MethodSignature key ,MethodHandle value){ test_print ( - "add_entry::" - + "(" - + key - + "," - +value + "(add_entry:: " + "(key " + key + ") " + "(value " + value + ")" + ")" ); map.put(key ,value); } public void add_class(Class class_metadata){ try{ + test_print("adding public methods"); add_methods_public(class_metadata); + + test_print("adding private methods"); add_methods_private(class_metadata); + + test_print("adding constructors"); add_constructors(class_metadata); + + /* + test_print("adding static methods"); + add_methods_static(class_metadata); + */ + }catch(Throwable t){ - System.out.println("MethodSignature_To_Handle_Map::add_class exception:"); + System.out.println("MethodSignature_To_Handle_Map::add_class exception: "); t.printStackTrace(); } } @@ -310,6 +319,35 @@ class MethodSignature_To_Handle_Map{ } } + public void add_methods_static(Class class_metadata) { + MethodHandles.Lookup lookup = MethodHandles.lookup(); + + for (Method method : class_metadata.getDeclaredMethods()) { + try { + if (Modifier.isStatic(method.getModifiers())) { // Only static methods + Class[] parameter_type_list = method.getParameterTypes(); + MethodType method_type = MethodType.methodType(method.getReturnType(), parameter_type_list); + MethodHandle method_handle = lookup.findStatic(class_metadata, method.getName(), method_type); + + MethodSignature signature = new MethodSignature( + method.getReturnType(), + class_metadata.getName(), + method.getName(), + parameter_type_list + ); + + add_entry(signature, method_handle); + } + } catch (NoSuchMethodException e) { + System.err.println("Skipping static method: " + method); + e.printStackTrace(); + } catch (Throwable t) { + t.printStackTrace(); + } + } + } + + // methods for looking up handles // public MethodHandle lookup(MethodSignature s){ @@ -321,7 +359,7 @@ class MethodSignature_To_Handle_Map{ @Override public String toString(){ StringBuilder sb = new StringBuilder(); - sb.append("MethodSignature_To_Handle_Map: {").append(System.lineSeparator()); + sb.append("MethodSignature_To_Handle_Map:{").append(System.lineSeparator()); for (Map.Entry entry : map.entrySet()){ sb.append(" ") @@ -342,29 +380,32 @@ class MethodSignature_To_Handle_Map{ */ public class Mosaic_Dispatcher{ - private MethodSignature_To_Handle_Map map; - private Class target; - // test facilities + // Static test messaging // - private boolean test = false; - public void test_switch(boolean test){ - if(this.test && !test){ + private static boolean test = false; + public static void test_switch(boolean test){ + if (Mosaic_Dispatcher.test && !test){ test_print("Mosaic_Dispatcher:: test messages off"); - this.test = test; } - if(!this.test && test){ - this.test = test; + if (!Mosaic_Dispatcher.test && test){ test_print("Mosaic_Dispatcher:: test messages on"); - map.test_switch(true); + MethodSignature_To_Handle_Map.test_switch(true); } + Mosaic_Dispatcher.test = test; } - private void test_print(String message){ - if(test){ - System.out.println("Mosaic_Dispatcher::" + message); + private static void test_print(String message){ + if (test){ + System.out.println(message); } } + // instance data + // + private MethodSignature_To_Handle_Map map; + private Class target; + + // field access and strings // public Class get_target(){ @@ -385,19 +426,17 @@ public class Mosaic_Dispatcher{ // construct given the class metadata for the target class public Mosaic_Dispatcher(Class target){ this.map = new MethodSignature_To_Handle_Map(); - test_switch(true); this.target = target; - test_print("Mosaic_Dispatcher:: mapping class from metadata:" + to_string_target()); + test_print("Mosaic_Dispatcher:: mapping methods given class_metadata object: " + to_string_target()); this.map.add_class(target); } // Constructor accepting a fully qualified class name of the target class public Mosaic_Dispatcher(String fully_qualified_class_name) throws ClassNotFoundException{ this.map = new MethodSignature_To_Handle_Map(); - test_switch(true); try{ this.target = Class.forName(fully_qualified_class_name); - test_print("Mosaic_Dispatcher:: mapping class from name string:" + to_string_target()); + test_print("Mosaic_Dispatcher:: mapping methods from class specified by string:" + to_string_target()); this.map.add_class(target); }catch(ClassNotFoundException e){ throw new ClassNotFoundException("Class not found: " + fully_qualified_class_name ,e); @@ -409,6 +448,7 @@ public class Mosaic_Dispatcher{ // Factory method to create an instance (dispatch a constructor) public Object make(Object... arg_list){ + test_print("Call to Mosaic_Dispatcher::make"); return dispatch_1 ( null // there is no instance passed in when calling a constructor @@ -418,91 +458,64 @@ public class Mosaic_Dispatcher{ ); } - @SuppressWarnings("unchecked") + // dispatch static methods public T dispatch + ( + Class return_type + ,String method_name + ,Object... arg_list + ){ + test_print("Call to Mosaic_Dispatcher::dispatch for a static method."); + return dispatch_1 ( - Object instance - ,Class return_type - ,String method_name - ,Object... arg_list - ){ - if(instance == null || !target.isInstance(instance)){ - throw new IllegalArgumentException - ( - "Provided instance is not of target type: " - + target.getName() - + ", but received: " - + (instance == null ? "null" : instance.getClass().getName()) - ); - } - - Object result = dispatch_1( - instance - ,return_type - ,method_name - ,arg_list - ); - - // Handle primitive return types explicitly - if(return_type.isPrimitive()){ - if(return_type == boolean.class) return (T) (Boolean) result; - if(return_type == int.class) return (T) (Integer) result; - if(return_type == double.class) return (T) (Double) result; - if(return_type == float.class) return (T) (Float) result; - if(return_type == long.class) return (T) (Long) result; - if(return_type == short.class) return (T) (Short) result; - if(return_type == byte.class) return (T) (Byte) result; - if(return_type == char.class) return (T) (Character) result; - } - - // For non-primitives, cast normally - return return_type.cast(result); + null // No instance for static methods + ,return_type // Return type + ,method_name // Method name + ,arg_list // Argument list + ); } - - /* + // dispatch instance binded methods + @SuppressWarnings("unchecked") public T dispatch - ( - Object instance - ,Class return_type - ,String method_name - ,Object... arg_list - ){ - + ( + Object instance, + Class return_type, + String method_name, + Object... arg_list + ){ + test_print("Call to Mosaic_Dispatcher::dispatch for a method bound to an instance."); if(instance == null || !target.isInstance(instance)){ throw new IllegalArgumentException ( - "Provided instance is not of target type: " - + target.getName() - + ", but received: " + "Provided instance is not of target type: " + + target.getName() + + ", but received: " + (instance == null ? "null" : instance.getClass().getName()) ); } - - return return_type.cast(dispatch_1( - instance - ,return_type - ,method_name - ,arg_list - )); + return dispatch_1(instance, return_type, method_name, arg_list); } - */ - private Object dispatch_1( - Object instance - ,Class return_type - ,String method_name - ,Object... arg_list + private T dispatch_1( + Object instance, + Class return_type, + String method_name, + Object... arg_list ){ try{ + if(arg_list == null){ + arg_list = new Object[0]; // Treat null as an empty argument list + } + // Resolve method/constructor signature MethodSignature signature = new MethodSignature( - return_type - ,to_string_target() - ,method_name - ,arg_list + return_type, + to_string_target(), + method_name, + arg_list ); - test_print("dispatch_1:: signature is:" + signature.toString()); + test_print("dispatch_1:: signature key:" + signature.toString()); MethodHandle handle = map.lookup(signature); @@ -513,20 +526,38 @@ public class Mosaic_Dispatcher{ // Unwrap Mosaic_IsPrimitive arguments Object[] unwrapped_arg_list = new Object[arg_list.length]; for(int i = 0; i < arg_list.length; i++){ - if (arg_list[i] instanceof Mosaic_IsPrimitive){ + if(arg_list[i] instanceof Mosaic_IsPrimitive){ unwrapped_arg_list[i] = ((Mosaic_IsPrimitive) arg_list[i]).get_value(); - } else { + }else{ unwrapped_arg_list[i] = arg_list[i]; } } - // Handle constructor vs method + // Handle method invocation + Object result; if("".equals(method_name)){ - return handle.invokeWithArguments(unwrapped_arg_list); // Constructor: no binding needed + result = handle.invokeWithArguments(unwrapped_arg_list); // Constructor: no binding needed + }else if(instance == null){ + result = handle.invokeWithArguments(unwrapped_arg_list); // Static method }else{ - return handle.bindTo(instance).invokeWithArguments(unwrapped_arg_list); // Method: bind instance + result = handle.bindTo(instance).invokeWithArguments(unwrapped_arg_list); // Instance method } + // Handle primitive return types explicitly + if(return_type.isPrimitive()){ + if(return_type == boolean.class) return(T)(Boolean) result; + if(return_type == int.class) return(T)(Integer) result; + if(return_type == double.class) return(T)(Double) result; + if(return_type == float.class) return(T)(Float) result; + if(return_type == long.class) return(T)(Long) result; + if(return_type == short.class) return(T)(Short) result; + if(return_type == byte.class) return(T)(Byte) result; + if(return_type == char.class) return(T)(Character) result; + } + + // For non-primitives, cast normally + return return_type.cast(result); + }catch(Throwable t){ System.out.println("Mosaic_Dispatcher::dispatch exception:"); t.printStackTrace(); @@ -539,7 +570,7 @@ public class Mosaic_Dispatcher{ @Override public String toString(){ return - "Mosaic_Dispatcher {" + "Mosaic_Dispatcher{" + "target=" + to_string_target() + " ,map=" diff --git "a/developer/javac\360\237\226\211/Mosaic_TestClasses_0.java" "b/developer/javac\360\237\226\211/Mosaic_TestClasses_0.java" deleted file mode 100644 index 7c09e36..0000000 --- "a/developer/javac\360\237\226\211/Mosaic_TestClasses_0.java" +++ /dev/null @@ -1,50 +0,0 @@ -package com.ReasoningTechnology.Mosaic; - -/* - These are used for testing that Mosaic can be used for white box - testing. Mosaic tests for Mosaic itself access each of these as - part of regression. Users are welcome to also check accessing these - when debugging any access problems that might arise. -*/ - -// Public class with public and private methods -public class Mosaic_TestClasses_0 { - public boolean a_public_method_1() { - return true; - } - - private boolean a_private_method_2() { - return true; - } - - public class PublicClass { - public boolean a_public_method_3() { - return true; - } - - private boolean a_private_method_4() { - return true; - } - } - - private class PrivateClass { - public boolean a_public_method_5() { - return true; - } - - private boolean a_private_method_6() { - return true; - } - } -} - -// Default (package-private) class with public and private methods -class DefaultClass { - public boolean a_public_method_7() { - return true; - } - - private boolean a_private_method_8() { - return true; - } -} diff --git "a/developer/javac\360\237\226\211/Mosaic_TestClasses_1.java" "b/developer/javac\360\237\226\211/Mosaic_TestClasses_1.java" deleted file mode 100644 index 7c3f2db..0000000 --- "a/developer/javac\360\237\226\211/Mosaic_TestClasses_1.java" +++ /dev/null @@ -1,31 +0,0 @@ -package com.ReasoningTechnology.Mosaic; - -/* - These are used for testing that Mosaic can be used for white box - testing. Mosaic tests for Mosaic itself access each of these as - part of regression. Users are welcome to also check accessing these - when debugging any access problems that might arise. -*/ - -// Public class with public and private methods -public class Mosaic_TestClasses_1 { - - private int i; - - public Mosaic_TestClasses_1(){ - i = 0; - } - - public Mosaic_TestClasses_1(int a){ - i = a; - } - - public Mosaic_TestClasses_1(int a ,int b){ - i = a + b; - } - - public int get_i() { - return i; - } - -} diff --git a/release/Mosaic.jar b/release/Mosaic.jar index d1937e2..4acbf18 100644 Binary files a/release/Mosaic.jar and b/release/Mosaic.jar differ diff --git a/tester/idea/0 b/tester/idea/0 deleted file mode 100755 index 51b4923..0000000 --- a/tester/idea/0 +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 0 diff --git a/tester/idea/Access_0 b/tester/idea/Access_0 deleted file mode 100755 index f25e6f8..0000000 --- a/tester/idea/Access_0 +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Access_0 diff --git a/tester/idea/IO b/tester/idea/IO deleted file mode 100755 index 235da3f..0000000 --- a/tester/idea/IO +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 IO diff --git a/tester/idea/IsPrimitive b/tester/idea/IsPrimitive deleted file mode 100755 index f835393..0000000 --- a/tester/idea/IsPrimitive +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 IsPrimitive diff --git a/tester/idea/Logger b/tester/idea/Logger deleted file mode 100755 index f127e85..0000000 --- a/tester/idea/Logger +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Logger diff --git a/tester/idea/MockClass_0 b/tester/idea/MockClass_0 deleted file mode 100755 index b047e64..0000000 --- a/tester/idea/MockClass_0 +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 MockClass_0 diff --git a/tester/idea/Test0 b/tester/idea/Test0 deleted file mode 100755 index b0355f5..0000000 --- a/tester/idea/Test0 +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Test0 diff --git a/tester/idea/Test_Access_0 b/tester/idea/Test_Access_0 deleted file mode 100755 index cea74ff..0000000 --- a/tester/idea/Test_Access_0 +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Test_Access_0 diff --git a/tester/idea/Test_IO b/tester/idea/Test_IO deleted file mode 100755 index c1872c0..0000000 --- a/tester/idea/Test_IO +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Test_IO diff --git a/tester/idea/Test_IsPrimitive b/tester/idea/Test_IsPrimitive deleted file mode 100755 index f0342ce..0000000 --- a/tester/idea/Test_IsPrimitive +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Test_IsPrimitive diff --git a/tester/idea/Test_Logger b/tester/idea/Test_Logger deleted file mode 100755 index 89ada20..0000000 --- a/tester/idea/Test_Logger +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Test_Logger diff --git a/tester/idea/Test_MockClass_0 b/tester/idea/Test_MockClass_0 deleted file mode 100755 index 854787e..0000000 --- a/tester/idea/Test_MockClass_0 +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Test_MockClass_0 diff --git a/tester/idea/Test_Testbench b/tester/idea/Test_Testbench deleted file mode 100755 index dac80be..0000000 --- a/tester/idea/Test_Testbench +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Test_Testbench diff --git a/tester/idea/Test_Util b/tester/idea/Test_Util deleted file mode 100755 index 345f1af..0000000 --- a/tester/idea/Test_Util +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Test_Util diff --git a/tester/idea/Testbench b/tester/idea/Testbench deleted file mode 100755 index e1fed4e..0000000 --- a/tester/idea/Testbench +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Testbench diff --git a/tester/idea/Util b/tester/idea/Util deleted file mode 100755 index bc24d32..0000000 --- a/tester/idea/Util +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Util diff --git a/tester/idea/smoke b/tester/idea/smoke deleted file mode 100755 index c7aa8e4..0000000 --- a/tester/idea/smoke +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 smoke diff --git "a/tester/javac\360\237\226\211/Access_0.java" "b/tester/javac\360\237\226\211/Access_0.java" deleted file mode 100644 index fe3dd69..0000000 --- "a/tester/javac\360\237\226\211/Access_0.java" +++ /dev/null @@ -1,94 +0,0 @@ -import com.ReasoningTechnology.Mosaic.Mosaic_Dispatcher; -import com.ReasoningTechnology.Mosaic.Mosaic_IsPrimitive; -import com.ReasoningTechnology.Mosaic.Mosaic_TestClasses_0; -import com.ReasoningTechnology.Mosaic.Mosaic_TestClasses_1; -import com.ReasoningTechnology.Mosaic.Mosaic_Util; - -public class Access_0{ - - private static Mosaic_Dispatcher dispatcher; - - static{ - // Initialize the dispatcher for Mosaic_TestClasses_0 - dispatcher = new Mosaic_Dispatcher(Mosaic_TestClasses_0.class); - dispatcher.test_switch(true); // Enable test messages for debugging - } - - // Test method to access the public method of the public class - public static boolean test_publicClass_publicMethod(){ - System.out.println("\nRunning test: test_publicClass_publicMethod"); - - Object instance = new Mosaic_TestClasses_0(); - - boolean result = dispatcher.dispatch - ( - instance // target instance - ,boolean.class // return type - ,"a_public_method_1" // method name - ); - - return result; - - } - - public static boolean test_make_0(){ - System.out.println("\nRunning test: test_make_0"); - Boolean[] condition_list = new Boolean[4]; - Mosaic_Util.all_set_false(condition_list); - int i = 0; - - Mosaic_Dispatcher d1 = new Mosaic_Dispatcher(Mosaic_TestClasses_1.class); - - Mosaic_TestClasses_1 tc0 = new Mosaic_TestClasses_1(); - condition_list[i++] = tc0.get_i() == 0; - - Mosaic_TestClasses_1 tc1 = (Mosaic_TestClasses_1) d1.make(); - condition_list[i++] = tc1.get_i() == 0; - - Mosaic_TestClasses_1 tc2 = (Mosaic_TestClasses_1) d1.make(new Mosaic_IsPrimitive(7)); - condition_list[i++] = tc2.get_i() == 7; - - Mosaic_TestClasses_1 tc3 = (Mosaic_TestClasses_1) d1.make(new Mosaic_IsPrimitive(21) ,new Mosaic_IsPrimitive(17) ); - condition_list[i++] = tc3.get_i() == 38; - - return Mosaic_Util.all(condition_list); - } - - // Run method to execute all tests - public static boolean run(){ - try{ - - // Run the individual test(s) - boolean result = true; - if( !test_publicClass_publicMethod() ){ - System.out.println("test_publicClass_publicMethod failed"); - result = false; - }else{ - System.out.println("test_publicClass_publicMethod passed"); - } - if( !test_make_0() ){ - System.out.println("test_make_0() failed"); - result = false; - }else{ - System.out.println("test_make_0() passed"); - } - - return result; - - }catch(Exception e){ - System.out.println("Exception in test Accept_0"); - e.printStackTrace(); - return false; - } - - } - - public static void main(String[] args){ - // Execute the run method and return its result as the exit code - if( run() ) - System.exit(0); - else - System.exit(1); - } - -} diff --git "a/tester/javac\360\237\226\211/AllMethodsPublicProxy_0.java" "b/tester/javac\360\237\226\211/AllMethodsPublicProxy_0.java" index 2b76f4b..327e04c 100644 --- "a/tester/javac\360\237\226\211/AllMethodsPublicProxy_0.java" +++ "b/tester/javac\360\237\226\211/AllMethodsPublicProxy_0.java" @@ -1,7 +1,7 @@ import com.ReasoningTechnology.Mosaic.Mosaic_AllMethodsPublicProxy; import com.ReasoningTechnology.Mosaic.Mosaic_IO; import com.ReasoningTechnology.Mosaic.Mosaic_Testbench; -import com.ReasoningTechnology.Mosaic.Mosaic_TestClasses; +import com.ReasoningTechnology.Mosaic.TestClasses; public class AllMethodsPublicProxy_0 { diff --git "a/tester/javac\360\237\226\211/Dispatch_0.java" "b/tester/javac\360\237\226\211/Dispatch_0.java" new file mode 100644 index 0000000..9847c46 --- /dev/null +++ "b/tester/javac\360\237\226\211/Dispatch_0.java" @@ -0,0 +1,134 @@ +import com.ReasoningTechnology.Mosaic.Mosaic_Dispatcher; +import com.ReasoningTechnology.Mosaic.Mosaic_IsPrimitive; +import com.ReasoningTechnology.Mosaic.Mosaic_Util; + +import tester.TestClasses_0; +import tester.TestClasses_1; + +public class Dispatch_0{ + + private static Mosaic_Dispatcher dispatcher; + + static{ + // Initialize the dispatcher for TestClasses_0 + Mosaic_Dispatcher.test_switch(true); + dispatcher = new Mosaic_Dispatcher(TestClasses_0.class); + } + + // Test method to access the public method of the public class + public static boolean test_publicClass_publicMethod(){ + Object instance = new TestClasses_0(); + boolean result = dispatcher.dispatch + ( + instance // target instance + ,boolean.class // return type + ,"a_public_method_1" // method name + ); + + return result; + } + + public static boolean test_make_0(){ + Boolean[] condition_list = new Boolean[4]; + Mosaic_Util.all_set_false(condition_list); + int i = 0; + + Mosaic_Dispatcher d1 = new Mosaic_Dispatcher(TestClasses_1.class); + + TestClasses_1 tc0 = new TestClasses_1(); + condition_list[i++] = tc0.get_i() == 0; + + TestClasses_1 tc1 = (TestClasses_1) d1.make(); + condition_list[i++] = tc1.get_i() == 0; + + TestClasses_1 tc2 = (TestClasses_1) d1.make(new Mosaic_IsPrimitive(7)); + condition_list[i++] = tc2.get_i() == 7; + + TestClasses_1 tc3 = (TestClasses_1) d1.make(new Mosaic_IsPrimitive(21) ,new Mosaic_IsPrimitive(17) ); + condition_list[i++] = tc3.get_i() == 38; + + return Mosaic_Util.all(condition_list); + } + + // Test public static method + public static boolean test_publicStaticMethod_7(){ + boolean result = dispatcher.dispatch( + boolean.class, // return type + "a_public_static_method_7" // method name + ); + return result; + } + + // Test private static method + public static boolean test_privateStaticMethod_9(){ + boolean result = dispatcher.dispatch( + boolean.class, // return type + "a_private_static_method_9" // method name + ); + return result; + } + + // Extend the run method to include static method tests + public static boolean run(){ + try{ + boolean result = true; + + /* + System.out.println(""); + System.out.println("running test: publicClass_publicMethod"); + if (Boolean.TRUE.equals(test_publicClass_publicMethod())){ + System.out.println("passed"); + }else{ + System.out.println("FAILED"); + result = false; + } + */ + + System.out.println(""); + System.out.println("running test: make_0"); + if (Boolean.TRUE.equals(test_make_0())){ + System.out.println("passed"); + }else{ + System.out.println("FAILED"); + result = false; + } + + /* + System.out.println(""); + System.out.println("running test: publicStaticMethod_7"); + if (Boolean.TRUE.equals(test_publicStaticMethod_7())){ + System.out.println("passed"); + }else{ + System.out.println("FAILED"); + result = false; + } + + System.out.println(""); + System.out.println("running test: privateStaticMethod_9"); + if (Boolean.TRUE.equals(test_privateStaticMethod_9())){ + System.out.println("passed"); + }else{ + System.out.println("FAILED"); + result = false; + } + */ + + System.out.println(""); + return result; + + }catch (Exception e){ + System.out.println("Exception in Dispatch_0 test:"); + e.printStackTrace(); + return false; + } + } + + public static void main(String[] args){ + // Execute the run method and return its result as the exit code + if( run() ) + System.exit(0); + else + System.exit(1); + } + +} diff --git "a/tester/javac\360\237\226\211/Dispatch_1.java" "b/tester/javac\360\237\226\211/Dispatch_1.java" new file mode 100644 index 0000000..48d5f3b --- /dev/null +++ "b/tester/javac\360\237\226\211/Dispatch_1.java" @@ -0,0 +1,211 @@ +import com.ReasoningTechnology.Mosaic.Mosaic_Dispatcher; +import com.ReasoningTechnology.Mosaic.Mosaic_Util; + +import tester.TestClasses_0; + +public class Dispatch_1{ + + private static Mosaic_Dispatcher dispatcher; + + static{ + // Initialize the dispatcher for TestClasses_0 + dispatcher = new Mosaic_Dispatcher(TestClasses_0.class); + // Test messages are disabled for now + } + + // Test public method in the public class + public static boolean test_publicMethod_1(){ + Object instance = new TestClasses_0(); + boolean result = dispatcher.dispatch( + instance, // target instance + boolean.class, // return type + "a_public_method_1" // method name + ); + return result; + } + + // Test private method in the public class + public static boolean test_privateMethod_2(){ + Object instance = new TestClasses_0(); + boolean result = dispatcher.dispatch( + instance, // target instance + boolean.class, // return type + "a_private_method_2" // method name + ); + return result; + } + + public static boolean test_nestedPublicMethod_3(){ + try{ + + // Create a dispatcher for the nested public class + Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher(TestClasses_0.APublicClass_01.class); + + // Create an instance of the outer class + TestClasses_0 outer_instance = new TestClasses_0(); + + // Create an instance of the nested public class + TestClasses_0.APublicClass_01 nested_instance = outer_instance.new APublicClass_01(); + + // Dispatch the public method call on the nested class + boolean result = nested_dispatcher.dispatch( + nested_instance, // Target instance + boolean.class, // Return type + "a_public_method_3" // Method name + ); + + return result; + + } catch (Exception e){ + System.out.println("Exception in test_nestedPublicMethod_3"); + e.printStackTrace(); + return false; + } + } + + // Test private method in the nested public class + public static boolean test_nestedPrivateMethod_4(){ + + // Create a dispatcher for the nested public class + Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher(TestClasses_0.APublicClass_01.class); + + // Create an instance of the outer class + TestClasses_0 outer_instance = new TestClasses_0(); + + // Create an instance of the nested public class + TestClasses_0.APublicClass_01 nested_instance = outer_instance.new APublicClass_01(); + + boolean result = nested_dispatcher.dispatch( + nested_instance, // target instance + boolean.class, // return type + "a_private_method_4" // method name + ); + return result; + } + + // Test public method in the nested private class + public static boolean test_private_class_public_method_5(){ + + // Use Mosaic_Dispatch to access the private class + Class private_class_metadata = Mosaic_Dispatch.resolve_class( + TestClasses_0.class ,"tester.TestClasses_0$APrivateClass_02" + ); + + // Create a dispatcher for the private class + Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher(private_class_metadata); + + // Instance of the private class is created via the dispatcher + Object nested_instance = nested_dispatcher.make(); + + boolean result = nested_dispatcher.dispatch( + nested_instance + ,boolean.class + ,"a_public_method_5" + ); + + return result; + } + + + // Test public method in the nested private class + public static boolean test_privateClassPublicMethod_5(){ + + // Create a dispatcher for the nested public class + Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher(TestClasses_0.APrivateClass_02.class); + + // Instance of the private class is created via the dispatcher + Object nested_instance = nested_dispatcher.make(); + boolean result = nested_dispatcher.dispatch( + nested_instance, // target instance + boolean.class, // return type + "a_public_method_5" // method name + ); + return result; + } + + // Test private method in the nested private class + public static boolean test_privateClassPrivateMethod_6(){ + Object nested_instance = dispatcher.make( + TestClasses_0.class, + "APrivateClass_02", + null + ); + boolean result = dispatcher.dispatch( + nested_instance, + boolean.class, + "a_private_method_6" + ); + return result; + } + + // Run method to execute all tests + public static boolean run(){ + try{ + boolean result = true; + + /* + System.out.println("\nRunning test: publicMethod_1"); + if (Boolean.TRUE.equals(test_publicMethod_1())){ + System.out.println("PASSED"); + } else{ + System.out.println("FAILED"); + result = false; + } + + System.out.println("\nRunning test: privateMethod_2"); + if (Boolean.TRUE.equals(test_privateMethod_2())){ + System.out.println("PASSED"); + } else{ + System.out.println("FAILED"); + result = false; + } + + System.out.println("\nRunning test: nestedPublicMethod_3"); + if (Boolean.TRUE.equals(test_nestedPublicMethod_3())){ + System.out.println("PASSED"); + } else{ + System.out.println("FAILED"); + result = false; + } + + System.out.println("\nRunning test: nestedPrivateMethod_4"); + if (Boolean.TRUE.equals(test_nestedPrivateMethod_4())){ + System.out.println("PASSED"); + } else{ + System.out.println("FAILED"); + result = false; + } + */ + + System.out.println("\nRunning test: privateClassPublicMethod_5"); + if (Boolean.TRUE.equals(test_privateClassPublicMethod_5())){ + System.out.println("PASSED"); + } else{ + System.out.println("FAILED"); + result = false; + } + + System.out.println("\nRunning test: privateClassPrivateMethod_6"); + if (Boolean.TRUE.equals(test_privateClassPrivateMethod_6())){ + System.out.println("PASSED"); + } else{ + System.out.println("FAILED"); + result = false; + } + + return result; + } catch (Exception e){ + System.out.println("Exception in Dispatch_1 test:"); + e.printStackTrace(); + return false; + } + } + + public static void main(String[] args){ + if (run()){ + System.exit(0); + } else{ + System.exit(1); + } + } +} diff --git "a/tester/javac\360\237\226\211/TestClasses_0.java" "b/tester/javac\360\237\226\211/TestClasses_0.java" new file mode 100644 index 0000000..edf975f --- /dev/null +++ "b/tester/javac\360\237\226\211/TestClasses_0.java" @@ -0,0 +1,61 @@ +package tester; + +/* + These are used for testing that Mosaic can be used for white box + testing. Mosaic tests for Mosaic itself access each of these as + part of regression. Users are welcome to also check accessing these + when debugging any access problems that might arise. +*/ + +// Public class with public and private methods +public class TestClasses_0{ + public boolean a_public_method_1(){ + return true; + } + + private boolean a_private_method_2(){ + return true; + } + + public class APublicClass_01{ + public boolean a_public_method_3(){ + return true; + } + + private boolean a_private_method_4(){ + return true; + } + } + + private class APrivateClass_02{ + public boolean a_public_method_5(){ + return true; + } + + private boolean a_private_method_6(){ + return true; + } + } + + /* + public static boolean a_public_static_method_7(){ + return true; + } + + private static boolean a_private_static_method_9(){ + return true; + } + */ + +} + +// Default (package-private) class with public and private methods +class DefaultTestClass{ + public boolean a_public_method_7(){ + return true; + } + + private boolean a_private_method_8(){ + return true; + } +} diff --git "a/tester/javac\360\237\226\211/TestClasses_1.java" "b/tester/javac\360\237\226\211/TestClasses_1.java" new file mode 100644 index 0000000..7c425ce --- /dev/null +++ "b/tester/javac\360\237\226\211/TestClasses_1.java" @@ -0,0 +1,31 @@ +package tester; + +/* + These are used for testing that Mosaic can be used for white box + testing. Mosaic tests for Mosaic itself access each of these as + part of regression. Users are welcome to also check accessing these + when debugging any access problems that might arise. +*/ + +// Public class with public and private methods +public class TestClasses_1 { + + private int i; + + public TestClasses_1(){ + i = 0; + } + + public TestClasses_1(int a){ + i = a; + } + + public TestClasses_1(int a ,int b){ + i = a + b; + } + + public int get_i() { + return i; + } + +} diff --git a/tester/jdwp_server/.gitignore b/tester/jdwp_server/.gitignore new file mode 100644 index 0000000..120f485 --- /dev/null +++ b/tester/jdwp_server/.gitignore @@ -0,0 +1,2 @@ +* +!/.gitignore diff --git a/tester/jdwp_server/Access_0 b/tester/jdwp_server/Access_0 deleted file mode 100755 index f25e6f8..0000000 --- a/tester/jdwp_server/Access_0 +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Access_0 diff --git a/tester/jdwp_server/IO b/tester/jdwp_server/IO deleted file mode 100755 index 235da3f..0000000 --- a/tester/jdwp_server/IO +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 IO diff --git a/tester/jdwp_server/IsPrimitive b/tester/jdwp_server/IsPrimitive deleted file mode 100755 index f835393..0000000 --- a/tester/jdwp_server/IsPrimitive +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 IsPrimitive diff --git a/tester/jdwp_server/Logger b/tester/jdwp_server/Logger deleted file mode 100755 index f127e85..0000000 --- a/tester/jdwp_server/Logger +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Logger diff --git a/tester/jdwp_server/MockClass_0 b/tester/jdwp_server/MockClass_0 deleted file mode 100755 index b047e64..0000000 --- a/tester/jdwp_server/MockClass_0 +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 MockClass_0 diff --git a/tester/jdwp_server/Testbench b/tester/jdwp_server/Testbench deleted file mode 100755 index e1fed4e..0000000 --- a/tester/jdwp_server/Testbench +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Testbench diff --git a/tester/jdwp_server/Util b/tester/jdwp_server/Util deleted file mode 100755 index bc24d32..0000000 --- a/tester/jdwp_server/Util +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Util diff --git a/tester/jdwp_server/smoke b/tester/jdwp_server/smoke deleted file mode 100755 index c7aa8e4..0000000 --- a/tester/jdwp_server/smoke +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/env bash -java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 smoke diff --git "a/tester/tool\360\237\226\211/list" "b/tester/tool\360\237\226\211/list" index b5bef5c..9e538ca 100755 --- "a/tester/tool\360\237\226\211/list" +++ "b/tester/tool\360\237\226\211/list" @@ -20,5 +20,7 @@ echo\ Testbench\ MockClass_0\ IsPrimitive\ - Access_0\ + Dispatch_0\ "" + +# Dispatch_1\ diff --git "a/tester/tool\360\237\226\211/make" "b/tester/tool\360\237\226\211/make" index 947d919..1d2f173 100755 --- "a/tester/tool\360\237\226\211/make" +++ "b/tester/tool\360\237\226\211/make" @@ -15,6 +15,11 @@ echo "Compiling files..." set -x cd $REPO_HOME/tester +# setup a couple of test classes + +javac -g -d scratchpad javac🖉/TestClasses* + + # Get the list of tests to compile # wrapper is a space-separated list list=$(list) diff --git "a/tester/tool\360\237\226\211/run" "b/tester/tool\360\237\226\211/run" index da69708..a3bcf3a 100755 --- "a/tester/tool\360\237\226\211/run" +++ "b/tester/tool\360\237\226\211/run" @@ -10,11 +10,11 @@ fi cd "$REPO_HOME/tester/jvm" || exit # Get the list of test scripts in the specific order from bash_wrapper_list -test_list=$(test_list) -echo test_list: $test_list +list=$(list) +echo list: $list # Execute each test in the specified order -for file in $test_list; do +for file in $list; do echo if [[ -x "$file" && ! -d "$file" ]]; then echo "... Running $file"