test_result.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright 2013 The Chromium 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.
  4. #ifndef BASE_TEST_LAUNCHER_TEST_RESULT_H_
  5. #define BASE_TEST_LAUNCHER_TEST_RESULT_H_
  6. #include <map>
  7. #include <string>
  8. #include <vector>
  9. #include "base/time/time.h"
  10. namespace base {
  11. // Structure contains result of a single EXPECT/ASSERT/SUCCESS/SKIP.
  12. struct TestResultPart {
  13. enum Type {
  14. kSuccess, // SUCCESS
  15. kNonFatalFailure, // EXPECT
  16. kFatalFailure, // ASSERT
  17. kSkip, // SKIP
  18. };
  19. Type type;
  20. TestResultPart();
  21. ~TestResultPart();
  22. TestResultPart(const TestResultPart& other);
  23. TestResultPart(TestResultPart&& other);
  24. TestResultPart& operator=(const TestResultPart& other);
  25. TestResultPart& operator=(TestResultPart&& other);
  26. // Convert type to string and back.
  27. static bool TypeFromString(const std::string& str, Type* type);
  28. std::string TypeAsString() const;
  29. // Filename and line of EXPECT/ASSERT.
  30. std::string file_name;
  31. int line_number;
  32. // Message without stacktrace, etc.
  33. std::string summary;
  34. // Complete message.
  35. std::string message;
  36. };
  37. // Structure containing result of a single test.
  38. struct TestResult {
  39. enum Status {
  40. TEST_UNKNOWN, // Status not set.
  41. TEST_SUCCESS, // Test passed.
  42. TEST_FAILURE, // Assertion failure (e.g. EXPECT_TRUE, not DCHECK).
  43. TEST_FAILURE_ON_EXIT, // Passed but executable exit code was non-zero.
  44. TEST_TIMEOUT, // Test timed out and was killed.
  45. TEST_CRASH, // Test crashed (includes CHECK/DCHECK failures).
  46. TEST_SKIPPED, // Test skipped (not run at all).
  47. TEST_EXCESSIVE_OUTPUT, // Test exceeded output limit.
  48. TEST_NOT_RUN, // Test has not yet been run.
  49. };
  50. TestResult();
  51. ~TestResult();
  52. TestResult(const TestResult& other);
  53. TestResult(TestResult&& other);
  54. TestResult& operator=(const TestResult& other);
  55. TestResult& operator=(TestResult&& other);
  56. // Returns the test status as string (e.g. for display).
  57. std::string StatusAsString() const;
  58. // Returns the test name (e.g. "B" for "A.B").
  59. std::string GetTestName() const;
  60. // Returns the test case name (e.g. "A" for "A.B").
  61. std::string GetTestCaseName() const;
  62. // Add link in the xml output.
  63. // See more in gtest_links.h.
  64. void AddLink(const std::string& name, const std::string& url);
  65. // Returns true if the test has completed (i.e. the test binary exited
  66. // normally, possibly with an exit code indicating failure, but didn't crash
  67. // or time out in the middle of the test).
  68. bool completed() const {
  69. return status == TEST_SUCCESS ||
  70. status == TEST_FAILURE ||
  71. status == TEST_FAILURE_ON_EXIT ||
  72. status == TEST_EXCESSIVE_OUTPUT;
  73. }
  74. // Full name of the test (e.g. "A.B").
  75. std::string full_name;
  76. Status status;
  77. // Time it took to run the test.
  78. base::TimeDelta elapsed_time;
  79. // Output of just this test (optional).
  80. std::string output_snippet;
  81. // Information about failed expectations.
  82. std::vector<TestResultPart> test_result_parts;
  83. // The key is link name.
  84. std::map<std::string, std::string> links;
  85. };
  86. } // namespace base
  87. #endif // BASE_TEST_LAUNCHER_TEST_RESULT_H_