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

Function testRemove

POSIX/demo/UnitTest.cpp:202–247  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200}
201
202void testRemove(MMKV *mmkv) {
203 auto ret = mmkv->set(true, "bool_1");
204 ret &= mmkv->set(numeric_limits<int32_t>::max(), "int_1");
205 ret &= mmkv->set(numeric_limits<int64_t>::max(), "long_1");
206 ret &= mmkv->set(numeric_limits<float>::min(), "float_1");
207 ret &= mmkv->set(numeric_limits<double>::min(), "double_1");
208 ret &= mmkv->set("hello", "string_1");
209 vector<string> v = vector<string>{"key", "value"};
210 ret &= mmkv->set(v, "vector_1");
211 assert(ret);
212
213 {
214 long count = mmkv->count();
215
216 mmkv->removeValueForKey("bool_1");
217 mmkv->removeValuesForKeys({"int_1", "long_1"});
218
219 auto newCount = mmkv->count();
220 assert(count == newCount + 3);
221 }
222
223 auto bValue = mmkv->getBool("bool_1");
224 assert(!bValue);
225
226 auto iValue = mmkv->getInt32("int_1");
227 assert(iValue == 0);
228
229 auto lValue = mmkv->getInt64("long_1");
230 assert(lValue == 0);
231
232 auto fValue = mmkv->getFloat("float_1");
233 assert(EqualWithAccuracy(fValue, numeric_limits<float>::min(), 0.001f));
234
235 double dValue = mmkv->getDouble("double_1");
236 assert(EqualWithAccuracy(dValue, numeric_limits<double>::min(), 0.001));
237
238 string sValue;
239 ret = mmkv->getString("string_1", sValue);
240 assert(ret && sValue == "hello");
241
242 vector<string> vValue;
243 ret = mmkv->getVector("vector_1", vValue);
244 assert(ret && vValue == v);
245
246 printf("test remove: passed\n");
247}
248
249int main() {
250 locale::global(locale(""));

Callers 1

mainFunction · 0.85

Calls 12

EqualWithAccuracyFunction · 0.85
setMethod · 0.45
countMethod · 0.45
removeValueForKeyMethod · 0.45
removeValuesForKeysMethod · 0.45
getBoolMethod · 0.45
getInt32Method · 0.45
getInt64Method · 0.45
getFloatMethod · 0.45
getDoubleMethod · 0.45
getStringMethod · 0.45
getVectorMethod · 0.45

Tested by

no test coverage detected