1 module ut.wrap.wrap; 2 3 import test; 4 import xlld.wrap.wrap; 5 import xlld.conv.to: toXlOper; 6 7 8 // this has to be a top-level function and can't be declared in the unittest 9 double twice(double d) { return d * 2; } 10 11 /// 12 @Flaky 13 @("wrapAsync") 14 @system unittest { 15 import xlld.test.util: asyncReturn, newAsyncHandle; 16 import xlld.conv.from: fromXlOper; 17 import core.time: MonoTime; 18 import core.thread; 19 20 const start = MonoTime.currTime; 21 auto asyncHandle = newAsyncHandle; 22 auto oper = (3.2).toXlOper(theGC); 23 wrapAsync!twice(theGC, cast(immutable)asyncHandle, oper); 24 const expected = 6.4; 25 while(asyncReturn(asyncHandle).fromXlOper!double(theGC) != expected && 26 MonoTime.currTime - start < 1.seconds) 27 { 28 Thread.sleep(10.msecs); 29 } 30 asyncReturn(asyncHandle).shouldEqualDlang(expected); 31 } 32 33 @("xltypeNum can convert to array") 34 unittest { 35 import std.typecons: tuple; 36 37 void fun(double[] arg) {} 38 auto arg = 33.3.toSRef(theGC); 39 toDArgs!fun(theGC, &arg).shouldEqual(tuple([33.3])); 40 } 41 42 @("xltypeNil can convert to array") 43 unittest { 44 import xlld.sdk.xlcall: XlType; 45 import std.typecons: tuple; 46 47 void fun(double[] arg) {} 48 XLOPER12 arg; 49 arg.xltype = XlType.xltypeNil; 50 double[] empty; 51 toDArgs!fun(theGC, &arg).shouldEqual(tuple(empty)); 52 } 53 54 55 @("excelRet!double[] from row caller") 56 unittest { 57 import xlld.sdk.xlcall: XlType, xlfCaller; 58 import xlld.conv.misc: stripMemoryBitmask; 59 import xlld.memorymanager: autoFree; 60 61 XLOPER12 caller; 62 caller.xltype = XlType.xltypeSRef; 63 caller.val.sref.ref_.rwFirst = 1; 64 caller.val.sref.ref_.rwLast = 1; 65 caller.val.sref.ref_.colFirst = 2; 66 caller.val.sref.ref_.colLast = 4; 67 68 with(MockXlFunction(xlfCaller, caller)) { 69 auto doubles = [1.0, 2.0, 3.0, 4.0]; 70 auto oper = excelRet(doubles); 71 scope(exit) autoFree(&oper); 72 73 oper.shouldEqualDlang(doubles); 74 oper.xltype.stripMemoryBitmask.shouldEqual(XlType.xltypeMulti); 75 oper.val.array.rows.shouldEqual(1); 76 oper.val.array.columns.shouldEqual(4); 77 } 78 } 79 80 @("excelRet!double[] from column caller") 81 unittest { 82 import xlld.sdk.xlcall: XlType, xlfCaller; 83 import xlld.conv.misc: stripMemoryBitmask; 84 import xlld.memorymanager: autoFree; 85 86 XLOPER12 caller; 87 caller.xltype = XlType.xltypeSRef; 88 caller.val.sref.ref_.rwFirst = 1; 89 caller.val.sref.ref_.rwLast = 4; 90 caller.val.sref.ref_.colFirst = 5; 91 caller.val.sref.ref_.colLast = 5; 92 93 with(MockXlFunction(xlfCaller, caller)) { 94 auto doubles = [1.0, 2.0, 3.0, 4.0]; 95 auto oper = excelRet(doubles); 96 scope(exit) autoFree(&oper); 97 98 oper.shouldEqualDlang(doubles); 99 oper.xltype.stripMemoryBitmask.shouldEqual(XlType.xltypeMulti); 100 oper.val.array.rows.shouldEqual(4); 101 oper.val.array.columns.shouldEqual(1); 102 } 103 } 104 105 @("excelRet!double[] from other caller") 106 unittest { 107 import xlld.sdk.xlcall: XlType, xlfCaller; 108 import xlld.conv.misc: stripMemoryBitmask; 109 import xlld.memorymanager: autoFree; 110 111 XLOPER12 caller; 112 caller.xltype = XlType.xltypeErr; 113 114 with(MockXlFunction(xlfCaller, caller)) { 115 auto doubles = [1.0, 2.0, 3.0, 4.0]; 116 auto oper = excelRet(doubles); 117 scope(exit) autoFree(&oper); 118 119 oper.shouldEqualDlang(doubles); 120 oper.xltype.stripMemoryBitmask.shouldEqual(XlType.xltypeMulti); 121 oper.val.array.rows.shouldEqual(1); 122 oper.val.array.columns.shouldEqual(4); 123 } 124 }