add reKey testcase on POSIX/Win32

This commit is contained in:
guoling
2025-12-01 17:05:10 +08:00
parent ff25ca45e2
commit 5c2bce40a3
2 changed files with 52 additions and 0 deletions
+26
View File
@@ -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();
}
+26
View File
@@ -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();
}