[cluttermm] Test file for ActorBox class.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cluttermm] Test file for ActorBox class.
- Date: Fri, 21 Mar 2014 09:45:40 +0000 (UTC)
commit be4dea9bc99876fe8db4c2c6f02cb55a5d15e615
Author: Ian Martin <martin_id vodafone co nz>
Date: Thu Mar 20 14:30:34 2014 +1300
Test file for ActorBox class.
Also adds the test to tests/Makefile.am
tests/Makefile.am | 5 +-
tests/test-actor-box.cc | 133 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 136 insertions(+), 2 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7603a26..5fcf26c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -17,7 +17,7 @@
check_PROGRAMS = \
test-alpha-creation test-alpha-func \
-test-interval-creation test-point-class
+test-interval-creation test-point-class test-actor-box
local_includes = -I$(top_builddir)/clutter $(if $(srcdir:.=),-I$(top_srcdir)/clutter)
local_libs = $(top_builddir)/clutter/cluttermm/libcluttermm-$(CLUTTERMM_API_VERSION).la
@@ -30,8 +30,9 @@ test_alpha_creation_SOURCES = test-alpha-creation.cc
test_alpha_func_SOURCES = test-alpha-func.cc
test_interval_creation_SOURCES = test-interval-creation.cc
test_point_class_SOURCES = test-point-class.cc
+test_actor_box_SOURCES = test-actor-box.cc
# Only tests that don't require user input are added here, as they will
# run automatically on building:
-TESTS = test-interval-creation test-point-class
+TESTS = test-interval-creation test-point-class test-actor-box
diff --git a/tests/test-actor-box.cc b/tests/test-actor-box.cc
new file mode 100644
index 0000000..f699bf2
--- /dev/null
+++ b/tests/test-actor-box.cc
@@ -0,0 +1,133 @@
+/* Copyright (C) 2014 The cluttermm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <cluttermm.h>
+#include <iostream>
+
+int main(int argc, char** argv)
+{
+ // initialize the C++ wrapper types
+ Clutter::init(&argc, &argv);
+
+ //a return value to allow make check to output a useful summary:
+ int errorval(0);
+
+ int int_a(1);
+ int int_b(2);
+ int int_c(400);
+ int int_d(500);
+ std::cout << "Creating Clutter::ActorBox with (int) values:"<< int_a << "/" << int_b << " and " << int_c
<< "/" << int_d << std::endl;
+
+ Clutter::ActorBox box1 = Clutter::ActorBox( int_a, int_b, int_c, int_d );
+
+ if( ( box1.get_x() != int_a ) || ( box1.get_y() != int_b ) )
+ {
+ errorval++;
+ std::cerr << "Getting incorrect values from Box1: " << box1.get_x() <<
+ " should be " << int_a << " , " << box1.get_y() << "should be " <<
+ int_b << std::endl;
+ }
+ if( ( box1.get_width() != ( int_c - int_a ) ) ||
+ ( box1.get_height() != (int_d - int_b ) ) )
+ {
+ errorval++;
+ std::cerr << "Getting incorrect values from Box1: " << box1.get_width() <<
+ " should be " << int_c - int_a << " , " << box1.get_height() << "should be " <<
+ int_d - int_b << std::endl;
+ }
+
+ // copy and (in)equality:
+ Clutter::ActorBox box2 = box1;
+
+ if(box1 != box2)
+ {
+ errorval+= 10;
+ std::cerr << " box1 and box2 not equal." << std::endl;
+ std::cerr << "box1: origin " << box1.get_x() << "/" << box1.get_y() <<
+ ", width = " << box1.get_width() << ", height = " << box1.get_height()
+ <<std::endl;
+ }
+
+ //get and set origin (and default constructor):
+ Clutter::ActorBox box3;
+ float new_origin_x(100);
+ float new_origin_y(101);
+
+ box3.set_origin( new_origin_x, new_origin_y );
+ float origin_x(0);
+ float origin_y(0);
+ box3.get_origin(origin_x, origin_y);
+
+ if( ( origin_x != new_origin_x ) || ( origin_y != new_origin_y ) )
+ {
+ errorval += 20;
+ std::cerr<< "get/set origin not correct: Set " << new_origin_x << "/ " <<
+ new_origin_y << "; returned " <<
+ origin_x << "/ " << origin_y <<std::endl;
+ }
+
+ //get and set size:
+ float new_size_x(200);
+ float new_size_y(201);
+ box3.set_size( new_size_x, new_size_y );
+
+ float size_x(0);
+ float size_y(0);
+ box3.get_size(size_x, size_y);
+
+ if( ( size_x != new_size_x ) || ( size_y != new_size_y ) )
+ {
+ errorval += 30;
+ std::cerr << "get/set size not correct: Set " << new_size_x << "/ " <<
+ new_size_y << "; returned " <<
+ size_x << "/ " << size_y <<std::endl;
+ }
+
+ //get_area:
+ if( box1.get_area() != ( (int_d - int_b ) * ( int_c - int_a ) ) )
+ {
+ errorval += 100;
+ std::cerr<< "get area incorrect for box1 " << box1.get_area() << " vs " <<
+ ( (int_d - int_b ) * ( int_c - int_a ) ) << std::endl;
+ }
+
+ if( box3.get_area() != ( new_size_x * new_size_y ) )
+ {
+ errorval += 200;
+ std::cerr<< "get area incorrect for box3 " << box3.get_area() << " vs " <<
+ new_size_x * new_size_y << std::endl;
+ }
+
+ // contains:
+ Clutter::ActorBox box4(30, 30, 100, 101);
+ // outside:
+ if( box4.contains(25, 50) )
+ {
+ errorval+= 1000;
+ std::cerr << "ActorBox::contains is wrong: box4 contains 25-50." << std::endl;
+ }
+ // inside:
+ if( box4.contains(50, 50) == false)
+ {
+ errorval += 2000;
+ std::cerr << " ActorBox::contains : 30, 30, 100, 101 doesn't contain 50-50." << std::endl;
+ }
+
+ // TODO: clamp_to_pixel, interpolate, unite.
+
+ return errorval;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]