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 "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. {
  30. cmXMLSafe xs(p->in);
  31. std::ostringstream oss;
  32. oss << xs;
  33. std::string out = oss.str();
  34. if(out != p->out)
  35. {
  36. printf("expected [%s], got [%s]\n", p->out, out.c_str());
  37. result = 1;
  38. }
  39. }
  40. return result;
  41. }