作者: 韩晨旭 10225101440 李畅 10225102463
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

53 rindas
1.7 KiB

  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. #ifndef STORAGE_LEVELDB_UTIL_TESTUTIL_H_
  5. #define STORAGE_LEVELDB_UTIL_TESTUTIL_H_
  6. #include "leveldb/env.h"
  7. #include "leveldb/slice.h"
  8. #include "util/random.h"
  9. namespace leveldb {
  10. namespace test {
  11. // Store in *dst a random string of length "len" and return a Slice that
  12. // references the generated data.
  13. extern Slice RandomString(Random* rnd, int len, std::string* dst);
  14. // Return a random key with the specified length that may contain interesting
  15. // characters (e.g. \x00, \xff, etc.).
  16. extern std::string RandomKey(Random* rnd, int len);
  17. // Store in *dst a string of length "len" that will compress to
  18. // "N*compressed_fraction" bytes and return a Slice that references
  19. // the generated data.
  20. extern Slice CompressibleString(Random* rnd, double compressed_fraction,
  21. int len, std::string* dst);
  22. // A wrapper that allows injection of errors.
  23. class ErrorEnv : public EnvWrapper {
  24. public:
  25. bool writable_file_error_;
  26. int num_writable_file_errors_;
  27. ErrorEnv() : EnvWrapper(Env::Default()),
  28. writable_file_error_(false),
  29. num_writable_file_errors_(0) { }
  30. virtual Status NewWritableFile(const std::string& fname,
  31. WritableFile** result) {
  32. if (writable_file_error_) {
  33. ++num_writable_file_errors_;
  34. *result = NULL;
  35. return Status::IOError(fname, "fake error");
  36. }
  37. return target()->NewWritableFile(fname, result);
  38. }
  39. };
  40. }
  41. }
  42. #endif // STORAGE_LEVELDB_UTIL_TESTUTIL_H_