testXMLSafe.cxx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include <cmXMLSafe.h>
  11. #include "cmStandardIncludes.h"
  12. struct test_pair
  13. {
  14. const char* in;
  15. const char* out;
  16. };
  17. static test_pair const pairs[] = {
  18. { "copyright \xC2\xA9", "copyright \xC2\xA9" },
  19. { "form-feed \f", "form-feed [NON-XML-CHAR-0xC]" },
  20. { "angles <>", "angles &lt;&gt;" },
  21. { "ampersand &", "ampersand &amp;" },
  22. { "bad-byte \x80", "bad-byte [NON-UTF-8-BYTE-0x80]" },
  23. { 0, 0 }
  24. };
  25. int testXMLSafe(int, char* [])
  26. {
  27. int result = 0;
  28. for (test_pair const* p = pairs; p->in; ++p) {
  29. cmXMLSafe xs(p->in);
  30. std::ostringstream oss;
  31. oss << xs;
  32. std::string out = oss.str();
  33. if (out != p->out) {
  34. printf("expected [%s], got [%s]\n", p->out, out.c_str());
  35. result = 1;
  36. }
  37. }
  38. return result;
  39. }