?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. // Copyright 2008 Google Inc.
  2. // All Rights Reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. //     * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. //     * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. //     * Neither the name of Google Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from
  16. // this software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29.  
  30. #include "gtest/gtest-test-part.h"
  31.  
  32. #include "gtest/gtest.h"
  33.  
  34. using testing::Message;
  35. using testing::Test;
  36. using testing::TestPartResult;
  37. using testing::TestPartResultArray;
  38.  
  39. namespace {
  40.  
  41. // Tests the TestPartResult class.
  42.  
  43. // The test fixture for testing TestPartResult.
  44. class TestPartResultTest : public Test {
  45.  protected:
  46.   TestPartResultTest()
  47.       : r1_(TestPartResult::kSuccess, "foo/bar.cc", 10, "Success!"),
  48.         r2_(TestPartResult::kNonFatalFailure, "foo/bar.cc", -1, "Failure!"),
  49.         r3_(TestPartResult::kFatalFailure, NULL, -1, "Failure!") {}
  50.  
  51.   TestPartResult r1_, r2_, r3_;
  52. };
  53.  
  54.  
  55. TEST_F(TestPartResultTest, ConstructorWorks) {
  56.   Message message;
  57.   message << "something is terribly wrong";
  58.   message << static_cast<const char*>(testing::internal::kStackTraceMarker);
  59.   message << "some unimportant stack trace";
  60.  
  61.   const TestPartResult result(TestPartResult::kNonFatalFailure,
  62.                               "some_file.cc",
  63.                               42,
  64.                               message.GetString().c_str());
  65.  
  66.   EXPECT_EQ(TestPartResult::kNonFatalFailure, result.type());
  67.   EXPECT_STREQ("some_file.cc", result.file_name());
  68.   EXPECT_EQ(42, result.line_number());
  69.   EXPECT_STREQ(message.GetString().c_str(), result.message());
  70.   EXPECT_STREQ("something is terribly wrong", result.summary());
  71. }
  72.  
  73. TEST_F(TestPartResultTest, ResultAccessorsWork) {
  74.   const TestPartResult success(TestPartResult::kSuccess,
  75.                                "file.cc",
  76.                                42,
  77.                                "message");
  78.   EXPECT_TRUE(success.passed());
  79.   EXPECT_FALSE(success.failed());
  80.   EXPECT_FALSE(success.nonfatally_failed());
  81.   EXPECT_FALSE(success.fatally_failed());
  82.  
  83.   const TestPartResult nonfatal_failure(TestPartResult::kNonFatalFailure,
  84.                                         "file.cc",
  85.                                         42,
  86.                                         "message");
  87.   EXPECT_FALSE(nonfatal_failure.passed());
  88.   EXPECT_TRUE(nonfatal_failure.failed());
  89.   EXPECT_TRUE(nonfatal_failure.nonfatally_failed());
  90.   EXPECT_FALSE(nonfatal_failure.fatally_failed());
  91.  
  92.   const TestPartResult fatal_failure(TestPartResult::kFatalFailure,
  93.                                      "file.cc",
  94.                                      42,
  95.                                      "message");
  96.   EXPECT_FALSE(fatal_failure.passed());
  97.   EXPECT_TRUE(fatal_failure.failed());
  98.   EXPECT_FALSE(fatal_failure.nonfatally_failed());
  99.   EXPECT_TRUE(fatal_failure.fatally_failed());
  100. }
  101.  
  102. // Tests TestPartResult::type().
  103. TEST_F(TestPartResultTest, type) {
  104.   EXPECT_EQ(TestPartResult::kSuccess, r1_.type());
  105.   EXPECT_EQ(TestPartResult::kNonFatalFailure, r2_.type());
  106.   EXPECT_EQ(TestPartResult::kFatalFailure, r3_.type());
  107. }
  108.  
  109. // Tests TestPartResult::file_name().
  110. TEST_F(TestPartResultTest, file_name) {
  111.   EXPECT_STREQ("foo/bar.cc", r1_.file_name());
  112.   EXPECT_STREQ(NULL, r3_.file_name());
  113. }
  114.  
  115. // Tests TestPartResult::line_number().
  116. TEST_F(TestPartResultTest, line_number) {
  117.   EXPECT_EQ(10, r1_.line_number());
  118.   EXPECT_EQ(-1, r2_.line_number());
  119. }
  120.  
  121. // Tests TestPartResult::message().
  122. TEST_F(TestPartResultTest, message) {
  123.   EXPECT_STREQ("Success!", r1_.message());
  124. }
  125.  
  126. // Tests TestPartResult::passed().
  127. TEST_F(TestPartResultTest, Passed) {
  128.   EXPECT_TRUE(r1_.passed());
  129.   EXPECT_FALSE(r2_.passed());
  130.   EXPECT_FALSE(r3_.passed());
  131. }
  132.  
  133. // Tests TestPartResult::failed().
  134. TEST_F(TestPartResultTest, Failed) {
  135.   EXPECT_FALSE(r1_.failed());
  136.   EXPECT_TRUE(r2_.failed());
  137.   EXPECT_TRUE(r3_.failed());
  138. }
  139.  
  140. // Tests TestPartResult::fatally_failed().
  141. TEST_F(TestPartResultTest, FatallyFailed) {
  142.   EXPECT_FALSE(r1_.fatally_failed());
  143.   EXPECT_FALSE(r2_.fatally_failed());
  144.   EXPECT_TRUE(r3_.fatally_failed());
  145. }
  146.  
  147. // Tests TestPartResult::nonfatally_failed().
  148. TEST_F(TestPartResultTest, NonfatallyFailed) {
  149.   EXPECT_FALSE(r1_.nonfatally_failed());
  150.   EXPECT_TRUE(r2_.nonfatally_failed());
  151.   EXPECT_FALSE(r3_.nonfatally_failed());
  152. }
  153.  
  154. // Tests the TestPartResultArray class.
  155.  
  156. class TestPartResultArrayTest : public Test {
  157.  protected:
  158.   TestPartResultArrayTest()
  159.       : r1_(TestPartResult::kNonFatalFailure, "foo/bar.cc", -1, "Failure 1"),
  160.         r2_(TestPartResult::kFatalFailure, "foo/bar.cc", -1, "Failure 2") {}
  161.  
  162.   const TestPartResult r1_, r2_;
  163. };
  164.  
  165. // Tests that TestPartResultArray initially has size 0.
  166. TEST_F(TestPartResultArrayTest, InitialSizeIsZero) {
  167.   TestPartResultArray results;
  168.   EXPECT_EQ(0, results.size());
  169. }
  170.  
  171. // Tests that TestPartResultArray contains the given TestPartResult
  172. // after one Append() operation.
  173. TEST_F(TestPartResultArrayTest, ContainsGivenResultAfterAppend) {
  174.   TestPartResultArray results;
  175.   results.Append(r1_);
  176.   EXPECT_EQ(1, results.size());
  177.   EXPECT_STREQ("Failure 1", results.GetTestPartResult(0).message());
  178. }
  179.  
  180. // Tests that TestPartResultArray contains the given TestPartResults
  181. // after two Append() operations.
  182. TEST_F(TestPartResultArrayTest, ContainsGivenResultsAfterTwoAppends) {
  183.   TestPartResultArray results;
  184.   results.Append(r1_);
  185.   results.Append(r2_);
  186.   EXPECT_EQ(2, results.size());
  187.   EXPECT_STREQ("Failure 1", results.GetTestPartResult(0).message());
  188.   EXPECT_STREQ("Failure 2", results.GetTestPartResult(1).message());
  189. }
  190.  
  191. typedef TestPartResultArrayTest TestPartResultArrayDeathTest;
  192.  
  193. // Tests that the program dies when GetTestPartResult() is called with
  194. // an invalid index.
  195. TEST_F(TestPartResultArrayDeathTest, DiesWhenIndexIsOutOfBound) {
  196.   TestPartResultArray results;
  197.   results.Append(r1_);
  198.  
  199.   EXPECT_DEATH_IF_SUPPORTED(results.GetTestPartResult(-1), "");
  200.   EXPECT_DEATH_IF_SUPPORTED(results.GetTestPartResult(1), "");
  201. }
  202.  
  203. // FIXME: Add a test for the class HasNewFatalFailureHelper.
  204.  
  205. }  // namespace
  206.