@@ -150,6 +150,8 @@ struct ValueTest : JsonTest::TestCase {
150150 // / Normalize the representation of floating-point number by stripped leading
151151 // / 0 in exponent.
152152 static Json::String normalizeFloatingPointStr (const Json::String& s);
153+
154+ void runCZStringTests ();
153155};
154156
155157Json::String ValueTest::normalizeFloatingPointStr (const Json::String& s) {
@@ -167,6 +169,44 @@ Json::String ValueTest::normalizeFloatingPointStr(const Json::String& s) {
167169 return normalized + exponent;
168170}
169171
172+ void ValueTest::runCZStringTests () {
173+ // 1. Copy Constructor (Index)
174+ Json::Value::CZString idx1 (123 );
175+ Json::Value::CZString idx2 (idx1);
176+ JSONTEST_ASSERT_EQUAL (idx2.index (), 123 );
177+
178+ // 2. Move Constructor (Index)
179+ Json::Value::CZString idx3 (std::move (idx1));
180+ JSONTEST_ASSERT_EQUAL (idx3.index (), 123 );
181+
182+ // 3. Move Assignment (Index)
183+ Json::Value::CZString idx4 (456 );
184+ idx4 = std::move (idx3);
185+ JSONTEST_ASSERT_EQUAL (idx4.index (), 123 );
186+
187+ // 4. Copy Constructor (String)
188+ Json::Value::CZString str1 (" param" , 5 ,
189+ Json::Value::CZString::duplicateOnCopy);
190+ Json::Value::CZString str2 ((str1)); // copy makes it duplicate (owning)
191+ JSONTEST_ASSERT_STRING_EQUAL (str2.data (), " param" );
192+
193+ // 5. Move Constructor (String)
194+ // Move from Owning string (str2)
195+ Json::Value::CZString str3 (std::move (str2));
196+ JSONTEST_ASSERT_STRING_EQUAL (str3.data (), " param" );
197+
198+ // 6. Move Assignment (String)
199+ Json::Value::CZString str4 (" other" , 5 ,
200+ Json::Value::CZString::duplicateOnCopy);
201+ Json::Value::CZString str5 ((str4)); // owning "other"
202+ // Move-assign owning "param" (str3) into owning "other" (str5)
203+ // This verifies we don't leak "other" (if fixed) and correctly take "param"
204+ str5 = std::move (str3);
205+ JSONTEST_ASSERT_STRING_EQUAL (str5.data (), " param" );
206+ }
207+
208+ JSONTEST_FIXTURE_LOCAL (ValueTest, CZStringCoverage) { runCZStringTests (); }
209+
170210JSONTEST_FIXTURE_LOCAL (ValueTest, checkNormalizeFloatingPointStr) {
171211 struct TestData {
172212 std::string in;
0 commit comments