Mercurial > hg > orthanc
changeset 6420:c557f6bdcbfd default
added unit test for ErrorPayload
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Sat, 15 Nov 2025 11:49:39 +0100 |
| parents | 9aa989b6ce31 |
| children | d0920767534e 36aff9f84264 |
| files | OrthancFramework/Sources/OrthancException.h OrthancFramework/UnitTestsSources/FrameworkTests.cpp |
| diffstat | 2 files changed, 62 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancFramework/Sources/OrthancException.h Sat Nov 15 11:00:42 2025 +0100 +++ b/OrthancFramework/Sources/OrthancException.h Sat Nov 15 11:49:39 2025 +0100 @@ -87,6 +87,7 @@ ErrorPayload payload_; public: + // WARNING: Do not add additional constructors, to prevent ambiguities in overloading OrthancException(const OrthancException& other); explicit OrthancException(ErrorCode errorCode);
--- a/OrthancFramework/UnitTestsSources/FrameworkTests.cpp Sat Nov 15 11:00:42 2025 +0100 +++ b/OrthancFramework/UnitTestsSources/FrameworkTests.cpp Sat Nov 15 11:49:39 2025 +0100 @@ -1793,3 +1793,64 @@ ASSERT_FALSE(Toolbox::IsVersionAbove("18.19.20", 18, 20, 0)); ASSERT_FALSE(Toolbox::IsVersionAbove("18.19.20", 19, 0, 0)); } + + +TEST(OrthancException, ErrorPayload) +{ + ErrorPayload b; + + { + ErrorPayload a; + ASSERT_THROW(a.SetContent(ErrorPayloadType_None, ""), OrthancException); + ASSERT_FALSE(a.HasContent()); + ASSERT_THROW(a.GetType(), OrthancException); + ASSERT_THROW(a.GetContent(), OrthancException); + + { + ErrorPayload c(a); + ASSERT_FALSE(c.HasContent()); + ASSERT_THROW(c.GetType(), OrthancException); + ASSERT_THROW(c.GetContent(), OrthancException); + } + + b = a; + } + + ASSERT_FALSE(b.HasContent()); + ASSERT_THROW(b.GetType(), OrthancException); + ASSERT_THROW(b.GetContent(), OrthancException); + + { + ErrorPayload a; + a.SetContent(ErrorPayloadType_Dimse, "Hello"); + ASSERT_TRUE(a.HasContent()); + ASSERT_EQ(ErrorPayloadType_Dimse, a.GetType()); + ASSERT_TRUE(a.GetContent().isString()); + ASSERT_EQ("Hello", a.GetContent().asString()); + + { + ErrorPayload c(a); + ASSERT_TRUE(c.HasContent()); + ASSERT_EQ(ErrorPayloadType_Dimse, c.GetType()); + ASSERT_TRUE(c.GetContent().isString()); + ASSERT_EQ("Hello", c.GetContent().asString()); + + c = ErrorPayload(); + ASSERT_FALSE(c.HasContent()); + ASSERT_THROW(c.GetType(), OrthancException); + ASSERT_THROW(c.GetContent(), OrthancException); + } + + b = a; + + a.ClearContent(); + ASSERT_FALSE(a.HasContent()); + ASSERT_THROW(a.GetType(), OrthancException); + ASSERT_THROW(a.GetContent(), OrthancException); + } + + ASSERT_TRUE(b.HasContent()); + ASSERT_EQ(ErrorPayloadType_Dimse, b.GetType()); + ASSERT_TRUE(b.GetContent().isString()); + ASSERT_EQ("Hello", b.GetContent().asString()); +}
