21 #include "procTypes.h"
22 #include "EXISerializer.h"
23 #include "EXIParser.h"
24 #include "stringManipulate.h"
25 #include "grammarGenerator.h"
27 #define OUTPUT_BUFFER_SIZE 2000
37 QName qname= {&uri, &ln};
63 fail_unless (tmp_err_code ==
EXIP_OK,
"initStream returns an error code %d", tmp_err_code);
67 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.exiHeader returns an error code %d", tmp_err_code);
70 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.startDocument returns an error code %d", tmp_err_code);
75 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.startElement returns an error code %d", tmp_err_code);
80 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.attribute returns an error code %d", tmp_err_code);
84 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.stringData returns an error code %d", tmp_err_code);
89 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.attribute returns an error code %d", tmp_err_code);
93 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.stringData returns an error code %d", tmp_err_code);
95 tmp_err_code +=
asciiToString(
"This is an example of serializing EXI streams using EXIP low level API", &chVal, &testStrm.
memList,
FALSE);
97 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.stringData returns an error code %d", tmp_err_code);
102 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.startElement returns an error code %d", tmp_err_code);
107 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.attribute returns an error code %d", tmp_err_code);
112 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.qnameData returns an error code %d", tmp_err_code);
115 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.intData returns an error code %d", tmp_err_code);
123 fail_unless (tmp_err_code ==
EXIP_OK,
"serialization ended with error code %d", tmp_err_code);
127 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize.closeEXIStream ended with error code %d", tmp_err_code);
137 fail_unless (tmp_err_code ==
EXIP_OK,
"initParser returns an error code %d", tmp_err_code);
144 fail_unless (tmp_err_code ==
EXIP_OK,
"parsing the header returns an error code %d", tmp_err_code);
147 fail_unless (tmp_err_code ==
EXIP_OK,
"setSchema() returns an error code %d", tmp_err_code);
167 char *
XSI =
"http://www.w3.org/2001/XMLSchema-instance";
168 char *
XS =
"http://www.w3.org/2001/XMLSchema";
169 char *
EXEMPLE =
"http://www.exemple.com/XMLNameSpace";
170 #define MAX_XSD_FILES_COUNT 10 // up to 10 XSD files
171 static char *dataDir;
172 #define MAX_PATH_LEN 200
176 static void parseSchema(
const char* fileName,
EXIPSchema* schema);
178 static errorCode sample_fatalError(
const errorCode code,
const char* msg,
void* app_data);
179 static errorCode sample_startDocument(
void* app_data);
180 static errorCode sample_endDocument(
void* app_data);
181 static errorCode sample_startElement(
QName qname,
void* app_data);
182 static errorCode sample_endElement(
void* app_data);
184 static errorCode sample_stringData(
const String value,
void* app_data);
188 static errorCode sample_booleanData(
boolean bool_val,
void* app_data);
190 static errorCode sample_binaryData(
const char* binary_val,
Index nbytes,
void* app_data);
191 static errorCode sample_qnameData(
const QName qname,
void* app_data);
195 const char* schemafname =
"xsitype/Product.exs";
200 QName qname= {&uri, &ln};
213 parseSchema(schemafname, &schema);
223 fail_unless (tmp_err_code ==
EXIP_OK,
"asciiToString returns an error code %d", tmp_err_code);
228 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize returns an error code %d", tmp_err_code);
230 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize returns an error code %d", tmp_err_code);
232 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize returns an error code %d", tmp_err_code);
249 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize returns an error code %d", tmp_err_code);
259 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize returns an error code %d", tmp_err_code);
281 fail_unless (tmp_err_code ==
EXIP_OK,
"serialize returns an error code %d", tmp_err_code);
314 tmp_err_code =
setSchema(&testParser, schemaPtr);
315 fail_unless (tmp_err_code ==
EXIP_OK,
"setSchema() returns an error code %d", tmp_err_code);
328 static void printURI(
const String *str) {
340 printURI (qname.
uri);
346 static errorCode sample_fatalError(
const errorCode code,
const char* msg,
void* app_data)
349 printf(
"\n### %d : FATAL ERROR: %s\n", code, msg);
354 static errorCode sample_startDocument(
void* app_data)
362 static errorCode sample_endDocument(
void* app_data)
380 static errorCode sample_endElement(
void* app_data)
397 expectAttributeData = 1;
403 if(expectAttributeData)
409 expectAttributeData = 0;
429 if(expectAttributeData)
433 sprintf(tmp_buf,
"%lld", (
long long int) int_val);
434 printf(
"### intData %s", tmp_buf);
437 expectAttributeData = 0;
443 printf(
"### intData ");
444 sprintf(tmp_buf,
"%lld", (
long long int) int_val);
445 printf(
"%s", tmp_buf);
452 static errorCode sample_booleanData(
boolean bool_val,
void* app_data)
467 static errorCode sample_binaryData(
const char* binary_val,
Index nbytes,
void* app_data)
472 static errorCode sample_qnameData(
const QName qname,
void* app_data)
475 printf (
"### qnameData : ");
479 expectAttributeData = 0;
483 static void parseSchema(
const char* fileName,
EXIPSchema* schema)
488 size_t pathlen = strlen(dataDir);
491 memcpy(exipath, dataDir, pathlen);
492 exipath[pathlen] =
'/';
493 memcpy(&exipath[pathlen+1], fileName, strlen(fileName)+1);
494 schemaFile = fopen(exipath,
"rb" );
497 fail(
"Unable to open file %s", exipath);
502 fseek(schemaFile, 0, SEEK_END);
503 buffer.
bufLen = ftell(schemaFile) + 1;
504 fseek(schemaFile, 0, SEEK_SET);
507 buffer.
buf = (
char *)malloc(buffer.
bufLen);
511 fail(
"Memory allocation error!");
515 fread(buffer.
buf, buffer.
bufLen, 1, schemaFile);
526 fail(
"\n Error reading schema: %d", tmp_err_code);
555 int main (
int argc,
char *argv[])
563 printf(
"ERR: Expected test data directory\n");
568 printf(
"ERR: Test data pathname too long: %u", (
unsigned int) strlen(argv[1]));
580 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;