コード例 #1
0
TEST(TestObHashMap, destroy)
{
  ObHashMap<HashKey, HashValue> hm;

  // 没有create
  EXPECT_EQ(0, hm.destroy());
  hm.create(cal_next_prime(gHashItemNum));
  EXPECT_EQ(0, hm.destroy());
  EXPECT_EQ(0, hm.create(gHashItemNum));
}
コード例 #2
0
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");
}