PageRenderTime 61ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/test/lltranscode_tut.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 89 lines | 50 code | 12 blank | 27 comment | 0 complexity | f29a1f3a9878dab0f9b9d7e9e58ec3e6 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llscriptresource_tut.cpp
  3. * @brief Test LLScriptResource
  4. *
  5. * $LicenseInfo:firstyear=2008&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. //#include <tut/tut.h>
  27. #include "linden_common.h"
  28. #include "lltut.h"
  29. #include "../newsim/lltranscode.cpp" // include TU to pull in newsim implementation.
  30. static const char test_utf8[] = "Edelwei\xc3\x9f";
  31. static const char test_utf7[] = "Edelwei+AN8-";
  32. static const char test_latin1[] = "Edelwei\xdf";
  33. static const char test_latin2[] = "Edelwei\xdf";
  34. namespace tut
  35. {
  36. class LLTranscodeTestData
  37. {
  38. };
  39. typedef test_group<LLTranscodeTestData> LLTranscodeTestGroup;
  40. typedef LLTranscodeTestGroup::object LLTranscodeTestObject;
  41. LLTranscodeTestGroup transcodeTestGroup("transcode");
  42. template<> template<>
  43. void LLTranscodeTestObject::test<1>()
  44. {
  45. #if LL_WINDOWS
  46. skip("Windows APR libs can't transcode.");
  47. #endif
  48. // Test utf8
  49. std::stringstream input;
  50. std::stringstream output;
  51. input.str(test_utf7);
  52. output.clear();
  53. LLTranscode::transcode("charset=UTF-7", input, output);
  54. ensure_equals("UTF-7 to UTF-8 transcoding", output.str(),
  55. std::string(test_utf8));
  56. input.str(test_latin1);
  57. output.clear();
  58. LLTranscode::transcode("", input, output);
  59. ensure_equals("Default (latin_1) to UTF8 transcoding", output.str(),
  60. std::string(test_utf8));
  61. input.str(test_latin1);
  62. output.clear();
  63. LLTranscode::transcode("charset=iso-8859-1", input, output);
  64. ensure_equals("latin_1 (ISO-8859-1) to UTF8 transcoding", output.str(),
  65. std::string(test_utf8));
  66. input.str(test_latin2);
  67. output.clear();
  68. LLTranscode::transcode("charset=iso-8859-2", input, output);
  69. ensure_equals("latin_2 (ISO-8859-2) to UTF8 transcoding", output.str(),
  70. std::string(test_utf8));
  71. input.str(test_utf8);
  72. output.clear();
  73. LLTranscode::transcode("charset=utf-8", input, output);
  74. ensure_equals("UTF8 to UTF8 transcoding", output.str(),
  75. std::string(test_utf8));
  76. }
  77. }