forked from rticommunity/rticonnextdds-connector-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
127 lines (112 loc) · 2.39 KB
/
example_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
120
121
122
123
124
125
126
127
package rti
import (
"fmt"
"github.com/rticommunity/rticonnextdds-connector-go/types"
"path"
"runtime"
)
func ExampleNewConnector() {
// Get the path for test XML configs
_, curPath, _, _ := runtime.Caller(0)
xmlPath := path.Join(path.Dir(curPath), "./test/xml/Test.xml")
participantProfile := "MyParticipantLibrary::Zero"
connector, err := NewConnector(participantProfile, xmlPath)
if err != nil {
// Handle an error
}
connector.Delete()
// Output:
}
func ExampleConnector_GetInput() {
// Create Connector
connector := newTestConnector()
defer connector.Delete()
input, err := connector.GetInput("MySubscriber::MyReader")
if input == nil || err != nil {
// Handle an error
}
// Output:
}
func ExampleConnector_GetOutput() {
// Create Connector
connector := newTestConnector()
defer connector.Delete()
output, err := connector.GetInput("MyPublisher::MyWriter")
if output == nil || err != nil {
// Handle an error
}
// Output:
}
func ExampleInput_AsyncSubscribe() {
connector := newTestConnector()
defer connector.Delete()
input := newTestInput(connector)
output := newTestOutput(connector)
done := make(chan bool)
var outputTestData types.Test
outputTestData.St = "test"
output.Instance.Set(&outputTestData)
output.Write()
input.AsyncSubscribe(func(samples *Samples, infos *Infos) {
numOfSamples := samples.GetLength()
for i := 0; i < numOfSamples; i++ {
if infos.IsValid(i) {
json, _ := samples.GetJSON(i)
fmt.Printf("---Received Sample---\n%s", json)
done <- true
}
}
})
<-done
// Output:
// ---Received Sample---
//{
//"st":"test",
//"b":false,
//"c":0,
//"s":0,
//"us":0,
//"l":0,
//"ul":0,
//"ll":0,
//"ull":0,
//"f":0,
//"d":0
//}
}
func ExampleInput_ChannelSubscribe() {
connector := newTestConnector()
defer connector.Delete()
input := newTestInput(connector)
output := newTestOutput(connector)
ch := make(chan *Samples)
input.ChannelSubscribe(ch)
var outputTestData types.Test
outputTestData.St = "test"
output.Instance.Set(&outputTestData)
output.Write()
for {
samples := <-ch
numOfSamples := samples.GetLength()
for i := 0; i < numOfSamples; i++ {
json, _ := samples.GetJSON(i)
fmt.Printf("---Received Sample---\n%s", json)
return
}
}
// Output:
// ---Received Sample---
//{
//"st":"test",
//"b":false,
//"c":0,
//"s":0,
//"us":0,
//"l":0,
//"ul":0,
//"ll":0,
//"ull":0,
//"f":0,
//"d":0
//}
}