mirror of
https://github.com/Tencent/MMKV.git
synced 2026-10-17 04:30:56 +08:00
add reKey testcase on POSIX/Win32
This commit is contained in:
@@ -1326,6 +1326,31 @@ void testImport() {
|
||||
assert(dst->count(true) == 0);
|
||||
}
|
||||
|
||||
MMKV* testMMKV(const string& mmapID, const string* cryptKey, bool aes256, bool decodeOnly, const string* rootPath) {
|
||||
MMKV* kv = MMKV::mmkvWithID(mmapID, MMKV_SINGLE_PROCESS, cryptKey, rootPath, 0, aes256);
|
||||
functionalTest(kv, decodeOnly);
|
||||
return kv;
|
||||
}
|
||||
|
||||
void testReKey() {
|
||||
string mmapID = "test/AES_reKey1";
|
||||
MMKV* kv = testMMKV(mmapID, nullptr, false, false, nullptr);
|
||||
|
||||
string cryptKey = "Key_seq_1";
|
||||
kv->reKey(cryptKey);
|
||||
kv->clearMemoryCache();
|
||||
testMMKV(mmapID, &cryptKey, false, true, nullptr);
|
||||
|
||||
string cryptKey2 = "Key_Seq_Very_Looooooooong";
|
||||
kv->reKey(cryptKey2, true);
|
||||
kv->clearMemoryCache();
|
||||
testMMKV(mmapID, &cryptKey2, true, true, nullptr);
|
||||
|
||||
kv->reKey(string());
|
||||
kv->clearMemoryCache();
|
||||
testMMKV(mmapID, nullptr, false, true, nullptr);
|
||||
}
|
||||
|
||||
void MyLogHandler(MMKVLogLevel level, const char *file, int line, const char *function, const string &message) {
|
||||
|
||||
auto desc = [level] {
|
||||
@@ -1402,4 +1427,5 @@ int main() {
|
||||
testReadonlyCrash();
|
||||
testImport();
|
||||
itemSizeHolderTest();
|
||||
testReKey();
|
||||
}
|
||||
|
||||
@@ -457,6 +457,31 @@ void testImport() {
|
||||
assert(dst->count(true) == 0);
|
||||
}
|
||||
|
||||
MMKV* testMMKV(const string& mmapID, const string* cryptKey, bool aes256, bool decodeOnly, const wstring* rootPath) {
|
||||
MMKV* kv = MMKV::mmkvWithID(mmapID, MMKV_SINGLE_PROCESS, cryptKey, rootPath, 0, aes256);
|
||||
functionalTest(kv, decodeOnly);
|
||||
return kv;
|
||||
}
|
||||
|
||||
void testReKey() {
|
||||
string mmapID = "test/AES_reKey1";
|
||||
MMKV* kv = testMMKV(mmapID, nullptr, false, false, nullptr);
|
||||
|
||||
string cryptKey = "Key_seq_1";
|
||||
kv->reKey(cryptKey);
|
||||
kv->clearMemoryCache();
|
||||
testMMKV(mmapID, &cryptKey, false, true, nullptr);
|
||||
|
||||
string cryptKey2 = "Key_Seq_Very_Looooooooong";
|
||||
kv->reKey(cryptKey2, true);
|
||||
kv->clearMemoryCache();
|
||||
testMMKV(mmapID, &cryptKey2, true, true, nullptr);
|
||||
|
||||
kv->reKey(string());
|
||||
kv->clearMemoryCache();
|
||||
testMMKV(mmapID, nullptr, false, true, nullptr);
|
||||
}
|
||||
|
||||
static void
|
||||
LogHandler(MMKVLogLevel level, const char *file, int line, const char *function, const std::string &message) {
|
||||
|
||||
@@ -519,4 +544,5 @@ int main() {
|
||||
testRemoveStorage();
|
||||
testReadOnly();
|
||||
testImport();
|
||||
testReKey();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user