Added li_std_map.i as a generic test.
This is the test borrowed from python and changed to be made generic. Added ruby's runme script for it too. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9734 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
c0a7c7e081
commit
128386f928
2 changed files with 136 additions and 0 deletions
76
Examples/test-suite/li_std_map.i
Normal file
76
Examples/test-suite/li_std_map.i
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
* @file li_std_map.i
|
||||
* @author gga
|
||||
* @date Mon Apr 30 15:03:58 2007
|
||||
*
|
||||
* @brief a test of map containers.
|
||||
* Languages should define swig::LANGUAGE_OBJ to be
|
||||
* an entity of their native pointer type which can be
|
||||
* included in a STL container.
|
||||
*
|
||||
* For example:
|
||||
* swig::LANGUAGE_OBJ is GC_VALUE in Ruby
|
||||
* swig::LANGUAGE_OBJ is PyObject_ptr in python
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
%module("templatereduce") li_std_map
|
||||
%trackobjects;
|
||||
|
||||
%include std_pair.i
|
||||
%include std_map.i
|
||||
%include std_multimap.i
|
||||
|
||||
%inline %{
|
||||
struct A{
|
||||
int val;
|
||||
|
||||
A(int v = 0): val(v)
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
%}
|
||||
|
||||
namespace std
|
||||
{
|
||||
%template(pairii) pair<int, int>;
|
||||
%template(pairAA) pair<int, A>;
|
||||
%template(pairA) pair<int, A*>;
|
||||
%template(mapA) map<int, A*>;
|
||||
%template(mmapA) multimap<int, A*>;
|
||||
|
||||
%template(paircA1) pair<const int, A*>;
|
||||
%template(paircA2) pair<const int, const A*>;
|
||||
%template(pairiiA) pair<int,pair<int, A*> >;
|
||||
%template(pairiiAc) pair<int,const pair<int, A*> >;
|
||||
|
||||
|
||||
%template() pair< swig::LANGUAGE_OBJ, swig::LANGUAGE_OBJ >;
|
||||
%template(LanguageMap) map< swig::LANGUAGE_OBJ, swig::LANGUAGE_OBJ >;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
%inline
|
||||
{
|
||||
std::pair<int, A*>
|
||||
p_identa(std::pair<int, A*> p) {
|
||||
return p;
|
||||
}
|
||||
|
||||
std::map<int,A*> m_identa(const std::map<int,A*>& v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace std
|
||||
{
|
||||
%template(mapii) map<int,int>;
|
||||
}
|
||||
60
Examples/test-suite/ruby/li_std_map_runme.rb
Executable file
60
Examples/test-suite/ruby/li_std_map_runme.rb
Executable file
|
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env ruby
|
||||
#
|
||||
# Tests for std::map and std::multimap
|
||||
#
|
||||
# Author:: gga
|
||||
# Copyright:: 2007
|
||||
# License:: Ruby
|
||||
#
|
||||
|
||||
require 'swig_assert'
|
||||
require 'li_std_map'
|
||||
|
||||
swig_assert_each_line(<<'EOF', binding)
|
||||
|
||||
a1 = Li_std_map::A.new(3)
|
||||
a2 = Li_std_map::A.new(7)
|
||||
|
||||
p0 = Li_std_map::Pairii.new(1,2)
|
||||
p1 = Li_std_map::PairA.new(1,a1)
|
||||
m = {}
|
||||
m[1] = a1
|
||||
m[2] = a2
|
||||
|
||||
pp1 = Li_std_map::p_identa(p1)
|
||||
mm = Li_std_map::m_identa(m)
|
||||
|
||||
m = Li_std_map::MapA.new
|
||||
m[1] = a1
|
||||
m[2] = a2
|
||||
m.respond_to?(:each_key) == true
|
||||
m.respond_to?(:each_value) == true
|
||||
|
||||
pm ={}
|
||||
m.each_key { |k| pm[k] = m[k] }
|
||||
m.each_key { |k| swig_assert_equal("pm[k].object_id", "m[k].object_id", binding, 'only true if %trackings is on') }
|
||||
|
||||
m = {}
|
||||
m[1] = [1,2]
|
||||
m["foo"] = "hello"
|
||||
|
||||
pm = Li_std_map::LanguageMap.new
|
||||
m.each_key { |k| pm[k] = m[k] }
|
||||
m.each_key { |k| swig_assert("#{pm[k].inspect} == #{m[k].inspect}") }
|
||||
|
||||
m = Li_std_map::MmapA.new
|
||||
m[0] = a1
|
||||
m[0] = a2
|
||||
m[0].size == 2
|
||||
m.respond_to?(:each) == true
|
||||
m.respond_to?(:each_key) == true
|
||||
m.respond_to?(:each_value) == true
|
||||
|
||||
EOF
|
||||
|
||||
mii = Li_std_map::Mapii.new
|
||||
|
||||
mii[1] = 1
|
||||
mii[1] = 2
|
||||
|
||||
swig_assert( "mii[1] == 2", binding )
|
||||
Loading…
Add table
Add a link
Reference in a new issue