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