diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-01-10 01:24:55 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-01-10 01:24:55 +0300 |
commit | 009f1f8585c17ac27087bf96fed27db580bcfdc4 (patch) | |
tree | 9f7630b096f7b42be929e4ad24e83eea84070cf4 /src/render | |
parent | 633ae1cce17a9d5026e9812e9668a1c8f353e929 (diff) | |
download | mv-009f1f8585c17ac27087bf96fed27db580bcfdc4.tar.gz mv-009f1f8585c17ac27087bf96fed27db580bcfdc4.tar.bz2 mv-009f1f8585c17ac27087bf96fed27db580bcfdc4.tar.xz mv-009f1f8585c17ac27087bf96fed27db580bcfdc4.zip |
Add mock object for Graphics class.
Add tests for MapLayer::draw.
Diffstat (limited to 'src/render')
-rw-r--r-- | src/render/mockdrawitem.h | 56 | ||||
-rw-r--r-- | src/render/mockgraphics.cc | 311 | ||||
-rw-r--r-- | src/render/mockgraphics.h | 54 |
3 files changed, 421 insertions, 0 deletions
diff --git a/src/render/mockdrawitem.h b/src/render/mockdrawitem.h new file mode 100644 index 000000000..94198329a --- /dev/null +++ b/src/render/mockdrawitem.h @@ -0,0 +1,56 @@ +/* + * The ManaPlus Client + * Copyright (C) 2017 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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 2 of the License, or + * 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, see <http://www.gnu.org/licenses/>. + */ + +#ifndef RENDER_MOCKDRAWITEM_H +#define RENDER_MOCKDRAWITEM_H + +#ifdef UNITTESTS + +#include "enums/render/mockdrawtype.h" + +#include "localconsts.h" + +struct MockDrawItem final +{ + MockDrawItem(const MockDrawTypeT type, + const Image *const image0, + const int x0, + const int y0, + const int width0, + const int height0) : + image(image0), + drawType(type), + x(x0), + y(y0), + width(width0), + height(height0) + { + } + + const Image *image; + MockDrawTypeT drawType; + int x; + int y; + int width; + int height; +}; + +#endif // UNITTESTS +#endif // RENDER_MOCKDRAWITEM_H diff --git a/src/render/mockgraphics.cc b/src/render/mockgraphics.cc new file mode 100644 index 000000000..273e1f354 --- /dev/null +++ b/src/render/mockgraphics.cc @@ -0,0 +1,311 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2017 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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 2 of the License, or + * 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, see <http://www.gnu.org/licenses/>. + */ + +#include "render/mockgraphics.h" + +#include "graphicsmanager.h" + +#include "utils/sdlcheckutils.h" + +#include "utils/sdlpixel.h" + +#include "render/vertexes/imagecollection.h" + +#include "resources/imagerect.h" + +#include "resources/image/image.h" + +#include "debug.h" + +#ifndef SDL_BIG_ENDIAN +#error missing SDL_endian.h +#endif // SDL_BYTEORDER + +MockGraphics::MockGraphics() : + Graphics() +{ + mOpenGL = RENDER_SOFTWARE; + mName = "Software"; +} + +MockGraphics::~MockGraphics() +{ +} + +void MockGraphics::drawRescaledImage(const Image *restrict const image + A_UNUSED, + int dstX A_UNUSED, + int dstY A_UNUSED, + const int desiredWidth A_UNUSED, + const int desiredHeight A_UNUSED) + restrict2 +{ +} + +void MockGraphics::drawImage(const Image *restrict const image, + int dstX, + int dstY) restrict2 +{ + mDraws.push_back(MockDrawItem(MockDrawType::DrawImage, + image, + dstX, + dstY, + 0, + 0)); +} + +void MockGraphics::drawImageInline(const Image *restrict const image A_UNUSED, + int dstX A_UNUSED, + int dstY A_UNUSED) restrict2 +{ +} + +void MockGraphics::copyImage(const Image *restrict const image A_UNUSED, + int dstX A_UNUSED, + int dstY A_UNUSED) restrict2 +{ +} + +void MockGraphics::drawImageCached(const Image *restrict const image A_UNUSED, + int x A_UNUSED, + int y A_UNUSED) restrict2 +{ +} + +void MockGraphics::drawPatternCached(const Image *restrict const image + A_UNUSED, + const int x A_UNUSED, + const int y A_UNUSED, + const int w A_UNUSED, + const int h A_UNUSED) restrict2 +{ +} + +void MockGraphics::completeCache() restrict2 +{ +} + +void MockGraphics::drawPattern(const Image *restrict const image, + const int x, + const int y, + const int w, + const int h) restrict2 +{ + mDraws.push_back(MockDrawItem(MockDrawType::DrawPattern, + image, + x, + y, + w, + h)); +} + +void MockGraphics::drawPatternInline(const Image *restrict const image + A_UNUSED, + const int x A_UNUSED, + const int y A_UNUSED, + const int w A_UNUSED, + const int h A_UNUSED) restrict2 +{ +} + +void MockGraphics::drawRescaledPattern(const Image *restrict const image + A_UNUSED, + const int x A_UNUSED, + const int y A_UNUSED, + const int w A_UNUSED, + const int h A_UNUSED, + const int scaledWidth A_UNUSED, + const int scaledHeight A_UNUSED) + restrict2 +{ +} + +void MockGraphics::calcPattern(ImageVertexes *restrict const vert A_UNUSED, + const Image *restrict const image A_UNUSED, + const int x A_UNUSED, + const int y A_UNUSED, + const int w A_UNUSED, + const int h A_UNUSED) const restrict2 +{ +} + +void MockGraphics::calcPatternInline(ImageVertexes *restrict const vert + A_UNUSED, + const Image *restrict const image + A_UNUSED, + const int x A_UNUSED, + const int y A_UNUSED, + const int w A_UNUSED, + const int h A_UNUSED) const restrict2 +{ +} + +void MockGraphics::calcPattern(ImageCollection *restrict const vertCol + A_UNUSED, + const Image *restrict const image A_UNUSED, + const int x A_UNUSED, + const int y A_UNUSED, + const int w A_UNUSED, + const int h A_UNUSED) const restrict2 +{ +} + +void MockGraphics::calcTileVertexes(ImageVertexes *restrict const vert, + const Image *restrict const image, + int x, int y) const restrict2 +{ + vert->image = image; + calcTileSDL(vert, x, y); +} + +void MockGraphics::calcTileVertexesInline(ImageVertexes *restrict const vert + A_UNUSED, + const Image *restrict const image + A_UNUSED, + int x A_UNUSED, + int y A_UNUSED) const restrict2 +{ +} + +void MockGraphics::calcTileSDL(ImageVertexes *restrict const vert A_UNUSED, + int x A_UNUSED, + int y A_UNUSED) const restrict2 +{ +} + +void MockGraphics::calcTileCollection(ImageCollection *restrict const vertCol + A_UNUSED, + const Image *restrict const image + A_UNUSED, + int x A_UNUSED, + int y A_UNUSED) restrict2 +{ +} + +void MockGraphics::drawTileCollection(const ImageCollection *restrict const + vertCol A_UNUSED) restrict2 +{ +} + +void MockGraphics::drawTileVertexes(const ImageVertexes *restrict const + vert A_UNUSED) restrict2 +{ +} + +void MockGraphics::updateScreen() restrict2 +{ +} + +void MockGraphics::calcWindow(ImageCollection *restrict const vertCol A_UNUSED, + const int x A_UNUSED, + const int y A_UNUSED, + const int w A_UNUSED, + const int h A_UNUSED, + const ImageRect &restrict imgRect A_UNUSED) + restrict2 +{ +} + +void MockGraphics::fillRectangle(const Rect &restrict rectangle A_UNUSED) + restrict2 +{ +} + +void MockGraphics::beginDraw() restrict2 +{ + pushClipArea(Rect(0, 0, mRect.w, mRect.h)); +} + +void MockGraphics::endDraw() restrict2 +{ + popClipArea(); +} + +void MockGraphics::pushClipArea(const Rect &restrict area) restrict2 +{ + Graphics::pushClipArea(area); +} + +void MockGraphics::popClipArea() restrict2 +{ + Graphics::popClipArea(); +} + +void MockGraphics::drawPoint(int x A_UNUSED, + int y A_UNUSED) restrict2 +{ +} + +void MockGraphics::drawRectangle(const Rect &restrict rectangle A_UNUSED) + restrict2 +{ +} + +void MockGraphics::drawLine(int x1 A_UNUSED, + int y1 A_UNUSED, + int x2 A_UNUSED, + int y2 A_UNUSED) restrict2 +{ +} + +bool MockGraphics::setVideoMode(const int w, const int h, + const int scale, + const int bpp, + const bool fs, + const bool hwaccel, + const bool resize, + const bool noFrame) restrict2 +{ + setMainFlags(w, h, scale, bpp, fs, hwaccel, resize, noFrame); + + if (!(mWindow = graphicsManager.createWindow(w, h, bpp, + getSoftwareFlags()))) + { + mRect.w = 0; + mRect.h = 0; + return false; + } + + mRect.w = CAST_U16(mWindow->w); + mRect.h = CAST_U16(mWindow->h); + + return videoInfo(); +} + +void MockGraphics::drawImageRect(const int x A_UNUSED, + const int y A_UNUSED, + const int w A_UNUSED, + const int h A_UNUSED, + const ImageRect &restrict imgRect A_UNUSED) + restrict2 +{ +} + +void MockGraphics::calcImageRect(ImageVertexes *restrict const vert A_UNUSED, + const int x A_UNUSED, + const int y A_UNUSED, + const int w A_UNUSED, + const int h A_UNUSED, + const ImageRect &restrict imgRect A_UNUSED) + restrict2 +{ +} diff --git a/src/render/mockgraphics.h b/src/render/mockgraphics.h new file mode 100644 index 000000000..3d38f4a51 --- /dev/null +++ b/src/render/mockgraphics.h @@ -0,0 +1,54 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2017 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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 2 of the License, or + * 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, see <http://www.gnu.org/licenses/>. + */ + +#ifndef RENDER_MOCKGRAPHICS_H +#define RENDER_MOCKGRAPHICS_H + +#ifdef UNITTESTS + +#include "render/graphics.h" +#include "render/mockdrawitem.h" + +#include "localconsts.h" + +#include <vector> + +class MockGraphics final : public Graphics +{ + public: + MockGraphics(); + + A_DELETE_COPY(MockGraphics) + + ~MockGraphics(); + + #include "render/graphicsdef.hpp" + RENDER_GRAPHICSDEF_HPP + + #include "render/softwaregraphicsdef.hpp" + RENDER_SOFTWAREGRAPHICSDEF_HPP + + std::vector<MockDrawItem> mDraws; +}; + +#endif // UNITTESTS +#endif // RENDER_MOCKGRAPHICS_H |