tdbTest.cpp 774 字节
Newer Older
H
Hongze Cheng 已提交
1 2
#include "gtest/gtest.h"

H
Hongze Cheng 已提交
3
#include "tdbInt.h"
H
more  
Hongze Cheng 已提交
4

H
Hongze Cheng 已提交
5
TEST(tdb_test, simple_test) {
H
Hongze Cheng 已提交
6 7
  int    ret;
  STEnv *pEnv;
H
Hongze Cheng 已提交
8
  STDb  *pDb;
H
more  
Hongze Cheng 已提交
9

H
Hongze Cheng 已提交
10 11 12
  // Open Env
  ret = tdbEnvOpen("tdb", 1024, 20, &pEnv);
  GTEST_ASSERT_EQ(ret, 0);
H
Hongze Cheng 已提交
13

H
Hongze Cheng 已提交
14
  // Create a database
H
more  
Hongze Cheng 已提交
15
  ret = tdbDbOpen("db.db", TDB_VARIANT_LEN, TDB_VARIANT_LEN, NULL, pEnv, &pDb);
H
Hongze Cheng 已提交
16
  GTEST_ASSERT_EQ(ret, 0);
H
Hongze Cheng 已提交
17

H
Hongze Cheng 已提交
18
  {  // Insert some data
H
Hongze Cheng 已提交
19 20 21
    char key[64];
    char val[64];

H
Hongze Cheng 已提交
22
    for (int i = 1; i <= 92; i++) {
H
Hongze Cheng 已提交
23 24 25 26 27
      sprintf(key, "key%d", i);
      sprintf(key, "value%d", i);
      ret = tdbDbInsert(pDb, key, strlen(key), val, strlen(val));
      GTEST_ASSERT_EQ(ret, 0);
    }
H
Hongze Cheng 已提交
28
  }
H
Hongze Cheng 已提交
29 30

  ret = tdbDbDrop(pDb);
H
Hongze Cheng 已提交
31
  GTEST_ASSERT_EQ(ret, 0);
H
Hongze Cheng 已提交
32

H
Hongze Cheng 已提交
33 34
  // Close a database
  tdbDbClose(pDb);
H
Hongze Cheng 已提交
35

H
Hongze Cheng 已提交
36 37 38
  // Close Env
  ret = tdbEnvClose(pEnv);
  GTEST_ASSERT_EQ(ret, 0);
H
Hongze Cheng 已提交
39
}