PageRenderTime 43ms CodeModel.GetById 35ms app.highlight 4ms RepoModel.GetById 1ms 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
 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
29#if ! defined(LL_WRAPLLERRS_H)
30#define LL_WRAPLLERRS_H
31
32#include "llerrorcontrol.h"
33
34struct WrapLL_ERRS
35{
36    WrapLL_ERRS():
37        // Resetting Settings discards the default Recorder that writes to
38        // stderr. Otherwise, expected llerrs (LL_ERRS) messages clutter the
39        // console output of successful tests, potentially confusing things.
40        mPriorErrorSettings(LLError::saveAndResetSettings()),
41        // Save shutdown function called by LL_ERRS
42        mPriorFatal(LLError::getFatalFunction())
43    {
44        // Make LL_ERRS call our own operator() method
45        LLError::setFatalFunction(boost::bind(&WrapLL_ERRS::operator(), this, _1));
46    }
47
48    ~WrapLL_ERRS()
49    {
50        LLError::setFatalFunction(mPriorFatal);
51        LLError::restoreSettings(mPriorErrorSettings);
52    }
53
54    struct FatalException: public std::runtime_error
55    {
56        FatalException(const std::string& what): std::runtime_error(what) {}
57    };
58
59    void operator()(const std::string& message)
60    {
61        // Save message for later in case consumer wants to sense the result directly
62        error = message;
63        // Also throw an appropriate exception since calling code is likely to
64        // assume that control won't continue beyond LL_ERRS.
65        throw FatalException(message);
66    }
67
68    std::string error;
69    LLError::Settings* mPriorErrorSettings;
70    LLError::FatalFunction mPriorFatal;
71};
72
73#endif /* ! defined(LL_WRAPLLERRS_H) */