first commit

This commit is contained in:
2025-11-25 10:55:38 +07:00
commit 88ebdb465c
57 changed files with 9213 additions and 0 deletions

207
test/Validator.cpp Normal file
View File

@@ -0,0 +1,207 @@
// Validator.cpp : XMLRPC server based on the compliancy test at validator.xmlrpc.com.
//
#include "XmlRpc.h"
using namespace XmlRpc;
#include <iostream>
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<n; ++i)
sum += int(arg1[i]["curly"]);
result = sum;
}
} arrayOfStructsTest(&s);
// This handler takes a single parameter, a string, that contains any number of predefined
// entities, namely <, >, &, ' 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<n; ++i)
switch (arg[i])
{
case '<': ++ctLeftAngleBrackets; break;
case '>': ++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 <i4>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];