PageRenderTime 30ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/thirdparty/breakpad/third_party/glog/src/mock-log_test.cc

http://github.com/tomahawk-player/tomahawk
C++ | 106 lines | 55 code | 16 blank | 35 comment | 0 complexity | 7fd188f06f80ba9e3af7a8852986cc2b MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-3.0, GPL-2.0
  1. // Copyright (c) 2007, 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. // Author: Zhanyong Wan
  31. // Tests the ScopedMockLog class.
  32. #include "mock-log.h"
  33. #include <string>
  34. #include <gmock/gmock.h>
  35. #include <gtest/gtest.h>
  36. namespace {
  37. using GOOGLE_NAMESPACE::INFO;
  38. using GOOGLE_NAMESPACE::WARNING;
  39. using GOOGLE_NAMESPACE::ERROR;
  40. using GOOGLE_NAMESPACE::glog_testing::ScopedMockLog;
  41. using std::string;
  42. using testing::_;
  43. using testing::HasSubstr;
  44. using testing::InSequence;
  45. using testing::InvokeWithoutArgs;
  46. // Tests that ScopedMockLog intercepts LOG()s when it's alive.
  47. TEST(ScopedMockLogTest, InterceptsLog) {
  48. ScopedMockLog log;
  49. InSequence s;
  50. EXPECT_CALL(log, Log(WARNING, HasSubstr("/mock-log_test.cc"), "Fishy."));
  51. EXPECT_CALL(log, Log(INFO, _, "Working..."))
  52. .Times(2);
  53. EXPECT_CALL(log, Log(ERROR, _, "Bad!!"));
  54. LOG(WARNING) << "Fishy.";
  55. LOG(INFO) << "Working...";
  56. LOG(INFO) << "Working...";
  57. LOG(ERROR) << "Bad!!";
  58. }
  59. void LogBranch() {
  60. LOG(INFO) << "Logging a branch...";
  61. }
  62. void LogTree() {
  63. LOG(INFO) << "Logging the whole tree...";
  64. }
  65. void LogForest() {
  66. LOG(INFO) << "Logging the entire forest.";
  67. LOG(INFO) << "Logging the entire forest..";
  68. LOG(INFO) << "Logging the entire forest...";
  69. }
  70. // The purpose of the following test is to verify that intercepting logging
  71. // continues to work properly if a LOG statement is executed within the scope
  72. // of a mocked call.
  73. TEST(ScopedMockLogTest, LogDuringIntercept) {
  74. ScopedMockLog log;
  75. InSequence s;
  76. EXPECT_CALL(log, Log(INFO, __FILE__, "Logging a branch..."))
  77. .WillOnce(InvokeWithoutArgs(LogTree));
  78. EXPECT_CALL(log, Log(INFO, __FILE__, "Logging the whole tree..."))
  79. .WillOnce(InvokeWithoutArgs(LogForest));
  80. EXPECT_CALL(log, Log(INFO, __FILE__, "Logging the entire forest."));
  81. EXPECT_CALL(log, Log(INFO, __FILE__, "Logging the entire forest.."));
  82. EXPECT_CALL(log, Log(INFO, __FILE__, "Logging the entire forest..."));
  83. LogBranch();
  84. }
  85. } // namespace
  86. int main(int argc, char **argv) {
  87. GOOGLE_NAMESPACE::InitGoogleLogging(argv[0]);
  88. testing::InitGoogleMock(&argc, argv);
  89. return RUN_ALL_TESTS();
  90. }