| 493 | } |
| 494 | |
| 495 | void 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 | |
| 523 | void testRestore() { |
| 524 | string rootDir = "/tmp/mmkv_backup"; |
no test coverage detected