Skip to content

Commit cd5a04e

Browse files
committed
added more exception tests
1 parent 8668815 commit cd5a04e

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

test/HephCommon/ExceptionTest.cpp

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "gtest/gtest.h"
22
#include "Exceptions/Exception.h"
33
#include "Exceptions/ExceptionEventArgs.h"
4+
#include "Exceptions/ExternalException.h"
45
#include "Exceptions/InsufficientMemoryException.h"
56
#include "Exceptions/InvalidArgumentException.h"
67
#include "Exceptions/InvalidOperationException.h"
@@ -60,33 +61,15 @@ TEST_F(ExceptionTest, Handler)
6061

6162
TEST_F(ExceptionTest, GetName)
6263
{
63-
std::vector<std::string> names;
64-
65-
auto test = [&names](const std::string& name)
66-
{
67-
bool exists = false;
68-
69-
for (const std::string& n : names)
70-
{
71-
if (n == name)
72-
{
73-
exists = true;
74-
EXPECT_NE(n, name) << "Duplicate exception name \"" << n << "\"";
75-
}
76-
}
77-
78-
if (!exists)
79-
names.push_back(name);
80-
};
81-
82-
test(Exception().GetName());
83-
test(InsufficientMemoryException().GetName());
84-
test(InvalidArgumentException().GetName());
85-
test(InvalidOperationException().GetName());
86-
test(NotFoundException().GetName());
87-
test(NotImplementedException().GetName());
88-
test(NotSupportedException().GetName());
89-
test(TimeoutException().GetName());
64+
EXPECT_EQ(Exception().GetName(), "Exception");
65+
EXPECT_EQ(ExternalException().GetName(), "ExternalException");
66+
EXPECT_EQ(InsufficientMemoryException().GetName(), "InsufficientMemoryException");
67+
EXPECT_EQ(InvalidArgumentException().GetName(), "InvalidArgumentException");
68+
EXPECT_EQ(InvalidOperationException().GetName(), "InvalidOperationException");
69+
EXPECT_EQ(NotFoundException().GetName(), "NotFoundException");
70+
EXPECT_EQ(NotImplementedException().GetName(), "NotImplementedException");
71+
EXPECT_EQ(NotSupportedException().GetName(), "NotSupportedException");
72+
EXPECT_EQ(TimeoutException().GetName(), "TimeoutException");
9073
}
9174

9275
TEST_F(ExceptionTest, GetExceptions)
@@ -112,4 +95,14 @@ TEST_F(ExceptionTest, GetLastException)
11295
Exception::OnException = &Handler2;
11396
HEPH_RAISE_EXCEPTION(nullptr, InvalidArgumentException());
11497
CHECK_EX_TYPE(Exception::GetLastException().get(), InvalidArgumentException);
98+
}
99+
100+
TEST_F(ExceptionTest, ExternalException)
101+
{
102+
ExternalException e("method", "message", "externalSource", "externalMessage");
103+
104+
EXPECT_EQ(e.GetMethod(), "method");
105+
EXPECT_EQ(e.GetMessage(), "message");
106+
EXPECT_EQ(e.GetExternalSource(), "externalSource");
107+
EXPECT_EQ(e.GetExternalMessage(), "externalMessage");
115108
}

0 commit comments

Comments
 (0)