1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
// -*- Mode: C++; tab-width:2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi:tw=80:et:ts=2:sts=2
//
// -----------------------------------------------------------------------
//
// This file is part of RLVM, a RealLive virtual machine clone.
//
// -----------------------------------------------------------------------
//
// Copyright (C) 2008 Elliot Glaysher
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
//
// -----------------------------------------------------------------------
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "effects/blind_effect.h"
#include "effects/effect.h"
#include "machine/rlmachine.h"
#include "test_system/mock_surface.h"
#include "test_system/test_event_system.h"
#include "test_system/test_system.h"
#include "test_utils.h"
#include <memory>
using namespace testing;
// Helper to specify the return value of GetTicks().
class EffectEventSystemTest : public EventSystemMockHandler {
public:
EffectEventSystemTest() : ticks(0) {}
void setTicks(unsigned int in) { ticks = in; }
virtual unsigned int GetTicks() const { return ticks; }
private:
unsigned int ticks;
};
class EffectTest : public FullSystemTest {
protected:
EffectTest() : event_system_impl(new EffectEventSystemTest) {
dynamic_cast<TestEventSystem&>(system.event())
.SetMockHandler(event_system_impl);
}
std::shared_ptr<EffectEventSystemTest> event_system_impl;
};
class MockEffect : public Effect {
public:
MockEffect(RLMachine& machine,
std::shared_ptr<Surface> src,
std::shared_ptr<Surface> dst,
Size size,
int time)
: Effect(machine, src, dst, size, time) {}
MOCK_METHOD2(PerformEffectForTime, void(RLMachine& machine, int));
MOCK_CONST_METHOD0(BlitOriginalImage, bool());
};
TEST_F(EffectTest, TestBase) {
std::shared_ptr<Surface> src(MockSurface::Create("src"));
std::shared_ptr<Surface> dst(MockSurface::Create("dst"));
std::unique_ptr<MockEffect> effect(
new MockEffect(rlmachine, src, dst, Size(640, 480), 2));
bool retVal = false;
for (int i = 0; i < 2; ++i) {
EXPECT_CALL(*effect, BlitOriginalImage()).WillOnce(Return(false));
EXPECT_CALL(*effect, PerformEffectForTime(_, i)).Times(1);
EXPECT_FALSE((*effect)(rlmachine)) << "Didn't prematurely quit";
ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(effect.get()));
event_system_impl->setTicks(i + 1);
}
EXPECT_TRUE((*effect)(rlmachine)) << "We didn't quit?";
}
// -----------------------------------------------------------------------
class MockBlitTopToBottom : public BlindTopToBottomEffect {
public:
MockBlitTopToBottom(RLMachine& machine,
std::shared_ptr<Surface> src,
std::shared_ptr<Surface> dst,
int width,
int height,
int time,
int blindSize)
: BlindTopToBottomEffect(machine,
src,
dst,
Size(width, height),
time,
blindSize) {}
MOCK_METHOD2(PerformEffectForTime, void(const RLMachine& machine, int));
MOCK_METHOD2(RenderPolygon, void(int, int));
};
TEST_F(EffectTest, BlindTopToBottomEffect) {
std::shared_ptr<MockSurface> src(MockSurface::Create("src"));
std::shared_ptr<MockSurface> dst(MockSurface::Create("dst"));
const int DURATION = 100;
const int BLIND_SIZE = 50;
const int HEIGHT = 480;
std::unique_ptr<MockBlitTopToBottom> effect(new MockBlitTopToBottom(
rlmachine, src, dst, 640, HEIGHT, DURATION, BLIND_SIZE));
int numBlinds = (HEIGHT / BLIND_SIZE) + 1;
bool retVal = false;
// Test at 0
EXPECT_CALL(*effect, RenderPolygon(0, 0)).Times(1);
EXPECT_FALSE((*effect)(rlmachine)) << "Prematurely quit";
ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(effect.get()));
// Test at 25
event_system_impl->setTicks(25);
EXPECT_CALL(*effect, RenderPolygon(0, 15)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(50, 64)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(100, 113)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(150, 162)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(200, 211)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(250, 260)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(300, 309)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(350, 358)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(400, 407)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(450, 456)).Times(1);
EXPECT_FALSE((*effect)(rlmachine)) << "Prematurely quit";
ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(effect.get()));
// Test at 50
event_system_impl->setTicks(50);
EXPECT_CALL(*effect, RenderPolygon(0, 30)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(50, 79)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(100, 128)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(150, 177)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(200, 226)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(250, 275)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(300, 324)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(350, 373)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(400, 422)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(450, 471)).Times(1);
EXPECT_FALSE((*effect)(rlmachine)) << "Prematurely quit";
ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(effect.get()));
// Test at 75
event_system_impl->setTicks(75);
EXPECT_CALL(*effect, RenderPolygon(0, 45)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(50, 94)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(100, 143)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(150, 192)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(200, 241)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(250, 290)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(300, 339)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(350, 388)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(400, 437)).Times(1);
EXPECT_CALL(*effect, RenderPolygon(450, 486)).Times(1);
EXPECT_FALSE((*effect)(rlmachine)) << "Prematurely quit";
ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(effect.get()));
// Test at the end
event_system_impl->setTicks(100);
EXPECT_TRUE((*effect)(rlmachine)) << "We didn't quit?";
}
|