MCPcopy Create free account
hub / github.com/couchbase/fleece / testEncodingMutableDictWithSharedKeys

Function testEncodingMutableDictWithSharedKeys

Tests/MutableTests.cc:583–691  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

581
582
583 static void testEncodingMutableDictWithSharedKeys(SharedKeys *sk) {
584 auto psk = dynamic_cast<PersistentSharedKeys*>(sk);
585 alloc_slice data;
586 if (psk) psk->transactionBegan();
587 {
588 Encoder enc;
589 enc.setSharedKeys(sk);
590 enc.beginDictionary();
591 enc.writeKey("Asleep");
592 enc << "true";
593 enc.writeKey("Mood");
594 enc << "happy";
595 enc.writeKey("Name");
596 enc << "totoro";
597 enc.writeKey("zzShirt Size"); // will not become a shared key due to space
598 enc << "XXXL";
599 enc.writeKey("Vehicle");
600 enc << "catbus";
601 enc.endDictionary();
602 data = enc.finish();
603 }
604 if (psk) {psk->save(); psk->transactionEnded();}
605
606 Retained<Doc> original = new Doc(data, Doc::kTrusted, sk);
607 const Dict* originalDict = original->asDict();
608 std::cerr << "Contents: " << originalDict->toJSON().asString() << "\n";
609 std::cerr << "Original data: " << data << "\n\n";
610 Value::dump(data, std::cerr);
611
612 Retained<MutableDict> update = MutableDict::newDict(originalDict);
613 CHECK(update->count() == 5);
614 update->set("zFriend"_sl, "catbus"_sl);
615 CHECK(update->count() == 6);
616 update->set("Vehicle"_sl, "top"_sl);
617 CHECK(update->count() == 6);
618 update->remove("Asleep"_sl);
619 CHECK(update->count() == 5);
620 update->remove("Asleep"_sl);
621 CHECK(update->count() == 5);
622 update->remove("Q"_sl);
623 CHECK(update->count() == 5);
624
625 {
626 MutableDict::iterator i(update);
627 CHECKiter(i, "Mood", "happy");
628 CHECKiter(i, "Name", "totoro");
629 CHECKiter(i, "Vehicle", "top");
630 CHECKiter(i, "zFriend", "catbus");
631 CHECKiter(i, "zzShirt Size", "XXXL");
632 CHECK(!i);
633 }
634
635 { // Try the same thing but with a Dict iterator:
636 Dict::iterator i(update);
637 CHECKiter(i, "Mood", "happy");
638 CHECKiter(i, "Name", "totoro");
639 CHECKiter(i, "Vehicle", "top");
640 CHECKiter(i, "zFriend", "catbus");

Callers 1

MutableTests.ccFile · 0.85

Calls 15

CHECKiterFunction · 0.85
transactionBeganMethod · 0.80
saveMethod · 0.80
transactionEndedMethod · 0.80
setBaseMethod · 0.80
reuseBaseStringsMethod · 0.80
setSharedKeysMethod · 0.45
beginDictionaryMethod · 0.45
writeKeyMethod · 0.45
endDictionaryMethod · 0.45
finishMethod · 0.45
asDictMethod · 0.45

Tested by

no test coverage detected