diff options
| author | Andrey Kleshchev <117672381+akleshchev@users.noreply.github.com> | 2026-05-08 17:56:00 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-05-08 17:56:00 +0300 |
| commit | dfeed0c398f961bce8cdbc24fbfc1cab758a9fd4 (patch) | |
| tree | 7b02515451af7c4af2b5e72c248a1dc9616205bd /indra/llcommon/tests/llsdserialize_test.cpp | |
| parent | d2a3a157a023f8608c44dfd3b07e8986df88c416 (diff) | |
#5777 Exception handling for an LLSD formatter
Attempt to catch an inventory and name cache shutdown crash that we see in bugsplat.
Diffstat (limited to 'indra/llcommon/tests/llsdserialize_test.cpp')
| -rw-r--r-- | indra/llcommon/tests/llsdserialize_test.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/indra/llcommon/tests/llsdserialize_test.cpp b/indra/llcommon/tests/llsdserialize_test.cpp index fae9f7023f..f52b3fec71 100644 --- a/indra/llcommon/tests/llsdserialize_test.cpp +++ b/indra/llcommon/tests/llsdserialize_test.cpp @@ -243,6 +243,58 @@ namespace tut xml_test("binary", expected); } + template<> template<> + void sd_xml_object::test<7>() + { + // Test that stream state (precision and exceptions) is correctly restored after format() + { + std::ostringstream ostr; + + // Set custom precision + ostr.precision(10); + + // Set some exception bits + ostr.exceptions(std::ios_base::badbit); + std::ios_base::iostate original_exceptions = ostr.exceptions(); + + // Format some LLSD data + mSD = 3.141592653589793; + S32 result = mFormatter->format(mSD, ostr); + + // Verify formatting succeeded + ensure("format should succeed", result >= 0); + + // Verify precision was restored + ensure_equals("precision should be restored", + ostr.precision(), 10); + + // Verify exceptions were restored + ensure_equals("exception bits should be restored", + ostr.exceptions(), original_exceptions); + } + + // Test with no bits set + { + std::ostringstream ostr; + ostr.precision(5); + std::ios_base::iostate original_exceptions = ostr.exceptions(); // 0 + + mSD = "test"; + S32 result = mFormatter->format(mSD, ostr); + + // Verify formatting succeeded + ensure("format should succeed", result >= 0); + + // Verify exceptions were removed + ensure_equals("exception bits should remain unchanged", + ostr.exceptions(), original_exceptions); + + // Verify precision was still restored even on failure + ensure_equals("precision should be restored even on stream failure", + ostr.precision(), (std::streamsize)5); + } + } + class TestLLSDSerializeData { public: |
