summaryrefslogtreecommitdiff
path: root/java/test/IceUtil/inputUtil/Client.java
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2006-01-31 14:12:50 +0000
committerBenoit Foucher <benoit@zeroc.com>2006-01-31 14:12:50 +0000
commit9f1a650d4ef5adb2f85cc079607e3482ddea738b (patch)
tree6c8d52f6a0c2b8fb7eb14ca6ac2f6196fb49b2dc /java/test/IceUtil/inputUtil/Client.java
parentAdded test for IceUtil::Options::split (diff)
downloadice-9f1a650d4ef5adb2f85cc079607e3482ddea738b.tar.bz2
ice-9f1a650d4ef5adb2f85cc079607e3482ddea738b.tar.xz
ice-9f1a650d4ef5adb2f85cc079607e3482ddea738b.zip
Fixed minor bugs in IceUtil.Options.split() and added inputUtil tests.
Diffstat (limited to 'java/test/IceUtil/inputUtil/Client.java')
-rw-r--r--java/test/IceUtil/inputUtil/Client.java108
1 files changed, 108 insertions, 0 deletions
diff --git a/java/test/IceUtil/inputUtil/Client.java b/java/test/IceUtil/inputUtil/Client.java
new file mode 100644
index 00000000000..ec4c5da4e02
--- /dev/null
+++ b/java/test/IceUtil/inputUtil/Client.java
@@ -0,0 +1,108 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+public class Client
+{
+ private static void
+ test(boolean b)
+ {
+ if(!b)
+ {
+ throw new RuntimeException();
+ }
+ }
+
+ public static void
+ main(String[] argvs)
+ {
+ System.out.print("testing string to command line arguments... ");
+ System.out.flush();
+ String[] args;
+
+ try
+ {
+ test(IceUtil.Options.split("").length == 0);
+
+ args = IceUtil.Options.split("\"\"");
+ test(args.length == 1 && args[0].equals(""));
+ args = IceUtil.Options.split("''");
+ test(args.length == 1 && args[0].equals(""));
+ args = IceUtil.Options.split("$''");
+ test(args.length == 1 && args[0].equals(""));
+
+ args = IceUtil.Options.split("-a -b -c");
+ test(args.length == 3 && args[0].equals("-a") && args[1].equals("-b") && args[2].equals("-c"));
+ args = IceUtil.Options.split("\"-a\" '-b' $'-c'");
+ test(args.length == 3 && args[0].equals("-a") && args[1].equals("-b") && args[2].equals("-c"));
+ args = IceUtil.Options.split(" '-b' \"-a\" $'-c' ");
+ test(args.length == 3 && args[0].equals("-b") && args[1].equals("-a") && args[2].equals("-c"));
+ args = IceUtil.Options.split(" $'-c' '-b' \"-a\" ");
+ test(args.length == 3 && args[0].equals("-c") && args[1].equals("-b") && args[2].equals("-a"));
+
+ // Testing single quote
+ args = IceUtil.Options.split("-Dir='C:\\\\test\\\\file'"); // -Dir='C:\\test\\file'
+ test(args.length == 1 && args[0].equals("-Dir=C:\\\\test\\\\file")); // -Dir=C:\\test\\file
+ args = IceUtil.Options.split("-Dir='C:\\test\\file'"); // -Dir='C:\test\file'
+ test(args.length == 1 && args[0].equals("-Dir=C:\\test\\file")); // -Dir=C:\test\file
+ args = IceUtil.Options.split("-Dir='C:\\test\\filewith\"quote'"); // -Dir='C:\test\filewith"quote'
+ test(args.length == 1 && args[0].equals("-Dir=C:\\test\\filewith\"quote")); // -Dir=C:\test\filewith"quote
+
+ // Testing double quote
+ args = IceUtil.Options.split("-Dir=\"C:\\\\test\\\\file\""); // -Dir="C:\\test\\file"
+ test(args.length == 1 && args[0].equals("-Dir=C:\\test\\file")); // -Dir=C:\test\file
+ args = IceUtil.Options.split("-Dir=\"C:\\test\\file\""); // -Dir="C:\test\file"
+ test(args.length == 1 && args[0].equals("-Dir=C:\\test\\file")); // -Dir=C:\test\file
+ args = IceUtil.Options.split("-Dir=\"C:\\test\\filewith\\\"quote\""); // -Dir="C:\test\filewith\"quote"
+ test(args.length == 1 && args[0].equals("-Dir=C:\\test\\filewith\"quote")); // -Dir=C:\test\filewith"quote
+
+ // Testing ANSI quote
+ args = IceUtil.Options.split("-Dir=$'C:\\\\test\\\\file'"); // -Dir=$'C:\\test\\file'
+ test(args.length == 1 && args[0].equals("-Dir=C:\\test\\file")); // -Dir=C:\test\file
+ args = IceUtil.Options.split("-Dir=$'C:\\oest\\oile'"); // -Dir='C:\oest\oile'
+ test(args.length == 1 && args[0].equals("-Dir=C:\\oest\\oile")); // -Dir=C:\oest\oile
+ args = IceUtil.Options.split("-Dir=$'C:\\oest\\oilewith\"quote'"); // -Dir=$'C:\oest\oilewith"quote'
+ test(args.length == 1 && args[0].equals("-Dir=C:\\oest\\oilewith\"quote")); // -Dir=C:\oest\oilewith"quote
+ args = IceUtil.Options.split("-Dir=$'\\103\\072\\134\\164\\145\\163\\164\\134\\146\\151\\154\\145'");
+ test(args.length == 1 && args[0].equals("-Dir=C:\\test\\file")); // -Dir=C:\test\file
+ args = IceUtil.Options.split("-Dir=$'\\x43\\x3A\\x5C\\x74\\x65\\x73\\x74\\x5C\\x66\\x69\\x6C\\x65'");
+ test(args.length == 1 && args[0].equals("-Dir=C:\\test\\file")); // -Dir=C:\test\file
+ args = IceUtil.Options.split("-Dir=$'\\cM\\c_'"); // Control characters
+ test(args.length == 1 && args[0].equals("-Dir=\015\037"));
+ args = IceUtil.Options.split("-Dir=$'C:\\\\\\146\\x66\\cMi'"); // -Dir=$'C:\\\146\x66i\cMi'
+ test(args.length == 1 && args[0].equals("-Dir=C:\\ff\015i"));
+ args = IceUtil.Options.split("-Dir=$'C:\\\\\\cM\\x66\\146i'"); // -Dir=$'C:\\\cM\x66\146i'
+ test(args.length == 1 && args[0].equals("-Dir=C:\\\015ffi"));
+ }
+ catch(IceUtil.Options.BadQuote ex)
+ {
+ test(false);
+ }
+
+ String[] badQuoteCommands = new String[6];
+ badQuoteCommands[0] = "\"";
+ badQuoteCommands[1] = "'";
+ badQuoteCommands[2] = "\\$'";
+ badQuoteCommands[3] = "-Dir=\"test";
+ badQuoteCommands[4] = "-Dir='test";
+ badQuoteCommands[5] = "-Dir=$'test";
+ for(int i = 0; i < 6; ++i)
+ {
+ try
+ {
+ IceUtil.Options.split(badQuoteCommands[i]);
+ test(false);
+ }
+ catch(IceUtil.Options.BadQuote ex)
+ {
+ }
+ }
+
+ System.out.println("ok");
+ }
+}