Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
testharness.cc
Go to the documentation of this file.
1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 
5 #include "util/testharness.h"
6 
7 #include <string>
8 #include <stdlib.h>
9 #include <sys/stat.h>
10 #include <sys/types.h>
11 
12 namespace leveldb {
13 namespace test {
14 
15 namespace {
16 struct Test {
17  const char* base;
18  const char* name;
19  void (*func)();
20 };
21 std::vector<Test>* tests;
22 }
23 
24 bool RegisterTest(const char* base, const char* name, void (*func)()) {
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 }
35 
36 int RunAllTests() {
37  const char* matcher = getenv("LEVELDB_TESTS");
38 
39  int num = 0;
40  if (tests != NULL) {
41  for (int 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 }
59 
60 std::string TmpDir() {
61  std::string dir;
63  ASSERT_TRUE(s.ok()) << s.ToString();
64  return dir;
65 }
66 
67 int RandomSeed() {
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 }
75 
76 } // namespace test
77 } // namespace leveldb
bool RegisterTest(const char *base, const char *name, void(*func)())
Definition: testharness.cc:24
std::string TmpDir()
Definition: testharness.cc:60
int RandomSeed()
Definition: testharness.cc:67
int RunAllTests()
Definition: testharness.cc:36
#define ASSERT_TRUE(c)
Definition: testharness.h:105
virtual Status GetTestDirectory(std::string *path)=0
DBTest * test
Definition: db_test.cc:1701
const char * base
Definition: testharness.cc:17
void(* func)()
Definition: testharness.cc:19
bool ok() const
Definition: status.h:52
int atoi(const std::string &str)
Definition: util.h:271
static Env * Default()
Definition: env_posix.cc:800
const char * name
Definition: testharness.cc:18
std::string ToString() const
Definition: status.cc:36