/indra/llcommon/tests/stringize_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 104 lines · 53 code · 10 blank · 41 comment · 0 complexity · 2cfaf1b420f60ad342d65ee400374c28 MD5 · raw file

  1. /**
  2. * @file stringize_test.cpp
  3. * @author Nat Goodspeed
  4. * @date 2008-09-12
  5. * @brief Test of stringize.h
  6. *
  7. * $LicenseInfo:firstyear=2008&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. /*==========================================================================*|
  29. #if LL_WINDOWS
  30. #pragma warning (disable : 4675) // "resolved by ADL" -- just as I want!
  31. #endif
  32. |*==========================================================================*/
  33. // STL headers
  34. #include <iomanip>
  35. // Precompiled header
  36. #include "linden_common.h"
  37. // associated header
  38. #include "../stringize.h"
  39. // std headers
  40. // external library headers
  41. // other Linden headers
  42. #include "../llsd.h"
  43. #include "../test/lltut.h"
  44. namespace tut
  45. {
  46. struct stringize_data
  47. {
  48. stringize_data():
  49. c('c'),
  50. s(17),
  51. i(34),
  52. l(68),
  53. f(3.14159265358979f),
  54. d(3.14159265358979),
  55. // Including a space differentiates this from
  56. // boost::lexical_cast<std::string>, which doesn't handle embedded
  57. // spaces so well.
  58. abc("abc def")
  59. {
  60. llsd["i"] = i;
  61. llsd["d"] = d;
  62. llsd["abc"] = abc;
  63. }
  64. char c;
  65. short s;
  66. int i;
  67. long l;
  68. float f;
  69. double d;
  70. std::string abc;
  71. LLSD llsd;
  72. };
  73. typedef test_group<stringize_data> stringize_group;
  74. typedef stringize_group::object stringize_object;
  75. tut::stringize_group strzgrp("stringize_h");
  76. template<> template<>
  77. void stringize_object::test<1>()
  78. {
  79. ensure_equals(stringize(c), "c");
  80. ensure_equals(stringize(s), "17");
  81. ensure_equals(stringize(i), "34");
  82. ensure_equals(stringize(l), "68");
  83. ensure_equals(stringize(f), "3.14159");
  84. ensure_equals(stringize(d), "3.14159");
  85. ensure_equals(stringize(abc), "abc def");
  86. ensure_equals(stringize(llsd), "{'abc':'abc def','d':r3.14159,'i':i34}");
  87. }
  88. template<> template<>
  89. void stringize_object::test<2>()
  90. {
  91. ensure_equals(STRINGIZE("c is " << c), "c is c");
  92. ensure_equals(STRINGIZE(std::setprecision(4) << d), "3.142");
  93. }
  94. } // namespace tut