testXMLSafe.cxx 997 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmConfigure.h" // IWYU pragma: keep
  4. #include <sstream>
  5. #include <stdio.h>
  6. #include <string>
  7. #include "cmXMLSafe.h"
  8. struct test_pair
  9. {
  10. const char* in;
  11. const char* out;
  12. };
  13. static test_pair const pairs[] = {
  14. { "copyright \xC2\xA9", "copyright \xC2\xA9" },
  15. { "form-feed \f", "form-feed [NON-XML-CHAR-0xC]" },
  16. { "angles <>", "angles &lt;&gt;" },
  17. { "ampersand &", "ampersand &amp;" },
  18. { "bad-byte \x80", "bad-byte [NON-UTF-8-BYTE-0x80]" },
  19. { nullptr, nullptr }
  20. };
  21. int testXMLSafe(int /*unused*/, char* /*unused*/ [])
  22. {
  23. int result = 0;
  24. for (test_pair const* p = pairs; p->in; ++p) {
  25. cmXMLSafe xs(p->in);
  26. std::ostringstream oss;
  27. oss << xs;
  28. std::string out = oss.str();
  29. if (out != p->out) {
  30. printf("expected [%s], got [%s]\n", p->out, out.c_str());
  31. result = 1;
  32. }
  33. }
  34. return result;
  35. }