From 5bdd606fffa7dcaa24448c112c4921778b24c9cd Mon Sep 17 00:00:00 2001 From: HiepLM Date: Mon, 29 Dec 2025 17:43:35 +0700 Subject: [PATCH] hiep sua file --- include/xmlrpcpp/XmlRpc.h | 2 + include/xmlrpcpp/XmlRpcClient.h | 2 + include/xmlrpcpp/XmlRpcDispatch.h | 2 + include/xmlrpcpp/XmlRpcException.h | 4 +- include/xmlrpcpp/XmlRpcServer.h | 2 + include/xmlrpcpp/XmlRpcServerConnection.h | 2 + include/xmlrpcpp/XmlRpcServerMethod.h | 2 + include/xmlrpcpp/XmlRpcSocket.h | 2 + include/xmlrpcpp/XmlRpcSource.h | 2 + include/xmlrpcpp/XmlRpcUtil.h | 2 + include/xmlrpcpp/XmlRpcValue.h | 4 +- include/xmlrpcpp/base64.h | 7 +- src/XmlRpcClient.cpp | 2 +- src/XmlRpcDispatch.cpp | 2 +- src/XmlRpcServer.cpp | 2 +- src/XmlRpcServerConnection.cpp | 2 +- src/XmlRpcServerMethod.cpp | 2 + src/XmlRpcSocket.cpp | 2 +- src/XmlRpcSource.cpp | 2 + src/XmlRpcUtil.cpp | 8 +- src/XmlRpcValue.cpp | 4 +- test/FileClient.cpp | 324 ++++++--- test/HelloClient.cpp | 4 +- test/HelloServer.cpp | 4 +- test/TestBase64Client.cpp | 135 ++-- test/TestBase64Server.cpp | 204 ++++-- test/TestValues.cpp | 699 +++++++++++++------- test/TestValuesWin32.cpp | 759 ++++++++++++++-------- test/TestXml.cpp | 159 +++-- test/Validator.cpp | 621 ++++++++++++------ 30 files changed, 1981 insertions(+), 987 deletions(-) diff --git a/include/xmlrpcpp/XmlRpc.h b/include/xmlrpcpp/XmlRpc.h index 9611af7..cb73d2c 100644 --- a/include/xmlrpcpp/XmlRpc.h +++ b/include/xmlrpcpp/XmlRpc.h @@ -32,6 +32,7 @@ #include "XmlRpcValue.h" #include "XmlRpcUtil.h" +namespace robot { namespace XmlRpc { @@ -90,5 +91,6 @@ namespace XmlRpc { extern const char XMLRPC_VERSION[]; } // namespace XmlRpc +} // namespace robot #endif // _XMLRPC_H_ diff --git a/include/xmlrpcpp/XmlRpcClient.h b/include/xmlrpcpp/XmlRpcClient.h index 26b6825..949850a 100644 --- a/include/xmlrpcpp/XmlRpcClient.h +++ b/include/xmlrpcpp/XmlRpcClient.h @@ -16,6 +16,7 @@ #include "xmlrpcpp/XmlRpcDispatch.h" #include "xmlrpcpp/XmlRpcSource.h" +namespace robot { namespace XmlRpc { // Arguments and results are represented by XmlRpcValues @@ -124,5 +125,6 @@ namespace XmlRpc { }; // class XmlRpcClient } // namespace XmlRpc +} // namespace robot #endif // _XMLRPCCLIENT_H_ diff --git a/include/xmlrpcpp/XmlRpcDispatch.h b/include/xmlrpcpp/XmlRpcDispatch.h index 35e7ac8..8bb7974 100644 --- a/include/xmlrpcpp/XmlRpcDispatch.h +++ b/include/xmlrpcpp/XmlRpcDispatch.h @@ -12,6 +12,7 @@ # include #endif +namespace robot { namespace XmlRpc { // An RPC source represents a file descriptor to monitor @@ -84,5 +85,6 @@ namespace XmlRpc { }; } // namespace XmlRpc +} // namespace robot #endif // _XMLRPCDISPATCH_H_ diff --git a/include/xmlrpcpp/XmlRpcException.h b/include/xmlrpcpp/XmlRpcException.h index 6090450..8a871cb 100644 --- a/include/xmlrpcpp/XmlRpcException.h +++ b/include/xmlrpcpp/XmlRpcException.h @@ -13,6 +13,7 @@ #endif +namespace robot { namespace XmlRpc { //! A class representing an error. @@ -37,6 +38,7 @@ namespace XmlRpc { int _code; }; -} +} // namespace XmlRpc +} // namespace robot #endif // _XMLRPCEXCEPTION_H_ diff --git a/include/xmlrpcpp/XmlRpcServer.h b/include/xmlrpcpp/XmlRpcServer.h index b9a0b01..4ef260c 100644 --- a/include/xmlrpcpp/XmlRpcServer.h +++ b/include/xmlrpcpp/XmlRpcServer.h @@ -16,6 +16,7 @@ #include "xmlrpcpp/XmlRpcDispatch.h" #include "xmlrpcpp/XmlRpcSource.h" +namespace robot { namespace XmlRpc { @@ -100,5 +101,6 @@ namespace XmlRpc { }; } // namespace XmlRpc +} // namespace robot #endif //_XMLRPCSERVER_H_ diff --git a/include/xmlrpcpp/XmlRpcServerConnection.h b/include/xmlrpcpp/XmlRpcServerConnection.h index f3b4d3d..a21b703 100644 --- a/include/xmlrpcpp/XmlRpcServerConnection.h +++ b/include/xmlrpcpp/XmlRpcServerConnection.h @@ -14,6 +14,7 @@ #include "xmlrpcpp/XmlRpcValue.h" #include "xmlrpcpp/XmlRpcSource.h" +namespace robot { namespace XmlRpc { @@ -98,5 +99,6 @@ namespace XmlRpc { bool _keepAlive; }; } // namespace XmlRpc +} // namespace robot #endif // _XMLRPCSERVERCONNECTION_H_ diff --git a/include/xmlrpcpp/XmlRpcServerMethod.h b/include/xmlrpcpp/XmlRpcServerMethod.h index 738a9c8..c7f1a17 100644 --- a/include/xmlrpcpp/XmlRpcServerMethod.h +++ b/include/xmlrpcpp/XmlRpcServerMethod.h @@ -12,6 +12,7 @@ # include #endif +namespace robot { namespace XmlRpc { // Representation of a parameter or result value @@ -43,5 +44,6 @@ namespace XmlRpc { XmlRpcServer* _server; }; } // namespace XmlRpc +} // namespace robot #endif // _XMLRPCSERVERMETHOD_H_ diff --git a/include/xmlrpcpp/XmlRpcSocket.h b/include/xmlrpcpp/XmlRpcSocket.h index dada163..017389a 100644 --- a/include/xmlrpcpp/XmlRpcSocket.h +++ b/include/xmlrpcpp/XmlRpcSocket.h @@ -11,6 +11,7 @@ # include #endif +namespace robot { namespace XmlRpc { //! A platform-independent socket API. @@ -65,5 +66,6 @@ namespace XmlRpc { }; } // namespace XmlRpc +} // namespace robot #endif diff --git a/include/xmlrpcpp/XmlRpcSource.h b/include/xmlrpcpp/XmlRpcSource.h index e5b700b..f4321e0 100644 --- a/include/xmlrpcpp/XmlRpcSource.h +++ b/include/xmlrpcpp/XmlRpcSource.h @@ -8,6 +8,7 @@ # pragma warning(disable:4786) // identifier was truncated in debug info #endif +namespace robot { namespace XmlRpc { //! An RPC source represents a file descriptor to monitor @@ -51,5 +52,6 @@ namespace XmlRpc { bool _keepOpen; }; } // namespace XmlRpc +} // namespace robot #endif //_XMLRPCSOURCE_H_ diff --git a/include/xmlrpcpp/XmlRpcUtil.h b/include/xmlrpcpp/XmlRpcUtil.h index 338de44..f857f0a 100644 --- a/include/xmlrpcpp/XmlRpcUtil.h +++ b/include/xmlrpcpp/XmlRpcUtil.h @@ -21,6 +21,7 @@ # define strncasecmp strnicmp #endif +namespace robot { namespace XmlRpc { //! Utilities for XML parsing, encoding, and decoding and message handlers. @@ -57,5 +58,6 @@ namespace XmlRpc { }; } // namespace XmlRpc +} // namespace robot #endif // _XMLRPCUTIL_H_ diff --git a/include/xmlrpcpp/XmlRpcValue.h b/include/xmlrpcpp/XmlRpcValue.h index 88a1eb0..0a1bb56 100644 --- a/include/xmlrpcpp/XmlRpcValue.h +++ b/include/xmlrpcpp/XmlRpcValue.h @@ -15,6 +15,7 @@ # include #endif +namespace robot { namespace XmlRpc { //! RPC method arguments and results are represented by Values @@ -181,9 +182,10 @@ namespace XmlRpc { }; } // namespace XmlRpc +} // namespace robot -std::ostream& operator<<(std::ostream& os, XmlRpc::XmlRpcValue& v); +std::ostream& operator<<(std::ostream& os, robot::XmlRpc::XmlRpcValue& v); #endif // _XMLRPCVALUE_H_ diff --git a/include/xmlrpcpp/base64.h b/include/xmlrpcpp/base64.h index fa4200c..486f836 100644 --- a/include/xmlrpcpp/base64.h +++ b/include/xmlrpcpp/base64.h @@ -50,8 +50,7 @@ public: // base64 requires max line length <= 72 characters // you can fill end of line // it may be crlf, crlfsp, noline or other class like it - - + struct crlf { template @@ -161,7 +160,7 @@ public: { _3to4.zero(); - // áåð¸ì ïî 3 ñèìâîëà + // ���� �� 3 ������� _3to4.set_0(*_First); _First++; @@ -194,7 +193,7 @@ public: *_To = _Tr::to_char_type(_base64Chars[_3to4.b64_2()]); ++_To; *_To = _Tr::to_char_type(_base64Chars[_3to4.b64_3()]); ++_To; - if(line_octets == 17) // base64 ïîçâîëÿåò äëèíó ñòðîêè íå áîëåå 72 ñèìâîëîâ + if(line_octets == 17) // base64 ��������� ����� ������ �� ����� 72 �������� { //_To = _Endl(_To); *_To = '\n'; ++_To; diff --git a/src/XmlRpcClient.cpp b/src/XmlRpcClient.cpp index b1db2ac..2709705 100644 --- a/src/XmlRpcClient.cpp +++ b/src/XmlRpcClient.cpp @@ -11,7 +11,7 @@ -using namespace XmlRpc; +using namespace robot::XmlRpc; // Static data const char XmlRpcClient::REQUEST_BEGIN[] = diff --git a/src/XmlRpcDispatch.cpp b/src/XmlRpcDispatch.cpp index 8bae373..8563e5c 100644 --- a/src/XmlRpcDispatch.cpp +++ b/src/XmlRpcDispatch.cpp @@ -19,7 +19,7 @@ #endif // _WINDOWS -using namespace XmlRpc; +using namespace robot::XmlRpc; XmlRpcDispatch::XmlRpcDispatch() diff --git a/src/XmlRpcServer.cpp b/src/XmlRpcServer.cpp index a380888..0affb67 100644 --- a/src/XmlRpcServer.cpp +++ b/src/XmlRpcServer.cpp @@ -7,7 +7,7 @@ #include "xmlrpcpp/XmlRpcException.h" -using namespace XmlRpc; +using namespace robot::XmlRpc; XmlRpcServer::XmlRpcServer() diff --git a/src/XmlRpcServerConnection.cpp b/src/XmlRpcServerConnection.cpp index df1f7db..67ed98d 100644 --- a/src/XmlRpcServerConnection.cpp +++ b/src/XmlRpcServerConnection.cpp @@ -11,7 +11,7 @@ #endif -using namespace XmlRpc; +using namespace robot::XmlRpc; // Static data const char XmlRpcServerConnection::METHODNAME_TAG[] = ""; diff --git a/src/XmlRpcServerMethod.cpp b/src/XmlRpcServerMethod.cpp index 6aecd98..4d6ad9f 100644 --- a/src/XmlRpcServerMethod.cpp +++ b/src/XmlRpcServerMethod.cpp @@ -2,6 +2,7 @@ #include "xmlrpcpp/XmlRpcServerMethod.h" #include "xmlrpcpp/XmlRpcServer.h" +namespace robot { namespace XmlRpc { @@ -19,3 +20,4 @@ namespace XmlRpc { } // namespace XmlRpc +} // namespace robot diff --git a/src/XmlRpcSocket.cpp b/src/XmlRpcSocket.cpp index 41afd5b..04997ec 100644 --- a/src/XmlRpcSocket.cpp +++ b/src/XmlRpcSocket.cpp @@ -30,7 +30,7 @@ extern "C" { #endif // MAKEDEPEND -using namespace XmlRpc; +using namespace robot::XmlRpc; diff --git a/src/XmlRpcSource.cpp b/src/XmlRpcSource.cpp index 9e4c03e..4e1f10b 100644 --- a/src/XmlRpcSource.cpp +++ b/src/XmlRpcSource.cpp @@ -3,6 +3,7 @@ #include "xmlrpcpp/XmlRpcSocket.h" #include "xmlrpcpp/XmlRpcUtil.h" +namespace robot { namespace XmlRpc { @@ -33,3 +34,4 @@ namespace XmlRpc { } } // namespace XmlRpc +} // namespace robot diff --git a/src/XmlRpcUtil.cpp b/src/XmlRpcUtil.cpp index e056452..e4f4a02 100644 --- a/src/XmlRpcUtil.cpp +++ b/src/XmlRpcUtil.cpp @@ -11,7 +11,7 @@ #include "xmlrpcpp/XmlRpc.h" -using namespace XmlRpc; +using namespace robot::XmlRpc; //#define USE_WINDOWS_DEBUG // To make the error and log messages go to VC++ debug output @@ -21,7 +21,7 @@ using namespace XmlRpc; #endif // Version id -const char XmlRpc::XMLRPC_VERSION[] = "XMLRPC++ 0.7"; +const char robot::XmlRpc::XMLRPC_VERSION[] = "XMLRPC++ 0.7"; // Default log verbosity: 0 for no messages through 5 (writes everything) int XmlRpcLogHandler::_verbosity = 0; @@ -63,8 +63,8 @@ XmlRpcErrorHandler* XmlRpcErrorHandler::_errorHandler = &defaultErrorHandler; // Easy API for log verbosity -int XmlRpc::getVerbosity() { return XmlRpcLogHandler::getVerbosity(); } -void XmlRpc::setVerbosity(int level) { XmlRpcLogHandler::setVerbosity(level); } +int robot::XmlRpc::getVerbosity() { return XmlRpcLogHandler::getVerbosity(); } +void robot::XmlRpc::setVerbosity(int level) { XmlRpcLogHandler::setVerbosity(level); } diff --git a/src/XmlRpcValue.cpp b/src/XmlRpcValue.cpp index 32b021f..f07f966 100644 --- a/src/XmlRpcValue.cpp +++ b/src/XmlRpcValue.cpp @@ -11,6 +11,7 @@ # include #endif +namespace robot { namespace XmlRpc { @@ -598,10 +599,11 @@ namespace XmlRpc { } } // namespace XmlRpc +} // namespace robot // ostream -std::ostream& operator<<(std::ostream& os, XmlRpc::XmlRpcValue& v) +std::ostream& operator<<(std::ostream& os, robot::XmlRpc::XmlRpcValue& v) { // If you want to output in xml format: //return os << v.toXml(); diff --git a/test/FileClient.cpp b/test/FileClient.cpp index 65fe3a5..6e99447 100644 --- a/test/FileClient.cpp +++ b/test/FileClient.cpp @@ -1,108 +1,216 @@ -// FileClient.cpp : A simple xmlrpc client. Usage: FileClient serverHost serverPort xmlfile -// Reads an xmlrpc request from the specified xmlfile and calls the method on the server. -// -// Link against xmlrpc lib and whatever socket libs your system needs (ws2_32.lib on windows) - -#include "XmlRpc.h" -#include -#include -#include - -using namespace XmlRpc; - -std::string parseRequest(std::string const& xml, XmlRpcValue& params); - - -int main(int argc, char* argv[]) -{ - if (argc != 4) { - std::cerr << "Usage: FileClient serverHost serverPort requestXmlFile\n"; - return -1; - } - int port = atoi(argv[2]); - - XmlRpc::setVerbosity(5); - XmlRpcClient c(argv[1], port); - - // - std::ifstream infile(argv[3]); - if (infile.fail()) { - std::cerr << "Could not open file '" << argv[3] << "'.\n"; - return -1; - } - - // Suck in the file. This is a one-liner in good compilers (which vc++ 6 is not)... - infile.seekg(0L, std::ios::end); - long nb = infile.tellg(); - infile.clear(); - infile.seekg(0L); - char* b = new char[nb+1]; - infile.read(b, nb); - b[nb] = 0; - - std::cout << "Read file.\n"; - - // Find the methodName and parse the params - std::string s(b); - XmlRpcValue params; - std::string name = parseRequest(s, params); - - if (name.empty()) { - std::cerr << "Could not parse file\n"; - return -1; - } - - for (;;) { - XmlRpcValue result; - std::cout << "Calling " << name << std::endl; - if (c.execute(name.c_str(), params, result)) - std::cout << result << "\n\n"; - else - std::cout << "Error calling '" << name << "'\n\n"; - std::cout << "Again? [y]: "; - std::string ans; - std::cin >> ans; - if (ans != "" && ans != "y") break; - } - - return 0; -} - - -// -std::string -parseRequest(std::string const& xml, XmlRpcValue& params) -{ - const char METHODNAME_TAG[] = ""; - const char PARAMS_TAG[] = ""; - const char PARAMS_ETAG[] = ""; - const char PARAM_TAG[] = ""; - const char PARAM_ETAG[] = ""; - - int offset = 0; // Number of chars parsed from the request - - std::string methodName = XmlRpcUtil::parseTag(METHODNAME_TAG, xml, &offset); - XmlRpcUtil::log(3, "XmlRpcServerConnection::parseRequest: parsed methodName %s.", methodName.c_str()); - - if (! methodName.empty() && XmlRpcUtil::findTag(PARAMS_TAG, xml, &offset)) - { - int nArgs = 0; - while (XmlRpcUtil::nextTagIs(PARAM_TAG, xml, &offset)) { - std::cout << "Parsing arg " << nArgs+1 << std::endl; - XmlRpcValue arg(xml, &offset); - if ( ! arg.valid()) { - std::cerr << "Invalid argument\n"; - return std::string(); - } - std::cout << "Adding arg " << nArgs+1 << " to params array." << std::endl; - params[nArgs++] = arg; - (void) XmlRpcUtil::nextTagIs(PARAM_ETAG, xml, &offset); - } - - XmlRpcUtil::log(3, "XmlRpcServerConnection::parseRequest: parsed %d params.", nArgs); - - (void) XmlRpcUtil::nextTagIs(PARAMS_ETAG, xml, &offset); - } - - return methodName; -} +// FileClient.cpp : A simple xmlrpc client. Usage: FileClient serverHost serverPort xmlfile + +// Reads an xmlrpc request from the specified xmlfile and calls the method on the server. + +// + +// Link against xmlrpc lib and whatever socket libs your system needs (ws2_32.lib on windows) + + + +#include "XmlRpc.h" + +#include + +#include + +#include + + + +using namespace robot::XmlRpc; + + + +std::string parseRequest(std::string const& xml, XmlRpcValue& params); + + + + + +int main(int argc, char* argv[]) + +{ + + if (argc != 4) { + + std::cerr << "Usage: FileClient serverHost serverPort requestXmlFile\n"; + + return -1; + + } + + int port = atoi(argv[2]); + + + + robot::XmlRpc::setVerbosity(5); + + XmlRpcClient c(argv[1], port); + + + + // + + std::ifstream infile(argv[3]); + + if (infile.fail()) { + + std::cerr << "Could not open file '" << argv[3] << "'.\n"; + + return -1; + + } + + + + // Suck in the file. This is a one-liner in good compilers (which vc++ 6 is not)... + + infile.seekg(0L, std::ios::end); + + long nb = infile.tellg(); + + infile.clear(); + + infile.seekg(0L); + + char* b = new char[nb+1]; + + infile.read(b, nb); + + b[nb] = 0; + + + + std::cout << "Read file.\n"; + + + + // Find the methodName and parse the params + + std::string s(b); + + XmlRpcValue params; + + std::string name = parseRequest(s, params); + + + + if (name.empty()) { + + std::cerr << "Could not parse file\n"; + + return -1; + + } + + + + for (;;) { + + XmlRpcValue result; + + std::cout << "Calling " << name << std::endl; + + if (c.execute(name.c_str(), params, result)) + + std::cout << result << "\n\n"; + + else + + std::cout << "Error calling '" << name << "'\n\n"; + + std::cout << "Again? [y]: "; + + std::string ans; + + std::cin >> ans; + + if (ans != "" && ans != "y") break; + + } + + + + return 0; + +} + + + + + +// + +std::string + +parseRequest(std::string const& xml, XmlRpcValue& params) + +{ + + const char METHODNAME_TAG[] = ""; + + const char PARAMS_TAG[] = ""; + + const char PARAMS_ETAG[] = ""; + + const char PARAM_TAG[] = ""; + + const char PARAM_ETAG[] = ""; + + + + int offset = 0; // Number of chars parsed from the request + + + + std::string methodName = XmlRpcUtil::parseTag(METHODNAME_TAG, xml, &offset); + + XmlRpcUtil::log(3, "XmlRpcServerConnection::parseRequest: parsed methodName %s.", methodName.c_str()); + + + + if (! methodName.empty() && XmlRpcUtil::findTag(PARAMS_TAG, xml, &offset)) + + { + + int nArgs = 0; + + while (XmlRpcUtil::nextTagIs(PARAM_TAG, xml, &offset)) { + + std::cout << "Parsing arg " << nArgs+1 << std::endl; + + XmlRpcValue arg(xml, &offset); + + if ( ! arg.valid()) { + + std::cerr << "Invalid argument\n"; + + return std::string(); + + } + + std::cout << "Adding arg " << nArgs+1 << " to params array." << std::endl; + + params[nArgs++] = arg; + + (void) XmlRpcUtil::nextTagIs(PARAM_ETAG, xml, &offset); + + } + + + + XmlRpcUtil::log(3, "XmlRpcServerConnection::parseRequest: parsed %d params.", nArgs); + + + + (void) XmlRpcUtil::nextTagIs(PARAMS_ETAG, xml, &offset); + + } + + + + return methodName; + +} + diff --git a/test/HelloClient.cpp b/test/HelloClient.cpp index 656a690..42e19af 100644 --- a/test/HelloClient.cpp +++ b/test/HelloClient.cpp @@ -3,7 +3,7 @@ // on windows) #include "XmlRpc.h" #include -using namespace XmlRpc; +using namespace robot::XmlRpc; int main(int argc, char* argv[]) { @@ -12,7 +12,7 @@ int main(int argc, char* argv[]) return -1; } int port = atoi(argv[2]); - //XmlRpc::setVerbosity(5); + //robot::XmlRpc::setVerbosity(5); // Use introspection API to look up the supported methods XmlRpcClient c(argv[1], port); diff --git a/test/HelloServer.cpp b/test/HelloServer.cpp index ff81ad8..1ad6661 100644 --- a/test/HelloServer.cpp +++ b/test/HelloServer.cpp @@ -5,7 +5,7 @@ #include #include -using namespace XmlRpc; +using namespace robot::XmlRpc; // The server XmlRpcServer s; @@ -66,7 +66,7 @@ int main(int argc, char* argv[]) } int port = atoi(argv[1]); - XmlRpc::setVerbosity(5); + robot::XmlRpc::setVerbosity(5); // Create the server socket on the specified port s.bindAndListen(port); diff --git a/test/TestBase64Client.cpp b/test/TestBase64Client.cpp index 8a8f057..3570afb 100644 --- a/test/TestBase64Client.cpp +++ b/test/TestBase64Client.cpp @@ -1,45 +1,90 @@ -// TestBase64Client.cpp : A simple xmlrpc client that returns a png file -// encoded as base64 data to the client. -// -// Usage: TestBase64Client serverHost serverPort outputfile -// Requests a png file from the specified server and saves it in outputfile. -// Link against xmlrpc lib and whatever socket libs your system needs (ws2_32.lib on windows) - -#include "XmlRpc.h" -#include -#include -#include - -using namespace XmlRpc; - -int main(int argc, char* argv[]) -{ - if (argc != 4) { - std::cerr << "Usage: TestBase64Client serverHost serverPort outputFile\n"; - return -1; - } - int port = atoi(argv[2]); - - //XmlRpc::setVerbosity(5); - XmlRpcClient c(argv[1], port); - - XmlRpcValue noArgs, result; - if (c.execute("TestBase64", noArgs, result)) - { - const XmlRpcValue::BinaryData& data = result; - std::ofstream outfile(argv[3], std::ios::binary | std::ios::trunc); - if (outfile.fail()) - std::cerr << "Error opening " << argv[3] << " for output.\n"; - else - { - int n = int(data.size()); - for (int i=0; i + +#include + +#include + + + +using namespace robot::XmlRpc; + + + +int main(int argc, char* argv[]) + +{ + + if (argc != 4) { + + std::cerr << "Usage: TestBase64Client serverHost serverPort outputFile\n"; + + return -1; + + } + + int port = atoi(argv[2]); + + + + //robot::XmlRpc::setVerbosity(5); + + XmlRpcClient c(argv[1], port); + + + + XmlRpcValue noArgs, result; + + if (c.execute("TestBase64", noArgs, result)) + + { + + const XmlRpcValue::BinaryData& data = result; + + std::ofstream outfile(argv[3], std::ios::binary | std::ios::trunc); + + if (outfile.fail()) + + std::cerr << "Error opening " << argv[3] << " for output.\n"; + + else + + { + + int n = int(data.size()); + + for (int i=0; i -#include -#include -#include - - -#include "XmlRpc.h" -using namespace XmlRpc; - - -// The server -XmlRpcServer s; - -// No arguments, result is Base64-encoded pngnow.png data. -class TestBase64 : public XmlRpcServerMethod -{ -public: - TestBase64(XmlRpcServer* s) : XmlRpcServerMethod("TestBase64", s) {} - - void execute(XmlRpcValue& params, XmlRpcValue& result) - { - std::ifstream infile("pngnow.png", std::ios::binary); - if (infile.fail()) - infile.open("../pngnow.png", std::ios::binary); - if (infile.fail()) - result = "Could not open file pngnow.png"; - else { - - XmlRpcValue::BinaryData& data = result; - int n = 0; - for (;; ++n) { - char c = infile.get(); - if (infile.eof()) break; - data.push_back(c); - } - std::cerr << "Read " << n << " bytes from pngnow.png\n"; - } - } -} TestBase64(&s); // This constructor registers the method with the server - - - -int main(int argc, char* argv[]) -{ - if (argc != 2) { - std::cerr << "Usage: TestBase64Server serverPort\n"; - return -1; - } - int port = atoi(argv[1]); - - //XmlRpc::setVerbosity(5); - - // Create the server socket on the specified port - s.bindAndListen(port); - - // Wait for requests indefinitely - s.work(-1.0); - - return 0; -} - +// TestBase64Server.cpp : Simple XMLRPC server example. Usage: TestBase64Server serverPort + +// + +#if defined(_MSC_VER) + +# pragma warning(disable:4786) // identifier was truncated in debug info + +#endif + + + + + +#include + +#include + +#include + +#include + + + + + +#include "XmlRpc.h" + +using namespace robot::XmlRpc; + + + + + +// The server + +XmlRpcServer s; + + + +// No arguments, result is Base64-encoded pngnow.png data. + +class TestBase64 : public XmlRpcServerMethod + +{ + +public: + + TestBase64(XmlRpcServer* s) : XmlRpcServerMethod("TestBase64", s) {} + + + + void execute(XmlRpcValue& params, XmlRpcValue& result) + + { + + std::ifstream infile("pngnow.png", std::ios::binary); + + if (infile.fail()) + + infile.open("../pngnow.png", std::ios::binary); + + if (infile.fail()) + + result = "Could not open file pngnow.png"; + + else { + + + + XmlRpcValue::BinaryData& data = result; + + int n = 0; + + for (;; ++n) { + + char c = infile.get(); + + if (infile.eof()) break; + + data.push_back(c); + + } + + std::cerr << "Read " << n << " bytes from pngnow.png\n"; + + } + + } + +} TestBase64(&s); // This constructor registers the method with the server + + + + + + + +int main(int argc, char* argv[]) + +{ + + if (argc != 2) { + + std::cerr << "Usage: TestBase64Server serverPort\n"; + + return -1; + + } + + int port = atoi(argv[1]); + + + + //robot::XmlRpc::setVerbosity(5); + + + + // Create the server socket on the specified port + + s.bindAndListen(port); + + + + // Wait for requests indefinitely + + s.work(-1.0); + + + + return 0; + +} + + + diff --git a/test/TestValues.cpp b/test/TestValues.cpp index 4b2c1ec..b8ecbc2 100644 --- a/test/TestValues.cpp +++ b/test/TestValues.cpp @@ -1,233 +1,466 @@ -// TestValues.cpp : Test XML encoding and decoding of XmlRpcValues. - -#include - -#include "XmlRpcValue.h" - - -#include -#include - - -using namespace XmlRpc; - - -void testBoolean() -{ - XmlRpcValue booleanFalse(false); - XmlRpcValue booleanTrue(true); - int offset = 0; - XmlRpcValue booleanFalseXml("0", &offset); - offset = 0; - XmlRpcValue booleanTrueXml("1", &offset); - assert(booleanFalse != booleanTrue); - assert(booleanFalse == booleanFalseXml); - assert(booleanFalse != booleanTrueXml); - - if (bool(booleanFalse)) - assert(false); - - if ( ! bool(booleanTrue)) - assert(false); -} - -// Int -void testInt() -{ - XmlRpcValue int0(0); - XmlRpcValue int1(1); - XmlRpcValue int10(10); - XmlRpcValue int_1(-1); - int offset = 0; - XmlRpcValue int0Xml("0", &offset); - offset = 0; - XmlRpcValue int9Xml("9", &offset); - assert(int0 == int0Xml); - assert(int(int10) - int(int1) == int(int9Xml)); - assert(9 == int(int9Xml)); - assert(int(int10) + int(int_1) == int(int9Xml)); -} - -void testDouble() -{ - // Double - XmlRpcValue d(43.7); - int offset = 0; - XmlRpcValue dXml("56.3", &offset); - assert(double(d) + double(dXml) == 100.0); // questionable practice... -} - -void testString() -{ - // String - XmlRpcValue s("Now is the time <&"); - char csxml[] = "Now is the time <&"; - std::string ssxml = csxml; - int offset = 0; - XmlRpcValue vscXml(csxml, &offset); - offset = 0; - XmlRpcValue vssXml(ssxml, &offset); - assert(s == vscXml); - assert(s == vssXml); - offset = 0; - XmlRpcValue fromXml(vssXml.toXml(), &offset); - assert(s == fromXml); - - // Empty or blank strings with no tags - std::string emptyStringXml(""); - offset = 0; - XmlRpcValue emptyStringVal1(emptyStringXml, &offset); - XmlRpcValue emptyStringVal2(""); - assert(emptyStringVal1 == emptyStringVal2); - - emptyStringXml = " "; - offset = 0; - XmlRpcValue blankStringVal(emptyStringXml, &offset); - assert(std::string(blankStringVal) == " "); -} - - -void testDateTime() -{ - // DateTime - int offset = 0; - XmlRpcValue dateTime("19040101T03:12:35", &offset); - struct tm &t = dateTime; - assert(t.tm_year == 1904 && t.tm_min == 12); -} - - -void testArray(XmlRpcValue const& d) -{ - // Array - XmlRpcValue a; - a.setSize(4); - a[0] = 1; - a[1] = std::string("two"); - a[2] = 43.7; - a[3] = "four"; - assert(int(a[0]) == 1); - assert(a[2] == d); - - char csaXml[] = - "\n" - " \n" - " 1 \n" - " two\n" - " 43.7\n" - " four\n" - " \n" - ""; - - int offset = 0; - XmlRpcValue aXml(csaXml, &offset); - assert(a == aXml); -} - -void testStruct() -{ - // Struct - XmlRpcValue struct1; - struct1["i4"] = 1; - struct1["str"] = "two"; - struct1["d"] = 43.7; - - XmlRpcValue a; - a.setSize(4); - a[0] = 1; - a[1] = std::string("two"); - a[2] = 43.7; - a[3] = "four"; - - assert(struct1["d"] == a[2]); - - char csStructXml[] = - "\n" - " \n" - " i4 \n" - " 1 \n" - " \n" - " \n" - " d \n" - " 43.7\n" - " \n" - " \n" - " str \n" - " two\n" - " \n" - ""; - - int offset = 0; - XmlRpcValue structXml(csStructXml, &offset); - assert(struct1 == structXml); - - XmlRpcValue astruct; - astruct["array"] = a; - assert(astruct["array"][2] == struct1["d"]); - - for (int i=0; i<10; i++) { - XmlRpcValue Event; - Event["Name"] = "string"; - - Event.clear(); - - const int NELMTS = 100; - int ii; - - for (ii=0; ii< NELMTS; ++ii) { - char buf[40]; - sprintf(buf,"%d", ii); - Event[std::string(buf)] = buf; - } - - Event.clear(); - - for (ii=0; ii< NELMTS; ++ii) { - char buf[40]; - sprintf(buf,"%d", ii); - if (ii != NELMTS/2) - Event[std::string(buf)] = ii; - else - for (int jj=0; jj< NELMTS; ++jj) { - char bufj[40]; - sprintf(bufj,"%d", jj); - Event[std::string(buf)][std::string(bufj)] = bufj; - } - } - - for (ii=0; ii< NELMTS; ++ii) { - char buf[40]; - sprintf(buf,"%d", ii); - if (ii != NELMTS/2) - assert(Event[std::string(buf)] == XmlRpcValue(ii)); - else - assert(Event[std::string(buf)].size() == NELMTS); - } - } -} - - - -int main(int argc, char* argv[]) -{ - testBoolean(); - - testInt(); - - - testDouble(); - - - testString(); - - - testDateTime(); - - - testArray(43.7); - - - testStruct(); - - return 0; -} +// TestValues.cpp : Test XML encoding and decoding of XmlRpcValues. + + + +#include + + + +#include "XmlRpcValue.h" + + + + + +#include + +#include + + + + + +using namespace robot::XmlRpc; + + + + + +void testBoolean() + +{ + + XmlRpcValue booleanFalse(false); + + XmlRpcValue booleanTrue(true); + + int offset = 0; + + XmlRpcValue booleanFalseXml("0", &offset); + + offset = 0; + + XmlRpcValue booleanTrueXml("1", &offset); + + assert(booleanFalse != booleanTrue); + + assert(booleanFalse == booleanFalseXml); + + assert(booleanFalse != booleanTrueXml); + + + + if (bool(booleanFalse)) + + assert(false); + + + + if ( ! bool(booleanTrue)) + + assert(false); + +} + + + +// Int + +void testInt() + +{ + + XmlRpcValue int0(0); + + XmlRpcValue int1(1); + + XmlRpcValue int10(10); + + XmlRpcValue int_1(-1); + + int offset = 0; + + XmlRpcValue int0Xml("0", &offset); + + offset = 0; + + XmlRpcValue int9Xml("9", &offset); + + assert(int0 == int0Xml); + + assert(int(int10) - int(int1) == int(int9Xml)); + + assert(9 == int(int9Xml)); + + assert(int(int10) + int(int_1) == int(int9Xml)); + +} + + + +void testDouble() + +{ + + // Double + + XmlRpcValue d(43.7); + + int offset = 0; + + XmlRpcValue dXml("56.3", &offset); + + assert(double(d) + double(dXml) == 100.0); // questionable practice... + +} + + + +void testString() + +{ + + // String + + XmlRpcValue s("Now is the time <&"); + + char csxml[] = "Now is the time <&"; + + std::string ssxml = csxml; + + int offset = 0; + + XmlRpcValue vscXml(csxml, &offset); + + offset = 0; + + XmlRpcValue vssXml(ssxml, &offset); + + assert(s == vscXml); + + assert(s == vssXml); + + offset = 0; + + XmlRpcValue fromXml(vssXml.toXml(), &offset); + + assert(s == fromXml); + + + + // Empty or blank strings with no tags + + std::string emptyStringXml(""); + + offset = 0; + + XmlRpcValue emptyStringVal1(emptyStringXml, &offset); + + XmlRpcValue emptyStringVal2(""); + + assert(emptyStringVal1 == emptyStringVal2); + + + + emptyStringXml = " "; + + offset = 0; + + XmlRpcValue blankStringVal(emptyStringXml, &offset); + + assert(std::string(blankStringVal) == " "); + +} + + + + + +void testDateTime() + +{ + + // DateTime + + int offset = 0; + + XmlRpcValue dateTime("19040101T03:12:35", &offset); + + struct tm &t = dateTime; + + assert(t.tm_year == 1904 && t.tm_min == 12); + +} + + + + + +void testArray(XmlRpcValue const& d) + +{ + + // Array + + XmlRpcValue a; + + a.setSize(4); + + a[0] = 1; + + a[1] = std::string("two"); + + a[2] = 43.7; + + a[3] = "four"; + + assert(int(a[0]) == 1); + + assert(a[2] == d); + + + + char csaXml[] = + + "\n" + + " \n" + + " 1 \n" + + " two\n" + + " 43.7\n" + + " four\n" + + " \n" + + ""; + + + + int offset = 0; + + XmlRpcValue aXml(csaXml, &offset); + + assert(a == aXml); + +} + + + +void testStruct() + +{ + + // Struct + + XmlRpcValue struct1; + + struct1["i4"] = 1; + + struct1["str"] = "two"; + + struct1["d"] = 43.7; + + + + XmlRpcValue a; + + a.setSize(4); + + a[0] = 1; + + a[1] = std::string("two"); + + a[2] = 43.7; + + a[3] = "four"; + + + + assert(struct1["d"] == a[2]); + + + + char csStructXml[] = + + "\n" + + " \n" + + " i4 \n" + + " 1 \n" + + " \n" + + " \n" + + " d \n" + + " 43.7\n" + + " \n" + + " \n" + + " str \n" + + " two\n" + + " \n" + + ""; + + + + int offset = 0; + + XmlRpcValue structXml(csStructXml, &offset); + + assert(struct1 == structXml); + + + + XmlRpcValue astruct; + + astruct["array"] = a; + + assert(astruct["array"][2] == struct1["d"]); + + + + for (int i=0; i<10; i++) { + + XmlRpcValue Event; + + Event["Name"] = "string"; + + + + Event.clear(); + + + + const int NELMTS = 100; + + int ii; + + + + for (ii=0; ii< NELMTS; ++ii) { + + char buf[40]; + + sprintf(buf,"%d", ii); + + Event[std::string(buf)] = buf; + + } + + + + Event.clear(); + + + + for (ii=0; ii< NELMTS; ++ii) { + + char buf[40]; + + sprintf(buf,"%d", ii); + + if (ii != NELMTS/2) + + Event[std::string(buf)] = ii; + + else + + for (int jj=0; jj< NELMTS; ++jj) { + + char bufj[40]; + + sprintf(bufj,"%d", jj); + + Event[std::string(buf)][std::string(bufj)] = bufj; + + } + + } + + + + for (ii=0; ii< NELMTS; ++ii) { + + char buf[40]; + + sprintf(buf,"%d", ii); + + if (ii != NELMTS/2) + + assert(Event[std::string(buf)] == XmlRpcValue(ii)); + + else + + assert(Event[std::string(buf)].size() == NELMTS); + + } + + } + +} + + + + + + + +int main(int argc, char* argv[]) + +{ + + testBoolean(); + + + + testInt(); + + + + + + testDouble(); + + + + + + testString(); + + + + + + testDateTime(); + + + + + + testArray(43.7); + + + + + + testStruct(); + + + + return 0; + +} + diff --git a/test/TestValuesWin32.cpp b/test/TestValuesWin32.cpp index b5136c7..d9113a6 100644 --- a/test/TestValuesWin32.cpp +++ b/test/TestValuesWin32.cpp @@ -1,253 +1,506 @@ -// TestValues.cpp : Test XML encoding and decoding of XmlRpcValues. - -#define _CRTDBG_MAP_ALLOC -#include -#include - -#include "XmlRpcValue.h" - - -#include -#include - - -using namespace XmlRpc; - - -void testBoolean() -{ - XmlRpcValue booleanFalse(false); - XmlRpcValue booleanTrue(true); - int offset = 0; - XmlRpcValue booleanFalseXml("0", &offset); - offset = 0; - XmlRpcValue booleanTrueXml("1", &offset); - assert(booleanFalse != booleanTrue); - assert(booleanFalse == booleanFalseXml); - assert(booleanFalse == booleanFalseXml); - if (booleanFalse) - assert(false); - - if (booleanTrue) - assert( ! false); - else - assert(false); -} - -// Int -void testInt() -{ - XmlRpcValue int0(0); - XmlRpcValue int1(1); - XmlRpcValue int10(10); - XmlRpcValue int_1(-1); - int offset = 0; - XmlRpcValue int0Xml("0", &offset); - offset = 0; - XmlRpcValue int9Xml("9", &offset); - assert(int0 == int0Xml); - assert(int(int10) - int(int1) == int(int9Xml)); - assert(9 == int(int9Xml)); - assert(int(int10) + int(int_1) == int(int9Xml)); -} - -void testDouble() -{ - // Double - XmlRpcValue d(43.7); - int offset = 0; - XmlRpcValue dXml("56.3", &offset); - assert(double(d) + double(dXml) == 100.0); // questionable practice... -} - -void testString() -{ - // String - XmlRpcValue s("Now is the time <&"); - char csxml[] = "Now is the time <&"; - std::string ssxml = csxml; - int offset = 0; - XmlRpcValue vscXml(csxml, &offset); - offset = 0; - XmlRpcValue vssXml(ssxml, &offset); - assert(s == vscXml); - assert(s == vssXml); - offset = 0; - XmlRpcValue fromXml(vssXml.toXml(), &offset); - assert(s == fromXml); - - // Empty or blank strings with no tags - std::string emptyStringXml(""); - offset = 0; - XmlRpcValue emptyStringVal1(emptyStringXml, &offset); - XmlRpcValue emptyStringVal2(""); - assert(emptyStringVal1 == emptyStringVal2); - - emptyStringXml = " "; - offset = 0; - XmlRpcValue blankStringVal(emptyStringXml, &offset); - assert(std::string(blankStringVal) == " "); -} - - -void testDateTime() -{ - // DateTime - int offset = 0; - XmlRpcValue dateTime("19040101T03:12:35", &offset); - struct tm &t = dateTime; - assert(t.tm_year == 1904 && t.tm_min == 12); -} - - -void testArray(XmlRpcValue const& d) -{ - // Array - XmlRpcValue a; - a.setSize(4); - a[0] = 1; - a[1] = std::string("two"); - a[2] = 43.7; - a[3] = "four"; - assert(int(a[0]) == 1); - assert(a[2] == d); - - char csaXml[] = - "\n" - " \n" - " 1 \n" - " two\n" - " 43.7\n" - " four\n" - " \n" - ""; - - int offset = 0; - XmlRpcValue aXml(csaXml, &offset); - assert(a == aXml); -} - -void testStruct() -{ - // Struct - XmlRpcValue struct1; - struct1["i4"] = 1; - struct1["str"] = "two"; - struct1["d"] = 43.7; - - XmlRpcValue a; - a.setSize(4); - a[0] = 1; - a[1] = std::string("two"); - a[2] = 43.7; - a[3] = "four"; - - assert(struct1["d"] == a[2]); - - char csStructXml[] = - "\n" - " \n" - " i4 \n" - " 1 \n" - " \n" - " \n" - " d \n" - " 43.7\n" - " \n" - " \n" - " str \n" - " two\n" - " \n" - ""; - - int offset = 0; - XmlRpcValue structXml(csStructXml, &offset); - assert(struct1 == structXml); - - XmlRpcValue astruct; - astruct["array"] = a; - assert(astruct["array"][2] == struct1["d"]); - - for (int i=0; i<10; i++) { - XmlRpcValue Event; - Event["Name"] = "string"; - - Event.clear(); - - const int NELMTS = 100; - int ii; - - for (ii=0; ii< NELMTS; ++ii) { - char buf[40]; - sprintf(buf,"%d", ii); - Event[buf] = buf; - } - - Event.clear(); - - for (ii=0; ii< NELMTS; ++ii) { - char buf[40]; - sprintf(buf,"%d", ii); - if (ii != NELMTS/2) - Event[buf] = ii; - else - for (int jj=0; jj< NELMTS; ++jj) { - char bufj[40]; - sprintf(bufj,"%d", jj); - Event[buf][bufj] = bufj; - } - } - - for (ii=0; ii< NELMTS; ++ii) { - char buf[40]; - sprintf(buf,"%d", ii); - if (ii != NELMTS/2) - assert(Event[buf] == XmlRpcValue(ii)); - else - assert(Event[buf].size() == NELMTS); - } - } -} - - - -int main(int argc, char* argv[]) -{ - _CrtDumpMemoryLeaks(); - _CrtCheckMemory( ); - - testBoolean(); - _CrtDumpMemoryLeaks(); - _CrtCheckMemory( ); - - testInt(); - _CrtDumpMemoryLeaks(); - _CrtCheckMemory( ); - - - testDouble(); - _CrtDumpMemoryLeaks(); - _CrtCheckMemory( ); - - - testString(); - _CrtDumpMemoryLeaks(); - _CrtCheckMemory( ); - - - testDateTime(); - _CrtDumpMemoryLeaks(); - _CrtCheckMemory( ); - - - testArray(43.7); - _CrtDumpMemoryLeaks(); - _CrtCheckMemory( ); - - - testStruct(); - _CrtDumpMemoryLeaks(); - _CrtCheckMemory( ); - - return 0; -} +// TestValues.cpp : Test XML encoding and decoding of XmlRpcValues. + + + +#define _CRTDBG_MAP_ALLOC + +#include + +#include + + + +#include "XmlRpcValue.h" + + + + + +#include + +#include + + + + + +using namespace robot::XmlRpc; + + + + + +void testBoolean() + +{ + + XmlRpcValue booleanFalse(false); + + XmlRpcValue booleanTrue(true); + + int offset = 0; + + XmlRpcValue booleanFalseXml("0", &offset); + + offset = 0; + + XmlRpcValue booleanTrueXml("1", &offset); + + assert(booleanFalse != booleanTrue); + + assert(booleanFalse == booleanFalseXml); + + assert(booleanFalse == booleanFalseXml); + + if (booleanFalse) + + assert(false); + + + + if (booleanTrue) + + assert( ! false); + + else + + assert(false); + +} + + + +// Int + +void testInt() + +{ + + XmlRpcValue int0(0); + + XmlRpcValue int1(1); + + XmlRpcValue int10(10); + + XmlRpcValue int_1(-1); + + int offset = 0; + + XmlRpcValue int0Xml("0", &offset); + + offset = 0; + + XmlRpcValue int9Xml("9", &offset); + + assert(int0 == int0Xml); + + assert(int(int10) - int(int1) == int(int9Xml)); + + assert(9 == int(int9Xml)); + + assert(int(int10) + int(int_1) == int(int9Xml)); + +} + + + +void testDouble() + +{ + + // Double + + XmlRpcValue d(43.7); + + int offset = 0; + + XmlRpcValue dXml("56.3", &offset); + + assert(double(d) + double(dXml) == 100.0); // questionable practice... + +} + + + +void testString() + +{ + + // String + + XmlRpcValue s("Now is the time <&"); + + char csxml[] = "Now is the time <&"; + + std::string ssxml = csxml; + + int offset = 0; + + XmlRpcValue vscXml(csxml, &offset); + + offset = 0; + + XmlRpcValue vssXml(ssxml, &offset); + + assert(s == vscXml); + + assert(s == vssXml); + + offset = 0; + + XmlRpcValue fromXml(vssXml.toXml(), &offset); + + assert(s == fromXml); + + + + // Empty or blank strings with no tags + + std::string emptyStringXml(""); + + offset = 0; + + XmlRpcValue emptyStringVal1(emptyStringXml, &offset); + + XmlRpcValue emptyStringVal2(""); + + assert(emptyStringVal1 == emptyStringVal2); + + + + emptyStringXml = " "; + + offset = 0; + + XmlRpcValue blankStringVal(emptyStringXml, &offset); + + assert(std::string(blankStringVal) == " "); + +} + + + + + +void testDateTime() + +{ + + // DateTime + + int offset = 0; + + XmlRpcValue dateTime("19040101T03:12:35", &offset); + + struct tm &t = dateTime; + + assert(t.tm_year == 1904 && t.tm_min == 12); + +} + + + + + +void testArray(XmlRpcValue const& d) + +{ + + // Array + + XmlRpcValue a; + + a.setSize(4); + + a[0] = 1; + + a[1] = std::string("two"); + + a[2] = 43.7; + + a[3] = "four"; + + assert(int(a[0]) == 1); + + assert(a[2] == d); + + + + char csaXml[] = + + "\n" + + " \n" + + " 1 \n" + + " two\n" + + " 43.7\n" + + " four\n" + + " \n" + + ""; + + + + int offset = 0; + + XmlRpcValue aXml(csaXml, &offset); + + assert(a == aXml); + +} + + + +void testStruct() + +{ + + // Struct + + XmlRpcValue struct1; + + struct1["i4"] = 1; + + struct1["str"] = "two"; + + struct1["d"] = 43.7; + + + + XmlRpcValue a; + + a.setSize(4); + + a[0] = 1; + + a[1] = std::string("two"); + + a[2] = 43.7; + + a[3] = "four"; + + + + assert(struct1["d"] == a[2]); + + + + char csStructXml[] = + + "\n" + + " \n" + + " i4 \n" + + " 1 \n" + + " \n" + + " \n" + + " d \n" + + " 43.7\n" + + " \n" + + " \n" + + " str \n" + + " two\n" + + " \n" + + ""; + + + + int offset = 0; + + XmlRpcValue structXml(csStructXml, &offset); + + assert(struct1 == structXml); + + + + XmlRpcValue astruct; + + astruct["array"] = a; + + assert(astruct["array"][2] == struct1["d"]); + + + + for (int i=0; i<10; i++) { + + XmlRpcValue Event; + + Event["Name"] = "string"; + + + + Event.clear(); + + + + const int NELMTS = 100; + + int ii; + + + + for (ii=0; ii< NELMTS; ++ii) { + + char buf[40]; + + sprintf(buf,"%d", ii); + + Event[buf] = buf; + + } + + + + Event.clear(); + + + + for (ii=0; ii< NELMTS; ++ii) { + + char buf[40]; + + sprintf(buf,"%d", ii); + + if (ii != NELMTS/2) + + Event[buf] = ii; + + else + + for (int jj=0; jj< NELMTS; ++jj) { + + char bufj[40]; + + sprintf(bufj,"%d", jj); + + Event[buf][bufj] = bufj; + + } + + } + + + + for (ii=0; ii< NELMTS; ++ii) { + + char buf[40]; + + sprintf(buf,"%d", ii); + + if (ii != NELMTS/2) + + assert(Event[buf] == XmlRpcValue(ii)); + + else + + assert(Event[buf].size() == NELMTS); + + } + + } + +} + + + + + + + +int main(int argc, char* argv[]) + +{ + + _CrtDumpMemoryLeaks(); + + _CrtCheckMemory( ); + + + + testBoolean(); + + _CrtDumpMemoryLeaks(); + + _CrtCheckMemory( ); + + + + testInt(); + + _CrtDumpMemoryLeaks(); + + _CrtCheckMemory( ); + + + + + + testDouble(); + + _CrtDumpMemoryLeaks(); + + _CrtCheckMemory( ); + + + + + + testString(); + + _CrtDumpMemoryLeaks(); + + _CrtCheckMemory( ); + + + + + + testDateTime(); + + _CrtDumpMemoryLeaks(); + + _CrtCheckMemory( ); + + + + + + testArray(43.7); + + _CrtDumpMemoryLeaks(); + + _CrtCheckMemory( ); + + + + + + testStruct(); + + _CrtDumpMemoryLeaks(); + + _CrtCheckMemory( ); + + + + return 0; + +} + diff --git a/test/TestXml.cpp b/test/TestXml.cpp index 58b96ed..3b9ea44 100644 --- a/test/TestXml.cpp +++ b/test/TestXml.cpp @@ -1,53 +1,106 @@ -// TestXml.cpp : Test XML encoding and decoding. -// The characters <>&'" are illegal in xml and must be encoded. - - -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers - -#include -// If you are using MSVC++6, you should update to fix -// BUG: getline Template Function Reads Extra Character -#include -#include -#include - -#include "XmlRpcUtil.h" - -using namespace XmlRpc; - - -int main(int argc, char* argv[]) -{ - // Basic tests - std::string empty; - assert(empty == XmlRpcUtil::xmlEncode(empty)); - assert(empty == XmlRpcUtil::xmlDecode(empty)); - assert(empty == XmlRpcUtil::xmlEncode("")); - assert(empty == XmlRpcUtil::xmlDecode("")); - - std::string raw("<>&'\""); - assert(XmlRpcUtil::xmlDecode(XmlRpcUtil::xmlEncode(raw)) == raw); - - std::cout << "Basic tests passed.\n"; - - // Interactive tests - std::string s; - for (;;) { - std::cout << "\nEnter line of raw text to encode:\n"; - std::getline(std::cin, s); - if (s.empty()) break; - - std::cout << XmlRpcUtil::xmlEncode(s) << std::endl; - } - - for (;;) { - std::cout << "\nEnter line of xml-encoded text to decode:\n"; - std::getline(std::cin, s); - if (s.empty()) break; - - std::cout << XmlRpcUtil::xmlDecode(s) << std::endl; - } - - return 0; -} - +// TestXml.cpp : Test XML encoding and decoding. + +// The characters <>&'" are illegal in xml and must be encoded. + + + + + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers + + + +#include + +// If you are using MSVC++6, you should update to fix + +// BUG: getline Template Function Reads Extra Character + +#include + +#include + +#include + + + +#include "XmlRpcUtil.h" + + + +using namespace robot::XmlRpc; + + + + + +int main(int argc, char* argv[]) + +{ + + // Basic tests + + std::string empty; + + assert(empty == XmlRpcUtil::xmlEncode(empty)); + + assert(empty == XmlRpcUtil::xmlDecode(empty)); + + assert(empty == XmlRpcUtil::xmlEncode("")); + + assert(empty == XmlRpcUtil::xmlDecode("")); + + + + std::string raw("<>&'\""); + + assert(XmlRpcUtil::xmlDecode(XmlRpcUtil::xmlEncode(raw)) == raw); + + + + std::cout << "Basic tests passed.\n"; + + + + // Interactive tests + + std::string s; + + for (;;) { + + std::cout << "\nEnter line of raw text to encode:\n"; + + std::getline(std::cin, s); + + if (s.empty()) break; + + + + std::cout << XmlRpcUtil::xmlEncode(s) << std::endl; + + } + + + + for (;;) { + + std::cout << "\nEnter line of xml-encoded text to decode:\n"; + + std::getline(std::cin, s); + + if (s.empty()) break; + + + + std::cout << XmlRpcUtil::xmlDecode(s) << std::endl; + + } + + + + return 0; + +} + + + diff --git a/test/Validator.cpp b/test/Validator.cpp index df4090d..622102b 100644 --- a/test/Validator.cpp +++ b/test/Validator.cpp @@ -1,207 +1,414 @@ -// Validator.cpp : XMLRPC server based on the compliancy test at validator.xmlrpc.com. -// -#include "XmlRpc.h" -using namespace XmlRpc; - -#include - - -XmlRpcServer s; - - -// One argument is passed, an array of structs, each with a member named curly with -// an integer value. Return the sum of those values. - -class ArrayOfStructsTest : public XmlRpcServerMethod -{ -public: - ArrayOfStructsTest(XmlRpcServer* s) : XmlRpcServerMethod("validator1.arrayOfStructsTest", s) {} - - void execute(XmlRpcValue& params, XmlRpcValue& result) - { - std::cerr << "ArrayOfStructsTest\n"; - XmlRpcValue& arg1 = params[0]; - int n = arg1.size(), sum = 0; - for (int i=0; i, &, ' and ". -// The handler must return a struct that contains five fields, all numbers: ctLeftAngleBrackets, -// ctRightAngleBrackets, ctAmpersands, ctApostrophes, ctQuotes. -// To validate, the numbers must be correct. - -class CountTheEntities : public XmlRpcServerMethod -{ -public: - CountTheEntities(XmlRpcServer* s) : XmlRpcServerMethod("validator1.countTheEntities", s) {} - - void execute(XmlRpcValue& params, XmlRpcValue& result) - { - std::cerr << "CountTheEntities\n"; - std::string& arg = params[0]; - int ctLeftAngleBrackets = 0; - int ctRightAngleBrackets = 0; - int ctAmpersands = 0; - int ctApostrophes = 0; - int ctQuotes = 0; - - int n = int(arg.length()); - for (int i=0; i': ++ctRightAngleBrackets; break; - case '&': ++ctAmpersands; break; - case '\'': ++ctApostrophes; break; - case '\"': ++ctQuotes; break; - } - - result["ctLeftAngleBrackets"] = ctLeftAngleBrackets; - result["ctRightAngleBrackets"] = ctRightAngleBrackets; - result["ctAmpersands"] = ctAmpersands; - result["ctApostrophes"] = ctApostrophes; - result["ctQuotes"] = ctQuotes; - } -} countTheEntities(&s); - - - -// This handler takes a single parameter, a struct, containing at least three elements -// named moe, larry and curly, all s. Your handler must add the three numbers and -// return the result. - -class EasyStructTest : public XmlRpcServerMethod -{ -public: - EasyStructTest(XmlRpcServer* s) : XmlRpcServerMethod("validator1.easyStructTest", s) {} - - void execute(XmlRpcValue& params, XmlRpcValue& result) - { - std::cerr << "EasyStructTest\n"; - XmlRpcValue& arg1 = params[0]; - int sum = int(arg1["moe"]) + int(arg1["larry"]) + int(arg1["curly"]); - result = sum; - } -} easyStructTest(&s); - - -// This handler takes a single parameter, a struct. Your handler must return the struct. - -class EchoStructTest : public XmlRpcServerMethod -{ -public: - EchoStructTest(XmlRpcServer* s) : XmlRpcServerMethod("validator1.echoStructTest", s) {} - - void execute(XmlRpcValue& params, XmlRpcValue& result) - { - std::cerr << "EchoStructTest\n"; - result = params[0]; - } -} echoStructTest(&s); - - - -// This handler takes six parameters, and returns an array containing all the parameters. - -class ManyTypesTest : public XmlRpcServerMethod -{ -public: - ManyTypesTest(XmlRpcServer* s) : XmlRpcServerMethod("validator1.manyTypesTest", s) {} - - void execute(XmlRpcValue& params, XmlRpcValue& result) - { - std::cerr << "ManyTypesTest\n"; - result = params; - } -} manyTypesTest(&s); - - - -// This handler takes a single parameter, which is an array containing between 100 and -// 200 elements. Each of the items is a string, your handler must return a string -// containing the concatenated text of the first and last elements. - - -class ModerateSizeArrayCheck : public XmlRpcServerMethod -{ -public: - ModerateSizeArrayCheck(XmlRpcServer* s) : XmlRpcServerMethod("validator1.moderateSizeArrayCheck", s) {} - - void execute(XmlRpcValue& params, XmlRpcValue& result) - { - std::cerr << "ModerateSizeArrayCheck\n"; - std::string s = params[0][0]; - s += params[0][params[0].size()-1]; - result = s; - } -} moderateSizeArrayCheck(&s); - - -// This handler takes a single parameter, a struct, that models a daily calendar. -// At the top level, there is one struct for each year. Each year is broken down -// into months, and months into days. Most of the days are empty in the struct -// you receive, but the entry for April 1, 2000 contains a least three elements -// named moe, larry and curly, all s. Your handler must add the three numbers -// and return the result. - -class NestedStructTest : public XmlRpcServerMethod -{ -public: - NestedStructTest(XmlRpcServer* s) : XmlRpcServerMethod("validator1.nestedStructTest", s) {} - - void execute(XmlRpcValue& params, XmlRpcValue& result) - { - std::cerr << "NestedStructTest\n"; - XmlRpcValue& dayStruct = params[0]["2000"]["04"]["01"]; - int sum = int(dayStruct["moe"]) + int(dayStruct["larry"]) + int(dayStruct["curly"]); - result = sum; - } -} nestedStructTest(&s); - - - -// This handler takes one parameter, and returns a struct containing three elements, -// times10, times100 and times1000, the result of multiplying the number by 10, 100 and 1000. - -class SimpleStructReturnTest : public XmlRpcServerMethod -{ -public: - SimpleStructReturnTest(XmlRpcServer* s) : XmlRpcServerMethod("validator1.simpleStructReturnTest", s) {} - - void execute(XmlRpcValue& params, XmlRpcValue& result) - { - std::cerr << "SimpleStructReturnTest\n"; - int n = params[0]; - result["times10"] = n * 10; - result["times100"] = n * 100; - result["times1000"] = n * 1000; - } -} simpleStructReturnTest(&s); - - - -int main(int argc, char* argv[]) -{ - if (argc != 2) { - std::cerr << "Usage: Validator port\n"; - return -1; - } - int port = atoi(argv[1]); - - XmlRpc::setVerbosity(5); - - // Create the server socket on the specified port - s.bindAndListen(port); - - // Wait for requests indefinitely - s.work(-1.0); - - return 0; -} - +// Validator.cpp : XMLRPC server based on the compliancy test at validator.xmlrpc.com. + +// + +#include "XmlRpc.h" + +using namespace robot::XmlRpc; + + + +#include + + + + + +XmlRpcServer s; + + + + + +// One argument is passed, an array of structs, each with a member named curly with + +// an integer value. Return the sum of those values. + + + +class ArrayOfStructsTest : public XmlRpcServerMethod + +{ + +public: + + ArrayOfStructsTest(XmlRpcServer* s) : XmlRpcServerMethod("validator1.arrayOfStructsTest", s) {} + + + + void execute(XmlRpcValue& params, XmlRpcValue& result) + + { + + std::cerr << "ArrayOfStructsTest\n"; + + XmlRpcValue& arg1 = params[0]; + + int n = arg1.size(), sum = 0; + + for (int i=0; i, &, ' and ". + +// The handler must return a struct that contains five fields, all numbers: ctLeftAngleBrackets, + +// ctRightAngleBrackets, ctAmpersands, ctApostrophes, ctQuotes. + +// To validate, the numbers must be correct. + + + +class CountTheEntities : public XmlRpcServerMethod + +{ + +public: + + CountTheEntities(XmlRpcServer* s) : XmlRpcServerMethod("validator1.countTheEntities", s) {} + + + + void execute(XmlRpcValue& params, XmlRpcValue& result) + + { + + std::cerr << "CountTheEntities\n"; + + std::string& arg = params[0]; + + int ctLeftAngleBrackets = 0; + + int ctRightAngleBrackets = 0; + + int ctAmpersands = 0; + + int ctApostrophes = 0; + + int ctQuotes = 0; + + + + int n = int(arg.length()); + + for (int i=0; i': ++ctRightAngleBrackets; break; + + case '&': ++ctAmpersands; break; + + case '\'': ++ctApostrophes; break; + + case '\"': ++ctQuotes; break; + + } + + + + result["ctLeftAngleBrackets"] = ctLeftAngleBrackets; + + result["ctRightAngleBrackets"] = ctRightAngleBrackets; + + result["ctAmpersands"] = ctAmpersands; + + result["ctApostrophes"] = ctApostrophes; + + result["ctQuotes"] = ctQuotes; + + } + +} countTheEntities(&s); + + + + + + + +// This handler takes a single parameter, a struct, containing at least three elements + +// named moe, larry and curly, all s. Your handler must add the three numbers and + +// return the result. + + + +class EasyStructTest : public XmlRpcServerMethod + +{ + +public: + + EasyStructTest(XmlRpcServer* s) : XmlRpcServerMethod("validator1.easyStructTest", s) {} + + + + void execute(XmlRpcValue& params, XmlRpcValue& result) + + { + + std::cerr << "EasyStructTest\n"; + + XmlRpcValue& arg1 = params[0]; + + int sum = int(arg1["moe"]) + int(arg1["larry"]) + int(arg1["curly"]); + + result = sum; + + } + +} easyStructTest(&s); + + + + + +// This handler takes a single parameter, a struct. Your handler must return the struct. + + + +class EchoStructTest : public XmlRpcServerMethod + +{ + +public: + + EchoStructTest(XmlRpcServer* s) : XmlRpcServerMethod("validator1.echoStructTest", s) {} + + + + void execute(XmlRpcValue& params, XmlRpcValue& result) + + { + + std::cerr << "EchoStructTest\n"; + + result = params[0]; + + } + +} echoStructTest(&s); + + + + + + + +// This handler takes six parameters, and returns an array containing all the parameters. + + + +class ManyTypesTest : public XmlRpcServerMethod + +{ + +public: + + ManyTypesTest(XmlRpcServer* s) : XmlRpcServerMethod("validator1.manyTypesTest", s) {} + + + + void execute(XmlRpcValue& params, XmlRpcValue& result) + + { + + std::cerr << "ManyTypesTest\n"; + + result = params; + + } + +} manyTypesTest(&s); + + + + + + + +// This handler takes a single parameter, which is an array containing between 100 and + +// 200 elements. Each of the items is a string, your handler must return a string + +// containing the concatenated text of the first and last elements. + + + + + +class ModerateSizeArrayCheck : public XmlRpcServerMethod + +{ + +public: + + ModerateSizeArrayCheck(XmlRpcServer* s) : XmlRpcServerMethod("validator1.moderateSizeArrayCheck", s) {} + + + + void execute(XmlRpcValue& params, XmlRpcValue& result) + + { + + std::cerr << "ModerateSizeArrayCheck\n"; + + std::string s = params[0][0]; + + s += params[0][params[0].size()-1]; + + result = s; + + } + +} moderateSizeArrayCheck(&s); + + + + + +// This handler takes a single parameter, a struct, that models a daily calendar. + +// At the top level, there is one struct for each year. Each year is broken down + +// into months, and months into days. Most of the days are empty in the struct + +// you receive, but the entry for April 1, 2000 contains a least three elements + +// named moe, larry and curly, all s. Your handler must add the three numbers + +// and return the result. + + + +class NestedStructTest : public XmlRpcServerMethod + +{ + +public: + + NestedStructTest(XmlRpcServer* s) : XmlRpcServerMethod("validator1.nestedStructTest", s) {} + + + + void execute(XmlRpcValue& params, XmlRpcValue& result) + + { + + std::cerr << "NestedStructTest\n"; + + XmlRpcValue& dayStruct = params[0]["2000"]["04"]["01"]; + + int sum = int(dayStruct["moe"]) + int(dayStruct["larry"]) + int(dayStruct["curly"]); + + result = sum; + + } + +} nestedStructTest(&s); + + + + + + + +// This handler takes one parameter, and returns a struct containing three elements, + +// times10, times100 and times1000, the result of multiplying the number by 10, 100 and 1000. + + + +class SimpleStructReturnTest : public XmlRpcServerMethod + +{ + +public: + + SimpleStructReturnTest(XmlRpcServer* s) : XmlRpcServerMethod("validator1.simpleStructReturnTest", s) {} + + + + void execute(XmlRpcValue& params, XmlRpcValue& result) + + { + + std::cerr << "SimpleStructReturnTest\n"; + + int n = params[0]; + + result["times10"] = n * 10; + + result["times100"] = n * 100; + + result["times1000"] = n * 1000; + + } + +} simpleStructReturnTest(&s); + + + + + + + +int main(int argc, char* argv[]) + +{ + + if (argc != 2) { + + std::cerr << "Usage: Validator port\n"; + + return -1; + + } + + int port = atoi(argv[1]); + + + + robot::XmlRpc::setVerbosity(5); + + + + // Create the server socket on the specified port + + s.bindAndListen(port); + + + + // Wait for requests indefinitely + + s.work(-1.0); + + + + return 0; + +} + + +