Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
testutil.h
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 #ifndef STORAGE_LEVELDB_UTIL_TESTUTIL_H_
6 #define STORAGE_LEVELDB_UTIL_TESTUTIL_H_
7 
8 #include "leveldb/env.h"
9 #include "leveldb/slice.h"
10 #include "util/random.h"
11 
12 namespace leveldb {
13 namespace test {
14 
15 // Store in *dst a random string of length "len" and return a Slice that
16 // references the generated data.
17 extern Slice RandomString(Random* rnd, int len, std::string* dst);
18 
19 // Return a random key with the specified length that may contain interesting
20 // characters (e.g. \x00, \xff, etc.).
21 extern std::string RandomKey(Random* rnd, int len);
22 
23 // Store in *dst a string of length "len" that will compress to
24 // "N*compressed_fraction" bytes and return a Slice that references
25 // the generated data.
26 extern Slice CompressibleString(Random* rnd, double compressed_fraction,
27  int len, std::string* dst);
28 
29 // A wrapper that allows injection of errors.
30 class ErrorEnv : public EnvWrapper {
31  public:
34 
36  writable_file_error_(false),
37  num_writable_file_errors_(0) { }
38 
39  virtual Status NewWritableFile(const std::string& fname,
40  WritableFile** result) {
41  if (writable_file_error_) {
43  *result = NULL;
44  return Status::IOError(fname, "fake error");
45  }
46  return target()->NewWritableFile(fname, result);
47  }
48 };
49 
50 } // namespace test
51 } // namespace leveldb
52 
53 #endif // STORAGE_LEVELDB_UTIL_TESTUTIL_H_
Slice CompressibleString(Random *rnd, double compressed_fraction, int len, std::string *dst)
Definition: testutil.cc:34
DBTest * test
Definition: db_test.cc:1701
virtual Status NewWritableFile(const std::string &fname, WritableFile **result)
Definition: testutil.h:39
virtual Status NewWritableFile(const std::string &fname, WritableFile **result)=0
std::string RandomKey(Random *rnd, int len)
Definition: testutil.cc:20
Slice RandomString(Random *rnd, int len, std::string *dst)
Definition: testutil.cc:12
Env * target() const
Definition: env.h:280
static Env * Default()
Definition: env_posix.cc:800
static Status IOError(const Slice &msg, const Slice &msg2=Slice())
Definition: status.h:47