Commit 90ef404d authored by Ian Henriksen's avatar Ian Henriksen

Added tests to make sure the correct exception handling routines are

called when different c++ exception handling needs to take place for
different parts of a given expression.
parent f5537bb0
......@@ -202,15 +202,15 @@ public:
return this->val;
}
wrapped_int &operator=(const wrapped_int &other) {
if (other.val == 4) {
throw std::overflow_error("4 is really too big!");
if ((other.val == 4) && (this->val == 4)) {
throw std::overflow_error("Can't assign 4 to 4!");
}
this->val = other.val;
return *this;
}
wrapped_int &operator=(const long long &v) {
if (v == 4) {
throw std::overflow_error("4 is really too small!");
if ((v == 4) && (this->val == 4)) {
throw std::overflow_error("Can't assign 4 to 4!");
}
this->val = v;
return *this;
......@@ -229,11 +229,11 @@ cdef extern from "wint.cpp" nogil:
wrapped_int()
wrapped_int(long long val)
wrapped_int(long long v1, long long v2) except +
wrapped_int operator+(wrapped_int &other) except +
wrapped_int operator+() except +
wrapped_int operator+(wrapped_int &other) except +ValueError
wrapped_int operator+() except +RuntimeError
wrapped_int operator-(wrapped_int &other) except +
wrapped_int operator-() except +
wrapped_int operator*(wrapped_int &other) except +
wrapped_int operator*(wrapped_int &other) except +OverflowError
wrapped_int operator/(wrapped_int &other) except +
wrapped_int operator%(wrapped_int &other) except +
long long operator^(wrapped_int &other) except +
......@@ -255,18 +255,26 @@ cdef extern from "wint.cpp" nogil:
wrapped_int operator--(int) except +
wrapped_int operator!() except +
bool operator bool() except +
wrapped_int &operator[](long long &index) except +
wrapped_int &operator[](long long &index) except +IndexError
long long &operator()() except +
wrapped_int &operator=(const wrapped_int &other) except +
wrapped_int &operator=(const wrapped_int &other) except +ArithmeticError
wrapped_int &operator=(const long long &vao) except +
def assert_raised(f, *args):
try:
f(*args)
raised = False
except:
raised = True
def assert_raised(f, *args, **kwargs):
err = kwargs.get('err', None)
if err is None:
try:
f(*args)
raised = False
except:
raised = True
else:
try:
f(*args)
raised = False
except err:
raised = True
assert raised
def initialization(long long a, long long b):
......@@ -424,33 +432,45 @@ def cascaded_assign(long long a, long long b, long long c):
a = b = c
return a.val
def separate_exceptions(long long a, long long b, long long c, long long d, long long e):
cdef:
wrapped_int wa = wrapped_int(a)
wrapped_int wc = wrapped_int(c)
wrapped_int wd = wrapped_int(d)
wrapped_int we = wrapped_int(e)
wa[b] = (+wc) * wd + we
return a.val
def test():
a = 1
b = 4
c = 4
assert_raised(initialization, a, b)
assert_raised(addition, a, b)
assert_raised(subtraction, a, b)
assert_raised(multiplication, a, b)
assert_raised(division, a, b)
assert_raised(mod, a, b)
assert_raised(minus, b)
assert_raised(plus, b)
assert_raised(xor, a, b)
assert_raised(address, b)
assert_raised(iseq, a, b)
assert_raised(neq, a, b)
assert_raised(left_shift, a, b)
assert_raised(right_shift, a, b)
assert_raised(cpp_preincrement, b)
assert_raised(cpp_predecrement, b)
assert_raised(cpp_postincrement, b)
assert_raised(cpp_postdecrement, b)
assert_raised(negate, b)
assert_raised(bool_cast, b)
assert_raised(index, a, b)
assert_raised(assign_index, a, b, c)
assert_raised(assign_same, a, b)
assert_raised(assign_different, a, b)
assert_raised(cascaded_assign, a, b, c)
assert_raised(cascaded_assign, b, a, c)
assert_raised(initialization, 1, 4)
assert_raised(addition, 1, 4)
assert_raised(subtraction, 1, 4)
assert_raised(multiplication, 1, 4)
assert_raised(division, 1, 4)
assert_raised(mod, 1, 4)
assert_raised(minus, 4)
assert_raised(plus, 4)
assert_raised(xor, 1, 4)
assert_raised(address, 4)
assert_raised(iseq, 1, 4)
assert_raised(neq, 1, 4)
assert_raised(left_shift, 1, 4)
assert_raised(right_shift, 1, 4)
assert_raised(cpp_preincrement, 4)
assert_raised(cpp_predecrement, 4)
assert_raised(cpp_postincrement, 4)
assert_raised(cpp_postdecrement, 4)
assert_raised(negate, 4)
assert_raised(bool_cast, 4)
assert_raised(index, 1, 4)
assert_raised(assign_index, 1, 4, 4)
assert_raised(call, 4)
assert_raised(assign_same, 4, 4)
assert_raised(assign_different, 4, 4)
assert_raised(cascaded_assign, 4, 4, 1)
assert_raised(cascaded_assign, 4, 1, 4)
assert_raised(separate_exceptions, 1, 1, 1, 1, 4, err=ValueError)
assert_raised(separate_exceptions, 1, 1, 1, 4, 1, err=OverflowError)
assert_raised(separate_exceptions, 1, 1, 4, 1, 1, err=RuntimeError)
assert_raised(separate_exceptions, 1, 4, 1, 1, 1, err=IndexError)
assert_raised(separate_exceptions, 4, 1, 1, 1, 3, err=ArithmeticError)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment