File tree Expand file tree Collapse file tree
test/unittest/return_code Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,10 +69,18 @@ class ReturnCode
6969 bool operator ==(
7070 const ReturnCode& c) const noexcept ;
7171
72+ CPP_UTILS_DllAPI
73+ bool operator ==(
74+ const ReturnCodeValue& c) const noexcept ;
75+
7276 CPP_UTILS_DllAPI
7377 bool operator !=(
7478 const ReturnCode& c) const noexcept ;
7579
80+ CPP_UTILS_DllAPI
81+ bool operator !=(
82+ const ReturnCodeValue& c) const noexcept ;
83+
7684 CPP_UTILS_DllAPI
7785 bool operator <(
7886 const ReturnCode& other) const noexcept ;
@@ -97,8 +105,28 @@ class ReturnCode
97105 std::ostream& os,
98106 const ReturnCode& code);
99107
108+ CPP_UTILS_DllAPI
109+ friend bool operator ==(
110+ const ReturnCodeValue& lhs,
111+ const ReturnCode& rhs) noexcept ;
112+
113+ CPP_UTILS_DllAPI
114+ friend bool operator !=(
115+ const ReturnCodeValue& lhs,
116+ const ReturnCode& rhs) noexcept ;
117+
100118};
101119
120+ CPP_UTILS_DllAPI
121+ bool operator ==(
122+ const ReturnCode::ReturnCodeValue& lhs,
123+ const ReturnCode& rhs) noexcept ;
124+
125+ CPP_UTILS_DllAPI
126+ bool operator !=(
127+ const ReturnCode::ReturnCodeValue& lhs,
128+ const ReturnCode& rhs) noexcept ;
129+
102130// ! \c ReturnCode to stream serializator
103131CPP_UTILS_DllAPI
104132std::ostream& operator <<(
Original file line number Diff line number Diff line change @@ -78,12 +78,24 @@ bool ReturnCode::operator ==(
7878 return value_ == c.value_ ;
7979}
8080
81+ bool ReturnCode::operator ==(
82+ const ReturnCode::ReturnCodeValue& c) const noexcept
83+ {
84+ return value_ == c;
85+ }
86+
8187bool ReturnCode::operator !=(
8288 const ReturnCode& c) const noexcept
8389{
8490 return value_ != c.value_ ;
8591}
8692
93+ bool ReturnCode::operator !=(
94+ const ReturnCode::ReturnCodeValue& c) const noexcept
95+ {
96+ return value_ != c;
97+ }
98+
8799bool ReturnCode::operator <(
88100 const ReturnCode& other) const noexcept
89101{
@@ -95,6 +107,20 @@ bool ReturnCode::operator !() const noexcept
95107 return value_ != ReturnCode::RETCODE_OK;
96108}
97109
110+ bool operator ==(
111+ const ReturnCode::ReturnCodeValue& lhs,
112+ const ReturnCode& rhs) noexcept
113+ {
114+ return rhs == lhs;
115+ }
116+
117+ bool operator !=(
118+ const ReturnCode::ReturnCodeValue& lhs,
119+ const ReturnCode& rhs) noexcept
120+ {
121+ return rhs != lhs;
122+ }
123+
98124const std::map<ReturnCode::ReturnCodeValue, std::string> ReturnCode::to_string_conversion_ =
99125{
100126 {ReturnCode::RETCODE_OK, " Ok" },
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ set(TEST_SOURCES
2121
2222set (TEST_LIST
2323 serializator
24+ compare_against_return_code_value_rhs
25+ compare_against_return_code_value_lhs
2426 )
2527
2628set (TEST_EXTRA_LIBRARIES
Original file line number Diff line number Diff line change @@ -43,6 +43,34 @@ TEST(ReturnCodeTest, serializator)
4343 }
4444}
4545
46+ /* *
47+ * Test ReturnCode compares directly against ReturnCodeValue values.
48+ */
49+ TEST (ReturnCodeTest, compare_against_return_code_value_rhs)
50+ {
51+ // Right side of the comparation
52+
53+ ReturnCode from_fastdds (fastdds::dds::RETCODE_NO_DATA);
54+
55+ ASSERT_TRUE (from_fastdds == ReturnCode::RETCODE_NO_DATA);
56+ ASSERT_FALSE (from_fastdds == ReturnCode::RETCODE_ERROR);
57+ ASSERT_TRUE (from_fastdds != ReturnCode::RETCODE_ERROR);
58+ }
59+
60+ /* *
61+ * Test ReturnCodeValue compares directly against ReturnCode from lhs.
62+ */
63+ TEST (ReturnCodeTest, compare_against_return_code_value_lhs)
64+ {
65+ // Left side of the comparation
66+
67+ ReturnCode ret (ReturnCode::RETCODE_NOT_ENABLED);
68+
69+ ASSERT_TRUE (ReturnCode::RETCODE_NOT_ENABLED == ret);
70+ ASSERT_TRUE (ReturnCode::RETCODE_OK != ret);
71+ ASSERT_FALSE (ReturnCode::RETCODE_OK == ret);
72+ }
73+
4674int main (
4775 int argc,
4876 char ** argv)
You can’t perform that action at this time.
0 commit comments