From 896a0821b78c9aadf38e0d881922e03849584984 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 18 Jan 2013 02:23:44 +0100 Subject: Sync LauncherUtil w/ GlueGen commit 1b9f0739ecc25105384b557afa698c42e08d4cc6 (adding main-cmdline-args) --- .../jogamp/opengl/test/android/LauncherUtil.java | 70 ++++++++++++++++++---- 1 file changed, 57 insertions(+), 13 deletions(-) (limited to 'src/test/com/jogamp') diff --git a/src/test/com/jogamp/opengl/test/android/LauncherUtil.java b/src/test/com/jogamp/opengl/test/android/LauncherUtil.java index 11416cd67..d5caeef9b 100644 --- a/src/test/com/jogamp/opengl/test/android/LauncherUtil.java +++ b/src/test/com/jogamp/opengl/test/android/LauncherUtil.java @@ -67,9 +67,11 @@ public class LauncherUtil { static final String PKG = "pkg"; + static final String ARG = "arg"; + public static abstract class BaseActivityLauncher extends Activity { final OrderedProperties props = new OrderedProperties(); - + final ArrayList args = new ArrayList(); /** * Returns the default {@link LauncherUtil#LAUNCH_ACTIVITY_NORMAL} action. *

@@ -86,6 +88,14 @@ public class LauncherUtil { */ public final OrderedProperties getProperties() { return props; } + /** + * Returns the commandline arguments, which are being propagated to the target activity. + *

+ * Maybe be used to set custom commandline arguments. + *

+ */ + public final ArrayList getArguments() { return args; } + /** Custom initialization hook which can be overriden to setup data, e.g. fill the properties retrieved by {@link #getProperties()}. */ public void init() { } @@ -108,6 +118,7 @@ public class LauncherUtil { data.setActivityName(getActivityName()); data.addAllPackages(getPackages()); data.addAllProperties(props); + data.addAllArguments(args); final Intent intent = LauncherUtil.getIntent(getAction(), data); Log.d(getClass().getSimpleName(), "Launching Activity: "+intent); @@ -127,6 +138,9 @@ public class LauncherUtil { if(key.equals(PKG)) { throw new IllegalArgumentException("Illegal property key, '"+PKG+"' is reserved"); } + if(key.equals(ARG)) { + throw new IllegalArgumentException("Illegal property key, '"+ARG+"' is reserved"); + } final String oval = map.put(key, value); if(null != oval) { map.put(key, oval); // restore @@ -175,6 +189,7 @@ public class LauncherUtil { String activityName = null; ArrayList packages = new ArrayList(); OrderedProperties properties = new OrderedProperties(); + ArrayList arguments = new ArrayList(); public final void setActivityName(String name) { activityName = name; } public final String getActivityName() { return activityName; } @@ -201,7 +216,13 @@ public class LauncherUtil { } public final String getProperty(String key) { return properties.getProperty(key); } public final OrderedProperties getProperties() { return properties; } - public final List getPropertyKeys() { return properties.getPropertyKeys(); } + public final List getPropertyKeys() { return properties.getPropertyKeys(); } + + public final void addArgument(String arg) { arguments.add(arg); } + public final void addAllArguments(List args) { + arguments.addAll(args); + } + public final ArrayList getArguments() { return arguments; } public final Uri getUri() { StringBuilder sb = new StringBuilder(); @@ -217,15 +238,23 @@ public class LauncherUtil { needsSep = true; } } - Iterator argKeys = properties.keyList.iterator(); - while(argKeys.hasNext()) { + Iterator propKeys = properties.keyList.iterator(); + while(propKeys.hasNext()) { if(needsSep) { sb.append(AMPER); } - final String key = argKeys.next(); + final String key = propKeys.next(); sb.append(key).append(ASSIG).append(properties.map.get(key)); needsSep = true; } + Iterator args = arguments.iterator(); + while(args.hasNext()) { + if(needsSep) { + sb.append(AMPER); + } + sb.append(ARG).append(ASSIG).append(args.next()); + needsSep = true; + } return Uri.parse(sb.toString()); } @@ -255,7 +284,7 @@ public class LauncherUtil { int q_b = q_e + 1; // next term q_e = q.indexOf(AMPER, q_b); if(0 == q_e) { - // single seperator + // single separator continue; } if(0 > q_e) { @@ -274,13 +303,18 @@ public class LauncherUtil { throw new IllegalArgumentException("Empty package name: part <"+part+">, query <"+q+"> of "+uri); } data.addPackage(v); + } else if(k.equals(ARG)) { + if(v.length()==0) { + throw new IllegalArgumentException("Empty argument name: part <"+part+">, query <"+q+"> of "+uri); + } + data.addArgument(v); } else { data.setProperty(k, v); } } else { // property key only - if(part.equals(PKG)) { - throw new IllegalArgumentException("Empty package name: part <"+part+">, query <"+q+"> of "+uri); + if( part.equals(PKG) || part.equals(ARG) ) { + throw new IllegalArgumentException("Reserved key <"+part+"> in query <"+q+"> of "+uri); } data.setProperty(part, EMPTY); } @@ -306,21 +340,31 @@ public class LauncherUtil { args = new String[] { SCHEME+"://"+HOST+"/com.jogamp.TestActivity?"+PKG+"=jogamp.pack1&"+PKG+"=javax.pack2&"+PKG+"=com.jogamp.pack3&jogamp.common.debug=true&com.jogamp.test=false", SCHEME+"://"+HOST+"/com.jogamp.TestActivity?"+PKG+"=jogamp.pack1&jogamp.common.debug=true&com.jogamp.test=false", - SCHEME+"://"+HOST+"/com.jogamp.TestActivity?"+PKG+"=jogamp.pack1" + SCHEME+"://"+HOST+"/com.jogamp.TestActivity?"+PKG+"=jogamp.pack1", + SCHEME+"://"+HOST+"/com.jogamp.TestActivity?"+PKG+"=jogamp.pack1&"+PKG+"=javax.pack2&"+PKG+"=com.jogamp.pack3&jogamp.common.debug=true&com.jogamp.test=false&"+ARG+"=arg1&"+ARG+"=arg2=arg2value&"+ARG+"=arg3", + SCHEME+"://"+HOST+"/com.jogamp.TestActivity?"+PKG+"=jogamp.pack1&jogamp.common.debug=true&com.jogamp.test=false&"+ARG+"=arg1&"+ARG+"=arg2=arg2value&"+ARG+"=arg3", + SCHEME+"://"+HOST+"/com.jogamp.TestActivity?"+PKG+"=jogamp.pack1&"+ARG+"=arg1&"+ARG+"=arg2=arg2value&"+ARG+"=arg3" }; } + int errors = 0; for(int i=0; i -> "+uri0+" -> NULL"); - } - Uri uri1 = data.getUri(); - if(!uri0.equals(uri1)) { - System.err.println("Error: Not equal: <"+uri_s+"> -> "+uri0+" -> "+uri1); + } else { + Uri uri1 = data.getUri(); + if(!uri0.equals(uri1)) { + errors++; + System.err.println("Error: Not equal: <"+uri_s+"> -> "+uri0+" -> "+uri1); + } else { + System.err.println("OK: "+uri1); + } } } + System.err.println("LauncherUtil Self Test: Errors: "+errors); } } -- cgit v1.2.3