MCPcopy Create free account
hub / github.com/Tencent/MMKV / testBackup

Function testBackup

POSIX/demo/demo.cpp:495–521  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

493}
494
495void testBackup() {
496 string rootDir = "/tmp/mmkv_backup";
497 string mmapID = "test/Encrypt";
498 string aesKey = "cryptKey";
499 auto ret = MMKV::backupOneToDirectory(mmapID, rootDir);
500 printf("backup one return %d\n", ret);
501 if (ret) {
502 auto mmkv = MMKV::mmkvWithID(mmapID, MMKV_SINGLE_PROCESS, &aesKey, &rootDir);
503 cout << "after backup allKeys: " << ::to_string(mmkv->allKeys()) << endl;
504 }
505
506 auto count = MMKV::backupAllToDirectory(rootDir);
507 printf("backup all count: %zu\n", count);
508 if (count > 0) {
509 auto backupMMKV = MMKV::mmkvWithID(mmapID, MMKV_SINGLE_PROCESS, &aesKey, &rootDir);
510 cout << "check on backup [" << backupMMKV->mmapID() << "] allKeys: " << ::to_string(backupMMKV->allKeys(), ",\n") << endl;
511
512 backupMMKV = MMKV::mmkvWithID("brutleTest", MMKV_SINGLE_PROCESS, nullptr, &rootDir);
513 cout << "check on backup [" << backupMMKV->mmapID() << "] allKeys count: " << backupMMKV->count() << endl;
514
515 backupMMKV = MMKV::mmkvWithID("process_test", MMKV_MULTI_PROCESS, nullptr, &rootDir);
516 cout << "check on backup [" << backupMMKV->mmapID() << "] allKeys count: " << backupMMKV->count() << endl;
517
518 backupMMKV = MMKV::mmkvWithID("thread_test1", MMKV_SINGLE_PROCESS, nullptr, &rootDir);
519 cout << "check on backup [" << backupMMKV->mmapID() << "] allKeys count: " << backupMMKV->count() << endl;
520 }
521}
522
523void testRestore() {
524 string rootDir = "/tmp/mmkv_backup";

Callers 1

mainFunction · 0.70

Calls 7

mmkvWithIDFunction · 0.85
mmapIDMethod · 0.80
to_stringFunction · 0.70
backupOneToDirectoryFunction · 0.50
backupAllToDirectoryFunction · 0.50
allKeysMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected