gmock_test.cc
Go to the documentation of this file.
00001 // Copyright 2008, Google Inc.
00002 // All rights reserved.
00003 //
00004 // Redistribution and use in source and binary forms, with or without
00005 // modification, are permitted provided that the following conditions are
00006 // met:
00007 //
00008 //     * Redistributions of source code must retain the above copyright
00009 // notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above
00011 // copyright notice, this list of conditions and the following disclaimer
00012 // in the documentation and/or other materials provided with the
00013 // distribution.
00014 //     * Neither the name of Google Inc. nor the names of its
00015 // contributors may be used to endorse or promote products derived from
00016 // this software without specific prior written permission.
00017 //
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // Author: wan@google.com (Zhanyong Wan)
00031 
00032 // Google Mock - a framework for writing C++ mock classes.
00033 //
00034 // This file tests code in gmock.cc.
00035 
00036 #include "gmock/gmock.h"
00037 
00038 #include <string>
00039 #include "gtest/gtest.h"
00040 
00041 using testing::GMOCK_FLAG(verbose);
00042 using testing::InitGoogleMock;
00043 using testing::internal::g_init_gtest_count;
00044 
00045 // Verifies that calling InitGoogleMock() on argv results in new_argv,
00046 // and the gmock_verbose flag's value is set to expected_gmock_verbose.
00047 template <typename Char, int M, int N>
00048 void TestInitGoogleMock(const Char* (&argv)[M], const Char* (&new_argv)[N],
00049                         const ::std::string& expected_gmock_verbose) {
00050   const ::std::string old_verbose = GMOCK_FLAG(verbose);
00051 
00052   int argc = M;
00053   InitGoogleMock(&argc, const_cast<Char**>(argv));
00054   ASSERT_EQ(N, argc) << "The new argv has wrong number of elements.";
00055 
00056   for (int i = 0; i < N; i++) {
00057     EXPECT_STREQ(new_argv[i], argv[i]);
00058   }
00059 
00060   EXPECT_EQ(expected_gmock_verbose, GMOCK_FLAG(verbose).c_str());
00061   GMOCK_FLAG(verbose) = old_verbose;  // Restores the gmock_verbose flag.
00062 }
00063 
00064 TEST(InitGoogleMockTest, ParsesInvalidCommandLine) {
00065   const char* argv[] = {
00066     NULL
00067   };
00068 
00069   const char* new_argv[] = {
00070     NULL
00071   };
00072 
00073   TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
00074 }
00075 
00076 TEST(InitGoogleMockTest, ParsesEmptyCommandLine) {
00077   const char* argv[] = {
00078     "foo.exe",
00079     NULL
00080   };
00081 
00082   const char* new_argv[] = {
00083     "foo.exe",
00084     NULL
00085   };
00086 
00087   TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
00088 }
00089 
00090 TEST(InitGoogleMockTest, ParsesSingleFlag) {
00091   const char* argv[] = {
00092     "foo.exe",
00093     "--gmock_verbose=info",
00094     NULL
00095   };
00096 
00097   const char* new_argv[] = {
00098     "foo.exe",
00099     NULL
00100   };
00101 
00102   TestInitGoogleMock(argv, new_argv, "info");
00103 }
00104 
00105 TEST(InitGoogleMockTest, ParsesUnrecognizedFlag) {
00106   const char* argv[] = {
00107     "foo.exe",
00108     "--non_gmock_flag=blah",
00109     NULL
00110   };
00111 
00112   const char* new_argv[] = {
00113     "foo.exe",
00114     "--non_gmock_flag=blah",
00115     NULL
00116   };
00117 
00118   TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
00119 }
00120 
00121 TEST(InitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) {
00122   const char* argv[] = {
00123     "foo.exe",
00124     "--non_gmock_flag=blah",
00125     "--gmock_verbose=error",
00126     NULL
00127   };
00128 
00129   const char* new_argv[] = {
00130     "foo.exe",
00131     "--non_gmock_flag=blah",
00132     NULL
00133   };
00134 
00135   TestInitGoogleMock(argv, new_argv, "error");
00136 }
00137 
00138 TEST(InitGoogleMockTest, CallsInitGoogleTest) {
00139   const int old_init_gtest_count = g_init_gtest_count;
00140   const char* argv[] = {
00141     "foo.exe",
00142     "--non_gmock_flag=blah",
00143     "--gmock_verbose=error",
00144     NULL
00145   };
00146 
00147   const char* new_argv[] = {
00148     "foo.exe",
00149     "--non_gmock_flag=blah",
00150     NULL
00151   };
00152 
00153   TestInitGoogleMock(argv, new_argv, "error");
00154   EXPECT_EQ(old_init_gtest_count + 1, g_init_gtest_count);
00155 }
00156 
00157 TEST(WideInitGoogleMockTest, ParsesInvalidCommandLine) {
00158   const wchar_t* argv[] = {
00159     NULL
00160   };
00161 
00162   const wchar_t* new_argv[] = {
00163     NULL
00164   };
00165 
00166   TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
00167 }
00168 
00169 TEST(WideInitGoogleMockTest, ParsesEmptyCommandLine) {
00170   const wchar_t* argv[] = {
00171     L"foo.exe",
00172     NULL
00173   };
00174 
00175   const wchar_t* new_argv[] = {
00176     L"foo.exe",
00177     NULL
00178   };
00179 
00180   TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
00181 }
00182 
00183 TEST(WideInitGoogleMockTest, ParsesSingleFlag) {
00184   const wchar_t* argv[] = {
00185     L"foo.exe",
00186     L"--gmock_verbose=info",
00187     NULL
00188   };
00189 
00190   const wchar_t* new_argv[] = {
00191     L"foo.exe",
00192     NULL
00193   };
00194 
00195   TestInitGoogleMock(argv, new_argv, "info");
00196 }
00197 
00198 TEST(WideInitGoogleMockTest, ParsesUnrecognizedFlag) {
00199   const wchar_t* argv[] = {
00200     L"foo.exe",
00201     L"--non_gmock_flag=blah",
00202     NULL
00203   };
00204 
00205   const wchar_t* new_argv[] = {
00206     L"foo.exe",
00207     L"--non_gmock_flag=blah",
00208     NULL
00209   };
00210 
00211   TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
00212 }
00213 
00214 TEST(WideInitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) {
00215   const wchar_t* argv[] = {
00216     L"foo.exe",
00217     L"--non_gmock_flag=blah",
00218     L"--gmock_verbose=error",
00219     NULL
00220   };
00221 
00222   const wchar_t* new_argv[] = {
00223     L"foo.exe",
00224     L"--non_gmock_flag=blah",
00225     NULL
00226   };
00227 
00228   TestInitGoogleMock(argv, new_argv, "error");
00229 }
00230 
00231 TEST(WideInitGoogleMockTest, CallsInitGoogleTest) {
00232   const int old_init_gtest_count = g_init_gtest_count;
00233   const wchar_t* argv[] = {
00234     L"foo.exe",
00235     L"--non_gmock_flag=blah",
00236     L"--gmock_verbose=error",
00237     NULL
00238   };
00239 
00240   const wchar_t* new_argv[] = {
00241     L"foo.exe",
00242     L"--non_gmock_flag=blah",
00243     NULL
00244   };
00245 
00246   TestInitGoogleMock(argv, new_argv, "error");
00247   EXPECT_EQ(old_init_gtest_count + 1, g_init_gtest_count);
00248 }
00249 
00250 // Makes sure Google Mock flags can be accessed in code.
00251 TEST(FlagTest, IsAccessibleInCode) {
00252   bool dummy = testing::GMOCK_FLAG(catch_leaked_mocks) &&
00253       testing::GMOCK_FLAG(verbose) == "";
00254   (void)dummy;  // Avoids the "unused local variable" warning.
00255 }


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Sat Jun 8 2019 18:24:43