2016-10-30 18:24:19 +01:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2017-04-14 19:02:05 +02:00
|
|
|
|
2018-01-26 17:06:56 +01:00
|
|
|
#include "cmConfigure.h" // IWYU pragma: keep
|
2010-03-17 14:00:29 +02:00
|
|
|
|
2016-10-30 18:24:19 +01:00
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
2010-03-17 14:00:29 +02:00
|
|
|
|
2020-02-01 23:06:01 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2017-04-14 19:02:05 +02:00
|
|
|
#include "cmXMLSafe.h"
|
|
|
|
|
2010-03-17 14:00:29 +02:00
|
|
|
struct test_pair
|
|
|
|
{
|
|
|
|
const char* in;
|
|
|
|
const char* out;
|
|
|
|
};
|
|
|
|
|
|
|
|
static test_pair const pairs[] = {
|
2016-07-09 11:21:54 +02:00
|
|
|
{ "copyright \xC2\xA9", "copyright \xC2\xA9" },
|
|
|
|
{ "form-feed \f", "form-feed [NON-XML-CHAR-0xC]" },
|
|
|
|
{ "angles <>", "angles <>" },
|
|
|
|
{ "ampersand &", "ampersand &" },
|
|
|
|
{ "bad-byte \x80", "bad-byte [NON-UTF-8-BYTE-0x80]" },
|
2018-01-26 17:06:56 +01:00
|
|
|
{ nullptr, nullptr }
|
2010-03-17 14:00:29 +02:00
|
|
|
};
|
|
|
|
|
2023-05-23 16:38:00 +02:00
|
|
|
int testXMLSafe(int /*unused*/, char* /*unused*/[])
|
2010-03-17 14:00:29 +02:00
|
|
|
{
|
|
|
|
int result = 0;
|
2016-07-09 11:21:54 +02:00
|
|
|
for (test_pair const* p = pairs; p->in; ++p) {
|
2010-03-17 14:00:29 +02:00
|
|
|
cmXMLSafe xs(p->in);
|
2015-04-27 22:25:09 +02:00
|
|
|
std::ostringstream oss;
|
2010-03-17 14:00:29 +02:00
|
|
|
oss << xs;
|
|
|
|
std::string out = oss.str();
|
2016-07-09 11:21:54 +02:00
|
|
|
if (out != p->out) {
|
2010-03-17 14:00:29 +02:00
|
|
|
printf("expected [%s], got [%s]\n", p->out, out.c_str());
|
|
|
|
result = 1;
|
|
|
|
}
|
2016-07-09 11:21:54 +02:00
|
|
|
}
|
2010-03-17 14:00:29 +02:00
|
|
|
return result;
|
|
|
|
}
|