summaryrefslogtreecommitdiff
path: root/cpp/test/IceUtil/inputUtil/Client.cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2006-01-31 12:50:56 +0000
committerBenoit Foucher <benoit@zeroc.com>2006-01-31 12:50:56 +0000
commitac2b2ccafe8f194a01e90dcd30f4644aebad6120 (patch)
tree5dee801773ee1e49ea7c8c6db64dbf1de5616c0d /cpp/test/IceUtil/inputUtil/Client.cpp
parentFixed a bug in split() for control chars (diff)
downloadice-ac2b2ccafe8f194a01e90dcd30f4644aebad6120.tar.bz2
ice-ac2b2ccafe8f194a01e90dcd30f4644aebad6120.tar.xz
ice-ac2b2ccafe8f194a01e90dcd30f4644aebad6120.zip
Added test for IceUtil::Options::split
Diffstat (limited to 'cpp/test/IceUtil/inputUtil/Client.cpp')
-rw-r--r--cpp/test/IceUtil/inputUtil/Client.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/cpp/test/IceUtil/inputUtil/Client.cpp b/cpp/test/IceUtil/inputUtil/Client.cpp
index b50c8756586..940c00924e0 100644
--- a/cpp/test/IceUtil/inputUtil/Client.cpp
+++ b/cpp/test/IceUtil/inputUtil/Client.cpp
@@ -9,8 +9,11 @@
#include <IceUtil/Unicode.h>
#include <IceUtil/InputUtil.h>
+#include <IceUtil/Options.h>
#include <TestCommon.h>
+#include <vector>
+
using namespace IceUtil;
using namespace std;
@@ -108,5 +111,80 @@ main(int, char**)
cout << "ok" << endl;
+ cout << "testing string to command line arguments... ";
+ vector<string> args;
+
+ test(IceUtil::Options::split("").empty());
+
+ args = IceUtil::Options::split("\"\"");
+ test(args.size() == 1 && args[0] == "");
+ args = IceUtil::Options::split("''");
+ test(args.size() == 1 && args[0] == "");
+ args = IceUtil::Options::split("$''");
+ test(args.size() == 1 && args[0] == "");
+
+ args = IceUtil::Options::split("-a -b -c");
+ test(args.size() == 3 && args[0] == "-a" && args[1] == "-b" && args[2] == "-c");
+ args = IceUtil::Options::split("\"-a\" '-b' $'-c'");
+ test(args.size() == 3 && args[0] == "-a" && args[1] == "-b" && args[2] == "-c");
+ args = IceUtil::Options::split(" '-b' \"-a\" $'-c' ");
+ test(args.size() == 3 && args[0] == "-b" && args[1] == "-a" && args[2] == "-c");
+ args = IceUtil::Options::split(" $'-c' '-b' \"-a\" ");
+ test(args.size() == 3 && args[0] == "-c" && args[1] == "-b" && args[2] == "-a");
+
+ // Testing single quote
+ args = IceUtil::Options::split("-Dir='C:\\\\test\\\\file'"); // -Dir='C:\\test\\file'
+ test(args.size() == 1 && args[0] == "-Dir=C:\\\\test\\\\file"); // -Dir=C:\\test\\file
+ args = IceUtil::Options::split("-Dir='C:\\test\\file'"); // -Dir='C:\test\file'
+ test(args.size() == 1 && args[0] == "-Dir=C:\\test\\file"); // -Dir=C:\test\file
+ args = IceUtil::Options::split("-Dir='C:\\test\\filewith\"quote'"); // -Dir='C:\test\filewith"quote'
+ test(args.size() == 1 && args[0] == "-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.size() == 1 && args[0] == "-Dir=C:\\test\\file"); // -Dir=C:\test\file
+ args = IceUtil::Options::split("-Dir=\"C:\\test\\file\""); // -Dir="C:\test\file"
+ test(args.size() == 1 && args[0] == "-Dir=C:\\test\\file"); // -Dir=C:\test\file
+ args = IceUtil::Options::split("-Dir=\"C:\\test\\filewith\\\"quote\""); // -Dir="C:\test\filewith\"quote"
+ test(args.size() == 1 && args[0] == "-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.size() == 1 && args[0] == "-Dir=C:\\test\\file"); // -Dir=C:\test\file
+ args = IceUtil::Options::split("-Dir=$'C:\\oest\\oile'"); // -Dir='C:\oest\oile'
+ test(args.size() == 1 && args[0] == "-Dir=C:\\oest\\oile"); // -Dir=C:\oest\oile
+ args = IceUtil::Options::split("-Dir=$'C:\\oest\\oilewith\"quote'"); // -Dir=$'C:\oest\oilewith"quote'
+ test(args.size() == 1 && args[0] == "-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.size() == 1 && args[0] == "-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.size() == 1 && args[0] == "-Dir=C:\\test\\file"); // -Dir=C:\test\file
+ args = IceUtil::Options::split("-Dir=$'\\cM\\c_'"); // Control characters
+ test(args.size() == 1 && args[0] == "-Dir=\015\037");
+ args = IceUtil::Options::split("-Dir=$'C:\\\\\\146\\x66\\cMi'"); // -Dir=$'C:\\\146\x66i\cMi'
+ test(args.size() == 1 && args[0] == "-Dir=C:\\ff\015i");
+ args = IceUtil::Options::split("-Dir=$'C:\\\\\\cM\\x66\\146i'"); // -Dir=$'C:\\\cM\x66\146i'
+ test(args.size() == 1 && args[0] == "-Dir=C:\\\015ffi");
+
+ vector<string> badQuoteCommands;
+ badQuoteCommands.push_back("\"");
+ badQuoteCommands.push_back("'");
+ badQuoteCommands.push_back("\\$'");
+ badQuoteCommands.push_back("-Dir=\"test");
+ badQuoteCommands.push_back("-Dir='test");
+ badQuoteCommands.push_back("-Dir=$'test");
+ for(vector<string>::const_iterator p = badQuoteCommands.begin(); p != badQuoteCommands.end(); ++p)
+ {
+ try
+ {
+ IceUtil::Options::split(*p);
+ test(false);
+ }
+ catch(const IceUtil::Options::BadQuote&)
+ {
+ }
+ }
+ cout << "ok" << endl;
+
return EXIT_SUCCESS;
}