小组成员:10215300402-朱维清 & 10222140408 谷杰
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

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