Fix #3475492 - iterating through std::vector wrappers of enumerations.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12916 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2012-03-13 07:10:24 +00:00
commit 50693941c6
13 changed files with 253 additions and 0 deletions

View file

@ -472,6 +472,7 @@ CPP_STD_TEST_CASES += \
li_std_pair \
li_std_string \
li_std_vector \
li_std_vector_enum \
naturalvar \
smart_pointer_inherit \
template_typedef_fnc \

View file

@ -0,0 +1,27 @@
// This test tests all the methods in the C# collection wrapper
using System;
using li_std_vector_enumNamespace;
public class li_std_vector_enum_runme {
public static void Main() {
EnumVector ev = new EnumVector();
check((int)ev.nums[0], 10);
check((int)ev.nums[1], 20);
check((int)ev.nums[2], 30);
int expected = 10;
foreach (EnumVector.numbers val in ev.nums) {
check((int)val, expected);
expected += 10;
}
}
private static void check(int a, int b) {
if (a != b)
throw new ApplicationException("values don't match");
}
}

View file

@ -0,0 +1,27 @@
import li_std_vector_enum.*;
public class li_std_vector_enum_runme {
static {
try {
System.loadLibrary("li_std_vector_enum");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
public static void main(String argv[]) throws Throwable
{
EnumVector ev = new EnumVector();
check(ev.getNums().get(0).swigValue(), 10);
check(ev.getNums().get(1).swigValue(), 20);
check(ev.getNums().get(2).swigValue(), 30);
}
private static void check(int a, int b) {
if (a != b)
throw new RuntimeException("values don't match");
}
}

View file

@ -0,0 +1,23 @@
%module li_std_vector_enum
%include "std_vector.i"
%inline %{
class EnumVector {
public:
EnumVector() { fill_numbers(); }
enum numbers {ten=10, twenty=20, thirty=30};
std::vector<numbers> nums;
void fill_numbers() {
nums.push_back(ten);
nums.push_back(twenty);
nums.push_back(thirty);
}
};
%}
%template(vector_numbers) std::vector<EnumVector::numbers>;

View file

@ -0,0 +1,27 @@
li_std_vector_enum
function check(a, b)
if (a != b)
error("incorrect match");
endif
end
ev = EnumVector();
check(ev.nums(0), 10);
check(ev.nums(1), 20);
check(ev.nums(2), 30);
it = ev.nums.begin();
v = it.value();
check(v, 10);
it.next();
v = it.value();
check(v, 20);
#expected = 10
#ev.nums.each do|val|
# swig_assert(val == expected)
# expected += 10
#end

View file

@ -0,0 +1,24 @@
import li_std_vector_enum
def check(a, b):
if (a != b):
raise RuntimeError("Not equal: ", a, b)
ev = li_std_vector_enum.EnumVector()
check(ev.nums[0], 10)
check(ev.nums[1], 20)
check(ev.nums[2], 30)
it = ev.nums.iterator()
v = it.value()
check(v, 10)
it.next()
v = it.value()
check(v, 20)
expected = 10
for val in ev.nums:
check(val, expected)
expected += 10

View file

@ -0,0 +1,25 @@
#!/usr/bin/env ruby
require 'swig_assert'
require 'li_std_vector_enum'
include Li_std_vector_enum
ev = EnumVector.new()
swig_assert(ev.nums[0] == 10)
swig_assert(ev.nums[1] == 20)
swig_assert(ev.nums[2] == 30)
it = ev.nums.begin
v = it.value()
swig_assert(v == 10)
it.next()
v = it.value()
swig_assert(v == 20)
expected = 10
ev.nums.each do|val|
swig_assert(val == expected)
expected += 10
end