File: TestCommon.hpp

package info (click to toggle)
schroedinger-maeparser 1.3.3-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 356 kB
  • sloc: cpp: 4,182; makefile: 4
file content (37 lines) | stat: -rw-r--r-- 782 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once

#include <string>
#include <sstream>

#include <boost/test/unit_test.hpp>

template <class T> class CheckExceptionMsg
{
  public:
    CheckExceptionMsg(std::string msg)
        : m_expected(std::move(msg)), m_match(false)
    {
    }

    ~CheckExceptionMsg()
    {
        // This message should be printer after BOOST_REQUIRE_EXCEPTION's
        std::stringstream ss;
        ss << '\"' << m_expected << "\" not found in \"" << m_message << '\"';

        BOOST_CHECK_MESSAGE(m_match, ss.str());
    }

    bool operator()(const T& exc)
    {
        m_message = exc.what();
        m_match = m_message.find(m_expected) != std::string::npos;

        return m_match;
    }

  private:
    const std::string m_expected;
    std::string m_message;
    bool m_match;
};