PageRenderTime 28ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llcommon/tests/wrapllerrs.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 73 lines | 30 code | 8 blank | 35 comment | 0 complexity | f787e0898d7d4f14532cec8e8de60c96 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file wrapllerrs.h
  3. * @author Nat Goodspeed
  4. * @date 2009-03-11
  5. * @brief Define a class useful for unit tests that engage llerrs (LL_ERRS) functionality
  6. *
  7. * $LicenseInfo:firstyear=2009&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. #if ! defined(LL_WRAPLLERRS_H)
  29. #define LL_WRAPLLERRS_H
  30. #include "llerrorcontrol.h"
  31. struct WrapLL_ERRS
  32. {
  33. WrapLL_ERRS():
  34. // Resetting Settings discards the default Recorder that writes to
  35. // stderr. Otherwise, expected llerrs (LL_ERRS) messages clutter the
  36. // console output of successful tests, potentially confusing things.
  37. mPriorErrorSettings(LLError::saveAndResetSettings()),
  38. // Save shutdown function called by LL_ERRS
  39. mPriorFatal(LLError::getFatalFunction())
  40. {
  41. // Make LL_ERRS call our own operator() method
  42. LLError::setFatalFunction(boost::bind(&WrapLL_ERRS::operator(), this, _1));
  43. }
  44. ~WrapLL_ERRS()
  45. {
  46. LLError::setFatalFunction(mPriorFatal);
  47. LLError::restoreSettings(mPriorErrorSettings);
  48. }
  49. struct FatalException: public std::runtime_error
  50. {
  51. FatalException(const std::string& what): std::runtime_error(what) {}
  52. };
  53. void operator()(const std::string& message)
  54. {
  55. // Save message for later in case consumer wants to sense the result directly
  56. error = message;
  57. // Also throw an appropriate exception since calling code is likely to
  58. // assume that control won't continue beyond LL_ERRS.
  59. throw FatalException(message);
  60. }
  61. std::string error;
  62. LLError::Settings* mPriorErrorSettings;
  63. LLError::FatalFunction mPriorFatal;
  64. };
  65. #endif /* ! defined(LL_WRAPLLERRS_H) */