1 // Copyright 2014 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_TEST_SCOPED_DISABLE_EXIT_ON_DFATAL_H_ 6 #define NET_TEST_SCOPED_DISABLE_EXIT_ON_DFATAL_H_ 7 8 #include <string_view> 9 10 #include "base/logging.h" 11 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gtest/include/gtest/gtest.h" 13 14 namespace net::test { 15 16 // The ScopedDisableExitOnDFatal class is used to disable exiting the 17 // program when we encounter a LOG(DFATAL) within the current block. 18 // After we leave the current block, the default behavior is 19 // restored. 20 class ScopedDisableExitOnDFatal { 21 public: 22 ScopedDisableExitOnDFatal(); 23 24 ScopedDisableExitOnDFatal(const ScopedDisableExitOnDFatal&) = delete; 25 ScopedDisableExitOnDFatal& operator=(const ScopedDisableExitOnDFatal&) = 26 delete; 27 28 ~ScopedDisableExitOnDFatal(); 29 30 private: 31 // Static function which is set as the logging assert handler. 32 // Called when there is a check failure. 33 static void LogAssertHandler(const char* file, 34 int line, 35 const std::string_view message, 36 const std::string_view stack_trace); 37 38 logging::ScopedLogAssertHandler assert_handler_; 39 }; 40 41 } // namespace net::test 42 43 #endif // NET_TEST_SCOPED_DISABLE_EXIT_ON_DFATAL_H_ 44