json_saveload_ut.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #include <library/cpp/json/json_value.h>
  2. #include <library/cpp/testing/unittest/registar.h>
  3. #include <util/stream/buffer.h>
  4. #include <util/generic/buffer.h>
  5. #include <util/ysaveload.h>
  6. Y_UNIT_TEST_SUITE(JsonSaveLoad) {
  7. Y_UNIT_TEST(Serialize) {
  8. NJson::TJsonValue expected;
  9. expected["ui64"] = ui64(1);
  10. expected["i64"] = i64(2);
  11. expected["double"] = 2.0;
  12. expected["string"] = "text";
  13. expected["map"] = expected;
  14. expected["array"].SetType(NJson::JSON_ARRAY).GetArraySafe().emplace_back(expected);
  15. expected["null"].SetType(NJson::JSON_NULL);
  16. expected["undefined"].SetType(NJson::JSON_UNDEFINED);
  17. TBuffer buffer;
  18. {
  19. TBufferOutput output(buffer);
  20. ::Save(&output, expected);
  21. }
  22. NJson::TJsonValue load;
  23. {
  24. TBufferInput input(buffer);
  25. ::Load(&input, load);
  26. }
  27. UNIT_ASSERT_EQUAL_C(expected, load, "expected: " << expected << ", got: " << load);
  28. }
  29. }