Commit 38ca64dd by zhanyong.wan

Fixes link errors due to an MS VC bug. By Vlad Losev.

parent 4a5330d3
......@@ -101,8 +101,8 @@ test_gmock_internal_utils_test_LDADD = $(GTEST_LIBS) lib/libgmock_main.la
TESTS += test/gmock_link_test
check_PROGRAMS += test/gmock_link_test
test_gmock_link_test_SOURCES = test/gmock_link_test.cc \
test/gmock-sample.cc \
test/gmock-sample.h
test/gmock_link2_test.cc \
test/gmock_link_test.h
test_gmock_link_test_LDADD = $(GTEST_LIBS) lib/libgmock_main.la
TESTS += test/gmock-matchers_test
......
......@@ -908,31 +908,33 @@ class WithArgsAction {
explicit WithArgsAction(const InnerAction& action) : action_(action) {}
template <typename F>
operator Action<F>() const {
operator Action<F>() const { return MakeAction(new Impl<F>(action_)); }
private:
template <typename F>
class Impl : public ActionInterface<F> {
public:
typedef typename Function<F>::Result Result;
typedef typename Function<F>::ArgumentTuple ArgumentTuple;
typedef typename SelectArgs<Result, ArgumentTuple,
k1, k2, k3, k4, k5, k6, k7, k8, k9, k10>::type
InnerFunctionType;
class Impl : public ActionInterface<F> {
public:
explicit Impl(const InnerAction& action) : action_(action) {}
explicit Impl(const InnerAction& action) : action_(action) {}
virtual Result Perform(const ArgumentTuple& args) {
return action_.Perform(SelectArgs<Result, ArgumentTuple, k1, k2, k3,
k4, k5, k6, k7, k8, k9, k10>::Select(args));
}
private:
Action<InnerFunctionType> action_;
};
virtual Result Perform(const ArgumentTuple& args) {
return action_.Perform(SelectArgs<Result, ArgumentTuple, k1, k2, k3, k4,
k5, k6, k7, k8, k9, k10>::Select(args));
}
private:
typedef typename SelectArgs<Result, ArgumentTuple,
k1, k2, k3, k4, k5, k6, k7, k8, k9, k10>::type InnerFunctionType;
Action<InnerFunctionType> action_;
};
return MakeAction(new Impl(action_));
}
private:
const InnerAction action_;
};
// Does two actions sequentially. Used for implementing the DoAll(a1,
// a2, ...) action.
template <typename Action1, typename Action2>
......@@ -945,28 +947,31 @@ class DoBothAction {
// to be used in ANY function of compatible type.
template <typename F>
operator Action<F>() const {
return Action<F>(new Impl<F>(action1_, action2_));
}
private:
// Implements the DoAll(...) action for a particular function type F.
template <typename F>
class Impl : public ActionInterface<F> {
public:
typedef typename Function<F>::Result Result;
typedef typename Function<F>::ArgumentTuple ArgumentTuple;
typedef typename Function<F>::MakeResultVoid VoidResult;
// Implements the DoAll(...) action for a particular function type F.
class Impl : public ActionInterface<F> {
public:
Impl(const Action<VoidResult>& action1, const Action<F>& action2)
: action1_(action1), action2_(action2) {}
Impl(const Action<VoidResult>& action1, const Action<F>& action2)
: action1_(action1), action2_(action2) {}
virtual Result Perform(const ArgumentTuple& args) {
action1_.Perform(args);
return action2_.Perform(args);
}
private:
const Action<VoidResult> action1_;
const Action<F> action2_;
};
virtual Result Perform(const ArgumentTuple& args) {
action1_.Perform(args);
return action2_.Perform(args);
}
private:
const Action<VoidResult> action1_;
const Action<F> action2_;
};
return Action<F>(new Impl(action1_, action2_));
}
private:
Action1 action1_;
Action2 action2_;
};
......
......@@ -333,27 +333,28 @@ class WithArgsAction {
explicit WithArgsAction(const InnerAction& action) : action_(action) {}
template <typename F>
operator Action<F>() const {
operator Action<F>() const { return MakeAction(new Impl<F>(action_)); }
private:
template <typename F>
class Impl : public ActionInterface<F> {
public:
typedef typename Function<F>::Result Result;
typedef typename Function<F>::ArgumentTuple ArgumentTuple;
typedef typename SelectArgs<Result, ArgumentTuple,
$ks>::type
InnerFunctionType;
class Impl : public ActionInterface<F> {
public:
explicit Impl(const InnerAction& action) : action_(action) {}
explicit Impl(const InnerAction& action) : action_(action) {}
virtual Result Perform(const ArgumentTuple& args) {
return action_.Perform(SelectArgs<Result, ArgumentTuple, $ks>::Select(args));
}
private:
Action<InnerFunctionType> action_;
};
virtual Result Perform(const ArgumentTuple& args) {
return action_.Perform(SelectArgs<Result, ArgumentTuple, $ks>::Select(args));
}
private:
typedef typename SelectArgs<Result, ArgumentTuple,
$ks>::type InnerFunctionType;
Action<InnerFunctionType> action_;
};
return MakeAction(new Impl(action_));
}
private:
const InnerAction action_;
};
......@@ -369,28 +370,31 @@ class DoBothAction {
// to be used in ANY function of compatible type.
template <typename F>
operator Action<F>() const {
return Action<F>(new Impl<F>(action1_, action2_));
}
private:
// Implements the DoAll(...) action for a particular function type F.
template <typename F>
class Impl : public ActionInterface<F> {
public:
typedef typename Function<F>::Result Result;
typedef typename Function<F>::ArgumentTuple ArgumentTuple;
typedef typename Function<F>::MakeResultVoid VoidResult;
// Implements the DoAll(...) action for a particular function type F.
class Impl : public ActionInterface<F> {
public:
Impl(const Action<VoidResult>& action1, const Action<F>& action2)
: action1_(action1), action2_(action2) {}
virtual Result Perform(const ArgumentTuple& args) {
action1_.Perform(args);
return action2_.Perform(args);
}
private:
const Action<VoidResult> action1_;
const Action<F> action2_;
};
return Action<F>(new Impl(action1_, action2_));
}
private:
Impl(const Action<VoidResult>& action1, const Action<F>& action2)
: action1_(action1), action2_(action2) {}
virtual Result Perform(const ArgumentTuple& args) {
action1_.Perform(args);
return action2_.Perform(args);
}
private:
const Action<VoidResult> action1_;
const Action<F> action2_;
};
Action1 action1_;
Action2 action2_;
};
......
......@@ -89,15 +89,15 @@ gmock_main.a : gmock-all.o gtest-all.o gmock_main.o
# Builds a sample test.
gmock-sample.o : $(USER_DIR)/gmock-sample.cc $(USER_DIR)/gmock-sample.h \
$(GMOCK_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/gmock-sample.cc
gmock_link_test.o : $(USER_DIR)/gmock_link_test.cc \
$(USER_DIR)/gmock-sample.h $(GMOCK_HEADERS)
$(USER_DIR)/gmock_link_test.h $(GMOCK_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/gmock_link_test.cc
gmock_link_test : gmock-sample.o gmock_link_test.o gmock_main.a
gmock_link2_test.o : $(USER_DIR)/gmock_link2_test.cc \
$(USER_DIR)/gmock_link_test.h $(GMOCK_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/gmock_link2_test.cc
gmock_link_test : gmock_link_test.o gmock_link2_test.o gmock_main.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $^ -o $@
# Builds another sample test.
......
......@@ -183,7 +183,7 @@
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath="..\test\gmock-sample.cc"
RelativePath="..\test\gmock_link2_test.cc"
>
</File>
<File
......
// Copyright 2008, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
#ifndef GMOCK_TEST_GMOCK_SAMPLE_H_
#define GMOCK_TEST_GMOCK_SAMPLE_H_
#include <gmock/gmock.h>
class Sample {
public:
virtual ~Sample() {}
virtual bool Foo(int n) = 0;
};
class MockSample : public Sample {
public:
MOCK_METHOD1(Foo, bool(int n));
};
#endif // GMOCK_TEST_GMOCK_SAMPLE_H_
......@@ -27,6 +27,14 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// Author: wan@google.com (Zhanyong Wan), vladl@google.com (Vlad Losev)
#include "test/gmock-sample.h"
// Google Mock - a framework for writing C++ mock classes.
//
// This file is for verifying that various Google Mock constructs do not
// produce linker errors when instantiated in different translation units.
// Please see gmock_link_test.h for details.
#define LinkTest LinkTest2
#include "test/gmock_link_test.h"
......@@ -27,11 +27,14 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// Author: wan@google.com (Zhanyong Wan), vladl@google.com (Vlad Losev)
// This file is for verifying that a header file defining a mock class
// can be included in multiple translation units without causing a
// link error. It doesn't have to actually do anything - we are only
// checking that the test links correctly.
// Google Mock - a framework for writing C++ mock classes.
//
// This file is for verifying that various Google Mock constructs do not
// produce linker errors when instantiated in different translation units.
// Please see gmock_link_test.h for details.
#define LinkTest LinkTest1
#include "test/gmock-sample.h"
#include "test/gmock_link_test.h"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment