def TestTrickyTypesWithVariants(o, is_generated):
    if is_generated:
        got = o.TestByRefVariant(2)
    else:
        v = VARIANT((pythoncom.VT_BYREF | pythoncom.VT_VARIANT), 2)
        o.TestByRefVariant(v)
        got = v.value
    if (got != 4):
        raise error('TestByRefVariant failed')
    if is_generated:
        got = o.TestByRefString('Foo')
    else:
        v = VARIANT((pythoncom.VT_BYREF | pythoncom.VT_BSTR), 'Foo')
        o.TestByRefString(v)
        got = v.value
    if (got != 'FooFoo'):
        raise error('TestByRefString failed')
    vals = [1, 2, 3, 4]
    if is_generated:
        arg = vals
    else:
        arg = VARIANT((pythoncom.VT_ARRAY | pythoncom.VT_UI1), vals)
    TestApplyResult(o.SetBinSafeArray, (arg,), len(vals))
    vals = [0, 1.1, 2.2, 3.3]
    if is_generated:
        arg = vals
    else:
        arg = VARIANT((pythoncom.VT_ARRAY | pythoncom.VT_R8), vals)
    TestApplyResult(o.SetDoubleSafeArray, (arg,), len(vals))
    if is_generated:
        arg = vals
    else:
        arg = VARIANT((pythoncom.VT_ARRAY | pythoncom.VT_R4), vals)
    TestApplyResult(o.SetFloatSafeArray, (arg,), len(vals))
    vals = [1.1, 2.2, 3.3, 4.4]
    expected = ((1.1 * 2), (2.2 * 2), (3.3 * 2), (4.4 * 2))
    if is_generated:
        TestApplyResult(o.ChangeDoubleSafeArray, (vals,), expected)
    else:
        arg = VARIANT(((pythoncom.VT_BYREF | pythoncom.VT_ARRAY) | pythoncom.VT_R8), vals)
        o.ChangeDoubleSafeArray(arg)
        if (arg.value != expected):
            raise error('ChangeDoubleSafeArray got the wrong value')
    if is_generated:
        got = o.DoubleInOutString('foo')
    else:
        v = VARIANT((pythoncom.VT_BYREF | pythoncom.VT_BSTR), 'foo')
        o.DoubleInOutString(v)
        got = v.value
    assert (got == 'foofoo'), got
    val = decimal.Decimal('1234.5678')
    if is_generated:
        got = o.DoubleCurrencyByVal(val)
    else:
        v = VARIANT((pythoncom.VT_BYREF | pythoncom.VT_CY), val)
        o.DoubleCurrencyByVal(v)
        got = v.value
    assert (got == (val * 2))
def TestTrickyTypesWithVariants(o, is_generated):
    if is_generated:
        got = o.TestByRefVariant(2)
    else:
        v = VARIANT((pythoncom.VT_BYREF | pythoncom.VT_VARIANT), 2)
        o.TestByRefVariant(v)
        got = v.value
    if (got != 4):
        raise error('TestByRefVariant failed')
    if is_generated:
        got = o.TestByRefString('Foo')
    else:
        v = VARIANT((pythoncom.VT_BYREF | pythoncom.VT_BSTR), 'Foo')
        o.TestByRefString(v)
        got = v.value
    if (got != 'FooFoo'):
        raise error('TestByRefString failed')
    vals = [1, 2, 3, 4]
    if is_generated:
        arg = vals
    else:
        arg = VARIANT((pythoncom.VT_ARRAY | pythoncom.VT_UI1), vals)
    TestApplyResult(o.SetBinSafeArray, (arg,), len(vals))
    vals = [0, 1.1, 2.2, 3.3]
    if is_generated:
        arg = vals
    else:
        arg = VARIANT((pythoncom.VT_ARRAY | pythoncom.VT_R8), vals)
    TestApplyResult(o.SetDoubleSafeArray, (arg,), len(vals))
    if is_generated:
        arg = vals
    else:
        arg = VARIANT((pythoncom.VT_ARRAY | pythoncom.VT_R4), vals)
    TestApplyResult(o.SetFloatSafeArray, (arg,), len(vals))
    vals = [1.1, 2.2, 3.3, 4.4]
    expected = ((1.1 * 2), (2.2 * 2), (3.3 * 2), (4.4 * 2))
    if is_generated:
        TestApplyResult(o.ChangeDoubleSafeArray, (vals,), expected)
    else:
        arg = VARIANT(((pythoncom.VT_BYREF | pythoncom.VT_ARRAY) | pythoncom.VT_R8), vals)
        o.ChangeDoubleSafeArray(arg)
        if (arg.value != expected):
            raise error('ChangeDoubleSafeArray got the wrong value')
    if is_generated:
        got = o.DoubleInOutString('foo')
    else:
        v = VARIANT((pythoncom.VT_BYREF | pythoncom.VT_BSTR), 'foo')
        o.DoubleInOutString(v)
        got = v.value
    assert (got == 'foofoo'), got
    val = decimal.Decimal('1234.5678')
    if is_generated:
        got = o.DoubleCurrencyByVal(val)
    else:
        v = VARIANT((pythoncom.VT_BYREF | pythoncom.VT_CY), val)
        o.DoubleCurrencyByVal(v)
        got = v.value
    assert (got == (val * 2))