forked from go-ole/go-ole
-
Notifications
You must be signed in to change notification settings - Fork 1
/
safearrayconversion_test.go
119 lines (98 loc) · 2.27 KB
/
safearrayconversion_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// +build windows
package ole
import (
"fmt"
"strings"
"testing"
)
// This tests more than one function. It tests all of the functions needed in order to retrieve an
// SafeArray populated with Strings.
func TestSafeArrayConversionString(t *testing.T) {
CoInitialize(0)
defer CoUninitialize()
clsid, err := CLSIDFromProgID("QBXMLRP2.RequestProcessor.1")
if err != nil {
if err.(*OleError).Code() == CO_E_CLASSSTRING {
return
}
t.Log(err)
t.FailNow()
}
unknown, err := CreateInstance(clsid, IID_IUnknown)
if err != nil {
t.Log(err)
t.FailNow()
}
defer unknown.Release()
dispatch, err := unknown.QueryInterface(IID_IDispatch)
if err != nil {
t.Log(err)
t.FailNow()
}
var dispid []int32
dispid, err = dispatch.GetIDsOfName([]string{"OpenConnection2"})
if err != nil {
t.Log(err)
t.FailNow()
}
var result *VARIANT
_, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, "", "Test Application 1", 1)
if err != nil {
t.Log(err)
t.FailNow()
}
dispid, err = dispatch.GetIDsOfName([]string{"BeginSession"})
if err != nil {
t.Log(err)
t.FailNow()
}
result, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, "", 2)
if err != nil {
t.Log(err)
t.FailNow()
}
ticket := result.ToString()
dispid, err = dispatch.GetIDsOfName([]string{"QBXMLVersionsForSession"})
if err != nil {
t.Log(err)
t.FailNow()
}
result, err = dispatch.Invoke(dispid[0], DISPATCH_PROPERTYGET, ticket)
if err != nil {
t.Log(err)
t.FailNow()
}
// Where the real tests begin.
conversion := result.ToArray()
totalElements, _ := conversion.TotalElements(0)
if totalElements != 13 {
t.Log(fmt.Sprintf("%d total elements does not equal 13\n", totalElements))
t.Fail()
}
versions := conversion.ToStringArray()
if len(versions) != 13 {
t.Log(fmt.Sprintf("%s\n", strings.Join(versions, ", ")))
t.Fail()
}
conversion.Release()
dispid, err = dispatch.GetIDsOfName([]string{"EndSession"})
if err != nil {
t.Log(err)
t.FailNow()
}
_, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, ticket)
if err != nil {
t.Log(err)
t.FailNow()
}
dispid, err = dispatch.GetIDsOfName([]string{"CloseConnection"})
if err != nil {
t.Log(err)
t.FailNow()
}
_, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD)
if err != nil {
t.Log(err)
t.FailNow()
}
}