如何编写单元测试来调用以下函数计算?或者说如何用数字2和0.8构建参数VARIANT * pvarItems? 请注意这个参数是一个指针! 感谢。
STDMETHODIMP MyCom::Calculate(VARIANT* pvarItems)
{
HRESULT hr = S_OK;
if (V_VT(pvarItems) == (VT_ARRAY | VT_VARIANT))
{
SAFEARRAY *psa = V_ARRAY(pvarItems);
LONG lb, ub;
hr = SafeArrayGetLBound(psa, 1, &lb);
hr = SafeArrayGetUBound(psa, 1, &ub);
for (LONG i = lb; i <= ub; i++)
{
VARIANT out;
VariantInit(&out);
hr = SafeArrayGetElement(psa, &i, &out);
switch (V_VT(&out))
{
case VT_I4:
printf("Item number %d, Value is %d\n", i, V_I4(&out));
break;
case VT_BSTR:
printf("Item number %d, Value is %ls\n", i, V_BSTR(&out));
break;
default:
printf("Item number %d, Sample not coded for this data type\n", i);
}
VariantClear(&out);
}
}
return S_OK;
}