22 #include "EXISerializer.h"
23 #include "EXIParser.h"
24 #include "stringManipulate.h"
25 #include "grammarGenerator.h"
28 #define INPUT_BUFFER_SIZE 200
29 #define OUTPUT_BUFFER_SIZE 200
30 #define MAX_PATH_LEN 200
50 FILE *infile = (FILE*) stream;
51 return fread(buf, 1, readSize, infile);
56 FILE *outfile = (FILE*) stream;
57 return fwrite(buf, 1, readSize, outfile);
60 static void parseSchema(
const char* fileName,
EXIPSchema* schema)
65 size_t pathlen = strlen(dataDir);
68 memcpy(exipath, dataDir, pathlen);
69 exipath[pathlen] =
'/';
70 memcpy(&exipath[pathlen+1], fileName, strlen(fileName)+1);
71 schemaFile = fopen(exipath,
"rb" );
74 fail(
"Unable to open file %s", exipath);
79 fseek(schemaFile, 0, SEEK_END);
80 buffer.
bufLen = ftell(schemaFile) + 1;
81 fseek(schemaFile, 0, SEEK_SET);
84 buffer.
buf = (
char *)malloc(buffer.
bufLen);
88 fail(
"Memory allocation error!");
92 fread(buffer.
buf, buffer.
bufLen, 1, schemaFile);
103 fail(
"\n Error reading schema: %d", tmp_err_code);
113 static errorCode sample_fatalError(
const errorCode code,
const char* msg,
void* app_data)
115 printf(
"\n%3d : FATAL ERROR: %s\n", code, msg);
119 static errorCode sample_startDocument(
void* app_data)
127 static errorCode sample_endDocument(
void* app_data)
145 static errorCode sample_endElement(
void* app_data)
277 const char *schemafname =
"testStates/acceptance-xsd.exi";
278 const char *exifname =
"testStates/acceptance_a_01.exi";
291 parseSchema(schemafname, &schema);
294 size_t pathlen = strlen(dataDir);
295 memcpy(exipath, dataDir, pathlen);
296 exipath[pathlen] =
'/';
297 memcpy(&exipath[pathlen+1], exifname, strlen(exifname)+1);
299 infile = fopen(exipath,
"rb" );
301 fail(
"Unable to open file %s", exipath);
307 tmp_err_code =
initParser(&testParser, buffer, &parsingData);
308 fail_unless (tmp_err_code ==
EXIP_OK,
"initParser returns an error code %d", tmp_err_code);
314 fail(
"Memory allocation error!");
331 fail_unless (tmp_err_code ==
EXIP_OK,
"parsing the header returns an error code %d", tmp_err_code);
333 tmp_err_code =
setSchema(&testParser, &schema);
334 fail_unless (tmp_err_code ==
EXIP_OK,
"setSchema() returns an error code %d", tmp_err_code);
422 "Unexpected event count: %u", parsingData.
eventCount);
439 const char *schemafname =
"testStates/acceptance-xsd.exi";
440 const char *exifname =
"testStates/acceptance_a_01a.exi";
453 parseSchema(schemafname, &schema);
456 size_t pathlen = strlen(dataDir);
457 memcpy(exipath, dataDir, pathlen);
458 exipath[pathlen] =
'/';
459 memcpy(&exipath[pathlen+1], exifname, strlen(exifname)+1);
461 infile = fopen(exipath,
"rb" );
463 fail(
"Unable to open file %s", exipath);
469 tmp_err_code =
initParser(&testParser, buffer, &parsingData);
470 fail_unless (tmp_err_code ==
EXIP_OK,
"initParser returns an error code %d", tmp_err_code);
476 fail(
"Memory allocation error!");
492 fail_unless (tmp_err_code ==
EXIP_OK,
"parsing the header returns an error code %d", tmp_err_code);
494 tmp_err_code =
setSchema(&testParser, &schema);
495 fail_unless (tmp_err_code ==
EXIP_OK,
"setSchema() returns an error code %d", tmp_err_code);
531 "Unexpected event count: %u", parsingData.
eventCount);
557 const char *schemafname =
"testStates/acceptance-xsd.exi";
562 const String ELEM_A = {
"A", 1};
563 const String ELEM_AB = {
"AB", 2};
564 const String ELEM_AC = {
"AC", 2};
565 const String CH = {
"", 0};
575 parseSchema(schemafname, &schema);
593 fail_unless (tmp_err_code ==
EXIP_OK,
"initStream returns an error code %d", tmp_err_code);
603 fail_unless (tmp_err_code ==
EXIP_OK,
"serialization returns an error code %d", tmp_err_code);
609 fail_unless (tmp_err_code ==
EXIP_OK,
"serialization returns an error code %d", tmp_err_code);
615 fail_unless (tmp_err_code ==
EXIP_OK,
"serialization returns an error code %d", tmp_err_code);
620 fail_unless (tmp_err_code ==
EXIP_OK,
"serialization returns an error code %d", tmp_err_code);
625 "Expected EXIP_INCONSISTENT_PROC_STATE, but returns an error code %d", tmp_err_code);
732 static String ENUM_DATA_QUALITY[] = {{
"Good", 4},
733 {
"Good_LocalOverride", 18},
735 {
"Uncertain_LastUsable", 20},
736 {
"Uncertain_SensorCal", 19},
737 {
"Uncertain_EGUExeeded", 20},
738 {
"Uncertain_SubNormal", 19},
740 {
"Bad_ConfigError", 15},
741 {
"Bad_NotConnected", 16},
742 {
"Bad_DeviceFailure", 17},
743 {
"Bad_SensorFailure", 17},
744 {
"Bad_CommFailureLastKnownAvailable", 33},
745 {
"Bad_CommFailure", 15},
746 {
"Bad_OutOfService", 16}};
748 static String ENUM_DATA_VAL_TYPE[] = {{
"Bool", 4},
759 static errorCode lkab_fatalError(
const errorCode code,
const char* msg,
void* app_data);
760 static errorCode lkab_startElement_io(
QName qname,
void* app_data);
761 static errorCode lkab_startElement_desc(
QName qname,
void* app_data);
762 static errorCode lkab_endElement(
void* app_data);
763 static errorCode lkab_stringData_io(
const String value,
void* app_data);
764 static errorCode lkab_stringData_desc(
const String value,
void* app_data);
765 static errorCode lkab_booleanData_io(
boolean bool_val,
void* app_data);
766 static errorCode lkab_booleanData_desc(
boolean bool_val,
void* app_data);
777 static error_code parseIOMsg(
char* buf,
unsigned int buf_size,
BoolValue *val);
787 static error_code parseDevDescMsg(
char* buf,
unsigned int buf_size,
DevDescribtion* devDesc);
798 static error_code serializeIOMsg(
char* buf,
unsigned int buf_size,
unsigned int* msg_size,
BoolValue val);
809 static error_code serializeDevDescMsg(
char* buf,
unsigned int buf_size,
unsigned int* msg_size,
DevDescribtion devDesc);
812 static error_code serializeIOMsg(
char* buf,
unsigned int buf_size,
unsigned int* msg_size,
BoolValue val)
822 const char *schemafname =
"SchemaStrict/lkab-devices-xsd.exi";
832 parseSchema(schemafname, &lkab_schema);
835 serialize.initHeader(&strm);
846 tmp_err_code = serialize.initStream(&strm, buffer, &lkab_schema);
851 tmp_err_code += serialize.exiHeader(&strm);
853 tmp_err_code += serialize.startDocument(&strm);
857 tmp_err_code += serialize.startElement(&strm, qname, &valueType);
861 tmp_err_code += serialize.startElement(&strm, qname, &valueType);
874 tmp_err_code += serialize.dateTimeData(&strm, dt);
876 tmp_err_code += serialize.endElement(&strm);
880 tmp_err_code += serialize.startElement(&strm, qname, &valueType);
882 tmp_err_code += serialize.stringData(&strm, ENUM_DATA_QUALITY[val.
quality]);
884 tmp_err_code += serialize.endElement(&strm);
888 tmp_err_code += serialize.startElement(&strm, qname, &valueType);
890 tmp_err_code += serialize.booleanData(&strm, val.
val);
892 tmp_err_code += serialize.endElement(&strm);
894 tmp_err_code += serialize.endElement(&strm);
896 tmp_err_code += serialize.endDocument(&strm);
904 tmp_err_code = serialize.closeEXIStream(&strm);
909 static error_code serializeDevDescMsg(
char* buf,
unsigned int buf_size,
unsigned int* msg_size,
DevDescribtion devDesc)
919 const char *schemafname =
"SchemaStrict/lkab-devices-xsd.exi";
929 parseSchema(schemafname, &lkab_schema);
932 serialize.initHeader(&strm);
943 tmp_err_code = serialize.initStream(&strm, buffer, &lkab_schema);
948 tmp_err_code += serialize.exiHeader(&strm);
950 tmp_err_code += serialize.startDocument(&strm);
954 tmp_err_code += serialize.startElement(&strm, qname, &valueType);
958 tmp_err_code += serialize.startElement(&strm, qname, &valueType);
962 tmp_err_code += serialize.stringData(&strm, ch);
964 tmp_err_code += serialize.endElement(&strm);
968 tmp_err_code += serialize.startElement(&strm, qname, &valueType);
972 tmp_err_code += serialize.stringData(&strm, ch);
974 tmp_err_code += serialize.endElement(&strm);
978 tmp_err_code += serialize.startElement(&strm, qname, &valueType);
982 tmp_err_code += serialize.stringData(&strm, ch);
984 tmp_err_code += serialize.endElement(&strm);
988 tmp_err_code += serialize.startElement(&strm, qname, &valueType);
992 tmp_err_code += serialize.stringData(&strm, ch);
994 tmp_err_code += serialize.endElement(&strm);
998 tmp_err_code += serialize.startElement(&strm, qname, &valueType);
1002 tmp_err_code += serialize.startElement(&strm, qname, &valueType);
1006 tmp_err_code += serialize.stringData(&strm, ch);
1008 tmp_err_code += serialize.endElement(&strm);
1012 tmp_err_code += serialize.startElement(&strm, qname, &valueType);
1014 tmp_err_code += serialize.stringData(&strm, ENUM_DATA_VAL_TYPE[devDesc.
processValue.
type]);
1016 tmp_err_code += serialize.endElement(&strm);
1020 tmp_err_code += serialize.startElement(&strm, qname, &valueType);
1022 tmp_err_code += serialize.booleanData(&strm, 0);
1024 tmp_err_code += serialize.endElement(&strm);
1028 tmp_err_code += serialize.startElement(&strm, qname, &valueType);
1032 tmp_err_code += serialize.stringData(&strm, ch);
1034 tmp_err_code += serialize.endElement(&strm);
1036 tmp_err_code += serialize.endElement(&strm);
1038 tmp_err_code += serialize.endElement(&strm);
1040 tmp_err_code += serialize.endDocument(&strm);
1043 return tmp_err_code;
1048 tmp_err_code = serialize.closeEXIStream(&strm);
1053 static error_code parseIOMsg(
char* buf,
unsigned int buf_size,
BoolValue *val)
1060 const char *schemafname =
"SchemaStrict/lkab-devices-xsd.exi";
1063 buffer.
bufLen = buf_size;
1068 parseSchema(schemafname, &lkab_schema);
1074 tmp_err_code =
initParser(&lkabParser, buffer, &parsingData);
1076 return tmp_err_code;
1080 parsingData.currElementNumber = 0;
1081 parsingData.val.quality =
Good;
1082 parsingData.val.val = 0;
1083 parsingData.val.ts.year = 0;
1084 parsingData.val.ts.month = 0;
1085 parsingData.val.ts.mday = 0;
1086 parsingData.val.ts.hour = 0;
1087 parsingData.val.ts.min = 0;
1088 parsingData.val.ts.sec = 0;
1089 parsingData.val.ts.msec = 0;
1103 tmp_err_code =
setSchema(&lkabParser, &lkab_schema);
1106 while(tmp_err_code ==
EXIP_OK)
1115 val->
ts = parsingData.val.ts;
1116 val->
val = parsingData.val.val;
1117 val->
quality = parsingData.val.quality;
1122 return tmp_err_code;
1125 static error_code parseDevDescMsg(
char* buf,
unsigned int buf_size,
DevDescribtion* devDesc)
1132 const char *schemafname =
"SchemaStrict/lkab-devices-xsd.exi";
1135 buffer.
bufLen = buf_size;
1141 parseSchema(schemafname, &lkab_schema);
1147 tmp_err_code =
initParser(&lkabParser, buffer, &parsingData);
1149 return tmp_err_code;
1153 parsingData.currElementNumber = 0;
1154 parsingData.devDesc.id[0] =
'\0';
1155 parsingData.devDesc.location[0] =
'\0';
1156 parsingData.devDesc.name[0] =
'\0';
1157 parsingData.devDesc.type[0] =
'\0';
1158 parsingData.devDesc.processValue.description[0] =
'\0';
1159 parsingData.devDesc.processValue.name[0] =
'\0';
1160 parsingData.devDesc.processValue.isReadOnly = 0;
1161 parsingData.devDesc.processValue.type =
Bool;
1174 tmp_err_code =
setSchema(&lkabParser, &lkab_schema);
1177 while(tmp_err_code ==
EXIP_OK)
1186 strcpy(devDesc->
id, parsingData.devDesc.id);
1187 strcpy(devDesc->
location, parsingData.devDesc.location);
1188 strcpy(devDesc->
name, parsingData.devDesc.name);
1189 strcpy(devDesc->
type, parsingData.devDesc.type);
1198 return tmp_err_code;
1201 static errorCode lkab_fatalError(
const errorCode code,
const char* msg,
void* app_data)
1206 static errorCode lkab_startElement_io(
QName qname,
void* app_data)
1242 static errorCode lkab_startElement_desc(
QName qname,
void* app_data)
1296 static errorCode lkab_endElement(
void* app_data)
1301 static errorCode lkab_stringData_io(
const String value,
void* app_data)
1310 for(i = 0; i < 15; i++)
1322 static errorCode lkab_stringData_desc(
const String value,
void* app_data)
1368 static errorCode lkab_booleanData_io(
boolean bool_val,
void* app_data)
1376 appD->
val.
val = bool_val;
1382 static errorCode lkab_booleanData_desc(
boolean bool_val,
void* app_data)
1411 #define LKAB_BUFFER_SIZE 1000
1416 unsigned int msg_size;
1436 fail_if(msg_size == 0,
"0 Length message size");
1457 strcpy(devD.
id,
"AirPS");
1458 strcpy(devD.
location,
"Grate Support Shaft");
1459 strcpy(devD.
name,
"Pressure switch");
1460 strcpy(devD.
type,
"Air pressure switch");
1469 fail_if(msg_size == 0,
"0 Length message size");
1471 strcpy(devD.
id,
"00000000000");
1472 strcpy(devD.
location,
"00000000000");
1473 strcpy(devD.
name,
"00000000000");
1474 strcpy(devD.
type,
"00000000000");
1485 fail_unless (strcmp(devD.
id,
"AirPS") == 0,
"id not correct");
1487 fail_unless (strcmp(devD.
name,
"Pressure switch") == 0,
"name not correct");
1488 fail_unless (strcmp(devD.
type,
"Air pressure switch") == 0,
"type not correct");
1519 printf(
"ERR: Expected test data directory\n");
1524 printf(
"ERR: Test data pathname too long: %u", (
unsigned int) strlen(argv[1]));
1538 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;