@@ -378,6 +378,78 @@ TEST(SimJson, JsonStoreString) {
378378})" );
379379}
380380
381+ TEST (SimJson, JsonStoreString16) {
382+ JsonValueU json {
383+ {u" p1" , 1 },
384+ {u" p3" _h, true },
385+ {u" p2" _h, 2 },
386+ {u" p4" _h, {1 , 2 , false , Json::null, u" test\n test\x01 " , Json::emptyObject, Json::emptyArray}}
387+ };
388+ EXPECT_EQ (stringu{json.store (false , true )}, uR"( {"p1":1,"p2":2,"p3":true,"p4":[1,2,false,null,"test\ntest\u0001",{},[]]})" );
389+ EXPECT_EQ (stringu{json.store (true , true )}, uR"( {
390+ "p1": 1,
391+ "p2": 2,
392+ "p3": true,
393+ "p4": [
394+ 1,
395+ 2,
396+ false,
397+ null,
398+ "test\ntest\u0001",
399+ {},
400+ []
401+ ]
402+ })" );
403+ }
404+
405+ TEST (SimJson, JsonStoreString32) {
406+ JsonValueUU json {
407+ {U" p1" , 1 },
408+ {U" p3" _h, true },
409+ {U" p2" _h, 2 },
410+ {U" p4" _h, {1 , 2 , false , Json::null, U" test\n test\x01 " , Json::emptyObject, Json::emptyArray}}
411+ };
412+ EXPECT_EQ (stringuu{json.store (false , true )}, UR"( {"p1":1,"p2":2,"p3":true,"p4":[1,2,false,null,"test\ntest\u0001",{},[]]})" );
413+ EXPECT_EQ (stringuu{json.store (true , true )}, UR"( {
414+ "p1": 1,
415+ "p2": 2,
416+ "p3": true,
417+ "p4": [
418+ 1,
419+ 2,
420+ false,
421+ null,
422+ "test\ntest\u0001",
423+ {},
424+ []
425+ ]
426+ })" );
427+ }
428+
429+ TEST (SimJson, JsonStoreStringW) {
430+ JsonValueW json {
431+ {L" p1" , 1 },
432+ {L" p3" _h, true },
433+ {L" p2" _h, 2 },
434+ {L" p4" _h, {1 , 2 , false , Json::null, L" test\n test\x01 " , Json::emptyObject, Json::emptyArray}}
435+ };
436+ EXPECT_EQ (stringw{json.store (false , true )}, LR"( {"p1":1,"p2":2,"p3":true,"p4":[1,2,false,null,"test\ntest\u0001",{},[]]})" );
437+ EXPECT_EQ (stringw{json.store (true , true )}, LR"( {
438+ "p1": 1,
439+ "p2": 2,
440+ "p3": true,
441+ "p4": [
442+ 1,
443+ 2,
444+ false,
445+ null,
446+ "test\ntest\u0001",
447+ {},
448+ []
449+ ]
450+ })" );
451+ }
452+
381453TEST (SimJson, JsonThrow) {
382454 JsonValue val = 10 ;
383455 lstringa<100 > err_descr;
@@ -428,44 +500,35 @@ TEST(SimJson, JsonStdInitMap) {
428500 EXPECT_EQ (json2.type (), Json::Object);
429501 EXPECT_EQ (json2.store (false , true ), " {\" four\" :4,\" one\" :1,\" three\" :3,\" two\" :2}" );
430502}
431- /*
432- stringa getFileContent(stra fileName) {
433- std::ifstream file(fileName, std::ios::binary | std::ios::ate);
434- std::streamsize size = file.tellg();
435- file.seekg(0, std::ios::beg);
436- lstringsa<0> result;
437- file.read(result.reserve(size), size);
438- return result;
439- }
440503
504+ #if 0
441505TEST(SimJson, JsonParseBig) {
442- {
443- stringa content1 = get_file_content("citm_catalog.json");
444- stringa content2 = get_file_content("canada.json");
445- stringa content3 = get_file_content("twitter.json");
446-
447- auto t1 = std::chrono::high_resolution_clock::now();
448-
449- for (size_t idx = 0; idx < 10; idx++) {
450- auto json1 = JsonValue::parse(content1);
451- EXPECT_EQ(std::get<1>(json1), JsonParseResult::Success);
452- auto json2 = JsonValue::parse(content2);
453- EXPECT_EQ(std::get<1>(json2), JsonParseResult::Success);
454- auto json3 = JsonValue::parse(content3);
455- EXPECT_EQ(std::get<1>(json3), JsonParseResult::Success);
456- }
506+ stringa content1 = get_file_content("citm_catalog.json");
507+ stringa content2 = get_file_content("canada.json");
508+ stringa content3 = get_file_content("twitter.json");
509+
510+ auto t1 = std::chrono::high_resolution_clock::now();
511+
512+ for (size_t idx = 0; idx < 10; idx++) {
513+ auto json1 = JsonValue::parse(content1);
514+ EXPECT_EQ(std::get<1>(json1), JsonParseResult::Success);
515+ stringa t = std::get<0>(json1).store(true, false, ' ', 4);
516+ EXPECT_EQ(content1.length(), t.length());
517+ auto json2 = JsonValue::parse(content2);
518+ EXPECT_EQ(std::get<1>(json2), JsonParseResult::Success);
519+ t = std::get<0>(json2).store();
520+ auto json3 = JsonValue::parse(content3);
521+ EXPECT_EQ(std::get<1>(json3), JsonParseResult::Success);
522+ t = std::get<0>(json3).store();
523+ }
457524
458- auto t2 = std::chrono::high_resolution_clock::now();
525+ auto t2 = std::chrono::high_resolution_clock::now();
459526
460- std::chrono::duration<double, std::milli> ms_double = t2 - t1;
527+ std::chrono::duration<double, std::milli> ms_double = t2 - t1;
461528
462- std::cout << "Parse at " << ms_double.count() / 10.0 << std::endl;
529+ std::cout << "Parse and store at " << ms_double.count() / 10.0 << std::endl;
463530
464- //EXPECT_TRUE(json1.is_object());
465- //EXPECT_TRUE(json2.is_object());
466- //EXPECT_TRUE(json3.is_object());
467- }
468531}
469- */
532+ # endif
470533
471534} // namespace simjson::tests
0 commit comments