21 #include "procTypes.h"
22 #include "EXISerializer.h"
23 #include "EXIParser.h"
24 #include "stringManipulate.h"
25 #include "grammarGenerator.h"
27 #define MAX_PATH_LEN 200
28 #define OUTPUT_BUFFER_SIZE 2000
34 static void parseSchema(
char** xsdList,
int count,
EXIPSchema* schema);
36 #define TRY_CATCH_ENCODE(func) TRY_CATCH(func, serialize.closeEXIStream(&testStrm))
70 fail_unless (tmp_err_code ==
EXIP_OK,
"initStream returns an error code %d", tmp_err_code);
74 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.exiHeader returns an error code %d", tmp_err_code);
77 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.startDocument returns an error code %d", tmp_err_code);
82 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.startElement returns an error code %d", tmp_err_code);
87 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.attribute returns an error code %d", tmp_err_code);
91 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.stringData returns an error code %d", tmp_err_code);
96 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.attribute returns an error code %d", tmp_err_code);
100 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.stringData returns an error code %d", tmp_err_code);
102 tmp_err_code +=
asciiToString(
"This is an example of serializing EXI streams using EXIP low level API", &chVal, &testStrm.
memList,
FALSE);
109 fail_unless (tmp_err_code ==
EXIP_OK,
"serialization ended with error code %d", tmp_err_code);
113 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.closeEXIStream ended with error code %d", tmp_err_code);
123 fail_unless (tmp_err_code ==
EXIP_OK,
"initParser returns an error code %d", tmp_err_code);
130 fail_unless (tmp_err_code ==
EXIP_OK,
"parsing the header returns an error code %d", tmp_err_code);
133 fail_unless (tmp_err_code ==
EXIP_OK,
"setSchema() returns an error code %d", tmp_err_code);
182 fail_unless (tmp_err_code ==
EXIP_OK,
"initStream returns an error code %d", tmp_err_code);
186 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.exiHeader returns an error code %d", tmp_err_code);
189 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.startDocument returns an error code %d", tmp_err_code);
194 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.startElement returns an error code %d", tmp_err_code);
199 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.attribute returns an error code %d", tmp_err_code);
203 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.stringData returns an error code %d", tmp_err_code);
208 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.attribute returns an error code %d", tmp_err_code);
212 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.stringData returns an error code %d", tmp_err_code);
216 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.startElement returns an error code %d", tmp_err_code);
220 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.stringData returns an error code %d", tmp_err_code);
228 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.startElement returns an error code %d", tmp_err_code);
232 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.stringData returns an error code %d", tmp_err_code);
235 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.endElement returns an error code %d", tmp_err_code);
238 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.endDocument returns an error code %d", tmp_err_code);
241 fail_unless (tmp_err_code ==
EXIP_OK,
"serialization ended with error code %d", tmp_err_code);
245 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.closeEXIStream ended with error code %d", tmp_err_code);
255 fail_unless (tmp_err_code ==
EXIP_OK,
"initParser returns an error code %d", tmp_err_code);
262 fail_unless (tmp_err_code ==
EXIP_OK,
"parsing the header returns an error code %d", tmp_err_code);
265 fail_unless (tmp_err_code ==
EXIP_OK,
"setSchema() returns an error code %d", tmp_err_code);
283 const String ELEM_COBS_STR = {
"cobs", 4};
284 const String ELEM_TM_STAMP_STR = {
"timestamp", 9};
285 const String ELEM_RPM_STR = {
"rpm", 3};
286 const String ELEM_ACC_RNDS_STR = {
"accRounds", 9};
287 const String ELEM_TEMP_STR = {
"temp", 4};
288 const String ELEM_LEFT_STR = {
"left", 4};
289 const String ELEM_RIGHT_STR = {
"right", 5};
290 const String ELEM_RSSI_STR = {
"RSSI", 4};
291 const String ELEM_MIN_STR = {
"min", 3};
292 const String ELEM_MAX_STR = {
"max", 3};
293 const String ELEM_AVG_STR = {
"avg", 3};
294 const String ELEM_BATTERY_STR = {
"battery", 7};
295 const String ATTR_NODE_ID_STR = {
"nodeId", 6};
328 fail_unless (tmp_err_code ==
EXIP_OK,
"initStream returns an error code %d", tmp_err_code);
332 fail_unless (tmp_err_code ==
EXIP_OK,
"exiHeader returns an error code %d", tmp_err_code);
335 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
340 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
343 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
344 sprintf(valStr,
"%d", 111);
346 chVal.
length = strlen(valStr);
348 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
351 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
352 chVal.
str =
"2012-12-31T12:09:3.44";
353 chVal.
length = strlen(
"2012-12-31T12:09:3.44");
355 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
357 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
360 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
361 sprintf(valStr,
"%d", 222);
363 chVal.
length = strlen(valStr);
365 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
367 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
370 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
371 sprintf(valStr,
"%d", 4212);
373 chVal.
length = strlen(valStr);
375 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
377 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
380 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
383 sprintf(valStr,
"%f", 32.2);
385 chVal.
length = strlen(valStr);
388 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
391 sprintf(valStr,
"%f", 34.23);
393 chVal.
length = strlen(valStr);
396 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
398 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
401 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
404 sprintf(valStr,
"%d", 123);
406 chVal.
length = strlen(valStr);
409 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
412 sprintf(valStr,
"%d", 2746);
414 chVal.
length = strlen(valStr);
417 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
420 sprintf(valStr,
"%d", 112);
422 chVal.
length = strlen(valStr);
425 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
427 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
430 sprintf(valStr,
"%f", 1.214);
432 chVal.
length = strlen(valStr);
435 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
438 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
441 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
450 fail_unless (tmp_err_code ==
EXIP_OK,
"initParser returns an error code %d", tmp_err_code);
457 fail_unless (tmp_err_code ==
EXIP_OK,
"parsing the header returns an error code %d", tmp_err_code);
460 fail_unless (tmp_err_code ==
EXIP_OK,
"setSchema() returns an error code %d", tmp_err_code);
478 const String ELEM_OBJ_STR = {
"obj", 3};
479 const String ELEM_STR_STR = {
"str", 3};
480 const String ELEM_LIST_STR = {
"list", 4};
482 const String ATTR_XSTR_STR = {
"xsss", 4};
483 const String ATTR_XTEMP_STR = {
"x-template", 10};
484 const String ATTR_NAME_STR = {
"name", 4};
485 const String ATTR_VAL_STR = {
"val", 3};
519 fail_unless (tmp_err_code ==
EXIP_OK,
"initStream returns an error code %d", tmp_err_code);
523 fail_unless (tmp_err_code ==
EXIP_OK,
"exiHeader returns an error code %d", tmp_err_code);
526 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
531 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
534 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
535 sprintf(valStr,
"%s",
"http://obix.org/ns/schema/1.1");
537 chVal.
length = strlen(valStr);
539 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
542 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
543 sprintf(valStr,
"%s",
"ipu_inst.xml");
545 chVal.
length = strlen(valStr);
547 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
550 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
553 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
554 sprintf(valStr,
"%s",
"interworkingProxyID");
556 chVal.
length = strlen(valStr);
558 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
561 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
562 sprintf(valStr,
"%s",
"IPU_6LoWPAN");
564 chVal.
length = strlen(valStr);
566 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
568 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
571 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
574 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
575 sprintf(valStr,
"%s",
"supportedTechnologies");
577 chVal.
length = strlen(valStr);
579 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
582 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
586 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
589 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
590 sprintf(valStr,
"%s",
"anPhysical");
592 chVal.
length = strlen(valStr);
594 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
597 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
598 sprintf(valStr,
"%s",
"2003_2_4GHz");
600 chVal.
length = strlen(valStr);
602 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
604 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
608 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
611 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
612 sprintf(valStr,
"%s",
"anStandard");
614 chVal.
length = strlen(valStr);
616 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
619 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
620 sprintf(valStr,
"%s",
"Bee_1_0");
622 chVal.
length = strlen(valStr);
624 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
626 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
631 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
634 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
635 sprintf(valStr,
"%s",
"anProfile");
637 chVal.
length = strlen(valStr);
639 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
642 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
643 sprintf(valStr,
"%s",
"Bee_HA");
645 chVal.
length = strlen(valStr);
647 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
649 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
652 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
655 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
658 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
661 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
664 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.* returns an error code %d", tmp_err_code);
673 fail_unless (tmp_err_code ==
EXIP_OK,
"initParser returns an error code %d", tmp_err_code);
680 fail_unless (tmp_err_code ==
EXIP_OK,
"parsing the header returns an error code %d", tmp_err_code);
683 fail_unless (tmp_err_code ==
EXIP_OK,
"setSchema() returns an error code %d", tmp_err_code);
721 fail_unless(tmp_err_code ==
EXIP_OK,
"There is an error in the encoding of dynamic types through xsi:type switch.");
722 fail_unless(strmSize > 0,
"Encoding of dynamic types through xsi:type switch produces empty streams.");
734 fail_unless (tmp_err_code ==
EXIP_OK,
"initParser returns an error code %d", tmp_err_code);
741 fail_unless (tmp_err_code ==
EXIP_OK,
"parsing the header returns an error code %d", tmp_err_code);
744 fail_unless (tmp_err_code ==
EXIP_OK,
"setSchema() returns an error code %d", tmp_err_code);
763 const String NS_XSI = {
"http://www.w3.org/2001/XMLSchema-instance", 41};
764 const String NS_XSD = {
"http://www.w3.org/2001/XMLSchema", 32};
766 const String ELEM_TRIVIAL = {
"trivial", 7};
767 const String ELEM_AN_ELEMENT = {
"anElement", 9};
769 const String PREFIX_XSI = {
"xsi", 3};
771 const String ATTR_TYPE = {
"type", 4};
773 const String VALUE_DATE = {
"dateTime", 8};
811 qname.
uri = &NS_EMPTY;
817 qname.
uri = &NS_EMPTY;
855 #define OUTPUT_BUFFER_SIZE_LARGE_DOC 20000
856 #define MAX_XSD_FILES_COUNT 10 // up to 10 XSD files
863 const String ELEM_CONFIGURATION = {
"configuration", 13};
864 const String ELEM_CAPSWITCH = {
"capable-switch", 14};
865 const String ELEM_RESOURCES = {
"resources", 9};
866 const String ELEM_PORT = {
"port", 4};
867 const String ELEM_RESID = {
"resource-id", 11};
868 const String ELEM_ADMIN_STATE = {
"admin-state", 11};
869 const String ELEM_NORECEIVE = {
"no-receive", 10};
870 const String ELEM_NOFORWARD = {
"no-forward", 10};
871 const String ELEM_NOPACKET = {
"no-packet-in", 12};
873 const String ELEM_LOGSWITCHES = {
"logical-switches", 16};
874 const String ELEM_SWITCH = {
"switch", 6};
875 const String ELEM_ID = {
"id", 2};
876 const String ELEM_DATAPATHID = {
"datapath-id", 11};
877 const String ELEM_ENABLED = {
"enabled", 7};
878 const String ELEM_LOSTCONNBEH = {
"lost-connection-behavior", 24};
879 const String ELEM_CONTROLLERS = {
"controllers", 11};
880 const String ELEM_CONTROLLER = {
"controller", 10};
881 const String ELEM_ROLE = {
"role", 4};
882 const String ELEM_IPADDR = {
"ip-address", 10};
883 const String ELEM_PROTOCOL = {
"protocol", 8};
884 const String ELEM_STATE = {
"state", 5};
885 const String ELEM_CONNSTATE = {
"connection-state", 16};
886 const String ELEM_CURRVER = {
"current-version", 15};
888 const char * PORT_STR =
"port";
889 const char * SWITCH_STR =
"switch";
890 const char * STATE_UP_STR =
"up";
891 const char * DATAPATH_STR =
"10:14:56:7C:89:46:7A:";
892 const char * LOST_CONN_BEHAVIOR_STR =
"failSecureMode";
893 const char * CTRL_STR =
"ctrl";
894 const char * ROLE_STR =
"equal";
895 const char * IPADDR_STR =
"10.10.10.";
896 const char * PROTOCOL_STR =
"tcp";
897 const char * VER_STR =
"1.0";
901 char* sourceFile =
"testOutputFile.exi";
905 char* schemafname[1] = {
"exip/schema_demo.exi"};
920 parseSchema(schemafname, 1, &schema);
922 outfile = fopen(sourceFile,
"wb" );
923 fail_if(!outfile,
"Unable to open file %s", sourceFile);
970 for (i = 0; i < 100; i++)
980 sprintf(strbuffer,
"%s%d", PORT_STR, i);
1024 for (i = 0; i < 20; i++)
1034 sprintf(strbuffer,
"%s%d", SWITCH_STR, i);
1043 sprintf(strbuffer,
"%s%d", DATAPATH_STR, 10 + i);
1067 for (j = 0; j < 100; j++)
1073 sprintf(strbuffer,
"%s%d", PORT_STR, j);
1093 sprintf(strbuffer,
"%s%d", CTRL_STR, i);
1108 sprintf(strbuffer,
"%s%d", IPADDR_STR, i);
1187 parseSchema(schemafname, 1, &schema);
1190 infile = fopen(sourceFile,
"rb" );
1192 fail(
"Unable to open file %s", sourceFile);
1198 tmp_err_code =
initParser(&testParser, buffer, &eventCount);
1199 fail_unless (tmp_err_code ==
EXIP_OK,
"initParser returns an error code %d", tmp_err_code);
1203 fail_unless (tmp_err_code ==
EXIP_OK,
"parsing the header returns an error code %d", tmp_err_code);
1205 tmp_err_code =
setSchema(&testParser, &schema);
1206 fail_unless (tmp_err_code ==
EXIP_OK,
"setSchema() returns an error code %d", tmp_err_code);
1209 while(tmp_err_code ==
EXIP_OK)
1225 #define INPUT_BUFFER_SIZE 200
1234 char* schemafname[2] = {
"exip/subsGroups/root-xsd.exi",
"exip/subsGroups/sub-xsd.exi"};
1235 char *exifname =
"exip/subsGroups/root.exi";
1248 parseSchema(schemafname, 2, &schema);
1251 size_t pathlen = strlen(dataDir);
1252 memcpy(exipath, dataDir, pathlen);
1253 exipath[pathlen] =
'/';
1254 memcpy(&exipath[pathlen+1], exifname, strlen(exifname)+1);
1256 infile = fopen(exipath,
"rb" );
1258 fail(
"Unable to open file %s", exipath);
1264 tmp_err_code =
initParser(&testParser, buffer, &eventCount);
1265 fail_unless (tmp_err_code ==
EXIP_OK,
"initParser returns an error code %d", tmp_err_code);
1272 fail_unless (tmp_err_code ==
EXIP_OK,
"parsing the header returns an error code %d", tmp_err_code);
1274 tmp_err_code =
setSchema(&testParser, &schema);
1275 fail_unless (tmp_err_code ==
EXIP_OK,
"setSchema() returns an error code %d", tmp_err_code);
1277 while(tmp_err_code ==
EXIP_OK)
1284 "Unexpected event count: %u", eventCount);
1302 char* schemafname[1] = {
"exip/NonBlockingStreaming-xsd.exi"};
1305 unsigned int flushMarker;
1306 unsigned int bytesRead;
1308 parseSchema(schemafname, 1, &schema);
1311 fail_unless(tmp_err_code ==
EXIP_OK,
"There is an error in the encoding of non blocking EXI stream");
1312 fail_unless(strmSize > 0,
"Encoding using non blocking flushing produces empty streams.");
1315 memcpy(tmpBuf, flushBuf, flushMarker);
1318 buffer.
buf = tmpBuf;
1329 fail_unless (tmp_err_code ==
EXIP_OK,
"initParser returns an error code %d", tmp_err_code);
1336 fail_unless (tmp_err_code ==
EXIP_OK,
"parsing the header returns an error code %d", tmp_err_code);
1339 fail_unless (tmp_err_code ==
EXIP_OK,
"setSchema() returns an error code %d", tmp_err_code);
1343 while(tmp_err_code ==
EXIP_OK)
1350 tmp_err_code =
parse.
pushEXIData(flushBuf + flushMarker, strmSize - flushMarker, &bytesRead, &testParser);
1353 flushMarker += bytesRead;
1355 while(tmp_err_code ==
EXIP_OK)
1375 char* schemafname[1] = {
"exip/NonBlockingStreaming-xsd.exi"};
1378 unsigned int flushMarker;
1379 unsigned int bytesRead;
1381 parseSchema(schemafname, 1, &schema);
1384 fail_unless(tmp_err_code ==
EXIP_OK,
"There is an error in the encoding of non blocking EXI stream");
1385 fail_unless(strmSize > 0,
"Encoding using non blocking flushing produces empty streams.");
1388 memcpy(tmpBuf, flushBuf, flushMarker);
1391 buffer.
buf = tmpBuf;
1402 fail_unless (tmp_err_code ==
EXIP_OK,
"initParser returns an error code %d", tmp_err_code);
1409 fail_unless (tmp_err_code ==
EXIP_OK,
"parsing the header returns an error code %d", tmp_err_code);
1412 fail_unless (tmp_err_code ==
EXIP_OK,
"setSchema() returns an error code %d", tmp_err_code);
1416 while(tmp_err_code ==
EXIP_OK)
1423 tmp_err_code =
parse.
pushEXIData(flushBuf + flushMarker, strmSize - flushMarker, &bytesRead, &testParser);
1426 flushMarker += bytesRead;
1428 while(tmp_err_code ==
EXIP_OK)
1444 const String NS_URN_STR = {
"non:blocking:check", 18};
1446 const String ELEM_TEST = {
"test", 4};
1447 const String ELEM_LONG_TEST = {
"long-test", 9};
1449 const String ATTR_SAMPLE = {
"sample", 6};
1450 const String ATTR_SAMPLE_2 = {
"sample-2", 8};
1452 const String LONG_DATA_STR = {
"Test data.", 10};
1453 const String SHORT_DATA_STR = {
"echo-echoo-echooo", 17};
1454 const String LT1_DATA_STR = {
"long-test 1 data", 16};
1455 const String LT2_DATA_STR = {
"long-test 2 data", 16};
1456 const String LT3_DATA_STR = {
"long-test 3 data", 16};
1458 const String SCHEMA_ID_STR = {
"schemaID=test", 13};
1470 unsigned int bytesFlushed = 0;
1472 buffer.
buf = smallBuf;
1500 savedContext = testStrm.
context;
1502 qname.
uri = &NS_URN_STR;
1507 testStrm.
context = savedContext;
1510 *strmSize += bytesFlushed;
1513 else if(tmp_err_code !=
EXIP_OK)
1514 return tmp_err_code;
1516 savedContext = testStrm.
context;
1523 testStrm.
context = savedContext;
1526 *strmSize += bytesFlushed;
1529 else if(tmp_err_code !=
EXIP_OK)
1530 return tmp_err_code;
1532 savedContext = testStrm.
context;
1537 testStrm.
context = savedContext;
1540 *strmSize += bytesFlushed;
1543 else if(tmp_err_code !=
EXIP_OK)
1544 return tmp_err_code;
1546 savedContext = testStrm.
context;
1553 testStrm.
context = savedContext;
1556 *strmSize += bytesFlushed;
1559 else if(tmp_err_code !=
EXIP_OK)
1560 return tmp_err_code;
1562 savedContext = testStrm.
context;
1569 testStrm.
context = savedContext;
1572 *strmSize += bytesFlushed;
1575 else if(tmp_err_code !=
EXIP_OK)
1576 return tmp_err_code;
1578 savedContext = testStrm.
context;
1583 testStrm.
context = savedContext;
1586 *strmSize += bytesFlushed;
1589 else if(tmp_err_code !=
EXIP_OK)
1590 return tmp_err_code;
1592 savedContext = testStrm.
context;
1597 testStrm.
context = savedContext;
1600 *strmSize += bytesFlushed;
1603 else if(tmp_err_code !=
EXIP_OK)
1604 return tmp_err_code;
1606 savedContext = testStrm.
context;
1611 testStrm.
context = savedContext;
1614 *strmSize += bytesFlushed;
1617 else if(tmp_err_code !=
EXIP_OK)
1618 return tmp_err_code;
1622 savedContext = testStrm.
context;
1629 testStrm.
context = savedContext;
1632 *strmSize += bytesFlushed;
1635 else if(tmp_err_code !=
EXIP_OK)
1636 return tmp_err_code;
1638 savedContext = testStrm.
context;
1645 testStrm.
context = savedContext;
1648 *strmSize += bytesFlushed;
1651 else if(tmp_err_code !=
EXIP_OK)
1652 return tmp_err_code;
1654 savedContext = testStrm.
context;
1659 testStrm.
context = savedContext;
1662 *strmSize += bytesFlushed;
1665 else if(tmp_err_code !=
EXIP_OK)
1666 return tmp_err_code;
1668 savedContext = testStrm.
context;
1673 testStrm.
context = savedContext;
1676 *strmSize += bytesFlushed;
1679 else if(tmp_err_code !=
EXIP_OK)
1680 return tmp_err_code;
1682 savedContext = testStrm.
context;
1687 testStrm.
context = savedContext;
1690 *strmSize += bytesFlushed;
1693 else if(tmp_err_code !=
EXIP_OK)
1694 return tmp_err_code;
1698 savedContext = testStrm.
context;
1705 testStrm.
context = savedContext;
1708 *strmSize += bytesFlushed;
1711 else if(tmp_err_code !=
EXIP_OK)
1712 return tmp_err_code;
1714 savedContext = testStrm.
context;
1721 testStrm.
context = savedContext;
1724 *strmSize += bytesFlushed;
1727 else if(tmp_err_code !=
EXIP_OK)
1728 return tmp_err_code;
1730 savedContext = testStrm.
context;
1735 testStrm.
context = savedContext;
1738 *strmSize += bytesFlushed;
1741 else if(tmp_err_code !=
EXIP_OK)
1742 return tmp_err_code;
1744 savedContext = testStrm.
context;
1749 testStrm.
context = savedContext;
1752 *strmSize += bytesFlushed;
1755 else if(tmp_err_code !=
EXIP_OK)
1756 return tmp_err_code;
1758 savedContext = testStrm.
context;
1763 testStrm.
context = savedContext;
1766 *strmSize += bytesFlushed;
1769 else if(tmp_err_code !=
EXIP_OK)
1770 return tmp_err_code;
1774 savedContext = testStrm.
context;
1781 testStrm.
context = savedContext;
1784 *strmSize += bytesFlushed;
1787 else if(tmp_err_code !=
EXIP_OK)
1788 return tmp_err_code;
1790 savedContext = testStrm.
context;
1797 testStrm.
context = savedContext;
1800 *strmSize += bytesFlushed;
1803 else if(tmp_err_code !=
EXIP_OK)
1804 return tmp_err_code;
1806 savedContext = testStrm.
context;
1811 testStrm.
context = savedContext;
1814 *strmSize += bytesFlushed;
1817 else if(tmp_err_code !=
EXIP_OK)
1818 return tmp_err_code;
1820 savedContext = testStrm.
context;
1825 testStrm.
context = savedContext;
1828 *strmSize += bytesFlushed;
1831 else if(tmp_err_code !=
EXIP_OK)
1832 return tmp_err_code;
1834 savedContext = testStrm.
context;
1839 testStrm.
context = savedContext;
1842 *strmSize += bytesFlushed;
1845 else if(tmp_err_code !=
EXIP_OK)
1846 return tmp_err_code;
1850 savedContext = testStrm.
context;
1857 testStrm.
context = savedContext;
1860 *strmSize += bytesFlushed;
1863 else if(tmp_err_code !=
EXIP_OK)
1864 return tmp_err_code;
1866 savedContext = testStrm.
context;
1873 testStrm.
context = savedContext;
1876 *strmSize += bytesFlushed;
1879 else if(tmp_err_code !=
EXIP_OK)
1880 return tmp_err_code;
1882 savedContext = testStrm.
context;
1887 testStrm.
context = savedContext;
1890 *strmSize += bytesFlushed;
1893 else if(tmp_err_code !=
EXIP_OK)
1894 return tmp_err_code;
1896 savedContext = testStrm.
context;
1901 testStrm.
context = savedContext;
1904 *strmSize += bytesFlushed;
1907 else if(tmp_err_code !=
EXIP_OK)
1908 return tmp_err_code;
1910 savedContext = testStrm.
context;
1915 testStrm.
context = savedContext;
1918 *strmSize += bytesFlushed;
1921 else if(tmp_err_code !=
EXIP_OK)
1922 return tmp_err_code;
1926 savedContext = testStrm.
context;
1931 testStrm.
context = savedContext;
1934 *strmSize += bytesFlushed;
1937 else if(tmp_err_code !=
EXIP_OK)
1938 return tmp_err_code;
1940 savedContext = testStrm.
context;
1945 testStrm.
context = savedContext;
1948 *strmSize += bytesFlushed;
1951 else if(tmp_err_code !=
EXIP_OK)
1952 return tmp_err_code;
1966 #define BN_STR_SIZE 50
1967 #define ALL_STR_SIZE 20
2065 if(senmlData.
bn[0] !=
'\0')
2075 if(senmlData.
bt != LONG_MAX)
2084 if(senmlData.
bu[0] !=
'\0')
2115 if(senmlData.
eArray[e].
n[0] !=
'\0')
2132 if(senmlData.
eArray[e].
sv[0] !=
'\0')
2141 if(senmlData.
eArray[e].
t != INT_MAX)
2149 if(senmlData.
eArray[e].
u[0] !=
'\0')
2158 if(senmlData.
eArray[e].
ut != INT_MAX)
2186 return tmp_err_code;
2219 static errorCode sample_startElement(
QName qname,
void* app_data);
2221 static errorCode sample_stringData(
const String value,
void* app_data);
2223 static errorCode sample_booleanData(
boolean bool_val,
void* app_data);
2245 parsingData.
data = senmlData;
2277 while(tmp_err_code ==
EXIP_OK)
2289 return tmp_err_code;
2292 static errorCode sample_startElement(
QName qname,
void* app_data)
2374 static errorCode sample_stringData(
const String value,
void* app_data)
2446 static errorCode sample_booleanData(
boolean bool_val,
void* app_data)
2481 appD->
data->
bt = int_val;
2498 #define E_ELEM_COUNT 7 // The number of e elems in the senML to be encoded is 7
2504 char* schemafname[1] = {
"exip/SenML-xsd.exi"};
2508 senml senML_instance;
2513 parseSchema(schemafname, 1, &schema);
2515 strcpy(senML_instance.
bn,
"urn:dev:mac:0024befffe804ff1");
2516 senML_instance.
bt = 1415355691;
2518 senML_instance.
bu[0] =
'\0';
2521 senML_instance.
eArray = eArr;
2524 strcpy(eArr[0].n,
"pktid");
2525 strcpy(eArr[0].u,
"count");
2526 eArr[0].
v.mantissa = 1;
2527 eArr[0].
v.exponent = 0;
2530 strcpy(eArr[1].n,
"rpm");
2531 strcpy(eArr[1].u,
"r/m");
2532 eArr[1].
v.mantissa = 352;
2533 eArr[1].
v.exponent = 0;
2536 strcpy(eArr[2].n,
"rpm_av");
2537 strcpy(eArr[2].u,
"r/m");
2538 eArr[2].
v.mantissa = 352;
2539 eArr[2].
v.exponent = 0;
2542 strcpy(eArr[3].n,
"totrounds");
2543 strcpy(eArr[3].u,
"count");
2544 eArr[3].
v.mantissa = 461;
2545 eArr[3].
v.exponent = 3;
2548 strcpy(eArr[4].n,
"totrounds_r");
2549 strcpy(eArr[4].u,
"count");
2550 eArr[4].
v.mantissa = 0;
2551 eArr[4].
v.exponent = 0;
2554 strcpy(eArr[5].n,
"bearingtemp");
2555 strcpy(eArr[5].u,
"Cel");
2556 eArr[5].
v.mantissa = 454;
2557 eArr[5].
v.exponent = -1;
2560 strcpy(eArr[6].n,
"rssi");
2561 strcpy(eArr[6].u,
"%");
2562 eArr[6].
v.mantissa = 9;
2563 eArr[6].
v.exponent = 1;
2570 eArr[i].
sv[0] =
'\0';
2571 eArr[i].
t = INT_MAX;
2572 eArr[i].
ut = INT_MAX;
2576 fail_unless(tmp_err_code ==
EXIP_OK,
"There is an error in the encoding of an EXI SenML stream");
2577 fail_unless(exiSize > 0,
"Encoding SenML produces empty streams.");
2579 senMLParsed.
eArray = eArrParsed;
2580 senMLParsed.
bn[0] =
'\0';
2581 senMLParsed.
bt = LONG_MAX;
2583 senMLParsed.
bu[0] =
'\0';
2586 senMLParsed.
eArray = eArr;
2590 eArrParsed[i].
n[0] =
'\0';
2591 eArrParsed[i].
u[0] =
'\0';
2593 eArrParsed[i].
bv = 5;
2595 eArrParsed[i].
sv[0] =
'\0';
2596 eArrParsed[i].
t = INT_MAX;
2597 eArrParsed[i].
ut = INT_MAX;
2601 fail_unless(tmp_err_code ==
EXIP_OK,
"There is an error in the decoding of an EXI SenML stream");
2602 fail_unless(!strcmp(senMLParsed.
bn, senML_instance.
bn),
"SenML BN value error");
2603 fail_unless(senMLParsed.
bt == senML_instance.
bt,
"SenML BT value error");
2622 FILE *outfile = (FILE*) stream;
2623 return fwrite(buf, 1, readSize, outfile);
2628 FILE *infile = (FILE*) stream;
2629 return fread(buf, 1, readSize, infile);
2632 static void parseSchema(
char** xsdList,
int count,
EXIPSchema* schema)
2637 size_t pathlen = strlen(dataDir);
2641 for (i = 0; i < count; i++)
2643 memcpy(exipath, dataDir, pathlen);
2644 exipath[pathlen] =
'/';
2645 memcpy(&exipath[pathlen+1], xsdList[i], strlen(xsdList[i])+1);
2646 schemaFile = fopen(exipath,
"rb" );
2649 fail(
"Unable to open file %s", exipath);
2655 fseek(schemaFile, 0, SEEK_END);
2656 buffer[i].
bufLen = ftell(schemaFile) + 1;
2657 fseek(schemaFile, 0, SEEK_SET);
2660 buffer[i].
buf = (
char *) malloc(buffer[i].bufLen);
2664 fail(
"Memory allocation error!");
2668 fread(buffer[i].buf, buffer[i].bufLen, 1, schemaFile);
2680 for(i = 0; i < count; i++)
2682 free(buffer[i].buf);
2687 fail(
"\nGrammar generation error occurred: %d", tmp_err_code);
2711 tcase_add_test (tc_Schema, test_non_blocking_streaming_bytealigned);
2727 printf(
"ERR: Expected test data directory\n");
2732 printf(
"ERR: Test data pathname too long: %u", (
unsigned int) strlen(argv[1]));
2744 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;