Beefed up features test. The C++ code will fail to compile if features are not working as expected.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6662 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2004-11-04 22:11:35 +00:00
commit 209a16645c

View file

@ -1,7 +1,7 @@
%module features %module features
// This testcase checks that %feature is working for templates and non user supplied constructors/destructors // This testcase checks that %feature is working for templates and non user supplied constructors/destructors and is just generally working
// If the default %exception is used it will not compile. It shouldn't get used. // If the default %exception is used it will not compile. It shouldn't get used.
%exception "this_will_not_compile"; %exception "this_will_not_compile";
@ -15,14 +15,22 @@ class Simple {};
%} %}
%exception NS::SimpleNS::SimpleNS() "$action /*Simple::Simple*/"; %exception NS::SimpleNS::SimpleNS() "$action /*NS::SimpleNS::SimpleNS*/";
%exception NS::SimpleNS::~SimpleNS() "$action /*Simple::~Simple*/"; %exception NS::SimpleNS::~SimpleNS() "$action /*NS::SimpleNS::~SimpleNS*/";
// method tests
%exception NS::SimpleNS::method() "_failed_ /*NS::Simple::method() const*/";
%exception NS::SimpleNS::method() const "$action /*NS::Simple::method() const*/";
%exception NS::SimpleNS::function() "$action /*NS::Simple::function()*/";
%inline %{ %inline %{
namespace NS namespace NS
{ {
class SimpleNS {}; class SimpleNS {
public:
void method() const {}
void function() {}
};
} }
%} %}
@ -54,7 +62,12 @@ template<class T> class SimpleTemplate {
%exception Template<int>::Template() "$action /*Template<int>::Template<int>*/"; %exception Template<int>::Template() "$action /*Template<int>::Template<int>*/";
%exception Template<int>::Template(const Template&) "$action /*Template<int>::Template<int>(const Template&)*/"; %exception Template<int>::Template(const Template&) "$action /*Template<int>::Template<int>(const Template&)*/";
%exception Template<int>::~Template() "$action /*Template<int>::~Template*/"; %exception Template<int>::~Template() "$action /*Template<int>::~Template*/";
// method tests
%exception Template<int>::foo "$action /*Template<int>::foo*/"; %exception Template<int>::foo "$action /*Template<int>::foo*/";
%exception Template::get "$action /*Template<int>::get*/";
%exception Template<int>::set(const int &t) "$action /*Template<int>::set(const int &t)*/";
%exception Template<int>::bar(const int &t) "_failed_ /*Template<int>::bar(const int &t) const*/";
%exception Template<int>::bar(const int &t) const "$action /*Template<int>::bar(const int &t) const*/";
%inline %{ %inline %{
template<class T> class Template { template<class T> class Template {
@ -64,85 +77,56 @@ public:
Template(const Template&){} Template(const Template&){}
~Template(){} ~Template(){}
void foo(){} void foo(){}
void bar(const int &t) const {}
#ifdef SWIG
%extend {
T& get(int i) const {
throw 1;
}
void set(const T &t) {}
}
#endif
}; };
%} %}
%template(TemplateInt) Template<int>; %template(TemplateInt) Template<int>;
// Test 5: wildcards
%exception { %exception Space::WildCards::WildCards() "$action /* Space::WildCards::WildCards() */";
$action // default %exception %exception Space::WildCards::~WildCards() "$action /* Space::WildCards::WildCards() */";
} %exception *::incy "_failure_ /* *::incy */";
%exception *::incy(int a) "_failure_ /* *::incy(int a) */";
%exception *::incy(int a) const "$action /* *::incy(int a) const */";
%newobject One::getSquare() const; %exception *::wincy(int a) "$action /* *::wincy(int a) */";
%exception *::spider "$action /* *::spider */";
%exception *::spider(int a) "_failure_ /* *::spider(int a) */";
%inline %{ %inline %{
namespace Space {
struct Square struct WildCards {
{ virtual WildCards* incy(int a) const { return 0; }
Square(int) virtual WildCards* wincy(int a) { return 0; }
{ virtual WildCards* spider(int a) const { return 0; }
};
} }
};
struct One {
Square *getSquare() const { return new Square(10); }
};
%} %}
%newobject Two::getSquare(); // Test 6: default arguments
%exception Space::Animals::Animals(int a = 0, double d = 0.0) "$action /* Space::Animals::Animals(int a = 0, double d = 0.0) */";
%exception Space::Animals::~Animals() "$action /* Space::Animals::~Animals() */";
%exception Space::Animals::lions(int a = 0, double d = 0.0) const "$action /* Space::Animals::lions(int a = 0, double d = 0.0) const */";
%exception Space::Animals::leopards(int a = 0, double d = 0.0) "$action /* Space::Animals::leopards(int a = 0, double d = 0.0) */";
%exception *::cheetahs(int a = 0, double d = 0.0) const "$action /* *::cheetahs(int a = 0, double d = 0.0) const */";
%exception *::jackal(int a = 0, double d = 0.0) "$action /* *::jackal(int a = 0, double d = 0.0) */";
%inline %{ %inline %{
struct Two { namespace Space {
Square *getSquare() const { return new Square(10); } struct Animals {
}; Animals(int a = 0, double d = 0.0) {}
void* lions(int a = 0, double d = 0.0) const { return 0; }
char *foo() {return 0;} void* leopards(int a = 0, double d = 0.0) { return 0; }
int cheetahs(int a = 0, double d = 0.0) const { return 0; }
%} int jackal(int a = 0, double d = 0.0) { return 0; }
%exception std::Vector::get {
$action; // get %exception
}
%inline %{
namespace std {
template<class T> class Vector {
public:
void push_back(const T& x) {}
#ifdef SWIG
%extend {
T& get(int i) {
throw 1;
}
}
#endif
}; };
} }
%} %}
%template(VectorInt) std::Vector<int>;
%ignore TROOT::TROOT(const char *name, const char *title, void *initfunc = 0);
%inline %{
class TROOT {
public:
TROOT()
{
}
TROOT(const char *name, const char *title, void *initfunc = 0)
{
}
};
%}