File: test_enforce.cpp

package info (click to toggle)
exiv2 0.27.3-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 54,956 kB
  • sloc: cpp: 80,713; python: 4,360; sh: 1,497; makefile: 320; javascript: 237; awk: 92; ansic: 78; sed: 16
file content (27 lines) | stat: -rw-r--r-- 931 bytes parent folder | download
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
#include <exiv2/exiv2.hpp>
#include <enforce.hpp>

#include "gtestwrapper.h"

#include <stdexcept>

TEST(enforce, errMessage)
{
    try {
        enforce(false, Exiv2::kerErrorMessage, "an error occurred");
    } catch (const Exiv2::Error& e) {
        ASSERT_STREQ(e.what(), "an error occurred");
    }
}

TEST(enforce, exceptionThrown)
{
    ASSERT_NO_THROW(enforce(true, Exiv2::kerErrorMessage));

    ASSERT_THROW(enforce(false, Exiv2::kerErrorMessage), Exiv2::Error);
    ASSERT_THROW(enforce<std::overflow_error>(false, "error message"), std::overflow_error);
    ASSERT_THROW(enforce(false, Exiv2::kerMallocFailed), Exiv2::Error);
    ASSERT_THROW(enforce(false, Exiv2::kerErrorMessage, "error message"), Exiv2::Error);
    ASSERT_THROW(enforce(false, Exiv2::kerDataSourceOpenFailed, "path", "strerror"), Exiv2::Error);
    ASSERT_THROW(enforce(false, Exiv2::kerCallFailed, "path", "strerror", "function"), Exiv2::Error);
}