tdbTest.cpp 1.2 KB
Newer Older
H
Hongze Cheng 已提交
1 2
#include "gtest/gtest.h"

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

H
Hongze Cheng 已提交
5
TEST(tdb_test, simple_test) {
H
Hongze Cheng 已提交
6 7 8 9
  TENV*     pEnv;
  TDB *     pDb1, *pDb2, *pDb3;
  pgsz_t    pgSize = 1024;
  cachesz_t cacheSize = 10240;
H
more  
Hongze Cheng 已提交
10

H
Hongze Cheng 已提交
11
  // ENV
H
Hongze Cheng 已提交
12 13 14 15 16 17 18 19 20
  GTEST_ASSERT_EQ(tdbEnvCreate(&pEnv, "./tdbtest"), 0);

  GTEST_ASSERT_EQ(tdbEnvSetCache(pEnv, pgSize, cacheSize), 0);

  GTEST_ASSERT_EQ(tdbEnvGetCacheSize(pEnv), cacheSize);

  GTEST_ASSERT_EQ(tdbEnvGetPageSize(pEnv), pgSize);

  GTEST_ASSERT_EQ(tdbEnvOpen(pEnv), 0);
H
Hongze Cheng 已提交
21

H
Hongze Cheng 已提交
22
#if 1
H
Hongze Cheng 已提交
23 24

  tdbEnvBeginTxn(pEnv);
H
Hongze Cheng 已提交
25
  // DB
H
Hongze Cheng 已提交
26 27 28 29
  GTEST_ASSERT_EQ(tdbCreate(&pDb1), 0);

  GTEST_ASSERT_EQ(tdbSetKeyLen(pDb1, 8), 0);

H
Hongze Cheng 已提交
30 31
  GTEST_ASSERT_EQ(tdbGetKeyLen(pDb1), 8);

H
Hongze Cheng 已提交
32 33
  // GTEST_ASSERT_EQ(tdbSetValLen(pDb1, 3), 0);

H
Hongze Cheng 已提交
34 35 36 37 38 39 40
  // GTEST_ASSERT_EQ(tdbGetValLen(pDb1), 3);

  // GTEST_ASSERT_EQ(tdbSetDup(pDb1, 1), 0);

  // GTEST_ASSERT_EQ(tdbGetDup(pDb1), 1);

  // GTEST_ASSERT_EQ(tdbSetCmprFunc(pDb1, NULL), 0);
H
Hongze Cheng 已提交
41

H
Hongze Cheng 已提交
42 43
  GTEST_ASSERT_EQ(tdbOpen(pDb1, "db.db", "db1", pEnv), 0);

H
Hongze Cheng 已提交
44 45
  tdbEnvCommit(pEnv);

H
Hongze Cheng 已提交
46
#if 0
H
Hongze Cheng 已提交
47 48 49 50 51 52 53
  // Insert

  // Query

  // Delete

  // Query
H
Hongze Cheng 已提交
54
#endif
H
Hongze Cheng 已提交
55

H
Hongze Cheng 已提交
56 57 58 59
  // GTEST_ASSERT_EQ(tdbOpen(&pDb2, "db.db", "db2", pEnv), 0);
  // GTEST_ASSERT_EQ(tdbOpen(&pDb3, "index.db", NULL, pEnv), 0);
  // tdbClose(pDb3);
  // tdbClose(pDb2);
H
Hongze Cheng 已提交
60
  tdbClose(pDb1);
H
Hongze Cheng 已提交
61
#endif
H
Hongze Cheng 已提交
62

H
Hongze Cheng 已提交
63
  tdbEnvClose(pEnv);
H
Hongze Cheng 已提交
64
}