# HG changeset patch # User Sebastien Jodogne # Date 1763203779 -3600 # Node ID c557f6bdcbfd27ef2ef4447b053603f145586020 # Parent 9aa989b6ce3148315f6956d1ea51f36f40b6e33d added unit test for ErrorPayload diff -r 9aa989b6ce31 -r c557f6bdcbfd OrthancFramework/Sources/OrthancException.h --- 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); diff -r 9aa989b6ce31 -r c557f6bdcbfd OrthancFramework/UnitTestsSources/FrameworkTests.cpp --- 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()); +}