From 28f2baea42e44011c23b89473028b9bfc0376c00 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 21 Mar 2012 15:53:24 +0100 Subject: utils/rectangle: added constructor for array of values the new constructor is used to make a rectangle object from the array of values returned from glGet(GL_SCISSOR_BOX) --- src/utils/rectangle.hpp | 6 +++++ test/utils/rectangle.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 test/utils/rectangle.cpp diff --git a/src/utils/rectangle.hpp b/src/utils/rectangle.hpp index abe26ef1..2131afc8 100644 --- a/src/utils/rectangle.hpp +++ b/src/utils/rectangle.hpp @@ -63,6 +63,12 @@ namespace usdx { } + Rectangle(const T rectangle[]) : + point1(rectangle[0], rectangle[1]), + point2(rectangle[0] + rectangle[2], rectangle[1] + rectangle[3]) + { + } + Rectangle(const Rectangle& rectangle) : point1(rectangle.point1), point2(rectangle.point2) { diff --git a/test/utils/rectangle.cpp b/test/utils/rectangle.cpp new file mode 100644 index 00000000..f2fe93ea --- /dev/null +++ b/test/utils/rectangle.cpp @@ -0,0 +1,66 @@ +/* + * UltraStar Deluxe - Karaoke Game + * + * UltraStar Deluxe is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * 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 (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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + */ + +#include "rectangle.hpp" + +#include +#include +#include + +namespace usdx +{ + class RectangleTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(RectangleTest); + CPPUNIT_TEST(testInit); + CPPUNIT_TEST_SUITE_END(); + private: + static log4cpp::Category& log; + public: + void setUp() + { + } + + void tearDown() + { + } + + void testInit() + { + int coords[] = { 100, 150, 200, 250 }; + Rectangle rect(coords); + + CPPUNIT_ASSERT(rect.get_x() == 100); + CPPUNIT_ASSERT(rect.get_y() == 150); + CPPUNIT_ASSERT(rect.get_width() == 200); + CPPUNIT_ASSERT(rect.get_height() == 250); + } + }; + + log4cpp::Category& RectangleTest::log = + log4cpp::Category::getInstance("test.usdx.utils.rectangle"); + + CPPUNIT_TEST_SUITE_REGISTRATION(RectangleTest); +}; -- cgit v1.2.3