-
Notifications
You must be signed in to change notification settings - Fork 0
/
testPublisher.c
350 lines (280 loc) · 12.3 KB
/
testPublisher.c
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
//
// Created by abrighto on 2/12/20.
//
#include <stdio.h>
#include <libgen.h>
//#include <zconf.h>
#include <stdlib.h>
#include <unistd.h>
#include "zlog.h"
#include "csw/csw.h"
/*
* Note: This test assumes the following applications are running:
*
* CSW Services:
* csw-services start
*
* Test Assembly:
* cd testSupport
* sbt stage
* test-deploy/target/universal/stage/bin/test-container-cmd-app --local test-deploy/src/main/resources/TestContainer.conf
*
* Note: The test assembly subscribes to exactly the named events published by this test,
* so if you change any event names, update the assembly code in TestAssemblyHandlers.
*/
static char *prefix = "CSW.TestPublisher";
// Tests publishing a simple event with multiple values
static void publishSimpleEvent(CswEventServiceContext publisher) {
double ar1[] = {1.1, 2.2, 3.3};
CswArrayValue values1 = {.values = ar1, .numValues = 3};
CswParameter param1 = cswMakeParameter("DoubleValue", DoubleKey, values1, csw_unit_arcmin);
const char* ar2[] = {"one", "two"};
CswArrayValue values2 = {.values = ar2, .numValues = 2};
CswParameter param2 = cswMakeParameter("StringValue", StringKey, values2, csw_unit_NoUnits);
const char* ar3[] = {"choice1"};
CswArrayValue values3 = {.values = ar3, .numValues = 1};
CswParameter param3 = cswMakeParameter("ChoiceValue", ChoiceKey, values3, csw_unit_NoUnits);
CswParameter params[] = {param1, param2, param3};
CswParamSet paramSet = {.params = params, .numParams = 3};
CswEvent event = cswMakeEvent(SystemEvent, prefix, "SimpleEvent", paramSet);
cswEventPublish(publisher, event);
cswFreeEvent(event);
}
// Tests publishing a simple event containing a UTCTime parameter
static void publishUtcTimeEvent(CswEventServiceContext publisher) {
// CswUtcTime ar[] = {cswUtcTime()};
// Use fixed date so that test comparison works
CswUtcTime ar[] = {cswMakeUtcTime(1625066893, 372333847)};
CswArrayValue values = {.values = ar, .numValues = 1};
CswParameter param = cswMakeParameter("utcTimeValue", UTCTimeKey, values, csw_unit_NoUnits);
CswParameter params[] = {param};
CswParamSet paramSet = {.params = params, .numParams = 1};
CswEvent event = cswMakeEvent(SystemEvent, prefix, "UtcTimeEvent", paramSet);
cswEventPublish(publisher, event);
cswFreeEvent(event);
}
// Tests publishing a simple event containing a UTCTime parameter
static void publishTaiTimeEvent(CswEventServiceContext publisher) {
// CswTaiTime ar[] = {cswTaiTime()};
// Use fixed date so that test comparison works
CswTaiTime ar[] = {cswMakeTaiTime(1625066980, 763689367)};
CswArrayValue values = {.values = ar, .numValues = 1};
CswParameter param = cswMakeParameter("taiTimeValue", TAITimeKey, values, csw_unit_NoUnits);
CswParameter params[] = {param};
CswParamSet paramSet = {.params = params, .numParams = 1};
CswEvent event = cswMakeEvent(SystemEvent, prefix, "TaiTimeEvent", paramSet);
cswEventPublish(publisher, event);
cswFreeEvent(event);
}
// Tests publishing array and matrix values
static void publishInts(CswEventServiceContext publisher) {
// -- IntKey parameter contains one or more int values --
int intValues[] = {42, 43};
CswArrayValue arrayValues1 = {.values = intValues, .numValues = 2};
CswParameter intParam = cswMakeParameter("IntValue", IntKey, arrayValues1, csw_unit_arcsec);
// -- IntArrayKey parameter contains one or more int array values --
int intArrayValues[2][4] = {
{1, 2, 3, 4},
{5, 6, 7, 8}
};
CswArrayValue intArrayHolder[2];
CswParameter intArrayParam = cswMakeParameter(
"IntArrayValue",
IntArrayKey,
makeArrayValues((void **) intArrayValues, 2, intArrayHolder, 4),
csw_unit_arcsec);
// -- IntMatrixKey parameter contains one or more int matrix values (Sorry, this gets ugly in C...) --
int intMatrixValues[2][2][4] = {
{
{1, 2, 3, 4},
{5, 6, 7, 8}
},
{
{11, -22, 33, -44},
{-55, 66, -77, 88}
}
};
// CswArrayValue matrixValues = makeMatrixValues((void***)intMatrixValues, 2, 2, 4);
CswArrayValue arrayHolder[2][2];
CswArrayValue ar[] = {
makeArrayValues((void **) intMatrixValues[0], 2, arrayHolder[0], 4),
makeArrayValues((void **) intMatrixValues[1], 2, arrayHolder[1], 4),
};
CswArrayValue matrixValues = {.arrayValues = ar, .numValues = 2};
CswParameter intMatrixParam = cswMakeParameter("IntMatrixValue", IntMatrixKey, matrixValues, csw_unit_arcsec);
// -- ParamSet
CswParameter params[] = {intParam, intArrayParam, intMatrixParam};
CswParamSet paramSet = {.params = params, .numParams = 3};
// -- Event --
CswEvent event = cswMakeEvent(SystemEvent, prefix, "IntArrayMatrixEvent", paramSet);
// -- Publish --
cswEventPublish(publisher, event);
// -- Cleanup --
cswFreeEvent(event);
}
static void publishDoubles(CswEventServiceContext publisher) {
// -- DoubleKey parameter contains one or more double values --
double doubleValues[] = {42.1, 43.5};
CswArrayValue arrayValues1 = {.values = doubleValues, .numValues = 2};
CswParameter doubleParam = cswMakeParameter("DoubleValue", DoubleKey, arrayValues1, csw_unit_arcsec);
// -- DoubleArrayKey parameter contains one or more double array values --
double doubleArrayValues[2][4] = {
{1.1, 2.2, 3.3, 4.4},
{5.5, 6.6, 7.7, 8.8}
};
CswArrayValue doubleArrayHolder[2];
CswParameter doubleArrayParam = cswMakeParameter(
"DoubleArrayValue",
DoubleArrayKey,
makeArrayValues((void **) doubleArrayValues, 2, doubleArrayHolder, 4),
csw_unit_arcsec);
// -- DoubleMatrixKey parameter contains one or more double matrix values (Sorry, this gets ugly in C...) --
double doubleMatrixValues[2][2][4] = {
{
{1.3, 2.4, 3.5, 4.6},
{5.7, 6.8, 7.9, 8.0}
},
{
{11.1, -22.2, 33.3, -44.4},
{-55.5, 66.6, -77.7, 88.8}
}
};
// CswArrayValue matrixValues = makeMatrixValues((void***)doubleMatrixValues, 2, 2, 4);
CswArrayValue arrayHolder[2][2];
CswArrayValue ar[] = {
makeArrayValues((void **) doubleMatrixValues[0], 2, arrayHolder[0], 4),
makeArrayValues((void **) doubleMatrixValues[1], 2, arrayHolder[1], 4),
};
CswArrayValue matrixValues = {.arrayValues = ar, .numValues = 2};
CswParameter doubleMatrixParam = cswMakeParameter("DoubleMatrixValue", DoubleMatrixKey, matrixValues, csw_unit_arcsec);
// -- ParamSet
CswParameter params[] = {doubleParam, doubleArrayParam, doubleMatrixParam};
CswParamSet paramSet = {.params = params, .numParams = 3};
// -- Event --
CswEvent event = cswMakeEvent(SystemEvent, prefix, "DoubleArrayMatrtixEvent", paramSet);
// -- Publish --
cswEventPublish(publisher, event);
// -- Cleanup --
cswFreeEvent(event);
}
// -- Tests publishing coordinate values --
static void publishAltAzCoord(CswEventServiceContext publisher) {
CswAltAzCoord altAzCoord1 = cswMakeAltAzCoord("BASE", 1083600000000, 153000000000);
CswCoord values[1];
values[0].altAzCoord = altAzCoord1;
CswArrayValue arrayValues = {.values = values, .numValues = 1};
CswParameter coordParam = cswMakeParameter("CoordParam", CoordKey, arrayValues, csw_unit_NoUnits);
// -- ParamSet
CswParameter params[] = {coordParam};
CswParamSet paramSet = {.params = params, .numParams = 1};
// -- Event --
CswEvent event = cswMakeEvent(SystemEvent, prefix, "AltAzCoordEvent", paramSet);
// -- Publish --
cswEventPublish(publisher, event);
// -- Cleanup --
cswFreeEvent(event);
}
static void publishCometCoord(CswEventServiceContext publisher) {
CswCometCoord cometCoord1 = cswMakeCometCoord("BASE", 2000.0, 324000000000, 7200000000, 360000000000, 1.4, 0.234);
CswCoord values[1];
values[0].cometCoord = cometCoord1;
CswArrayValue arrayValues = {.values = values, .numValues = 1};
CswParameter coordParam = cswMakeParameter("CoordParam", CoordKey, arrayValues, csw_unit_NoUnits);
// -- ParamSet
CswParameter params[] = {coordParam};
CswParamSet paramSet = {.params = params, .numParams = 1};
// -- Event --
CswEvent event = cswMakeEvent(SystemEvent, prefix, "CometCoordEvent", paramSet);
// -- Publish --
cswEventPublish(publisher, event);
// -- Cleanup --
cswFreeEvent(event);
}
static void publishMinorPlanetCoord(CswEventServiceContext publisher) {
CswMinorPlanetCoord minorPlanetCoord1 = cswMakeMinorPlanetCoord("GUIDER1", 2000, 324000000000, 7200000000,
360000000000, 1.4, 0.234, 792000000000);
CswCoord values[1];
values[0].minorPlanetCoord = minorPlanetCoord1;
CswArrayValue arrayValues = {.values = values, .numValues = 1};
CswParameter coordParam = cswMakeParameter("CoordParam", CoordKey, arrayValues, csw_unit_NoUnits);
// -- ParamSet
CswParameter params[] = {coordParam};
CswParamSet paramSet = {.params = params, .numParams = 1};
// -- Event --
CswEvent event = cswMakeEvent(SystemEvent, prefix, "MinorPlanetCoordEvent", paramSet);
// -- Publish --
cswEventPublish(publisher, event);
// -- Cleanup --
cswFreeEvent(event);
}
static void publishSolarSystemCoords(CswEventServiceContext publisher) {
CswSolarSystemCoord solarSystemCoord1 = cswMakeSolarSystemCoord("BASE", Venus);
CswSolarSystemCoord solarSystemCoord2 = cswMakeSolarSystemCoord("TARGET", Venus);
CswCoord values[2];
values[0].solarSystemCoord = solarSystemCoord1;
values[1].solarSystemCoord = solarSystemCoord2;
CswArrayValue arrayValues = {.values = values, .numValues = 2};
CswParameter coordParam = cswMakeParameter("CoordParam", CoordKey, arrayValues, csw_unit_NoUnits);
// -- ParamSet
CswParameter params[] = {coordParam};
CswParamSet paramSet = {.params = params, .numParams = 1};
// -- Event --
CswEvent event = cswMakeEvent(SystemEvent, prefix, "SolarSystemCoordsEvent", paramSet);
// -- Publish --
cswEventPublish(publisher, event);
// -- Cleanup --
cswFreeEvent(event);
}
static void publishEqCoords(CswEventServiceContext publisher) {
CswEqCoord eqCoord1 = cswMakeEqCoord("BASE", 659912250000, -109892300000, FK5, "none", 0.5f, 2.33f);
CswEqCoord eqCoord2 = cswMakeEqCoord("TARGET", 649912250000, -129892300000, FK5, "none", 0.4f, 2.1f);
CswCoord values[2];
values[0].eqCoord = eqCoord1;
values[1].eqCoord = eqCoord2;
CswArrayValue arrayValues = {.values = values, .numValues = 2};
CswParameter coordParam = cswMakeParameter("CoordParam", CoordKey, arrayValues, csw_unit_NoUnits);
// -- ParamSet
CswParameter params[] = {coordParam};
CswParamSet paramSet = {.params = params, .numParams = 1};
// -- Event --
CswEvent event = cswMakeEvent(SystemEvent, prefix, "EqCoordsEvent", paramSet);
// -- Publish --
cswEventPublish(publisher, event);
// -- Cleanup --
cswFreeEvent(event);
}
#pragma clang diagnostic push
#pragma ide diagnostic ignored "UnusedParameter"
int main(int argc, char **argv) {
int rc = dzlog_init("test_default.conf", "my_cat");
if (rc) {
printf("zlog init failed\n");
return -1;
}
dzlog_info("Logging initialized");
CswEventServiceContext publisher = cswEventPublisherInit();
publishSimpleEvent(publisher);
publishUtcTimeEvent(publisher);
publishTaiTimeEvent(publisher);
publishInts(publisher);
publishDoubles(publisher);
publishEqCoords(publisher);
publishSolarSystemCoords(publisher);
publishMinorPlanetCoord(publisher);
publishCometCoord(publisher);
publishAltAzCoord(publisher);
// Give the assembly time to receive the events and write the file
sleep(3);
char *dir = dirname(argv[0]);
char cmd[1024];
sprintf(cmd, "cmp %s/TestAssemblyHandlers.out /tmp/TestAssemblyHandlers.out", dir);
dzlog_info("%s\n", cmd);
int status = system(cmd);
if (status == 0)
dzlog_info("All tests passed.\n");
else
dzlog_error("Test Failed\n");
zlog_fini();
return status;
}
#pragma clang diagnostic pop