new operator overload tests to locate bugs in pre- increment/decrement operators
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10338 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
128880ea1d
commit
ad93f971ca
3 changed files with 90 additions and 0 deletions
|
|
@ -206,6 +206,7 @@ CPP_TEST_CASES += \
|
|||
newobject1 \
|
||||
ordering \
|
||||
operator_overload \
|
||||
operator_overload_break \
|
||||
overload_copy \
|
||||
overload_extend \
|
||||
overload_rename \
|
||||
|
|
|
|||
51
Examples/test-suite/operator_overload_break.i
Normal file
51
Examples/test-suite/operator_overload_break.i
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
%module operator_overload_break
|
||||
|
||||
%{
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
|
||||
class Op
|
||||
{
|
||||
public:
|
||||
Op(int n) {k = n;}
|
||||
Op(const Op& other) {
|
||||
std::cerr << "COPY: "<< other.k << std::endl;
|
||||
k = other.k;
|
||||
}
|
||||
|
||||
bool operator==(const Op& rhs) {
|
||||
std::cerr << "Op: " << k << std::endl;
|
||||
std::cerr << "obj: " << rhs.k << std::endl;
|
||||
return (k == rhs.k);
|
||||
}
|
||||
bool operator==(int i) {
|
||||
std::cerr << "Op: " << k << std::endl;
|
||||
std::cerr << "other: " << i << std::endl;
|
||||
return (k == i);
|
||||
}
|
||||
|
||||
Op operator+(const Op& rhs) {return Op(k + rhs.k);}
|
||||
Op operator+(int rhs) {return Op(k + rhs);}
|
||||
|
||||
Op operator-(const Op& rhs) {return Op(k - rhs.k);}
|
||||
Op operator-(int rhs) {
|
||||
std::cerr << "sub: " << rhs << std::endl;
|
||||
return Op(k - rhs);
|
||||
}
|
||||
|
||||
Op __rsub__(int lhs) {
|
||||
std::cerr << "sub: " << lhs << std::endl;
|
||||
return Op(lhs - k);
|
||||
}
|
||||
|
||||
Op& operator++() {k++; return *this;}
|
||||
|
||||
void Print() {std::cerr << k << std::endl;}
|
||||
|
||||
int k;
|
||||
};
|
||||
|
||||
%}
|
||||
38
Examples/test-suite/perl5/operator_overload_break_runme.pl
Normal file
38
Examples/test-suite/perl5/operator_overload_break_runme.pl
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/perl -w
|
||||
use strict;
|
||||
use Test::More tests => 6;
|
||||
|
||||
use operator_overload_break;
|
||||
|
||||
# Workaround for
|
||||
# ok( not (expression) , "test description" );
|
||||
# does not working in older versions of Perl, eg 5.004_04
|
||||
sub ok_not ($;$) {
|
||||
my($test, $name) = @_;
|
||||
$test = not $test;
|
||||
ok($test, $name);
|
||||
}
|
||||
|
||||
pass("loaded");
|
||||
|
||||
my $op = operator_overload_break::Op->new(5);
|
||||
|
||||
isa_ok($op, "operator_overload_break::Op");
|
||||
|
||||
ok((2 == $op - 3),
|
||||
"subtraction");
|
||||
|
||||
$op->{k} = 37;
|
||||
|
||||
ok((40 == $op + 3),
|
||||
"addition");
|
||||
|
||||
($op + 3)->Print();
|
||||
|
||||
$op->{k} = 22;
|
||||
|
||||
ok((10 == (32 - $op)),
|
||||
"reversed subtraction");
|
||||
|
||||
ok_not((3 == $op),
|
||||
'not equal');
|
||||
Loading…
Add table
Add a link
Reference in a new issue