testXMLSafe.cxx 955 B

1234567891011121314151617181920212223242526272829303132333435363738
  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 "cmXMLSafe.h"
  4. #include <sstream>
  5. #include <stdio.h>
  6. #include <string>
  7. struct test_pair
  8. {
  9. const char* in;
  10. const char* out;
  11. };
  12. static test_pair const pairs[] = {
  13. { "copyright \xC2\xA9", "copyright \xC2\xA9" },
  14. { "form-feed \f", "form-feed [NON-XML-CHAR-0xC]" },
  15. { "angles <>", "angles &lt;&gt;" },
  16. { "ampersand &", "ampersand &amp;" },
  17. { "bad-byte \x80", "bad-byte [NON-UTF-8-BYTE-0x80]" },
  18. { CM_NULLPTR, CM_NULLPTR }
  19. };
  20. int testXMLSafe(int /*unused*/, char* /*unused*/ [])
  21. {
  22. int result = 0;
  23. for (test_pair const* p = pairs; p->in; ++p) {
  24. cmXMLSafe xs(p->in);
  25. std::ostringstream oss;
  26. oss << xs;
  27. std::string out = oss.str();
  28. if (out != p->out) {
  29. printf("expected [%s], got [%s]\n", p->out, out.c_str());
  30. result = 1;
  31. }
  32. }
  33. return result;
  34. }