diff options
author | Benoit Foucher <benoit@zeroc.com> | 2006-01-31 14:12:50 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2006-01-31 14:12:50 +0000 |
commit | 9f1a650d4ef5adb2f85cc079607e3482ddea738b (patch) | |
tree | 6c8d52f6a0c2b8fb7eb14ca6ac2f6196fb49b2dc /java | |
parent | Added test for IceUtil::Options::split (diff) | |
download | ice-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')
-rwxr-xr-x | java/allTests.py | 1 | ||||
-rw-r--r-- | java/src/IceUtil/Options.java | 8 | ||||
-rw-r--r-- | java/test/IceUtil/build.xml | 22 | ||||
-rw-r--r-- | java/test/IceUtil/inputUtil/Client.java | 108 | ||||
-rw-r--r-- | java/test/IceUtil/inputUtil/build.xml | 58 | ||||
-rwxr-xr-x | java/test/IceUtil/inputUtil/run.py | 38 | ||||
-rw-r--r-- | java/test/build.xml | 2 |
7 files changed, 237 insertions, 0 deletions
diff --git a/java/allTests.py b/java/allTests.py index 49ee1c1383a..2031d388109 100755 --- a/java/allTests.py +++ b/java/allTests.py @@ -52,6 +52,7 @@ def runTests(tests, num = 0): # List of all basic tests. # tests = [ \ + "IceUtil/inputUtil", \ "Ice/operations", \ "Ice/exceptions", \ "Ice/inheritance", \ diff --git a/java/src/IceUtil/Options.java b/java/src/IceUtil/Options.java index 7db0c20ed8d..65184b68592 100644 --- a/java/src/IceUtil/Options.java +++ b/java/src/IceUtil/Options.java @@ -30,6 +30,10 @@ public final class Options final int ANSIQuoteState = 4; line = line.trim(); + if(line.length() == 0) + { + return new String[0]; + } int state = NormalState; @@ -381,6 +385,10 @@ public final class Options { throw new BadQuote("missing closing double quote"); } + case ANSIQuoteState: + { + throw new BadQuote("unterminated $' quote"); + } default: { assert(false); diff --git a/java/test/IceUtil/build.xml b/java/test/IceUtil/build.xml new file mode 100644 index 00000000000..8c67ece6e77 --- /dev/null +++ b/java/test/IceUtil/build.xml @@ -0,0 +1,22 @@ +<!-- + ********************************************************************** + + 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. + + ********************************************************************** +--> + +<project name="test_Ice" default="all" basedir="."> + + <target name="all"> + <ant dir="inputUtil"/> + </target> + + <target name="clean"> + <ant dir="inputUtil" target="clean"/> + </target> + +</project> 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"); + } +} diff --git a/java/test/IceUtil/inputUtil/build.xml b/java/test/IceUtil/inputUtil/build.xml new file mode 100644 index 00000000000..cd24928e696 --- /dev/null +++ b/java/test/IceUtil/inputUtil/build.xml @@ -0,0 +1,58 @@ +<!-- + ********************************************************************** + + 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. + + ********************************************************************** +--> + +<!DOCTYPE project [ +<!ENTITY common SYSTEM "file:../../../config/common.xml"> +]> + +<project name="test_Ice_operations" default="all" basedir="."> + + <!-- set global properties for this build --> + <property name="top.dir" value="../../.."/> + + <!-- Include common definitions --> + &common; + + <property name="class.dir" value="classes"/> + <property name="generated.dir" value="generated"/> + + <target name="init" depends="config-init"> + <!-- Create the time stamp --> + <tstamp/> + </target> + + <target name="generate" depends="init"> + <!-- Create the output directory for generated code --> + <mkdir dir="${generated.dir}"/> + <slice2java outputdir="${generated.dir}"> + <fileset dir="." includes="Test.ice"/> + <includepath> + <pathelement path="${slice.dir}" /> + </includepath> + </slice2java> + </target> + + <target name="compile" depends="generate"> + <mkdir dir="${class.dir}"/> + <javac srcdir="${generated.dir}" destdir="${class.dir}" + source="1.4" classpath="${lib.dir}" debug="${debug}"/> + <javac srcdir="." destdir="${class.dir}" source="1.4" + classpath="${lib.dir}" excludes="generated/**" debug="${debug}"/> + </target> + + <target name="all" depends="compile"/> + + <target name="clean"> + <delete dir="${generated.dir}"/> + <delete dir="${class.dir}"/> + </target> + +</project> diff --git a/java/test/IceUtil/inputUtil/run.py b/java/test/IceUtil/inputUtil/run.py new file mode 100755 index 00000000000..a7154db7fb8 --- /dev/null +++ b/java/test/IceUtil/inputUtil/run.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# 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. +# +# ********************************************************************** + +import os, sys + +for toplevel in [".", "..", "../..", "../../..", "../../../.."]: + toplevel = os.path.normpath(toplevel) + if os.path.exists(os.path.join(toplevel, "config", "TestUtil.py")): + break +else: + raise "can't find toplevel directory!" + +sys.path.append(os.path.join(toplevel, "config")) +import TestUtil + +name = os.path.join("IceUtil", "inputUtil") +testdir = os.path.join(toplevel, "test", name) +os.environ["CLASSPATH"] = os.path.join(testdir, "classes") + TestUtil.sep + os.getenv("CLASSPATH", "") + +print "starting client...", +clientPipe = os.popen("java -ea Client 2>&1") +print "ok" + +TestUtil.printOutputFromPipe(clientPipe); + +clientStatus = clientPipe.close() + +if clientStatus: + sys.exit(1) + +sys.exit(0) diff --git a/java/test/build.xml b/java/test/build.xml index f6bf1bd0b3b..c1d149d9413 100644 --- a/java/test/build.xml +++ b/java/test/build.xml @@ -12,6 +12,7 @@ <project name="test" default="all" basedir="."> <target name="all"> + <ant dir="IceUtil"/> <ant dir="Ice"/> <ant dir="Freeze"/> <ant dir="Glacier2"/> @@ -19,6 +20,7 @@ </target> <target name="clean"> + <ant dir="IceUtil" target="clean"/> <ant dir="Ice" target="clean"/> <ant dir="Freeze" target="clean"/> <ant dir="Glacier2" target="clean"/> |