TEST(TestObHashMap, clear) { ObHashMap<HashKey, HashValue> hm; uint64_t key[4] = {1, 2, 1, 1 + cal_next_prime(gHashItemNum)}; uint64_t value[4] = {100, 200, 300, 301}; // 没有create EXPECT_EQ(-1, hm.clear()); hm.create(cal_next_prime(gHashItemNum)); EXPECT_EQ(0, hm.clear()); hm.set(key[0], value[0], 0); hm.set(key[1], value[1], 0); hm.set(key[3], value[3], 0); EXPECT_EQ(3, hm.size()); EXPECT_EQ(0, hm.clear()); EXPECT_EQ(0, hm.size()); }
TEST(TestObHashMap, serialization) { ObHashMap<HashKey, HashValue> hm; SimpleArchive arw, arr; arw.init("./hash.data", SimpleArchive::FILE_OPEN_WFLAG); arr.init("./hash.data", SimpleArchive::FILE_OPEN_RFLAG); SimpleArchive arw_nil, arr_nil; // 没有create EXPECT_EQ(-1, hm.serialization(arw)); hm.create(cal_next_prime(gHashItemNum)); // 没有元素 EXPECT_EQ(0, hm.serialization(arw)); EXPECT_EQ(0, hm.deserialization(arr)); uint64_t key[4] = {1, 2, 1, 1 + cal_next_prime(gHashItemNum)}; uint64_t value[4] = {100, 200, 300, 301}; for (uint32_t i = 0; i < 4; i++) { hm.set(key[i], value[i], 0); } EXPECT_EQ(-1, hm.serialization(arw_nil)); arw.destroy(); arr.destroy(); arw.init("./hash.data", SimpleArchive::FILE_OPEN_WFLAG); arr.init("./hash.data", SimpleArchive::FILE_OPEN_RFLAG); EXPECT_EQ(0, hm.serialization(arw)); hm.destroy(); EXPECT_EQ(0, hm.deserialization(arr)); EXPECT_EQ(-1, hm.deserialization(arr)); EXPECT_EQ(3, hm.size()); arr_nil.init("./hash.data.nil", SimpleArchive::FILE_OPEN_RFLAG); EXPECT_EQ(-1, hm.deserialization(arr_nil)); remove("./hash.data"); remove("./hash.data.nil"); }