From ab7bab0a4fd054f533ef4bb775f19c514cfd1c70 Mon Sep 17 00:00:00 2001 From: Lars Kanis <lars@greiz-reinsdorf.de> Date: Sat, 15 Mar 2014 15:20:41 +0100 Subject: [PATCH] Revert "width is a integer value, this is enforced by swig-2.0" Add test cases for non Integer assignment to FXuchar, FXshort and FXint. It's typically possible to assign Float values to methods expecting Integers and we also shouldn't break compatibility. This reverts commit 3360c669df027835ca8a06e69574478a4faa8d51. --- examples/shutter.rb | 2 +- swig-interfaces/ruby-typemaps.i | 9 +++++++++ test/TC_FXSize.rb | 12 ++++++++++++ test/TC_FXWindow.rb | 26 ++++++++++++++++++++++++++ test/TC_Misc.rb | 2 ++ 5 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 test/TC_FXWindow.rb diff --git a/examples/shutter.rb b/examples/shutter.rb index 7655500..136f93e 100755 --- a/examples/shutter.rb +++ b/examples/shutter.rb @@ -139,7 +139,7 @@ class ShutterWindow < FXMainWindow def create super - @shutter.width = (1.25*@shutter.width).to_i + @shutter.width = 1.25*@shutter.width show(PLACEMENT_SCREEN) end end diff --git a/swig-interfaces/ruby-typemaps.i b/swig-interfaces/ruby-typemaps.i index d51b8dd..929a054 100644 --- a/swig-interfaces/ruby-typemaps.i +++ b/swig-interfaces/ruby-typemaps.i @@ -34,6 +34,15 @@ FXWindow* owner } +%typemap(in) FXchar "$1 = NUM2INT($input);"; +%typemap(in) FXuchar "$1 = NUM2UINT($input);"; +%typemap(in) FXshort "$1 = NUM2INT($input);"; +%typemap(in) FXushort "$1 = NUM2UINT($input);"; +%typemap(in) FXint "$1 = NUM2INT($input);"; +%typemap(in) FXuint "$1 = NUM2UINT($input);"; +%typemap(in) FXlong "$1 = NUM2LONG($input);"; +%typemap(in) FXulong "$1 = NUM2ULONG($input);"; + /* Type-checking rules */ %typecheck(SWIG_TYPECHECK_STRING) const FXString&, FXuchar *data { $1 = (NIL_P($input) || TYPE($input) == T_STRING) ? 1 : 0; diff --git a/test/TC_FXSize.rb b/test/TC_FXSize.rb index 4865b7f..503541d 100755 --- a/test/TC_FXSize.rb +++ b/test/TC_FXSize.rb @@ -36,6 +36,18 @@ class TC_FXSize < Test::Unit::TestCase assert(size2.w == -(@size2.w) && size2.h == -(@size2.h)) end + def test_float + @size1.w = 2.8 + @size2.h = 5.8 + assert_equal(2, @size1.w) + assert_equal(5, @size2.h) + end + + def test_invalid_type + assert_raise(TypeError){ @size1.w = nil } + assert_raise(TypeError){ @size2.h = true } + end + def test_add assert_equal(FXSize.new(1, 2) + FXSize.new(3, 4), FXSize.new(4, 6)) end diff --git a/test/TC_FXWindow.rb b/test/TC_FXWindow.rb new file mode 100644 index 0000000..cb93678 --- /dev/null +++ b/test/TC_FXWindow.rb @@ -0,0 +1,26 @@ +require 'test/unit' +require 'fox16' +require 'testcase' + +class TC_FXWindow < Fox::TestCase + include Fox + + def setup + super(self.class.name) + @window = FXWindow.new(mainWindow) + end + + def test_width_accessor + pos = @window.width + assert_instance_of(Fixnum, pos) + @window.width = pos + 1 + assert_equal(pos + 1, @window.width) + @window.width = pos + 2.7 + assert_equal(pos + 2, @window.width) + assert_kind_of(Integer, @window.width) + end + + def test_width_invalid + assert_raise(TypeError){ @window.width = nil } + end +end diff --git a/test/TC_Misc.rb b/test/TC_Misc.rb index 9c91c5a..80ff085 100755 --- a/test/TC_Misc.rb +++ b/test/TC_Misc.rb @@ -44,6 +44,7 @@ class TC_Misc < Test::Unit::TestCase def test_FXREDVAL assert_equal(1, Fox.FXREDVAL(Fox.FXRGB(1, 0, 0))) + assert_equal(10, Fox.FXREDVAL(Fox.FXRGB(10.6, 0, 0))) end def test_FXGREENVAL @@ -56,6 +57,7 @@ class TC_Misc < Test::Unit::TestCase def test_FXALPHAVAL assert_equal(1, Fox.FXALPHAVAL(Fox.FXRGBA(0, 0, 0, 1))) + assert_equal(10, Fox.FXALPHAVAL(Fox.FXRGBA(0, 0, 0, 10.6))) end def test_FXRGBACOMPVAL -- GitLab