summaryrefslogtreecommitdiff
path: root/cpp/test/IceUtil/inputUtil/Client.cpp
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2002-07-08 02:26:16 +0000
committerMichi Henning <michi@zeroc.com>2002-07-08 02:26:16 +0000
commitb6b4680a72e2d45ed9fca0fde867ce7564dccc21 (patch)
tree73b4ba7f47fc1ca5ac00a2d77d18c5ac4d99bf0f /cpp/test/IceUtil/inputUtil/Client.cpp
parentMove the ICE_INT64_LITERAL macro into its own header file (Ice/Const.h). (diff)
downloadice-b6b4680a72e2d45ed9fca0fde867ce7564dccc21.tar.bz2
ice-b6b4680a72e2d45ed9fca0fde867ce7564dccc21.tar.xz
ice-b6b4680a72e2d45ed9fca0fde867ce7564dccc21.zip
Added stringToInt64() to IceUtil. (Windows only for the moment)
Diffstat (limited to 'cpp/test/IceUtil/inputUtil/Client.cpp')
-rw-r--r--cpp/test/IceUtil/inputUtil/Client.cpp99
1 files changed, 99 insertions, 0 deletions
diff --git a/cpp/test/IceUtil/inputUtil/Client.cpp b/cpp/test/IceUtil/inputUtil/Client.cpp
new file mode 100644
index 00000000000..5007bce6604
--- /dev/null
+++ b/cpp/test/IceUtil/inputUtil/Client.cpp
@@ -0,0 +1,99 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+#include <IceUtil/InputUtil.h>
+#include <TestCommon.h>
+
+using namespace IceUtil;
+using namespace std;
+
+#define WS " \f\n\r\t\v"
+
+int
+main(int, char**)
+{
+ cout << "testing string-to-64-bit integer conversion... ";
+
+ bool b;
+ Int64 result;
+ string::size_type pos;
+
+ b = stringToInt64("", result, pos);
+ test(!b && result == 0 && pos == string::npos);
+ b = stringToInt64(WS, result, pos);
+ test(!b && result == 0 && pos == string::npos);
+
+ b = stringToInt64("123", result, pos);
+ test(b && result == 123 && pos == string::npos);
+ b = stringToInt64("+123", result, pos);
+ test(b && result == 123 && pos == string::npos);
+ b = stringToInt64("-123", result, pos);
+ test(b && result == -123 && pos == string::npos);
+
+ b = stringToInt64("0123", result, pos);
+ test(b && result == 83 && pos == string::npos);
+ b = stringToInt64("+0123", result, pos);
+ test(b && result == 83 && pos == string::npos);
+ b = stringToInt64("-0123", result, pos);
+ test(b && result == -83 && pos == string::npos);
+
+ b = stringToInt64("0x123", result, pos);
+ test(b && result == 291 && pos == string::npos);
+ b = stringToInt64("+0x123", result, pos);
+ test(b && result == 291 && pos == string::npos);
+ b = stringToInt64("-0x123", result, pos);
+ test(b && result == -291 && pos == string::npos);
+
+ b = stringToInt64(WS "123", result, pos);
+ test(b && result == 123 && pos == string::npos);
+ b = stringToInt64("123" WS, result, pos);
+ test(b && result == 123 && pos == string::npos);
+ b = stringToInt64(WS "123" WS, result, pos);
+ test(b && result == 123 && pos == string::npos);
+
+ b = stringToInt64("123Q", result, pos);
+ test(b && result == 123 && pos == 3);
+ b = stringToInt64(" 123Q", result, pos);
+ test(b && result == 123 && pos == 4);
+ b = stringToInt64(" 123Q ", result, pos);
+ test(b && result == 123 && pos == 4);
+ b = stringToInt64(" 123 Q", result, pos);
+ test(b && result == 123 && pos == 4);
+
+ b = stringToInt64("Q", result, pos);
+ test(!b && result == 0 && pos == 0);
+ b = stringToInt64(" Q", result, pos);
+ test(!b && result == 0 && pos == 1);
+
+ b = stringToInt64("-9223372036854775807", result, pos);
+ test(b && result == -9223372036854775807 && pos == string::npos);
+ b = stringToInt64("-9223372036854775808", result, pos);
+ test(b && result == INT64MIN && pos == string::npos);
+ b = stringToInt64("-9223372036854775809", result, pos);
+ test(!b && result == INT64MIN && pos == string::npos);
+
+ b = stringToInt64("9223372036854775806", result, pos);
+ test(b && result == 9223372036854775806 && pos == string::npos);
+ b = stringToInt64("9223372036854775807", result, pos);
+ test(b && result == INT64MAX && pos == string::npos);
+ b = stringToInt64("9223372036854775808", result, pos);
+ test(!b && result == INT64MAX && pos == string::npos);
+
+ b = stringToInt64("-9223372036854775807Q", result, pos);
+ test(b && result == -9223372036854775807 && pos == 20);
+ b = stringToInt64("-9223372036854775808Q", result, pos);
+ test(b && result == INT64MIN && pos == 20);
+ b = stringToInt64("-9223372036854775809Q", result, pos);
+ test(!b && result == INT64MIN && pos == 20);
+
+ cout << "ok" << endl;
+
+ return EXIT_SUCCESS;
+}