diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2012-03-21 15:53:24 +0100 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2013-01-05 17:17:51 +0100 |
commit | 28f2baea42e44011c23b89473028b9bfc0376c00 (patch) | |
tree | 3f822c19c76f697e5a134ac0fad9b019223410fc | |
parent | 14989ee5a4bf1c60cb1455500f3dfabfa22441cb (diff) | |
download | usdx-28f2baea42e44011c23b89473028b9bfc0376c00.tar.gz usdx-28f2baea42e44011c23b89473028b9bfc0376c00.tar.xz usdx-28f2baea42e44011c23b89473028b9bfc0376c00.zip |
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)
-rw-r--r-- | src/utils/rectangle.hpp | 6 | ||||
-rw-r--r-- | test/utils/rectangle.cpp | 66 |
2 files changed, 72 insertions, 0 deletions
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<T>& 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 <exception> +#include <cppunit/extensions/HelperMacros.h> +#include <log4cpp/Category.hh> + +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<int> 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); +}; |