URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-12-04 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Work on values.
* mln/value/rgb.hh: (rgb<n>(const metal::vec<3, unsigned>& rhs)) New.
* tests/value/Makefile.am: Add rgb_full test.
* tests/value/int_u8.cc: Update include.
* tests/value_macros.hh: Rename as...
* tests/value/macros.hh: ...this.
* tests/value/rgb_full.cc: Test all operator of rgb, an interop
with int and int_u8.
---
mln/value/rgb.hh | 8 ++
tests/value/Makefile.am | 6 ++
tests/value/int_u8.cc | 2
tests/value/macros.hh | 104 ++++++++++++++++++++++++++++++++++++
tests/value/rgb_full.cc | 137 ++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 256 insertions(+), 1 deletion(-)
Index: trunk/milena/tests/value_macros.hh (deleted)
===================================================================
Index: trunk/milena/tests/value/rgb_full.cc
===================================================================
--- trunk/milena/tests/value/rgb_full.cc (revision 0)
+++ trunk/milena/tests/value/rgb_full.cc (revision 1587)
@@ -0,0 +1,137 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// 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
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/value_rgb.cc
+ *
+ * \brief Tests on mln::value::rgb.
+ */
+
+#include <mln/value/rgb.hh>
+#include <mln/value/rgb8.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/literal/all.hh>
+
+
+#define sym_compare_assert(V1, OP, V2) \
+ \
+ mln_assertion(V1 OP V2);
+
+#define compute_rgb(V1, OP, V2) \
+ \
+ rgb8( \
+ V1.red() OP V2.red() , \
+ V1.green() OP V2.green() , \
+ V1.blue() OP V2.blue() \
+ )
+
+#define compute_rgb_sc(V1, OP, V2) \
+ \
+ rgb8( \
+ V1.red() OP V2 , \
+ V1.green() OP V2 , \
+ V1.blue() OP V2 \
+ )
+
+#define test_interop(T1, T2, OP, V1, V2) \
+{ \
+ T1 i = V1; \
+ T2 j = V2; \
+ \
+ i = i OP j; \
+ sym_compare_assert(i, ==, compute_rgb(V1, OP, V2)); \
+ sym_compare_assert(j, ==, V2); \
+ \
+ i = V1; \
+ j = V2; \
+ \
+ j = i OP j; \
+ sym_compare_assert(j, ==, compute_rgb(V1, OP, V2)); \
+ sym_compare_assert(i, ==, V1); \
+ \
+ i = V1; \
+ i OP##= i; \
+ sym_compare_assert(i, ==, compute_rgb(V1, OP, V1)); \
+ \
+ i = V1; \
+ j = V2; \
+ i OP##= j; \
+ sym_compare_assert(i, ==, compute_rgb(V1, OP, V2)); \
+ \
+ j OP##= j; \
+ sym_compare_assert(j, ==, compute_rgb(V2, OP, V2)); \
+ \
+ i = V1; \
+ j = V2; \
+ j OP##= i; \
+ sym_compare_assert(j, ==, compute_rgb(V2, OP, V1)); \
+ \
+ i = V1; \
+ i OP##= i; \
+ sym_compare_assert(i, ==, compute_rgb(V1, OP, V1)); \
+}
+
+
+// T1 is rgb, T2 is scalar
+#define test_interop_sc(T1, T2, OP, V1, V2) \
+{ \
+ T1 i = V1; \
+ T2 j = V2; \
+ \
+ i = i OP j; \
+ sym_compare_assert(i, ==, compute_rgb_sc(V1, OP, V2)); \
+ sym_compare_assert(j, ==, V2); \
+ \
+ i = V1; \
+ i OP##= i; \
+ sym_compare_assert(i, ==, compute_rgb(V1, OP, V1)); \
+ \
+ i = V1; \
+ j = V2; \
+ i OP##= j; \
+ sym_compare_assert(i, ==, compute_rgb_sc(V1, OP, V2)); \
+}
+
+int main()
+{
+ using namespace mln;
+ using value::rgb;
+ using value::rgb8;
+ using value::int_u8;
+
+ using literal::blue;
+ using literal::white;
+
+ {
+ test_interop(rgb8, rgb8, +, rgb8(4,5,6), rgb8(1,2,3));
+ test_interop(rgb8, rgb8, -, rgb8(4,5,6), rgb8(1,2,3))
+ test_interop_sc(rgb8, int, *, rgb8(4,5,6), 4);
+ test_interop_sc(rgb8, int, /, rgb8(40,50,60), 10);
+
+ test_interop_sc(rgb8, int_u8, *, rgb8(4,5,6), 4);
+ test_interop_sc(rgb8, int_u8, /, rgb8(40,50,60), 10);
+ }
+}
Index: trunk/milena/tests/value/macros.hh
===================================================================
--- trunk/milena/tests/value/macros.hh (revision 0)
+++ trunk/milena/tests/value/macros.hh (revision 1587)
@@ -0,0 +1,104 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// 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
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/value_macros.hh
+ *
+ * \brief Utilities to tests value types.
+ */
+
+#define sym_compare_assert(V1, OP, V2) \
+ \
+ mln_assertion(V1 OP V2); \
+ mln_assertion(-V1 OP -V2); \
+ mln_assertion(V2 OP V1); \
+ mln_assertion(-V2 OP -V1);
+
+#define asym_compare_assert(V1, OP, V2) \
+ \
+ mln_assertion(V1 OP V2); \
+ mln_assertion(!(-V1 OP -V2)); \
+ mln_assertion(-V2 OP -V1); \
+ mln_assertion(!(V2 OP V1));
+
+// For unsigned types, V1 > V2 if op is minus
+#define test_interop(T1, T2, OP, V1, V2) \
+ \
+{ \
+ T1 i = V1; \
+ T2 j = V2; \
+ \
+ i = i OP j; \
+ sym_compare_assert(i, ==, float(V1 OP V2)); \
+ sym_compare_assert(j, ==, float(V2)); \
+ \
+ i = V1; \
+ j = V2; \
+ \
+ j = i OP j; \
+ sym_compare_assert(j, ==, float(V1 OP V2)); \
+ sym_compare_assert(i, ==, float(V1)); \
+ \
+ i = V1; \
+ i OP##= i; \
+ sym_compare_assert(i, ==, float(V1 OP V1)); \
+ \
+ i = V1; \
+ j = V2; \
+ i OP##= j; \
+ sym_compare_assert(i, ==, float(V1 OP V2)); \
+ \
+ j OP##= j; \
+ sym_compare_assert(j, ==, float(V2 OP V2)); \
+ \
+ i = V1; \
+ j = V2; \
+ j OP##= i; \
+ sym_compare_assert(j, ==, float(V2 OP V1)); \
+ \
+ i = V1; \
+ i OP##= i; \
+ sym_compare_assert(i, ==, float(((V1 OP V1)))); \
+}
+
+#define test_operator(T, OP, V1, V2) \
+ \
+{ \
+ T i = V1; \
+ T j = V2; \
+ \
+ i = i OP j; \
+ sym_compare_assert(i, ==, float(V1 OP V2)); \
+ sym_compare_assert(j, ==, float(V2)); \
+ \
+ i = V1; \
+ i OP##= i; \
+ sym_compare_assert(i, ==, float(V1 OP V1)); \
+ \
+ i = V1; \
+ j = V2; \
+ i OP##= j; \
+}
Index: trunk/milena/tests/value/int_u8.cc
===================================================================
--- trunk/milena/tests/value/int_u8.cc (revision 1586)
+++ trunk/milena/tests/value/int_u8.cc (revision 1587)
@@ -31,7 +31,7 @@
*/
#include <mln/value/int_u8.hh>
-#include <tests/value_macros.hh>
+#include <tests/value/macros.hh>
int main()
Index: trunk/milena/tests/value/Makefile.am
===================================================================
--- trunk/milena/tests/value/Makefile.am (revision 1586)
+++ trunk/milena/tests/value/Makefile.am (revision 1587)
@@ -24,6 +24,9 @@
scalar \
set
+check_full_PROGRAMS = \
+ rgb_full
+
bool_SOURCES = bool.cc
builtin_SOURCES = builtin.cc
equiv_SOURCES = equiv.cc
@@ -41,4 +44,7 @@
scalar_SOURCES = scalar.cc
set_SOURCES = set.cc
+rgb_full_SOURCES = rgb_full.cc
+
TESTS = $(check_PROGRAMS)
+TESTS_FULL = $(check_full_PROGRAMS)
Index: trunk/milena/mln/value/rgb.hh
===================================================================
--- trunk/milena/mln/value/rgb.hh (revision 1586)
+++ trunk/milena/mln/value/rgb.hh (revision 1587)
@@ -122,6 +122,7 @@
/// Constructor from a metal::vec.
rgb<n>(const metal::vec<3, int>& rhs);
+ rgb<n>(const metal::vec<3, unsigned>& rhs);
rgb<n>(const metal::vec<3, int_u<n> >& rhs);
/// \{ Constructors with literals.
@@ -188,6 +189,13 @@
template <unsigned n>
inline
+ rgb<n>::rgb(const metal::vec<3, unsigned>& v)
+ {
+ this->v_ = v;
+ }
+
+ template <unsigned n>
+ inline
rgb<n>::rgb(const metal::vec<3, int_u<n> >& v)
{
this->v_ = v;