add tests and factory extends

This commit is contained in:
Jean-Marie Mineau 2025-04-17 15:38:23 +02:00
parent d269206cbb
commit 83fd9d387a
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2
14 changed files with 494 additions and 20 deletions

View file

@ -1,6 +1,6 @@
package com.example.theseus.dynandref;
public class APReflectee {
public class APReflectee extends PCommonParent {
public String extendedTransfer(
boolean bool,
byte by,

View file

@ -78,4 +78,23 @@ public class AReflectee extends APReflectee implements AIReflectee, ICommonInter
}
return getReflecteeId() + ":" + val + "(" + bool + " " + by + " " + sh + " " + ch + " " + in + " " + lo + " " + fl + " " + dou + " " + str + ")";
}
public String commonParentTransfer(
boolean bool,
byte by,
short sh,
char ch,
int in,
long lo,
float fl,
double dou,
String str,
String... args
) {
String val = "";
for (String v : args) {
val += " " + v;
}
return getReflecteeId() + ":" + val + "(" + bool + " " + by + " " + sh + " " + ch + " " + in + " " + lo + " " + fl + " " + dou + " " + str + ")";
}
}

View file

@ -78,4 +78,23 @@ public class Collider extends PCollider implements ICollider, ICommonInterface {
}
return getColliderId() + ":" + val + "(" + bool + " " + by + " " + sh + " " + ch + " " + in + " " + lo + " " + fl + " " + dou + " " + str + ")";
}
public String commonParentTransfer(
boolean bool,
byte by,
short sh,
char ch,
int in,
long lo,
float fl,
double dou,
String str,
String... args
) {
String val = "";
for (String v : args) {
val += " " + v;
}
return getColliderId() + ":" + val + "(" + bool + " " + by + " " + sh + " " + ch + " " + in + " " + lo + " " + fl + " " + dou + " " + str + ")";
}
}

View file

@ -1,6 +1,6 @@
package com.example.theseus.dynandref;
public class PCollider {
public class PCollider extends PCommonParent{
public String extendedTransfer(
boolean bool,
byte by,

View file

@ -0,0 +1,16 @@
package com.example.theseus.dynandref;
public class PCommonParent {
public String commonParentTransfer(
boolean bool,
byte by,
short sh,
char ch,
int in,
long lo,
float fl,
double dou,
String str,
String... args
) {return "";}
}

View file

@ -78,4 +78,23 @@ public class Collider extends PCollider implements ICollider, ICommonInterface {
}
return getColliderId() + ":" + val + "(" + bool + " " + by + " " + sh + " " + ch + " " + in + " " + lo + " " + fl + " " + dou + " " + str + ")";
}
public String commonParentTransfer(
boolean bool,
byte by,
short sh,
char ch,
int in,
long lo,
float fl,
double dou,
String str,
String... args
) {
String val = "";
for (String v : args) {
val += " " + v;
}
return getColliderId() + ":" + val + "(" + bool + " " + by + " " + sh + " " + ch + " " + in + " " + lo + " " + fl + " " + dou + " " + str + ")";
}
}

View file

@ -31,6 +31,7 @@ public class Main {
public static void run(Activity ac, String clname, boolean hasCollision, boolean hasParent, String methodType) {
try {
Log.i("THESEUS", "clname: " + clname + ", hasCollision: " + hasCollision + ", hasParent: " + hasParent + ", methodType: " + methodType);
ClassLoader cl;
ClassLoader parent;
if (hasParent) {
@ -163,8 +164,21 @@ public class Main {
"",
new String[] {"some", "strings"}
);
} else if (methodType.equals("Factory Pattern")) {
factory(
} else if (methodType.equals("Factory Pattern Interface")) {
factoryInterface(
ac, clz,
true,
(byte)42,
(short)666,
'*',
0xDEAD_BEEF,
0xD1AB011C_5EAF00DL,
0.99f,
3.1415926535897932384626433d,
new String[] {"some", "strings"}
);
} else if (methodType.equals("Factory Pattern Extend")) {
factoryExtend(
ac, clz,
true,
(byte)42,
@ -184,7 +198,7 @@ public class Main {
}
}
public static void factory(
public static void factoryInterface(
Activity ac, Class clz,
boolean bool,
byte by,
@ -211,6 +225,33 @@ public class Main {
);
Utils.sink(ac, res);
}
public static void factoryExtend(
Activity ac, Class clz,
boolean bool,
byte by,
short sh,
char ch,
int in,
long lo,
float fl,
double dou,
String... args
) throws Exception {
PCommonParent instance = (PCommonParent)clz.getDeclaredConstructor().newInstance();
String res = instance.commonParentTransfer(
bool,
by,
sh,
ch,
in,
lo,
fl,
dou,
Utils.source(),
args
);
Utils.sink(ac, res);
}
public static void invoke(
Activity ac, boolean instanciate, Class clz, Method mth, Object[] args,

View file

@ -103,6 +103,13 @@ public class MethodActivity extends Activity {
linLayout.addView(b6);
}
Button b7 = new Button(this);
b7.generateViewId();
if (!classLoaderName.equals("DelegateLastClassLoader") && hasParent) {
// if no parent or use DelegateLastClassLoader, the type of the Interface is incompatible
linLayout.addView(b7);
}
scrollView.addView(linLayout);
relLayout.addView(scrollView);
setContentView(relLayout);
@ -149,18 +156,37 @@ public class MethodActivity extends Activity {
}
});
b6.setText("Factory Pattern");
b6.setText("Factory Pattern Interface");
b6.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
v.setBackgroundTintList(buttonColor);
Main.run(ac, classLoaderName, hasCollision, hasParent, "Factory Pattern");
Main.run(ac, classLoaderName, hasCollision, hasParent, "Factory Pattern Interface");
}
});
b7.setText("Factory Pattern Extend");
b7.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
v.setBackgroundTintList(buttonColor);
Main.run(ac, classLoaderName, hasCollision, hasParent, "Factory Pattern Extend");
}
});
// Allow to start Main.run from intent for automation
String methodType = intent.getStringExtra("methodType");
if (methodType != null) {
Main.run(ac, classLoaderName, hasCollision, hasParent, methodType);
}
}
public void nextActivity(String classLoaderName) {
Intent intent = new Intent(this, MethodActivity.class);
intent.putExtra("classLoaderName", classLoaderName);
startActivity(intent);
@Override
protected void onNewIntent(Intent intent) {
String classLoaderNameLocal = intent.getStringExtra("classLoaderName");
boolean hasCollisionLocal = intent.getBooleanExtra("collision", false);
boolean hasParentLocal = intent.getBooleanExtra("parent", false);
String methodType = intent.getStringExtra("methodType");
if (classLoaderNameLocal != null && methodType != null) {
Main.run(this, classLoaderNameLocal, hasCollisionLocal, hasParentLocal, methodType);
}
}
}

View file

@ -1,6 +1,6 @@
package com.example.theseus.dynandref;
public class PCollider {
public class PCollider extends PCommonParent {
public String extendedTransfer(
boolean bool,
byte by,

View file

@ -0,0 +1,16 @@
package com.example.theseus.dynandref;
public class PCommonParent {
public String commonParentTransfer(
boolean bool,
byte by,
short sh,
char ch,
int in,
long lo,
float fl,
double dou,
String str,
String... args
) {return "";}
}