@@ -113,13 +113,52 @@ void TestStatusIBErrorToString(nlTestSuite * aSuite, void * aContext)
113
113
}
114
114
#endif // !CHIP_CONFIG_SHORT_ERROR_STR
115
115
116
+ void TestStatusIBEqualityOperator (nlTestSuite * aSuite, void * /* aContext*/ )
117
+ {
118
+ // Equality against self is true.
119
+ StatusIB one;
120
+ NL_TEST_ASSERT (aSuite, one == one);
121
+
122
+ // Default constructors are equal.
123
+ NL_TEST_ASSERT (aSuite, one == StatusIB ());
124
+
125
+ // Different imStatus is not equal.
126
+ StatusIB with_imstatus (Status::Failure);
127
+ NL_TEST_ASSERT (aSuite, one != with_imstatus);
128
+
129
+ // Same imStatus are equal.
130
+ NL_TEST_ASSERT (aSuite, with_imstatus == StatusIB (Status::Failure));
131
+
132
+ // Same imStatus but different clusterStatus are not equal.
133
+ StatusIB with_cluster_status (Status::Failure, /* clusterStatus=*/ 2 );
134
+ NL_TEST_ASSERT (aSuite, with_imstatus != with_cluster_status);
135
+
136
+ // Different imStatus but same clusterStatus are not equal.
137
+ NL_TEST_ASSERT (aSuite, with_cluster_status != StatusIB (Status::Success, /* clusterStatus=*/ 2 ));
138
+
139
+ // Same imStatus and clusterStatus are equal.
140
+ NL_TEST_ASSERT (aSuite, with_cluster_status == StatusIB (Status::Failure, /* clusterStatus=*/ 2 ));
141
+
142
+ // From same CHIP_ERROR are equal.
143
+ StatusIB invalid_argument (CHIP_ERROR_INVALID_ARGUMENT);
144
+ NL_TEST_ASSERT (aSuite, invalid_argument == StatusIB (CHIP_ERROR_INVALID_ARGUMENT));
145
+
146
+ // Different CHIP_ERROR are equal if they are not from kIMClusterStatus or
147
+ // kIMGlobalStatus.
148
+ NL_TEST_ASSERT (aSuite, invalid_argument == StatusIB (CHIP_ERROR_INCORRECT_STATE));
149
+
150
+ // Error never equals NO_ERROR
151
+ NL_TEST_ASSERT (aSuite, invalid_argument != StatusIB (CHIP_NO_ERROR));
152
+ }
153
+
116
154
// clang-format off
117
155
const nlTest sTests [] =
118
156
{
119
157
NL_TEST_DEF (" StatusIBToFromChipError" , TestStatusIBToFromChipError),
120
158
#if !CHIP_CONFIG_SHORT_ERROR_STR
121
159
NL_TEST_DEF (" StatusIBErrorToString" , TestStatusIBErrorToString),
122
160
#endif // !CHIP_CONFIG_SHORT_ERROR_STR
161
+ NL_TEST_DEF (" StatusIBEqualityOperator" , TestStatusIBEqualityOperator),
123
162
NL_TEST_SENTINEL ()
124
163
};
125
164
// clang-format on
0 commit comments