/indra/llcommon/tests/llbase64_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 77 lines · 38 code · 13 blank · 26 comment · 4 complexity · a00c6f49cc5ad25da55f370c636a3eb5 MD5 · raw file

  1. /**
  2. * @file llbase64_test.cpp
  3. * @author James Cook
  4. * @date 2007-02-04
  5. *
  6. * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #include <string>
  28. #include "linden_common.h"
  29. #include "../llbase64.h"
  30. #include "../lluuid.h"
  31. #include "../test/lltut.h"
  32. namespace tut
  33. {
  34. struct base64_data
  35. {
  36. };
  37. typedef test_group<base64_data> base64_test;
  38. typedef base64_test::object base64_object;
  39. tut::base64_test base64("LLBase64");
  40. template<> template<>
  41. void base64_object::test<1>()
  42. {
  43. std::string result;
  44. result = LLBase64::encode(NULL, 0);
  45. ensure("encode nothing", (result == "") );
  46. LLUUID nothing;
  47. result = LLBase64::encode(&nothing.mData[0], UUID_BYTES);
  48. ensure("encode blank uuid",
  49. (result == "AAAAAAAAAAAAAAAAAAAAAA==") );
  50. LLUUID id("526a1e07-a19d-baed-84c4-ff08a488d15e");
  51. result = LLBase64::encode(&id.mData[0], UUID_BYTES);
  52. ensure("encode random uuid",
  53. (result == "UmoeB6Gduu2ExP8IpIjRXg==") );
  54. }
  55. template<> template<>
  56. void base64_object::test<2>()
  57. {
  58. std::string result;
  59. U8 blob[40] = { 115, 223, 172, 255, 140, 70, 49, 125, 236, 155, 45, 199, 101, 17, 164, 131, 230, 19, 80, 64, 112, 53, 135, 98, 237, 12, 26, 72, 126, 14, 145, 143, 118, 196, 11, 177, 132, 169, 195, 134 };
  60. result = LLBase64::encode(&blob[0], 40);
  61. ensure("encode 40 bytes",
  62. (result == "c9+s/4xGMX3smy3HZRGkg+YTUEBwNYdi7QwaSH4OkY92xAuxhKnDhg==") );
  63. }
  64. }