DryChem 1.0.0
A generic, compile-time C++ toolbox with no dependencies for the modern computational chemistry project.
Loading...
Searching...
No Matches
testFileExceptions.hpp
Go to the documentation of this file.
1// Copyright (c) 2020-2025 Cody R. Drisko. All rights reserved.
2// Licensed under the MIT License. See the LICENSE file in the project root for more information.
3//
4// Name: testFileExceptions.hpp
5// Author: crdrisko
6// Date: 01/03/2021-17:25:28
7// Description: Provides ~100% unit test coverage over all exceptions specifically relating to the file handling library
8
9#ifndef DRYCHEM_COMMON_UTILITIES_LIBS_FILES_TESTS_TESTUTILITIES_TESTFILEEXCEPTIONS_HPP
10#define DRYCHEM_COMMON_UTILITIES_LIBS_FILES_TESTS_TESTUTILITIES_TESTFILEEXCEPTIONS_HPP
11
12#include <sstream>
13
16#include <gtest/gtest.h>
17
18GTEST_TEST(testFileExceptions, fileNotFoundIsAFatalExceptionAndCanTerminateWhenHandled)
19{
20 std::stringstream deathRegex;
21
22 deathRegex << "Common-Utilities Fatal Error: ";
23
24#if GTEST_USES_POSIX_RE
25 deathRegex << "[(]testFileExceptions.hpp: *[0-9]*[)]\n\t";
26#elif GTEST_USES_SIMPLE_RE
27 deathRegex << "\\(testFileExceptions.hpp: \\d*\\)\n\t";
28#endif
29
30 deathRegex << "Could not find the requested file.\n";
31
32 DryChem::FileNotFound exception1 {"Common-Utilities", __FILE__, __LINE__};
33
34 ASSERT_DEATH(
35 {
36 try
37 {
38 throw exception1;
39 }
40 catch (const DryChem::FileNotFound& except)
41 {
42 except.handleErrorWithMessage();
43 }
44 },
45 deathRegex.str());
46}
47
48GTEST_TEST(testFileExceptions, derivedExceptionsCanBeCaughtByBaseFatalException)
49{
50 std::stringstream deathRegex;
51
52 deathRegex << "Common-Utilities Fatal Error: ";
53
54#if GTEST_USES_POSIX_RE
55 deathRegex << "[(]testFileExceptions.hpp: *[0-9]*[)]\n\t";
56#elif GTEST_USES_SIMPLE_RE
57 deathRegex << "\\(testFileExceptions.hpp: \\d*\\)\n\t";
58#endif
59
60 deathRegex << "Could not find the requested file.\n";
61
62 ASSERT_DEATH(
63 {
64 try
65 {
66 throw DryChem::FileNotFound("Common-Utilities", __FILE__, __LINE__);
67 }
68 catch (const DryChem::FatalException& except)
69 {
70 except.handleErrorWithMessage();
71 }
72 },
73 deathRegex.str());
74}
75
76#endif
GTEST_TEST(testFileExceptions, fileNotFoundIsAFatalExceptionAndCanTerminateWhenHandled)
Definition testFileExceptions.hpp:18