mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
.bazaar .google_test added google mock example,
git-svn-id: svn://ultimatepp.org/upp/trunk@10926 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
43599bbde1
commit
244d4cc57b
2 changed files with 29 additions and 14 deletions
|
|
@ -1,39 +1,54 @@
|
|||
#include <Core/Core.h>
|
||||
#include <plugin/gmock/gmock.h>
|
||||
#include <plugin/gtest/gtest.h>
|
||||
|
||||
#include <Core/Core.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
const String CAR_REGISTRATION_NUMBER = "UPP IS THE BEST";
|
||||
|
||||
class Car {
|
||||
public:
|
||||
virtual ~Car() {}
|
||||
|
||||
virtual void OpenHood() = 0;
|
||||
virtual String ReadRegistrationNumbers() = 0;
|
||||
};
|
||||
|
||||
class MockCar : public Car {
|
||||
public:
|
||||
MOCK_METHOD0(OpenHood, void());
|
||||
MOCK_METHOD0(ReadRegistrationNumbers, String());
|
||||
};
|
||||
|
||||
class CarRepairShop final {
|
||||
public:
|
||||
void Service(Car& car) {
|
||||
CarRepairShop()
|
||||
: carsWaitingForService({ CAR_REGISTRATION_NUMBER })
|
||||
{}
|
||||
|
||||
bool Service(Car& car) {
|
||||
if (carsWaitingForService.Find(car.ReadRegistrationNumbers()) < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
car.OpenHood();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
Index<String> carsWaitingForService;
|
||||
};
|
||||
|
||||
TEST(CarRepairShopTest, ServiceChecksAllMainCarElements) {
|
||||
MockCar car;
|
||||
CarRepairShop repairShop;
|
||||
|
||||
EXPECT_CALL(car, OpenHood())
|
||||
.Times(::testing::AtLeast(1));
|
||||
EXPECT_CALL(car, ReadRegistrationNumbers()).WillOnce(::testing::Return(String(CAR_REGISTRATION_NUMBER)));
|
||||
EXPECT_CALL(car, OpenHood()).Times(::testing::AtLeast(1));
|
||||
|
||||
CarRepairShop().Service(car);
|
||||
EXPECT_TRUE(repairShop.Service(car));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
TEST_APP_MAIN {}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
description "Unit test package that shows how to use Google Test with Google Mock\377";
|
||||
description "Google mock in action\377";
|
||||
|
||||
uses
|
||||
Core,
|
||||
plugin/gmock;
|
||||
plugin/gmock,
|
||||
Core;
|
||||
|
||||
file
|
||||
GoogleMockExample.cpp;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue