leveldb
Namespaces | Classes | Functions
leveldb::test Namespace Reference

Namespaces

 anonymous_namespace{testharness.cc}
 

Classes

class  ErrorEnv
 
class  Tester
 

Functions

bool RegisterTest (const char *base, const char *name, void(*func)())
 
int RunAllTests ()
 
std::string TmpDir ()
 
int RandomSeed ()
 
Slice RandomString (Random *rnd, int len, std::string *dst)
 
std::string RandomKey (Random *rnd, int len)
 
Slice CompressibleString (Random *rnd, double compressed_fraction, size_t len, std::string *dst)
 

Function Documentation

§ CompressibleString()

Slice leveldb::test::CompressibleString ( Random rnd,
double  compressed_fraction,
size_t  len,
std::string *  dst 
)

Definition at line 34 of file testutil.cc.

35  {
36  int raw = static_cast<int>(len * compressed_fraction);
37  if (raw < 1) raw = 1;
38  std::string raw_data;
39  RandomString(rnd, raw, &raw_data);
40 
41  // Duplicate the random data until we have filled "len" bytes
42  dst->clear();
43  while (dst->size() < len) {
44  dst->append(raw_data);
45  }
46  dst->resize(len);
47  return Slice(*dst);
48 }
Slice RandomString(Random *rnd, int len, std::string *dst)
Definition: testutil.cc:12
Here is the call graph for this function:
Here is the caller graph for this function:

§ RandomKey()

std::string leveldb::test::RandomKey ( Random rnd,
int  len 
)

Definition at line 20 of file testutil.cc.

20  {
21  // Make sure to generate a wide variety of characters so we
22  // test the boundary conditions for short-key optimizations.
23  static const char kTestChars[] = {
24  '\0', '\1', 'a', 'b', 'c', 'd', 'e', '\xfd', '\xfe', '\xff'
25  };
26  std::string result;
27  for (int i = 0; i < len; i++) {
28  result += kTestChars[rnd->Uniform(sizeof(kTestChars))];
29  }
30  return result;
31 }
Here is the call graph for this function:
Here is the caller graph for this function:

§ RandomSeed()

int leveldb::test::RandomSeed ( )

Definition at line 67 of file testharness.cc.

67  {
68  const char* env = getenv("TEST_RANDOM_SEED");
69  int result = (env != NULL ? atoi(env) : 301);
70  if (result <= 0) {
71  result = 301;
72  }
73  return result;
74 }
Here is the caller graph for this function:

§ RandomString()

Slice leveldb::test::RandomString ( Random rnd,
int  len,
std::string *  dst 
)

Definition at line 12 of file testutil.cc.

12  {
13  dst->resize(len);
14  for (int i = 0; i < len; i++) {
15  (*dst)[i] = static_cast<char>(' ' + rnd->Uniform(95)); // ' ' .. '~'
16  }
17  return Slice(*dst);
18 }
Here is the call graph for this function:
Here is the caller graph for this function:

§ RegisterTest()

bool leveldb::test::RegisterTest ( const char *  base,
const char *  name,
void(*)()  func 
)

Definition at line 24 of file testharness.cc.

24  {
25  if (tests == NULL) {
26  tests = new std::vector<Test>;
27  }
28  Test t;
29  t.base = base;
30  t.name = name;
31  t.func = func;
32  tests->push_back(t);
33  return true;
34 }

§ RunAllTests()

int leveldb::test::RunAllTests ( )

Definition at line 36 of file testharness.cc.

36  {
37  const char* matcher = getenv("LEVELDB_TESTS");
38 
39  int num = 0;
40  if (tests != NULL) {
41  for (size_t i = 0; i < tests->size(); i++) {
42  const Test& t = (*tests)[i];
43  if (matcher != NULL) {
44  std::string name = t.base;
45  name.push_back('.');
46  name.append(t.name);
47  if (strstr(name.c_str(), matcher) == NULL) {
48  continue;
49  }
50  }
51  fprintf(stderr, "==== Test %s.%s\n", t.base, t.name);
52  (*t.func)();
53  ++num;
54  }
55  }
56  fprintf(stderr, "==== PASSED %d tests\n", num);
57  return 0;
58 }
Here is the caller graph for this function:

§ TmpDir()

std::string leveldb::test::TmpDir ( )

Definition at line 60 of file testharness.cc.

60  {
61  std::string dir;
62  Status s = Env::Default()->GetTestDirectory(&dir);
63  ASSERT_TRUE(s.ok()) << s.ToString();
64  return dir;
65 }
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:
Here is the caller graph for this function: