testXMLSafe.cxx 1.3 KB

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