From ca4e7fc8dfa4187b76afae5d481e13e4ec6dac59 Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Sun, 15 Jan 2006 00:50:49 +0000 Subject: [PATCH] New Ruby test case for checking renames, predicate methods, bang methods and constants. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@8445 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Examples/test-suite/ruby/Makefile.in | 8 +- SWIG/Examples/test-suite/ruby/naming.i | 46 ++++++++++++ SWIG/Examples/test-suite/ruby/naming_runme.rb | 74 +++++++++++++++++++ 3 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 SWIG/Examples/test-suite/ruby/naming.i create mode 100644 SWIG/Examples/test-suite/ruby/naming_runme.rb diff --git a/SWIG/Examples/test-suite/ruby/Makefile.in b/SWIG/Examples/test-suite/ruby/Makefile.in index 81f3c074a..c4b1102fc 100644 --- a/SWIG/Examples/test-suite/ruby/Makefile.in +++ b/SWIG/Examples/test-suite/ruby/Makefile.in @@ -16,7 +16,8 @@ CPP_TEST_CASES = \ track_objects_directors \ primitive_types \ li_cdata \ - li_cstring + li_cstring \ + naming C_TEST_CASES += \ li_cdata \ @@ -27,7 +28,12 @@ include $(srcdir)/../common.mk # Overridden variables here SWIGOPT += -noautorename + # Rules for the different types of tests + +# make sure -autorename is true for the naming test +naming.cpptest: SWIGOPT = -autorename + %.cpptest: $(setup) \ ($(swig_and_compile_cpp); ) &&\ diff --git a/SWIG/Examples/test-suite/ruby/naming.i b/SWIG/Examples/test-suite/ruby/naming.i new file mode 100644 index 000000000..689f3dbd1 --- /dev/null +++ b/SWIG/Examples/test-suite/ruby/naming.i @@ -0,0 +1,46 @@ +%module naming + +%predicate predicateMethod(); +%bang bangMethod(); + +%inline %{ + + +class my_class { +public: + static const int const1 = 1; + + my_class() {} + + int methodOne() + { + return 1; + } + + int MethodTwo() + { + return 2; + } + + int Method_THREE() + { + return 3; + } + + int Method44_4() + { + return 4; + } + + bool predicateMethod() + { + return true; + } + + bool bangMethod() + { + return true; + } +}; + +%} \ No newline at end of file diff --git a/SWIG/Examples/test-suite/ruby/naming_runme.rb b/SWIG/Examples/test-suite/ruby/naming_runme.rb new file mode 100644 index 000000000..54c75f101 --- /dev/null +++ b/SWIG/Examples/test-suite/ruby/naming_runme.rb @@ -0,0 +1,74 @@ +require 'naming' + + +if not Naming + raise RuntimeError, 'Invalid module name for Naming' +end + +if not Naming::MyClass + raise RuntimeError, 'Invalid class name for MyClass' +end + +# Check constant names +if not Naming::MyClass::CONST1 + raise RuntimeError, 'Invalid constant name for CONST1' +end + + +# Check method names +if not Naming::MyClass.instance_methods.include?('method_one') + raise RuntimeError, 'Invalid method name for method_one' +end + +if not Naming::MyClass.instance_methods.include?('method_two') + raise RuntimeError, 'Invalid method name for method_two' +end + +if not Naming::MyClass.instance_methods.include?('method_three') + raise RuntimeError, 'Invalid method name for method_three' +end + +if not Naming::MyClass.instance_methods.include?('method44_4') + raise RuntimeError, 'Invalid method name for method44_4' +end + +# Check predicate methods +if not Naming::MyClass.instance_methods.include?('predicate_method?') + raise RuntimeError, 'Invalid method name for predicate_method?' +end + +# Check bang methods +if not Naming::MyClass.instance_methods.include?('bang_method!') + raise RuntimeError, 'Invalid method name for bang_method!' +end + +# Run all these methods as a sanity check +if Naming::MyClass::CONST1 != 1 + raise RuntimeError, "Incorrect value for CONST1" +end + +my_class = Naming::MyClass.new() + +if my_class.method_one != 1 + raise RuntimeError, "Incorrect value for method_one" +end + +if my_class.method_two != 2 + raise RuntimeError, "Incorrect value for method_two" +end + +if my_class.method_three != 3 + raise RuntimeError, "Incorrect value for method_three" +end + +if my_class.method44_4 != 4 + raise RuntimeError, "Incorrect value for method44_4" +end + +if my_class.predicate_method? != true + raise RuntimeError, "Incorrect value for predicate_method?" +end + +if my_class.bang_method! != true + raise RuntimeError, "Incorrect value for bang_method!" +end