gmock_link_test.h
Go to the documentation of this file.
00001 // Copyright 2009, 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: vladl@google.com (Vlad Losev)
00031 
00032 // Google Mock - a framework for writing C++ mock classes.
00033 //
00034 // This file tests that:
00035 // a. A header file defining a mock class can be included in multiple
00036 //    translation units without causing a link error.
00037 // b. Actions and matchers can be instantiated with identical template
00038 //    arguments in different translation units without causing link
00039 //    errors.
00040 //    The following constructs are currently tested:
00041 //    Actions:
00042 //      Return()
00043 //      Return(value)
00044 //      ReturnNull
00045 //      ReturnRef
00046 //      Assign
00047 //      SetArgPointee
00048 //      SetArrayArgument
00049 //      SetErrnoAndReturn
00050 //      Invoke(function)
00051 //      Invoke(object, method)
00052 //      InvokeWithoutArgs(function)
00053 //      InvokeWithoutArgs(object, method)
00054 //      InvokeArgument
00055 //      WithArg
00056 //      WithArgs
00057 //      WithoutArgs
00058 //      DoAll
00059 //      DoDefault
00060 //      IgnoreResult
00061 //      Throw
00062 //      ACTION()-generated
00063 //      ACTION_P()-generated
00064 //      ACTION_P2()-generated
00065 //    Matchers:
00066 //      _
00067 //      A
00068 //      An
00069 //      Eq
00070 //      Gt, Lt, Ge, Le, Ne
00071 //      NotNull
00072 //      Ref
00073 //      TypedEq
00074 //      DoubleEq
00075 //      FloatEq
00076 //      NanSensitiveDoubleEq
00077 //      NanSensitiveFloatEq
00078 //      ContainsRegex
00079 //      MatchesRegex
00080 //      EndsWith
00081 //      HasSubstr
00082 //      StartsWith
00083 //      StrCaseEq
00084 //      StrCaseNe
00085 //      StrEq
00086 //      StrNe
00087 //      ElementsAre
00088 //      ElementsAreArray
00089 //      ContainerEq
00090 //      Field
00091 //      Property
00092 //      ResultOf(function)
00093 //      Pointee
00094 //      Truly(predicate)
00095 //      AllOf
00096 //      AnyOf
00097 //      Not
00098 //      MatcherCast<T>
00099 //
00100 //  Please note: this test does not verify the functioning of these
00101 //  constructs, only that the programs using them will link successfully.
00102 //
00103 // Implementation note:
00104 // This test requires identical definitions of Interface and Mock to be
00105 // included in different translation units.  We achieve this by writing
00106 // them in this header and #including it in gmock_link_test.cc and
00107 // gmock_link2_test.cc.  Because the symbols generated by the compiler for
00108 // those constructs must be identical in both translation units,
00109 // definitions of Interface and Mock tests MUST be kept in the SAME
00110 // NON-ANONYMOUS namespace in this file.  The test fixture class LinkTest
00111 // is defined as LinkTest1 in gmock_link_test.cc and as LinkTest2 in
00112 // gmock_link2_test.cc to avoid producing linker errors.
00113 
00114 #ifndef GMOCK_TEST_GMOCK_LINK_TEST_H_
00115 #define GMOCK_TEST_GMOCK_LINK_TEST_H_
00116 
00117 #include "gmock/gmock.h"
00118 
00119 #if !GTEST_OS_WINDOWS_MOBILE
00120 # include <errno.h>
00121 #endif
00122 
00123 #include "gmock/internal/gmock-port.h"
00124 #include "gtest/gtest.h"
00125 #include <iostream>
00126 #include <vector>
00127 
00128 using testing::_;
00129 using testing::A;
00130 using testing::AllOf;
00131 using testing::AnyOf;
00132 using testing::Assign;
00133 using testing::ContainerEq;
00134 using testing::DoAll;
00135 using testing::DoDefault;
00136 using testing::DoubleEq;
00137 using testing::ElementsAre;
00138 using testing::ElementsAreArray;
00139 using testing::EndsWith;
00140 using testing::Eq;
00141 using testing::Field;
00142 using testing::FloatEq;
00143 using testing::Ge;
00144 using testing::Gt;
00145 using testing::HasSubstr;
00146 using testing::IgnoreResult;
00147 using testing::Invoke;
00148 using testing::InvokeArgument;
00149 using testing::InvokeWithoutArgs;
00150 using testing::IsNull;
00151 using testing::Le;
00152 using testing::Lt;
00153 using testing::Matcher;
00154 using testing::MatcherCast;
00155 using testing::NanSensitiveDoubleEq;
00156 using testing::NanSensitiveFloatEq;
00157 using testing::Ne;
00158 using testing::Not;
00159 using testing::NotNull;
00160 using testing::Pointee;
00161 using testing::Property;
00162 using testing::Ref;
00163 using testing::ResultOf;
00164 using testing::Return;
00165 using testing::ReturnNull;
00166 using testing::ReturnRef;
00167 using testing::SetArgPointee;
00168 using testing::SetArrayArgument;
00169 using testing::StartsWith;
00170 using testing::StrCaseEq;
00171 using testing::StrCaseNe;
00172 using testing::StrEq;
00173 using testing::StrNe;
00174 using testing::Truly;
00175 using testing::TypedEq;
00176 using testing::WithArg;
00177 using testing::WithArgs;
00178 using testing::WithoutArgs;
00179 
00180 #if !GTEST_OS_WINDOWS_MOBILE
00181 using testing::SetErrnoAndReturn;
00182 #endif
00183 
00184 #if GTEST_HAS_EXCEPTIONS
00185 using testing::Throw;
00186 #endif
00187 
00188 using testing::ContainsRegex;
00189 using testing::MatchesRegex;
00190 
00191 class Interface {
00192  public:
00193   virtual ~Interface() {}
00194   virtual void VoidFromString(char* str) = 0;
00195   virtual char* StringFromString(char* str) = 0;
00196   virtual int IntFromString(char* str) = 0;
00197   virtual int& IntRefFromString(char* str) = 0;
00198   virtual void VoidFromFunc(void(*func)(char* str)) = 0;
00199   virtual void VoidFromIntRef(int& n) = 0;  // NOLINT
00200   virtual void VoidFromFloat(float n) = 0;
00201   virtual void VoidFromDouble(double n) = 0;
00202   virtual void VoidFromVector(const std::vector<int>& v) = 0;
00203 };
00204 
00205 class Mock: public Interface {
00206  public:
00207   Mock() {}
00208 
00209   MOCK_METHOD1(VoidFromString, void(char* str));
00210   MOCK_METHOD1(StringFromString, char*(char* str));
00211   MOCK_METHOD1(IntFromString, int(char* str));
00212   MOCK_METHOD1(IntRefFromString, int&(char* str));
00213   MOCK_METHOD1(VoidFromFunc, void(void(*func)(char* str)));
00214   MOCK_METHOD1(VoidFromIntRef, void(int& n));  // NOLINT
00215   MOCK_METHOD1(VoidFromFloat, void(float n));
00216   MOCK_METHOD1(VoidFromDouble, void(double n));
00217   MOCK_METHOD1(VoidFromVector, void(const std::vector<int>& v));
00218 
00219  private:
00220   GTEST_DISALLOW_COPY_AND_ASSIGN_(Mock);
00221 };
00222 
00223 class InvokeHelper {
00224  public:
00225   static void StaticVoidFromVoid() {}
00226   void VoidFromVoid() {}
00227   static void StaticVoidFromString(char* /* str */) {}
00228   void VoidFromString(char* /* str */) {}
00229   static int StaticIntFromString(char* /* str */) { return 1; }
00230   static bool StaticBoolFromString(const char* /* str */) { return true; }
00231 };
00232 
00233 class FieldHelper {
00234  public:
00235   explicit FieldHelper(int a_field) : field_(a_field) {}
00236   int field() const { return field_; }
00237   int field_;  // NOLINT -- need external access to field_ to test
00238                //           the Field matcher.
00239 };
00240 
00241 // Tests the linkage of the ReturnVoid action.
00242 TEST(LinkTest, TestReturnVoid) {
00243   Mock mock;
00244 
00245   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Return());
00246   mock.VoidFromString(NULL);
00247 }
00248 
00249 // Tests the linkage of the Return action.
00250 TEST(LinkTest, TestReturn) {
00251   Mock mock;
00252   char ch = 'x';
00253 
00254   EXPECT_CALL(mock, StringFromString(_)).WillOnce(Return(&ch));
00255   mock.StringFromString(NULL);
00256 }
00257 
00258 // Tests the linkage of the ReturnNull action.
00259 TEST(LinkTest, TestReturnNull) {
00260   Mock mock;
00261 
00262   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Return());
00263   mock.VoidFromString(NULL);
00264 }
00265 
00266 // Tests the linkage of the ReturnRef action.
00267 TEST(LinkTest, TestReturnRef) {
00268   Mock mock;
00269   int n = 42;
00270 
00271   EXPECT_CALL(mock, IntRefFromString(_)).WillOnce(ReturnRef(n));
00272   mock.IntRefFromString(NULL);
00273 }
00274 
00275 // Tests the linkage of the Assign action.
00276 TEST(LinkTest, TestAssign) {
00277   Mock mock;
00278   char ch = 'x';
00279 
00280   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Assign(&ch, 'y'));
00281   mock.VoidFromString(NULL);
00282 }
00283 
00284 // Tests the linkage of the SetArgPointee action.
00285 TEST(LinkTest, TestSetArgPointee) {
00286   Mock mock;
00287   char ch = 'x';
00288 
00289   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(SetArgPointee<0>('y'));
00290   mock.VoidFromString(&ch);
00291 }
00292 
00293 // Tests the linkage of the SetArrayArgument action.
00294 TEST(LinkTest, TestSetArrayArgument) {
00295   Mock mock;
00296   char ch = 'x';
00297   char ch2 = 'y';
00298 
00299   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(SetArrayArgument<0>(&ch2,
00300                                                                     &ch2 + 1));
00301   mock.VoidFromString(&ch);
00302 }
00303 
00304 #if !GTEST_OS_WINDOWS_MOBILE
00305 
00306 // Tests the linkage of the SetErrnoAndReturn action.
00307 TEST(LinkTest, TestSetErrnoAndReturn) {
00308   Mock mock;
00309 
00310   int saved_errno = errno;
00311   EXPECT_CALL(mock, IntFromString(_)).WillOnce(SetErrnoAndReturn(1, -1));
00312   mock.IntFromString(NULL);
00313   errno = saved_errno;
00314 }
00315 
00316 #endif  // !GTEST_OS_WINDOWS_MOBILE
00317 
00318 // Tests the linkage of the Invoke(function) and Invoke(object, method) actions.
00319 TEST(LinkTest, TestInvoke) {
00320   Mock mock;
00321   InvokeHelper test_invoke_helper;
00322 
00323   EXPECT_CALL(mock, VoidFromString(_))
00324       .WillOnce(Invoke(&InvokeHelper::StaticVoidFromString))
00325       .WillOnce(Invoke(&test_invoke_helper, &InvokeHelper::VoidFromString));
00326   mock.VoidFromString(NULL);
00327   mock.VoidFromString(NULL);
00328 }
00329 
00330 // Tests the linkage of the InvokeWithoutArgs action.
00331 TEST(LinkTest, TestInvokeWithoutArgs) {
00332   Mock mock;
00333   InvokeHelper test_invoke_helper;
00334 
00335   EXPECT_CALL(mock, VoidFromString(_))
00336       .WillOnce(InvokeWithoutArgs(&InvokeHelper::StaticVoidFromVoid))
00337       .WillOnce(InvokeWithoutArgs(&test_invoke_helper,
00338                                   &InvokeHelper::VoidFromVoid));
00339   mock.VoidFromString(NULL);
00340   mock.VoidFromString(NULL);
00341 }
00342 
00343 // Tests the linkage of the InvokeArgument action.
00344 TEST(LinkTest, TestInvokeArgument) {
00345   Mock mock;
00346   char ch = 'x';
00347 
00348   EXPECT_CALL(mock, VoidFromFunc(_)).WillOnce(InvokeArgument<0>(&ch));
00349   mock.VoidFromFunc(InvokeHelper::StaticVoidFromString);
00350 }
00351 
00352 // Tests the linkage of the WithArg action.
00353 TEST(LinkTest, TestWithArg) {
00354   Mock mock;
00355 
00356   EXPECT_CALL(mock, VoidFromString(_))
00357       .WillOnce(WithArg<0>(Invoke(&InvokeHelper::StaticVoidFromString)));
00358   mock.VoidFromString(NULL);
00359 }
00360 
00361 // Tests the linkage of the WithArgs action.
00362 TEST(LinkTest, TestWithArgs) {
00363   Mock mock;
00364 
00365   EXPECT_CALL(mock, VoidFromString(_))
00366       .WillOnce(WithArgs<0>(Invoke(&InvokeHelper::StaticVoidFromString)));
00367   mock.VoidFromString(NULL);
00368 }
00369 
00370 // Tests the linkage of the WithoutArgs action.
00371 TEST(LinkTest, TestWithoutArgs) {
00372   Mock mock;
00373 
00374   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(WithoutArgs(Return()));
00375   mock.VoidFromString(NULL);
00376 }
00377 
00378 // Tests the linkage of the DoAll action.
00379 TEST(LinkTest, TestDoAll) {
00380   Mock mock;
00381   char ch = 'x';
00382 
00383   EXPECT_CALL(mock, VoidFromString(_))
00384       .WillOnce(DoAll(SetArgPointee<0>('y'), Return()));
00385   mock.VoidFromString(&ch);
00386 }
00387 
00388 // Tests the linkage of the DoDefault action.
00389 TEST(LinkTest, TestDoDefault) {
00390   Mock mock;
00391   char ch = 'x';
00392 
00393   ON_CALL(mock, VoidFromString(_)).WillByDefault(Return());
00394   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(DoDefault());
00395   mock.VoidFromString(&ch);
00396 }
00397 
00398 // Tests the linkage of the IgnoreResult action.
00399 TEST(LinkTest, TestIgnoreResult) {
00400   Mock mock;
00401 
00402   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(IgnoreResult(Return(42)));
00403   mock.VoidFromString(NULL);
00404 }
00405 
00406 #if GTEST_HAS_EXCEPTIONS
00407 // Tests the linkage of the Throw action.
00408 TEST(LinkTest, TestThrow) {
00409   Mock mock;
00410 
00411   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Throw(42));
00412   EXPECT_THROW(mock.VoidFromString(NULL), int);
00413 }
00414 #endif  // GTEST_HAS_EXCEPTIONS
00415 
00416 // The ACTION*() macros trigger warning C4100 (unreferenced formal
00417 // parameter) in MSVC with -W4.  Unfortunately they cannot be fixed in
00418 // the macro definition, as the warnings are generated when the macro
00419 // is expanded and macro expansion cannot contain #pragma.  Therefore
00420 // we suppress them here.
00421 #ifdef _MSC_VER
00422 # pragma warning(push)
00423 # pragma warning(disable:4100)
00424 #endif
00425 
00426 // Tests the linkage of actions created using ACTION macro.
00427 namespace {
00428 ACTION(Return1) { return 1; }
00429 }
00430 
00431 TEST(LinkTest, TestActionMacro) {
00432   Mock mock;
00433 
00434   EXPECT_CALL(mock, IntFromString(_)).WillOnce(Return1());
00435   mock.IntFromString(NULL);
00436 }
00437 
00438 // Tests the linkage of actions created using ACTION_P macro.
00439 namespace {
00440 ACTION_P(ReturnArgument, ret_value) { return ret_value; }
00441 }
00442 
00443 TEST(LinkTest, TestActionPMacro) {
00444   Mock mock;
00445 
00446   EXPECT_CALL(mock, IntFromString(_)).WillOnce(ReturnArgument(42));
00447   mock.IntFromString(NULL);
00448 }
00449 
00450 // Tests the linkage of actions created using ACTION_P2 macro.
00451 namespace {
00452 ACTION_P2(ReturnEqualsEitherOf, first, second) {
00453   return arg0 == first || arg0 == second;
00454 }
00455 }
00456 
00457 #ifdef _MSC_VER
00458 # pragma warning(pop)
00459 #endif
00460 
00461 TEST(LinkTest, TestActionP2Macro) {
00462   Mock mock;
00463   char ch = 'x';
00464 
00465   EXPECT_CALL(mock, IntFromString(_))
00466       .WillOnce(ReturnEqualsEitherOf("one", "two"));
00467   mock.IntFromString(&ch);
00468 }
00469 
00470 // Tests the linkage of the "_" matcher.
00471 TEST(LinkTest, TestMatcherAnything) {
00472   Mock mock;
00473 
00474   ON_CALL(mock, VoidFromString(_)).WillByDefault(Return());
00475 }
00476 
00477 // Tests the linkage of the A matcher.
00478 TEST(LinkTest, TestMatcherA) {
00479   Mock mock;
00480 
00481   ON_CALL(mock, VoidFromString(A<char*>())).WillByDefault(Return());
00482 }
00483 
00484 // Tests the linkage of the Eq and the "bare value" matcher.
00485 TEST(LinkTest, TestMatchersEq) {
00486   Mock mock;
00487   const char* p = "x";
00488 
00489   ON_CALL(mock, VoidFromString(Eq(p))).WillByDefault(Return());
00490   ON_CALL(mock, VoidFromString(const_cast<char*>("y")))
00491       .WillByDefault(Return());
00492 }
00493 
00494 // Tests the linkage of the Lt, Gt, Le, Ge, and Ne matchers.
00495 TEST(LinkTest, TestMatchersRelations) {
00496   Mock mock;
00497 
00498   ON_CALL(mock, VoidFromFloat(Lt(1.0f))).WillByDefault(Return());
00499   ON_CALL(mock, VoidFromFloat(Gt(1.0f))).WillByDefault(Return());
00500   ON_CALL(mock, VoidFromFloat(Le(1.0f))).WillByDefault(Return());
00501   ON_CALL(mock, VoidFromFloat(Ge(1.0f))).WillByDefault(Return());
00502   ON_CALL(mock, VoidFromFloat(Ne(1.0f))).WillByDefault(Return());
00503 }
00504 
00505 // Tests the linkage of the NotNull matcher.
00506 TEST(LinkTest, TestMatcherNotNull) {
00507   Mock mock;
00508 
00509   ON_CALL(mock, VoidFromString(NotNull())).WillByDefault(Return());
00510 }
00511 
00512 // Tests the linkage of the IsNull matcher.
00513 TEST(LinkTest, TestMatcherIsNull) {
00514   Mock mock;
00515 
00516   ON_CALL(mock, VoidFromString(IsNull())).WillByDefault(Return());
00517 }
00518 
00519 // Tests the linkage of the Ref matcher.
00520 TEST(LinkTest, TestMatcherRef) {
00521   Mock mock;
00522   int a = 0;
00523 
00524   ON_CALL(mock, VoidFromIntRef(Ref(a))).WillByDefault(Return());
00525 }
00526 
00527 // Tests the linkage of the TypedEq matcher.
00528 TEST(LinkTest, TestMatcherTypedEq) {
00529   Mock mock;
00530   long a = 0;
00531 
00532   ON_CALL(mock, VoidFromIntRef(TypedEq<int&>(a))).WillByDefault(Return());
00533 }
00534 
00535 // Tests the linkage of the FloatEq, DoubleEq, NanSensitiveFloatEq and
00536 // NanSensitiveDoubleEq matchers.
00537 TEST(LinkTest, TestMatchersFloatingPoint) {
00538   Mock mock;
00539   float a = 0;
00540 
00541   ON_CALL(mock, VoidFromFloat(FloatEq(a))).WillByDefault(Return());
00542   ON_CALL(mock, VoidFromDouble(DoubleEq(a))).WillByDefault(Return());
00543   ON_CALL(mock, VoidFromFloat(NanSensitiveFloatEq(a))).WillByDefault(Return());
00544   ON_CALL(mock, VoidFromDouble(NanSensitiveDoubleEq(a)))
00545       .WillByDefault(Return());
00546 }
00547 
00548 // Tests the linkage of the ContainsRegex matcher.
00549 TEST(LinkTest, TestMatcherContainsRegex) {
00550   Mock mock;
00551 
00552   ON_CALL(mock, VoidFromString(ContainsRegex(".*"))).WillByDefault(Return());
00553 }
00554 
00555 // Tests the linkage of the MatchesRegex matcher.
00556 TEST(LinkTest, TestMatcherMatchesRegex) {
00557   Mock mock;
00558 
00559   ON_CALL(mock, VoidFromString(MatchesRegex(".*"))).WillByDefault(Return());
00560 }
00561 
00562 // Tests the linkage of the StartsWith, EndsWith, and HasSubstr matchers.
00563 TEST(LinkTest, TestMatchersSubstrings) {
00564   Mock mock;
00565 
00566   ON_CALL(mock, VoidFromString(StartsWith("a"))).WillByDefault(Return());
00567   ON_CALL(mock, VoidFromString(EndsWith("c"))).WillByDefault(Return());
00568   ON_CALL(mock, VoidFromString(HasSubstr("b"))).WillByDefault(Return());
00569 }
00570 
00571 // Tests the linkage of the StrEq, StrNe, StrCaseEq, and StrCaseNe matchers.
00572 TEST(LinkTest, TestMatchersStringEquality) {
00573   Mock mock;
00574   ON_CALL(mock, VoidFromString(StrEq("a"))).WillByDefault(Return());
00575   ON_CALL(mock, VoidFromString(StrNe("a"))).WillByDefault(Return());
00576   ON_CALL(mock, VoidFromString(StrCaseEq("a"))).WillByDefault(Return());
00577   ON_CALL(mock, VoidFromString(StrCaseNe("a"))).WillByDefault(Return());
00578 }
00579 
00580 // Tests the linkage of the ElementsAre matcher.
00581 TEST(LinkTest, TestMatcherElementsAre) {
00582   Mock mock;
00583 
00584   ON_CALL(mock, VoidFromVector(ElementsAre('a', _))).WillByDefault(Return());
00585 }
00586 
00587 // Tests the linkage of the ElementsAreArray matcher.
00588 TEST(LinkTest, TestMatcherElementsAreArray) {
00589   Mock mock;
00590   char arr[] = { 'a', 'b' };
00591 
00592   ON_CALL(mock, VoidFromVector(ElementsAreArray(arr))).WillByDefault(Return());
00593 }
00594 
00595 // Tests the linkage of the ContainerEq matcher.
00596 TEST(LinkTest, TestMatcherContainerEq) {
00597   Mock mock;
00598   std::vector<int> v;
00599 
00600   ON_CALL(mock, VoidFromVector(ContainerEq(v))).WillByDefault(Return());
00601 }
00602 
00603 // Tests the linkage of the Field matcher.
00604 TEST(LinkTest, TestMatcherField) {
00605   FieldHelper helper(0);
00606 
00607   Matcher<const FieldHelper&> m = Field(&FieldHelper::field_, Eq(0));
00608   EXPECT_TRUE(m.Matches(helper));
00609 
00610   Matcher<const FieldHelper*> m2 = Field(&FieldHelper::field_, Eq(0));
00611   EXPECT_TRUE(m2.Matches(&helper));
00612 }
00613 
00614 // Tests the linkage of the Property matcher.
00615 TEST(LinkTest, TestMatcherProperty) {
00616   FieldHelper helper(0);
00617 
00618   Matcher<const FieldHelper&> m = Property(&FieldHelper::field, Eq(0));
00619   EXPECT_TRUE(m.Matches(helper));
00620 
00621   Matcher<const FieldHelper*> m2 = Property(&FieldHelper::field, Eq(0));
00622   EXPECT_TRUE(m2.Matches(&helper));
00623 }
00624 
00625 // Tests the linkage of the ResultOf matcher.
00626 TEST(LinkTest, TestMatcherResultOf) {
00627   Matcher<char*> m = ResultOf(&InvokeHelper::StaticIntFromString, Eq(1));
00628   EXPECT_TRUE(m.Matches(NULL));
00629 }
00630 
00631 // Tests the linkage of the ResultOf matcher.
00632 TEST(LinkTest, TestMatcherPointee) {
00633   int n = 1;
00634 
00635   Matcher<int*> m = Pointee(Eq(1));
00636   EXPECT_TRUE(m.Matches(&n));
00637 }
00638 
00639 // Tests the linkage of the Truly matcher.
00640 TEST(LinkTest, TestMatcherTruly) {
00641   Matcher<const char*> m = Truly(&InvokeHelper::StaticBoolFromString);
00642   EXPECT_TRUE(m.Matches(NULL));
00643 }
00644 
00645 // Tests the linkage of the AllOf matcher.
00646 TEST(LinkTest, TestMatcherAllOf) {
00647   Matcher<int> m = AllOf(_, Eq(1));
00648   EXPECT_TRUE(m.Matches(1));
00649 }
00650 
00651 // Tests the linkage of the AnyOf matcher.
00652 TEST(LinkTest, TestMatcherAnyOf) {
00653   Matcher<int> m = AnyOf(_, Eq(1));
00654   EXPECT_TRUE(m.Matches(1));
00655 }
00656 
00657 // Tests the linkage of the Not matcher.
00658 TEST(LinkTest, TestMatcherNot) {
00659   Matcher<int> m = Not(_);
00660   EXPECT_FALSE(m.Matches(1));
00661 }
00662 
00663 // Tests the linkage of the MatcherCast<T>() function.
00664 TEST(LinkTest, TestMatcherCast) {
00665   Matcher<const char*> m = MatcherCast<const char*>(_);
00666   EXPECT_TRUE(m.Matches(NULL));
00667 }
00668 
00669 #endif  // GMOCK_TEST_GMOCK_LINK_TEST_H_


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