1 module ut.wrap.all; 2 3 import test; 4 import ut.wrap.wrapped; 5 import xlld.wrap; 6 import xlld.conv.to: toXlOper; 7 8 /// 9 @("wrapAll function that returns Any[][]") 10 @safe unittest { 11 import xlld.memorymanager: autoFree; 12 13 auto oper = [[1.0, 2.0], [3.0, 4.0]].toSRef(theGC); 14 auto arg = () @trusted { return &oper; }(); 15 auto ret = DoubleArrayToAnyArray(arg); 16 scope(exit) () @trusted { autoFree(ret); }(); // usually done by Excel 17 18 auto opers = () @trusted { return ret.val.array.lparray[0 .. 4]; }(); 19 opers[0].shouldEqualDlang(2.0); 20 opers[1].shouldEqualDlang(6.0); 21 opers[2].shouldEqualDlang("3quux"); 22 opers[3].shouldEqualDlang("4toto"); 23 } 24 25 /// 26 @("wrapAll function that takes Any[][]") 27 unittest { 28 import xlld.memorymanager: allocatorContext; 29 30 XLOPER12* ret; 31 with(allocatorContext(theGC)) { 32 auto oper = [[any(1.0), any(2.0)], [any(3.0), any(4.0)], [any("foo"), any("bar")]].toXlOper(theGC); 33 auto arg = () @trusted { return &oper; }(); 34 ret = AnyArrayToDoubleArray(arg); 35 } 36 37 auto opers = () @trusted { return ret.val.array.lparray[0 .. 2]; }(); 38 opers[0].shouldEqualDlang(3.0); // number of rows 39 opers[1].shouldEqualDlang(2.0); // number of columns 40 } 41 42 43 /// 44 @("wrapAll Any[][] -> Any[][]") 45 unittest { 46 import xlld.memorymanager: allocatorContext; 47 import xlld.any: Any; 48 49 XLOPER12* ret; 50 with(allocatorContext(theGC)) { 51 auto oper = [[any(1.0), any(2.0)], [any(3.0), any(4.0)], [any("foo"), any("bar")]].toXlOper(theGC); 52 auto arg = () @trusted { return &oper; }(); 53 ret = AnyArrayToAnyArray(arg); 54 } 55 56 auto opers = () @trusted { return ret.val.array.lparray[0 .. 6]; }(); 57 ret.val.array.rows.shouldEqual(3); 58 ret.val.array.columns.shouldEqual(2); 59 opers[0].shouldEqualDlang(1.0); 60 opers[1].shouldEqualDlang(2.0); 61 opers[2].shouldEqualDlang(3.0); 62 opers[3].shouldEqualDlang(4.0); 63 opers[4].shouldEqualDlang("foo"); 64 opers[5].shouldEqualDlang("bar"); 65 } 66 67 /// 68 @("wrapAll Any[][] -> Any[][] -> Any[][]") 69 unittest { 70 import xlld.memorymanager: allocatorContext; 71 import xlld.any: Any; 72 73 XLOPER12* ret; 74 with(allocatorContext(theGC)) { 75 auto oper = [[any(1.0), any("foo"), any(3.0)], [any(4.0), any(5.0), any(6.0)]].toXlOper(theGC); 76 auto arg = () @trusted { return &oper; }(); 77 ret = FirstOfTwoAnyArrays(arg, arg); 78 } 79 80 auto opers = () @trusted { return ret.val.array.lparray[0 .. 6]; }(); 81 ret.val.array.rows.shouldEqual(2); 82 ret.val.array.columns.shouldEqual(3); 83 opers[0].shouldEqualDlang(1.0); 84 opers[1].shouldEqualDlang("foo"); 85 opers[2].shouldEqualDlang(3.0); 86 opers[3].shouldEqualDlang(4.0); 87 opers[4].shouldEqualDlang(5.0); 88 opers[5].shouldEqualDlang(6.0); 89 } 90 91 /// 92 @("wrapAll overloaded functions are not wrapped") 93 unittest { 94 auto double_ = (42.0).toXlOper(theGC); 95 auto string_ = "foobar".toXlOper(theGC); 96 static assert(!__traits(compiles, Overloaded(&double_).shouldEqualDlang(84.0))); 97 static assert(!__traits(compiles, Overloaded(&string_).shouldEqualDlang(84.0))); 98 } 99 100 /// 101 @("wrapAll bool -> int") 102 @safe unittest { 103 auto string_ = "true".toXlOper(theGC); 104 () @trusted { BoolToInt(&string_).shouldEqualDlang(1); }(); 105 } 106 107 /// 108 @("wrapAll FuncAddEverything") 109 unittest { 110 import xlld.memorymanager: allocator; 111 112 auto arg = toSRef(cast(double[][])[[1, 2, 3, 4], [11, 12, 13, 14]], allocator); 113 FuncAddEverything(&arg).shouldEqualDlang(60.0); 114 } 115 116 117 118 /// 119 @("wrapAll FuncReturnArrayNoGC") 120 @safe unittest { 121 import xlld.test.util: gTestAllocator; 122 import xlld.memorymanager: gTempAllocator; 123 124 // this is needed since gTestAllocator is global, so we can't rely 125 // on its destructor 126 scope(exit) gTestAllocator.verify; 127 128 double[4] args = [1.0, 2.0, 3.0, 4.0]; 129 auto oper = args[].toSRef(gTempAllocator); // don't use gTestAllocator 130 auto arg = () @trusted { return &oper; }(); 131 auto ret = () @safe @nogc { return FuncReturnArrayNoGc(arg); }(); 132 ret.shouldEqualDlang([2.0, 4.0, 6.0, 8.0]); 133 }