Duplicate tests that are run twice as both C and C++ tests to fix parallel make: li_carrays

This commit is contained in:
William S Fulton 2016-02-21 14:47:25 +00:00
parent 78b113558f
commit 9600c95234
11 changed files with 320 additions and 1 deletions

View File

@ -264,7 +264,7 @@ CPP_TEST_CASES += \
li_boost_shared_ptr_bits \
li_boost_shared_ptr_template \
li_boost_shared_ptr_attribute \
li_carrays \
li_carrays_cpp \
li_cdata \
li_cpointer \
li_std_auto_ptr \

View File

@ -0,0 +1,14 @@
package main
import . "./li_carrays_cpp"
func main() {
d := NewDoubleArray(10)
d.Setitem(0, 7)
d.Setitem(5, d.Getitem(0)+3)
if d.Getitem(5)+d.Getitem(0) != 17 {
panic(0)
}
}

View File

@ -0,0 +1,88 @@
import li_carrays_cpp.*;
public class li_carrays_cpp_runme {
static {
try {
System.loadLibrary("li_carrays_cpp");
} 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
{
// array_class
{
int length = 5;
XYArray xyArray = new XYArray(length);
for (int i=0; i<length; i++) {
XY xy = xyArray.getitem(i);
xy.setX(i*10);
xy.setY(i*100);
xyArray.setitem(i, xy);
}
for (int i=0; i<length; i++) {
Assert(xyArray.getitem(i).getX(), i*10);
Assert(xyArray.getitem(i).getY(), i*100);
}
}
{
// global array variable
int length = 3;
XY xyArrayPointer = li_carrays_cpp.getGlobalXYArray();
XYArray xyArray = XYArray.frompointer(xyArrayPointer);
for (int i=0; i<length; i++) {
XY xy = xyArray.getitem(i);
xy.setX(i*10);
xy.setY(i*100);
xyArray.setitem(i, xy);
}
for (int i=0; i<length; i++) {
Assert(xyArray.getitem(i).getX(), i*10);
Assert(xyArray.getitem(i).getY(), i*100);
}
}
// array_functions
{
int length = 5;
AB abArray = li_carrays_cpp.new_ABArray(length);
for (int i=0; i<length; i++) {
AB ab = li_carrays_cpp.ABArray_getitem(abArray, i);
ab.setA(i*10);
ab.setB(i*100);
li_carrays_cpp.ABArray_setitem(abArray, i, ab);
}
for (int i=0; i<length; i++) {
Assert(li_carrays_cpp.ABArray_getitem(abArray, i).getA(), i*10);
Assert(li_carrays_cpp.ABArray_getitem(abArray, i).getB(), i*100);
}
li_carrays_cpp.delete_ABArray(abArray);
}
{
// global array variable
int length = 3;
AB abArray = li_carrays_cpp.getGlobalABArray();
for (int i=0; i<length; i++) {
AB ab = li_carrays_cpp.ABArray_getitem(abArray, i);
ab.setA(i*10);
ab.setB(i*100);
li_carrays_cpp.ABArray_setitem(abArray, i, ab);
}
for (int i=0; i<length; i++) {
Assert(li_carrays_cpp.ABArray_getitem(abArray, i).getA(), i*10);
Assert(li_carrays_cpp.ABArray_getitem(abArray, i).getB(), i*100);
}
}
}
private static void Assert(int val1, int val2) {
// System.out.println("val1=" + val1 + " val2=" + val2);
if (val1 != val2)
throw new RuntimeException("Mismatch. val1=" + val1 + " val2=" + val2);
}
}

View File

@ -0,0 +1,28 @@
%module li_carrays_cpp
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) doubleArray; /* Ruby, wrong class name */
%include <carrays.i>
%array_functions(int,intArray);
%array_class(double, doubleArray);
%inline %{
typedef struct {
int x;
int y;
} XY;
XY globalXYArray[3];
typedef struct {
int a;
int b;
} AB;
AB globalABArray[3];
%}
// Note that struct XY { ... }; gives compiler error for C when using %array_class or %array_functions, but is okay in C++
%array_class(XY, XYArray)
%array_functions(AB, ABArray)

View File

@ -0,0 +1,29 @@
require("import") -- the import fn
import("li_carrays_cpp") -- import code
lc = li_carrays_cpp
-- catch "undefined" global variables
local env = _ENV -- Lua 5.2
if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
-- Testing for %array_functions(int,intArray)
ary = lc.new_intArray(2)
lc.intArray_setitem(ary, 0, 0)
lc.intArray_setitem(ary, 1, 1)
assert(lc.intArray_getitem(ary, 0)==0)
assert(lc.intArray_getitem(ary, 1)==1)
lc.delete_intArray(ary)
-- Testing for %array_class(double, doubleArray)
d = lc.doubleArray(10)
d[0] = 7
d[5] = d[0] + 3
assert(d[5] + d[0] == 17)
--print(d[5] + d[0])
ptr = d:cast() -- to ptr
d2 = lc.doubleArray_frompointer(ptr) -- and back to array
assert(d2[5] + d2[0] == 17)
--print(d2[5] + d2[0])

View File

@ -0,0 +1,10 @@
li_carrays_cpp
d = doubleArray(10);
d(0) = 7;
d(5) = d(0) + 3;
if (d(5) + d(0) != 17)
error
endif

View File

@ -0,0 +1,72 @@
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 34;
BEGIN { use_ok('li_carrays_cpp') }
require_ok('li_carrays_cpp');
# array_class
{
my $length = 5;
my $xyArray = new li_carrays_cpp::XYArray($length);
for (my $i=0; $i<$length; $i++) {
my $xy = $xyArray->getitem($i);
$xy->{x} = $i*10;
$xy->{y} = $i*100;
$xyArray->setitem($i, $xy);
}
for (my $i=0; $i<$length; $i++) {
is($xyArray->getitem($i)->{x}, $i*10);
is($xyArray->getitem($i)->{y}, $i*100);
}
}
{
# global array variable
my $length = 3;
my $xyArrayPointer = $li_carrays_cpp::globalXYArray;
my $xyArray = li_carrays_cpp::XYArray::frompointer($xyArrayPointer);
for (my $i=0; $i<$length; $i++) {
my $xy = $xyArray->getitem($i);
$xy->{x} = $i*10;
$xy->{y} = $i*100;
$xyArray->setitem($i, $xy);
}
for (my $i=0; $i<$length; $i++) {
is($xyArray->getitem($i)->{x}, $i*10);
is($xyArray->getitem($i)->{y}, $i*100);
}
}
# array_functions
{
my $length = 5;
my $abArray = li_carrays_cpp::new_ABArray($length);
for (my $i=0; $i<$length; $i++) {
my $ab = li_carrays_cpp::ABArray_getitem($abArray, $i);
$ab->{a} = $i*10;
$ab->{b} = $i*100;
li_carrays_cpp::ABArray_setitem($abArray, $i, $ab);
}
for (my $i=0; $i<$length; $i++) {
is(li_carrays_cpp::ABArray_getitem($abArray, $i)->{a}, $i*10);
is(li_carrays_cpp::ABArray_getitem($abArray, $i)->{b}, $i*100);
}
li_carrays_cpp::delete_ABArray($abArray);
}
{
# global array variable
my $length = 3;
my $abArray = $li_carrays_cpp::globalABArray;
for (my $i=0; $i<$length; $i++) {
my $ab = li_carrays_cpp::ABArray_getitem($abArray, $i);
$ab->{a} = $i*10;
$ab->{b} = $i*100;
li_carrays_cpp::ABArray_setitem($abArray, $i, $ab);
}
for (my $i=0; $i<$length; $i++) {
is(li_carrays_cpp::ABArray_getitem($abArray, $i)->{a}, $i*10);
is(li_carrays_cpp::ABArray_getitem($abArray, $i)->{b}, $i*100);
}
}

View File

@ -0,0 +1,22 @@
<?php
require "tests.php";
require "li_carrays_cpp.php";
// Check functions.
check::functions(array(new_intarray,delete_intarray,intarray_getitem,intarray_setitem,doublearray_getitem,doublearray_setitem,doublearray_cast,doublearray_frompointer,xyarray_getitem,xyarray_setitem,xyarray_cast,xyarray_frompointer,delete_abarray,abarray_getitem,abarray_setitem));
// Check classes.
// NB An "li_carrays_cpp" class is created as a mock namespace.
check::classes(array(li_carrays_cpp,doubleArray,AB,XY,XYArray));
// Check global variables.
check::globals(array(xy_x,xy_y,globalxyarray,ab_a,ab_b,globalabarray));
$d = new doubleArray(10);
$d->setitem(0, 7);
$d->setitem(5, $d->getitem(0) + 3);
check::equal($d->getitem(0) + $d->getitem(5), 17., "7+10==17");
check::done();
?>

View File

@ -0,0 +1,9 @@
from li_carrays_cpp import *
d = doubleArray(10)
d[0] = 7
d[5] = d[0] + 3
if d[5] + d[0] != 17:
raise RuntimeError

View File

@ -0,0 +1,36 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'li_carrays_cpp'
include Li_carrays_cpp
#
# Testing for %array_functions(int,intArray)
#
ary = new_intArray(2)
intArray_setitem(ary, 0, 0)
intArray_setitem(ary, 1, 1)
intArray_getitem(ary, 0)
intArray_getitem(ary, 1)
delete_intArray(ary)
#
# Testing for %array_class(double, doubleArray)
#
ary = DoubleArray.new(2)
ary[0] = 0.0
ary[1] = 1.0
ary[0]
ary[1]
ptr = ary.cast
ary2 = DoubleArray.frompointer(ptr)

View File

@ -0,0 +1,11 @@
exec("swigtest.start", -1);
d = new_intArray(10);
intArray_setitem(d, 0, 7);
intArray_setitem(d, 5, intArray_getitem(d, 0) + 3);
checkequal(intArray_getitem(d, 5) + intArray_getitem(d, 0), 17, "d(5) + d(0) <> 17");
exec("swigtest.quit", -1);