Skip to content

Commit f49d547

Browse files
committed
expand tests
1 parent c9b9250 commit f49d547

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

src/test_lib_json/main.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

155157
Json::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+
170210
JSONTEST_FIXTURE_LOCAL(ValueTest, checkNormalizeFloatingPointStr) {
171211
struct TestData {
172212
std::string in;

0 commit comments

Comments
 (0)