aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/utils/rectangle.hpp6
-rw-r--r--test/utils/rectangle.cpp66
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);
+};