"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "googlemock/test/gmock_test.cc" between
googletest-release-1.11.0.tar.gz and googletest-release-1.12.0.tar.gz

About: GoogleTest is Google's (unit) testing and mocking framework for C++ tests.

gmock_test.cc  (googletest-release-1.11.0):gmock_test.cc  (googletest-release-1.12.0)
skipping to change at line 37 skipping to change at line 37
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
// This file tests code in gmock.cc. // This file tests code in gmock.cc.
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include <string> #include <string>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "gtest/internal/custom/gtest.h" #include "gtest/internal/custom/gtest.h"
#if !defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) #if !defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
using testing::GMOCK_FLAG(default_mock_behavior);
using testing::GMOCK_FLAG(verbose);
using testing::InitGoogleMock; using testing::InitGoogleMock;
// Verifies that calling InitGoogleMock() on argv results in new_argv, // Verifies that calling InitGoogleMock() on argv results in new_argv,
// and the gmock_verbose flag's value is set to expected_gmock_verbose. // and the gmock_verbose flag's value is set to expected_gmock_verbose.
template <typename Char, int M, int N> template <typename Char, int M, int N>
void TestInitGoogleMock(const Char* (&argv)[M], const Char* (&new_argv)[N], void TestInitGoogleMock(const Char* (&argv)[M], const Char* (&new_argv)[N],
const ::std::string& expected_gmock_verbose) { const ::std::string& expected_gmock_verbose) {
const ::std::string old_verbose = GMOCK_FLAG(verbose); const ::std::string old_verbose = GMOCK_FLAG_GET(verbose);
int argc = M - 1; int argc = M - 1;
InitGoogleMock(&argc, const_cast<Char**>(argv)); InitGoogleMock(&argc, const_cast<Char**>(argv));
ASSERT_EQ(N - 1, argc) << "The new argv has wrong number of elements."; ASSERT_EQ(N - 1, argc) << "The new argv has wrong number of elements.";
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
EXPECT_STREQ(new_argv[i], argv[i]); EXPECT_STREQ(new_argv[i], argv[i]);
} }
EXPECT_EQ(expected_gmock_verbose, GMOCK_FLAG(verbose).c_str()); EXPECT_EQ(expected_gmock_verbose, GMOCK_FLAG_GET(verbose));
GMOCK_FLAG(verbose) = old_verbose; // Restores the gmock_verbose flag. GMOCK_FLAG_SET(verbose, old_verbose); // Restores the gmock_verbose flag.
} }
TEST(InitGoogleMockTest, ParsesInvalidCommandLine) { TEST(InitGoogleMockTest, ParsesInvalidCommandLine) {
const char* argv[] = {nullptr}; const char* argv[] = {nullptr};
const char* new_argv[] = {nullptr}; const char* new_argv[] = {nullptr};
TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose)); TestInitGoogleMock(argv, new_argv, GMOCK_FLAG_GET(verbose));
} }
TEST(InitGoogleMockTest, ParsesEmptyCommandLine) { TEST(InitGoogleMockTest, ParsesEmptyCommandLine) {
const char* argv[] = {"foo.exe", nullptr}; const char* argv[] = {"foo.exe", nullptr};
const char* new_argv[] = {"foo.exe", nullptr}; const char* new_argv[] = {"foo.exe", nullptr};
TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose)); TestInitGoogleMock(argv, new_argv, GMOCK_FLAG_GET(verbose));
} }
TEST(InitGoogleMockTest, ParsesSingleFlag) { TEST(InitGoogleMockTest, ParsesSingleFlag) {
const char* argv[] = {"foo.exe", "--gmock_verbose=info", nullptr}; const char* argv[] = {"foo.exe", "--gmock_verbose=info", nullptr};
const char* new_argv[] = {"foo.exe", nullptr}; const char* new_argv[] = {"foo.exe", nullptr};
TestInitGoogleMock(argv, new_argv, "info"); TestInitGoogleMock(argv, new_argv, "info");
} }
TEST(InitGoogleMockTest, ParsesMultipleFlags) { TEST(InitGoogleMockTest, ParsesMultipleFlags) {
int old_default_behavior = GMOCK_FLAG(default_mock_behavior); int old_default_behavior = GMOCK_FLAG_GET(default_mock_behavior);
const wchar_t* argv[] = {L"foo.exe", L"--gmock_verbose=info", const wchar_t* argv[] = {L"foo.exe", L"--gmock_verbose=info",
L"--gmock_default_mock_behavior=2", nullptr}; L"--gmock_default_mock_behavior=2", nullptr};
const wchar_t* new_argv[] = {L"foo.exe", nullptr}; const wchar_t* new_argv[] = {L"foo.exe", nullptr};
TestInitGoogleMock(argv, new_argv, "info"); TestInitGoogleMock(argv, new_argv, "info");
EXPECT_EQ(2, GMOCK_FLAG(default_mock_behavior)); EXPECT_EQ(2, GMOCK_FLAG_GET(default_mock_behavior));
EXPECT_NE(2, old_default_behavior); EXPECT_NE(2, old_default_behavior);
GMOCK_FLAG(default_mock_behavior) = old_default_behavior; GMOCK_FLAG_SET(default_mock_behavior, old_default_behavior);
} }
TEST(InitGoogleMockTest, ParsesUnrecognizedFlag) { TEST(InitGoogleMockTest, ParsesUnrecognizedFlag) {
const char* argv[] = {"foo.exe", "--non_gmock_flag=blah", nullptr}; const char* argv[] = {"foo.exe", "--non_gmock_flag=blah", nullptr};
const char* new_argv[] = {"foo.exe", "--non_gmock_flag=blah", nullptr}; const char* new_argv[] = {"foo.exe", "--non_gmock_flag=blah", nullptr};
TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose)); TestInitGoogleMock(argv, new_argv, GMOCK_FLAG_GET(verbose));
} }
TEST(InitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) { TEST(InitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) {
const char* argv[] = {"foo.exe", "--non_gmock_flag=blah", const char* argv[] = {"foo.exe", "--non_gmock_flag=blah",
"--gmock_verbose=error", nullptr}; "--gmock_verbose=error", nullptr};
const char* new_argv[] = {"foo.exe", "--non_gmock_flag=blah", nullptr}; const char* new_argv[] = {"foo.exe", "--non_gmock_flag=blah", nullptr};
TestInitGoogleMock(argv, new_argv, "error"); TestInitGoogleMock(argv, new_argv, "error");
} }
TEST(WideInitGoogleMockTest, ParsesInvalidCommandLine) { TEST(WideInitGoogleMockTest, ParsesInvalidCommandLine) {
const wchar_t* argv[] = {nullptr}; const wchar_t* argv[] = {nullptr};
const wchar_t* new_argv[] = {nullptr}; const wchar_t* new_argv[] = {nullptr};
TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose)); TestInitGoogleMock(argv, new_argv, GMOCK_FLAG_GET(verbose));
} }
TEST(WideInitGoogleMockTest, ParsesEmptyCommandLine) { TEST(WideInitGoogleMockTest, ParsesEmptyCommandLine) {
const wchar_t* argv[] = {L"foo.exe", nullptr}; const wchar_t* argv[] = {L"foo.exe", nullptr};
const wchar_t* new_argv[] = {L"foo.exe", nullptr}; const wchar_t* new_argv[] = {L"foo.exe", nullptr};
TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose)); TestInitGoogleMock(argv, new_argv, GMOCK_FLAG_GET(verbose));
} }
TEST(WideInitGoogleMockTest, ParsesSingleFlag) { TEST(WideInitGoogleMockTest, ParsesSingleFlag) {
const wchar_t* argv[] = {L"foo.exe", L"--gmock_verbose=info", nullptr}; const wchar_t* argv[] = {L"foo.exe", L"--gmock_verbose=info", nullptr};
const wchar_t* new_argv[] = {L"foo.exe", nullptr}; const wchar_t* new_argv[] = {L"foo.exe", nullptr};
TestInitGoogleMock(argv, new_argv, "info"); TestInitGoogleMock(argv, new_argv, "info");
} }
TEST(WideInitGoogleMockTest, ParsesMultipleFlags) { TEST(WideInitGoogleMockTest, ParsesMultipleFlags) {
int old_default_behavior = GMOCK_FLAG(default_mock_behavior); int old_default_behavior = GMOCK_FLAG_GET(default_mock_behavior);
const wchar_t* argv[] = {L"foo.exe", L"--gmock_verbose=info", const wchar_t* argv[] = {L"foo.exe", L"--gmock_verbose=info",
L"--gmock_default_mock_behavior=2", nullptr}; L"--gmock_default_mock_behavior=2", nullptr};
const wchar_t* new_argv[] = {L"foo.exe", nullptr}; const wchar_t* new_argv[] = {L"foo.exe", nullptr};
TestInitGoogleMock(argv, new_argv, "info"); TestInitGoogleMock(argv, new_argv, "info");
EXPECT_EQ(2, GMOCK_FLAG(default_mock_behavior)); EXPECT_EQ(2, GMOCK_FLAG_GET(default_mock_behavior));
EXPECT_NE(2, old_default_behavior); EXPECT_NE(2, old_default_behavior);
GMOCK_FLAG(default_mock_behavior) = old_default_behavior; GMOCK_FLAG_SET(default_mock_behavior, old_default_behavior);
} }
TEST(WideInitGoogleMockTest, ParsesUnrecognizedFlag) { TEST(WideInitGoogleMockTest, ParsesUnrecognizedFlag) {
const wchar_t* argv[] = {L"foo.exe", L"--non_gmock_flag=blah", nullptr}; const wchar_t* argv[] = {L"foo.exe", L"--non_gmock_flag=blah", nullptr};
const wchar_t* new_argv[] = {L"foo.exe", L"--non_gmock_flag=blah", nullptr}; const wchar_t* new_argv[] = {L"foo.exe", L"--non_gmock_flag=blah", nullptr};
TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose)); TestInitGoogleMock(argv, new_argv, GMOCK_FLAG_GET(verbose));
} }
TEST(WideInitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) { TEST(WideInitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) {
const wchar_t* argv[] = {L"foo.exe", L"--non_gmock_flag=blah", const wchar_t* argv[] = {L"foo.exe", L"--non_gmock_flag=blah",
L"--gmock_verbose=error", nullptr}; L"--gmock_verbose=error", nullptr};
const wchar_t* new_argv[] = {L"foo.exe", L"--non_gmock_flag=blah", nullptr}; const wchar_t* new_argv[] = {L"foo.exe", L"--non_gmock_flag=blah", nullptr};
TestInitGoogleMock(argv, new_argv, "error"); TestInitGoogleMock(argv, new_argv, "error");
} }
#endif // !defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) #endif // !defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
// Makes sure Google Mock flags can be accessed in code. // Makes sure Google Mock flags can be accessed in code.
TEST(FlagTest, IsAccessibleInCode) { TEST(FlagTest, IsAccessibleInCode) {
bool dummy = testing::GMOCK_FLAG(catch_leaked_mocks) && bool dummy =
testing::GMOCK_FLAG(verbose) == ""; GMOCK_FLAG_GET(catch_leaked_mocks) && GMOCK_FLAG_GET(verbose) == "";
(void)dummy; // Avoids the "unused local variable" warning. (void)dummy; // Avoids the "unused local variable" warning.
} }
 End of changes. 17 change blocks. 
19 lines changed or deleted 18 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)