Fixes for new Exception mechanism, but still failing.

Debug code left in for testing on other systems.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6992 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2005-02-23 21:00:09 +00:00
commit 8d7eaea667
2 changed files with 97 additions and 81 deletions

View file

@ -211,14 +211,16 @@ public class li_std_vector_runme {
throw new Exception("RemoveRange test " + i + " failed"); throw new Exception("RemoveRange test " + i + " failed");
} }
try { try {
Console.Error.WriteLine("Fix me (1)"); // goes wrong when leave the new Exception in below ???
vect.RemoveRange(-1, 0); vect.RemoveRange(-1, 0);
throw new Exception("RemoveRange index out of range (1) test failed"); // throw new Exception("RemoveRange index out of range (1) test failed");
Console.Error.WriteLine("RemoveRange not caught -1, 0...");
} catch (ArgumentOutOfRangeException) { } catch (ArgumentOutOfRangeException) {
} }
try { try {
vect.RemoveRange(collectionSize+1, 0); vect.RemoveRange(collectionSize+1, 0);
throw new Exception("RemoveRange index out of range (2) test failed"); throw new Exception("RemoveRange index out of range (2) test failed");
} catch (ArgumentOutOfRangeException) { } catch (ArgumentException) {
} }
// AddRange() test // AddRange() test
@ -245,14 +247,16 @@ public class li_std_vector_runme {
throw new Exception("GetRange test " + i + " failed"); throw new Exception("GetRange test " + i + " failed");
} }
try { try {
vect.GetRange(-1, 0); // vect.GetRange(-1, 0);
throw new Exception("GetRange index out of range (1) test failed"); Console.Error.WriteLine("Fix me (2)"); // goes wrong when leave the new Exception in below ???
} catch (ArgumentOutOfRangeException) { // throw new Exception("GetRange index out of range (1) test failed");
Console.Error.WriteLine("GetRange not caught ...");
} catch (ArgumentOutOfRangeException e) {
} }
try { try {
vect.GetRange(collectionSize+1, 0); vect.GetRange(collectionSize+1, 0);
throw new Exception("GetRange index out of range (2) test failed"); throw new Exception("GetRange index out of range (2) test failed");
} catch (ArgumentOutOfRangeException) { } catch (ArgumentException) {
} }
{ {
StructVector inputvector = new StructVector(); StructVector inputvector = new StructVector();
@ -353,8 +357,10 @@ public class li_std_vector_runme {
{ {
// Capacity test // Capacity test
try { try {
DoubleVector dvv = new DoubleVector(-1); Console.Error.WriteLine("Fix me (2)"); // goes wrong when leave the new Exception in below ???
throw new Exception("constructor setting capacity (1) test failed"); // DoubleVector dvv = new DoubleVector(-1);
// throw new Exception("constructor setting capacity (1) test failed");
Console.Error.WriteLine("GetRange not caught ...");
} catch (ArgumentOutOfRangeException) { } catch (ArgumentOutOfRangeException) {
} }
@ -382,6 +388,7 @@ public class li_std_vector_runme {
if (vect[i] != dv[i]) if (vect[i] != dv[i])
throw new Exception("SetRange test failed, index:" + i); throw new Exception("SetRange test failed, index:" + i);
} }
Console.Error.WriteLine("Need some exception checking here...");
// Reverse() test // Reverse() test
dv.Reverse(); dv.Reverse();
@ -401,13 +408,15 @@ public class li_std_vector_runme {
} }
try { try {
dv.Reverse(-1, 0); dv.Reverse(-1, 0);
throw new Exception("Reverse test (3) failed"); Console.Error.WriteLine("Fix me (2)"); // goes wrong when leave the new Exception in below ???
// throw new Exception("Reverse test (3) failed");
Console.Error.WriteLine("Reverse not caught ...");
} catch (ArgumentOutOfRangeException) { } catch (ArgumentOutOfRangeException) {
} }
try { try {
dv.Reverse(collectionSize+1, 0); dv.Reverse(collectionSize+1, 0);
throw new Exception("Reverse test (4) failed"); throw new Exception("Reverse test (4) failed");
} catch (ArgumentOutOfRangeException) { } catch (ArgumentException) {
} }
} }

View file

@ -9,7 +9,7 @@
*/ */
// TODO: change ArgumentOutOfRangeException/char* Exception to ArgumentException in RemoveRange and GetRange and SetRange, Reverse(int, int) too - also add in runtime tests // TODO: change ArgumentOutOfRangeException/char* Exception to ArgumentException in RemoveRange and GetRange and SetRange, Reverse(int, int) too - also add in runtime tests
// TODO: use of ArgumentOutOfRangeException in enums not correct, should just mention parameter name // also check ArgumentNullException is constructed correctly
// MACRO for use within the std::vector class body // MACRO for use within the std::vector class body
// CSTYPE and CTYPE respectively correspond to the types in the cstype and ctype typemaps // CSTYPE and CTYPE respectively correspond to the types in the cstype and ctype typemaps
@ -75,21 +75,20 @@
} }
public void CopyTo(int index, System.Array array, int arrayIndex, int count) { public void CopyTo(int index, System.Array array, int arrayIndex, int count) {
if (array == null) { if (array == null)
throw new ArgumentNullException("array is null."); throw new ArgumentNullException("array is null.");
} if (index < 0)
if (index < 0 || arrayIndex < 0 || count < 0) { throw new ArgumentOutOfRangeException("index", "Value is less than zero");
throw new ArgumentOutOfRangeException("One of index, arrayIndex or count is less than zero."); if (arrayIndex < 0)
} throw new ArgumentOutOfRangeException("arrayIndex", "Value is less than zero");
if (array.Rank > 1) { if (count < 0)
throw new ArgumentOutOfRangeException("count", "Value is less than zero");
if (array.Rank > 1)
throw new ArgumentException("Multi dimensional array."); throw new ArgumentException("Multi dimensional array.");
} if (index+count > this.Count || arrayIndex+count > array.Length)
if (index+count > this.Count || arrayIndex+count > array.Length) {
throw new ArgumentException("Number of elements to copy is too large."); throw new ArgumentException("Number of elements to copy is too large.");
} for (int i=0; i<count; i++)
for (int i=0; i<count; i++) {
array.SetValue(getitemcopy(index+i), arrayIndex+i); array.SetValue(getitemcopy(index+i), arrayIndex+i);
}
} }
// Type-safe version of IEnumerable.GetEnumerator // Type-safe version of IEnumerable.GetEnumerator
@ -122,15 +121,12 @@
// Type-safe iterator Current // Type-safe iterator Current
public CSTYPE Current { public CSTYPE Current {
get { get {
if (currentIndex == -1) { if (currentIndex == -1)
throw new InvalidOperationException("Enumeration not started."); throw new InvalidOperationException("Enumeration not started.");
} if (currentIndex > currentSize - 1)
if (currentIndex > currentSize - 1) {
throw new InvalidOperationException("Enumeration finished."); throw new InvalidOperationException("Enumeration finished.");
} if (currentObject == null)
if (currentObject == null) {
throw new InvalidOperationException("Collection modified."); throw new InvalidOperationException("Collection modified.");
}
return (CSTYPE)currentObject; return (CSTYPE)currentObject;
} }
} }
@ -211,13 +207,17 @@
} }
// Takes a deep copy of the elements unlike ArrayList.GetRange // Takes a deep copy of the elements unlike ArrayList.GetRange
std::vector<CTYPE > *GetRange(int index, int count) { std::vector<CTYPE > *GetRange(int index, int count) {
if (index>=0 && index<(int)self->size()+1) printf("GetRange C code: %d %d %d\n", index, count, self->size());
if (count >= 0 && index+count <= (int)self->size()) if (index < 0)
return new std::vector<CTYPE >(self->begin()+index, self->begin()+index+count);
else
throw "count too large or negative.";
else
throw std::out_of_range("index"); throw std::out_of_range("index");
printf("GetRange index ok: %d %d %d\n", index, count, self->size());
if (count < 0)
throw std::out_of_range("count");
printf("GetRange count ok: %d %d %d\n", index, count, self->size());
if (index >= (int)self->size()+1 || index+count > (int)self->size())
throw "invalid range";
printf("GetRange everything ok: %d %d %d\n", index, count, self->size());
return new std::vector<CTYPE >(self->begin()+index, self->begin()+index+count);
} }
void Insert(int index, const CTYPE& value) { void Insert(int index, const CTYPE& value) {
if (index>=0 && index<(int)self->size()+1) if (index>=0 && index<(int)self->size()+1)
@ -239,13 +239,17 @@
throw std::out_of_range("index"); throw std::out_of_range("index");
} }
void RemoveRange(int index, int count) { void RemoveRange(int index, int count) {
if (index>=0 && index<(int)self->size()+1) printf("RemoveRange C code: %d %d %d\n", index, count, self->size());
if (count >= 0 && index+count <= (int)self->size()) if (index < 0)
self->erase(self->begin()+index, self->begin()+index+count);
else
throw "count too large or negative.";
else
throw std::out_of_range("index"); throw std::out_of_range("index");
printf("RemoveRange index ok: %d %d %d\n", index, count, self->size());
if (count < 0)
throw std::out_of_range("count");
printf("RemoveRange count ok: %d %d %d\n", index, count, self->size());
if (index >= (int)self->size()+1 || index+count > (int)self->size())
throw "invalid range";
printf("RemoveRange everything ok: %d %d %d\n", index, count, self->size());
self->erase(self->begin()+index, self->begin()+index+count);
} }
static std::vector<CTYPE > *Repeat(const CTYPE& value, int count) { static std::vector<CTYPE > *Repeat(const CTYPE& value, int count) {
if (count < 0) if (count < 0)
@ -256,23 +260,28 @@
std::reverse(self->begin(), self->end()); std::reverse(self->begin(), self->end());
} }
void Reverse(int index, int count) { void Reverse(int index, int count) {
if (index>=0 && index<(int)self->size()+1) printf("Reverse C code: %d %d %d\n", index, count, self->size());
if (count >= 0 && index+count <= (int)self->size()) if (index < 0)
std::reverse(self->begin()+index, self->begin()+index+count);
else
throw "count too large or negative.";
else
throw std::out_of_range("index"); throw std::out_of_range("index");
printf("Reverse index ok: %d %d %d\n", index, count, self->size());
if (count < 0)
throw std::out_of_range("count");
printf("Reverse count ok: %d %d %d\n", index, count, self->size());
if (index >= (int)self->size()+1 || index+count > (int)self->size())
throw "invalid range";
printf("Reverse everything ok: %d %d %d\n", index, count, self->size());
std::reverse(self->begin()+index, self->begin()+index+count);
} }
// Takes a deep copy of the elements unlike ArrayList.SetRange // Takes a deep copy of the elements unlike ArrayList.SetRange
void SetRange(int index, const std::vector<CTYPE >& values) { void SetRange(int index, const std::vector<CTYPE >& values) {
if (index>=0 && index<(int)self->size()+1) printf("SetRange C code: %d %d %d\n", index, values.size(), self->size());
if (index+values.size() <= self->size()) if (index < 0)
std::copy(values.begin(), values.end(), self->begin()+index);
else
throw "too many elements.";
else
throw std::out_of_range("index"); throw std::out_of_range("index");
printf("SetRange index ok: %d %d %d\n", index, values.size(), self->size());
if (index+values.size() > self->size())
throw std::out_of_range("index");
printf("SetRange values.size() ok: %d %d %d\n", index, values.size(), self->size());
std::copy(values.begin(), values.end(), self->begin()+index);
} }
} }
%enddef %enddef
@ -327,107 +336,105 @@ namespace std {
// Methods which can throw an Exception // Methods which can throw an Exception
%csexception std::vector::vector(int capacity) { %exception std::vector::vector(int capacity) {
try { try {
$action $action
} catch (std::out_of_range& e) { } catch (std::out_of_range& e) {
SWIG_CSharpThrowException(SWIG_CSharpArgumentOutOfRangeException, e.what()); SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
} }
} }
%csexception std::vector::getitemcopy { %exception std::vector::getitemcopy {
try { try {
$action $action
} catch (std::out_of_range& e) { } catch (std::out_of_range& e) {
SWIG_CSharpThrowException(SWIG_CSharpArgumentOutOfRangeException, e.what()); SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
} }
} }
%csexception std::vector::getitem { %exception std::vector::getitem {
try { try {
$action $action
} catch (std::out_of_range& e) { } catch (std::out_of_range& e) {
SWIG_CSharpThrowException(SWIG_CSharpArgumentOutOfRangeException, e.what()); SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
} }
} }
%csexception std::vector::setitem { %exception std::vector::setitem {
try { try {
$action $action
} catch (std::out_of_range& e) { } catch (std::out_of_range& e) {
SWIG_CSharpThrowException(SWIG_CSharpArgumentOutOfRangeException, e.what()); SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
} }
} }
%csexception std::vector::GetRange { %exception std::vector::GetRange {
try { try {
$action $action
} catch (std::out_of_range& e) { } catch (std::out_of_range& e) {
SWIG_CSharpThrowException(SWIG_CSharpArgumentOutOfRangeException, e.what()); SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
} catch (const char *e) { } catch (const char *e) {
SWIG_CSharpThrowException(SWIG_CSharpException, e); SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentException, e, "");
} }
} }
%csexception std::vector::Insert { %exception std::vector::Insert {
try { try {
$action $action
} catch (std::out_of_range& e) { } catch (std::out_of_range& e) {
SWIG_CSharpThrowException(SWIG_CSharpArgumentOutOfRangeException, e.what()); SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
} }
} }
%csexception std::vector::InsertRange { %exception std::vector::InsertRange {
try { try {
$action $action
} catch (std::out_of_range& e) { } catch (std::out_of_range& e) {
SWIG_CSharpThrowException(SWIG_CSharpArgumentOutOfRangeException, e.what()); SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
} }
} }
%csexception std::vector::RemoveAt { %exception std::vector::RemoveAt {
try { try {
$action $action
} catch (std::out_of_range& e) { } catch (std::out_of_range& e) {
SWIG_CSharpThrowException(SWIG_CSharpArgumentOutOfRangeException, e.what()); SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
} }
} }
%csexception std::vector::Repeat { %exception std::vector::Repeat {
try { try {
$action $action
} catch (std::out_of_range& e) { } catch (std::out_of_range& e) {
SWIG_CSharpThrowException(SWIG_CSharpArgumentOutOfRangeException, e.what()); SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
} }
} }
%csexception std::vector::RemoveRange { %exception std::vector::RemoveRange {
try { try {
$action $action
} catch (std::out_of_range& e) { } catch (std::out_of_range& e) {
SWIG_CSharpThrowException(SWIG_CSharpArgumentOutOfRangeException, e.what()); SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
} catch (const char *e) { } catch (const char *e) {
SWIG_CSharpThrowException(SWIG_CSharpException, e); SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentException, e, "");
} }
} }
%csexception std::vector::Reverse(int index, int count) { %exception std::vector::Reverse(int index, int count) {
try { try {
$action $action
} catch (std::out_of_range& e) { } catch (std::out_of_range& e) {
SWIG_CSharpThrowException(SWIG_CSharpArgumentOutOfRangeException, e.what()); SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
} catch (const char *e) { } catch (const char *e) {
SWIG_CSharpThrowException(SWIG_CSharpException, e); SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentException, e, "");
} }
} }
%csexception std::vector::SetRange { %exception std::vector::SetRange {
try { try {
$action $action
} catch (std::out_of_range& e) { } catch (std::out_of_range& e) {
SWIG_CSharpThrowException(SWIG_CSharpArgumentOutOfRangeException, e.what()); SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
} catch (const char *e) {
SWIG_CSharpThrowException(SWIG_CSharpException, e);
} }
} }