10225501448 李度 10225101546 陈胤遒 10215501422 高宇菲
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

65 rader
1.3 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. #include "util/testharness.h"
  5. #include <sys/stat.h>
  6. #include <sys/types.h>
  7. namespace leveldb {
  8. namespace test {
  9. namespace {
  10. struct Test {
  11. const char* base;
  12. const char* name;
  13. void (*func)();
  14. };
  15. std::vector<Test>* tests;
  16. }
  17. bool RegisterTest(const char* base, const char* name, void (*func)()) {
  18. if (tests == NULL) {
  19. tests = new std::vector<Test>;
  20. }
  21. Test t;
  22. t.base = base;
  23. t.name = name;
  24. t.func = func;
  25. tests->push_back(t);
  26. return true;
  27. }
  28. int RunAllTests() {
  29. int num = 0;
  30. if (tests != NULL) {
  31. for (int i = 0; i < tests->size(); i++) {
  32. const Test& t = (*tests)[i];
  33. fprintf(stderr, "==== Test %s.%s\n", t.base, t.name);
  34. (*t.func)();
  35. ++num;
  36. }
  37. }
  38. fprintf(stderr, "==== PASSED %d tests\n", num);
  39. return 0;
  40. }
  41. std::string TmpDir() {
  42. std::string dir;
  43. Status s = Env::Default()->GetTestDirectory(&dir);
  44. ASSERT_TRUE(s.ok()) << s.ToString();
  45. return dir;
  46. }
  47. int RandomSeed() {
  48. const char* env = getenv("TEST_RANDOM_SEED");
  49. int result = (env != NULL ? atoi(env) : 301);
  50. if (result <= 0) {
  51. result = 301;
  52. }
  53. return result;
  54. }
  55. }
  56. }