Example #1
0
END_TEST

START_TEST (test_addValueEntry)
{
	EXIStream testStrm;
	errorCode tmp_err_code = EXIP_UNEXPECTED_ERROR;
	String testStr = {"TEST-007", 8};

	// IV: Initialize the stream
	{
		tmp_err_code = initAllocList(&(testStrm.memList));

		testStrm.context.bitPointer = 0;
		testStrm.buffer.bufLen = 0;
		testStrm.buffer.bufContent = 0;
		tmp_err_code += createValueTable(&testStrm.valueTable);
		testStrm.schema = memManagedAllocate(&testStrm.memList, sizeof(EXIPSchema));
		fail_unless (testStrm.schema != NULL, "Memory alloc error");
		/* Create and initialize initial string table entries */
		tmp_err_code += createDynArray(&testStrm.schema->uriTable.dynArray, sizeof(UriEntry), DEFAULT_URI_ENTRIES_NUMBER);
		tmp_err_code += createUriTableEntries(&testStrm.schema->uriTable, FALSE);
	}
	fail_unless (tmp_err_code == EXIP_OK, "initStream returns an error code %d", tmp_err_code);

	testStrm.gStack->currQNameID.uriId = 1; // http://www.w3.org/XML/1998/namespace
	testStrm.gStack->currQNameID.lnId = 2; // lang

	tmp_err_code = addValueEntry(&testStrm, testStr, testStrm.gStack->currQNameID);

	fail_unless (tmp_err_code == EXIP_OK, "addValueEntry returns an error code %d", tmp_err_code);
#if VALUE_CROSSTABLE_USE
	fail_unless (testStrm.schema->uriTable.uri[testStrm.gStack->currQNameID.uriId].lnTable.ln[testStrm.gStack->currQNameID.lnId].vxTable != NULL, "addValueEntry does not create vxTable");
	fail_unless (testStrm.schema->uriTable.uri[testStrm.gStack->currQNameID.uriId].lnTable.ln[testStrm.gStack->currQNameID.lnId].vxTable->count == 1, "addValueEntry does not create correct vxTable");
#endif
	fail_unless (testStrm.valueTable.count == 1, "addValueEntry does not create global value entry");

	destroyDynArray(&testStrm.valueTable.dynArray);
	destroyDynArray(&testStrm.schema->uriTable.dynArray);
	freeAllocList(&testStrm.memList);
}
Example #2
0
errorCode initSchema(EXIPSchema* schema, unsigned char initializationType)
{
	errorCode tmp_err_code = UNEXPECTED_ERROR;

	tmp_err_code = initAllocList(&schema->memList);
	if(tmp_err_code != ERR_OK)
		return tmp_err_code;

	schema->staticGrCount = 0;
	schema->docGrammar.contentIndex = 0;
	schema->docGrammar.count = 0;
	schema->docGrammar.props = 0;
	schema->docGrammar.rule = NULL;
	schema->simpleTypeTable.count = 0;
	schema->simpleTypeTable.sType = NULL;
	schema->grammarTable.count = 0;
	schema->grammarTable.grammar = NULL;
	schema->enumTable.count = 0;
	schema->enumTable.enumDef = NULL;

	/* Create and initialize initial string table entries */
	tmp_err_code = createDynArray(&schema->uriTable.dynArray, sizeof(UriEntry), DEFAULT_URI_ENTRIES_NUMBER);
	if(tmp_err_code != ERR_OK)
	{
		freeAllocList(&schema->memList);
		return tmp_err_code;
	}

	tmp_err_code = createUriTableEntries(&schema->uriTable, initializationType != INIT_SCHEMA_SCHEMA_LESS_MODE);
	if(tmp_err_code != ERR_OK)
	{
		freeAllocList(&schema->memList);
		return tmp_err_code;
	}

	if(initializationType == INIT_SCHEMA_SCHEMA_ENABLED)
	{
		/* Create and initialize enumDef table */
		tmp_err_code = createDynArray(&schema->enumTable.dynArray, sizeof(EnumDefinition), DEFAULT_ENUM_TABLE);
		if(tmp_err_code != ERR_OK)
		{
			freeAllocList(&schema->memList);
			return tmp_err_code;
		}
	}

	/* Create the schema grammar table */
	tmp_err_code = createDynArray(&schema->grammarTable.dynArray, sizeof(EXIGrammar), DEFAULT_GRAMMAR_TABLE);
	if(tmp_err_code != ERR_OK)
	{
		freeAllocList(&schema->memList);
		return tmp_err_code;
	}

	if(initializationType != INIT_SCHEMA_SCHEMA_LESS_MODE)
	{
		/* Create and initialize simple type table */
		tmp_err_code = createDynArray(&schema->simpleTypeTable.dynArray, sizeof(SimpleType), DEFAULT_SIMPLE_GRAMMAR_TABLE);
		if(tmp_err_code != ERR_OK)
		{
			freeAllocList(&schema->memList);
			return tmp_err_code;
		}

		tmp_err_code = createBuiltInTypesDefinitions(&schema->simpleTypeTable, &schema->memList);
		if(tmp_err_code != ERR_OK)
		{
			freeAllocList(&schema->memList);
			return tmp_err_code;
		}

		// Must be done after createBuiltInTypesDefinitions()
		tmp_err_code = generateBuiltInTypesGrammars(schema);
		if(tmp_err_code != ERR_OK)
		{
			freeAllocList(&schema->memList);
		}

		schema->staticGrCount = SIMPLE_TYPE_COUNT;
	}

	return tmp_err_code;
}
Example #3
0
void freeAllMem(EXIStream* strm)
{
	Index g, i, j;
	DynGrammarRule* tmp_rule;

	// Explicitly free the memory for any build-in grammars
	for(g = strm->schema->staticGrCount; g < strm->schema->grammarTable.count; g++)
	{
		for(i = 0; i < strm->schema->grammarTable.grammar[g].count; i++)
		{
			tmp_rule = &((DynGrammarRule*) strm->schema->grammarTable.grammar[g].rule)[i];
			for(j = 0; j < 3; j++)
			{
				if(tmp_rule->part[j].prod != NULL) {}
					EXIP_MFREE(tmp_rule->part[j].prod);
			}
		}
		EXIP_MFREE(strm->schema->grammarTable.grammar[g].rule);
	}

	strm->schema->grammarTable.count = strm->schema->staticGrCount;

	// Freeing the value cross tables

	for(i = 0; i < strm->schema->uriTable.count; i++)
	{
		for(j = 0; j < strm->schema->uriTable.uri[i].lnTable.count; j++)
		{
			if(GET_LN_URI_IDS(strm->schema->uriTable, i, j).vxTable.vx != NULL)
			{
				destroyDynArray(&GET_LN_URI_IDS(strm->schema->uriTable, i, j).vxTable.dynArray);
			}
			strm->schema->uriTable.uri[i].lnTable.ln[j].vxTable.vx = NULL;
			strm->schema->uriTable.uri[i].lnTable.ln[j].vxTable.count = 0;
		}
	}

	// Hash tables are freed separately
	// #DOCUMENT#
#if HASH_TABLE_USE == ON
	if(strm->valueTable.hashTbl != NULL)
		hashtable_destroy(strm->valueTable.hashTbl);
#endif

	// Freeing the value table if present

	if(strm->valueTable.value != NULL)
	{
		Index i;
		for(i = 0; i < strm->valueTable.count; i++)
		{
			EXIP_MFREE(strm->valueTable.value[i].valueStr.str);
		}

		destroyDynArray(&strm->valueTable.dynArray);
	}

	// In case a default schema was used for this stream
	if(strm->schema->staticGrCount <= SIMPLE_TYPE_COUNT)
	{
		// No schema-informed grammars. This is an empty EXIPSchema container that needs to be freed
		// Freeing the string tables

		for(i = 0; i < strm->schema->uriTable.count; i++)
		{
			if(strm->schema->uriTable.uri[i].pfxTable != NULL)
				EXIP_MFREE(strm->schema->uriTable.uri[i].pfxTable);

			destroyDynArray(&strm->schema->uriTable.uri[i].lnTable.dynArray);
		}

		destroyDynArray(&strm->schema->uriTable.dynArray);
		destroyDynArray(&strm->schema->grammarTable.dynArray);
		if(strm->schema->simpleTypeTable.sType != NULL)
			destroyDynArray(&strm->schema->simpleTypeTable.dynArray);
		freeAllocList(&strm->schema->memList);
	}

	freeAllocList(&(strm->memList));
}
END_TEST

/* Verifies a single global element also used as a reference. */
START_TEST (test_acceptance_for_A_01_exip1)
{
	EXIPSchema schema;
	FILE *infile;
	Parser testParser;
	char buf[INPUT_BUFFER_SIZE];
	const char *schemafname = "testStates/acceptance-xsd.exi";
	const char *exifname = "testStates/acceptance_a_01a.exi";
	char exipath[MAX_PATH_LEN + strlen(exifname)];
	struct appData parsingData;
	errorCode tmp_err_code = EXIP_UNEXPECTED_ERROR;
	BinaryBuffer buffer;

	buffer.buf = buf;
	buffer.bufContent = 0;
	buffer.bufLen = INPUT_BUFFER_SIZE;

	// Parsing steps:

	// I.A: First, read in the schema
	parseSchema(schemafname, &schema);

	// I.B: Define an external stream for the input to the parser if any
	size_t pathlen = strlen(dataDir);
	memcpy(exipath, dataDir, pathlen);
	exipath[pathlen] = '/';
	memcpy(&exipath[pathlen+1], exifname, strlen(exifname)+1);
	
	infile = fopen(exipath, "rb" );
	if(!infile)
		fail("Unable to open file %s", exipath);
	
	buffer.ioStrm.readWriteToStream = readFileInputStream;
	buffer.ioStrm.stream = infile;

	// II: Second, initialize the parser object
	tmp_err_code = initParser(&testParser, buffer, &parsingData);
	fail_unless (tmp_err_code == EXIP_OK, "initParser returns an error code %d", tmp_err_code);

	// III: Initialize the parsing data and hook the callback handlers to the parser object
	parsingData.eventCount = 0;
	parsingData.expectAttributeData = 0;
	if (EXIP_OK != initAllocList(&parsingData.allocList))
		fail("Memory allocation error!");

	testParser.handler.fatalError    = sample_fatalError;
	testParser.handler.error         = sample_fatalError;
	testParser.handler.startDocument = sample_startDocument;
	testParser.handler.endDocument   = sample_endDocument;
	testParser.handler.startElement  = sample_startElement;
	testParser.handler.attribute     = sample_attribute;
	testParser.handler.stringData    = sample_stringData;
	testParser.handler.endElement    = sample_endElement;
	testParser.handler.decimalData   = sample_decimalData;
	testParser.handler.intData       = sample_intData;
	testParser.handler.floatData     = sample_floatData;
	
	// IV: Parse the header of the stream
	tmp_err_code = parseHeader(&testParser, FALSE);
	fail_unless (tmp_err_code == EXIP_OK, "parsing the header returns an error code %d", tmp_err_code);

	tmp_err_code = setSchema(&testParser, &schema);
	fail_unless (tmp_err_code == EXIP_OK, "setSchema() returns an error code %d", tmp_err_code);

	// V: Parse the body of the EXI stream
	while(tmp_err_code == EXIP_OK)
	{
		switch (parsingData.eventCount)
		{
			case 0:
				fail_unless(stringEqualToAscii(parsingData.eventCode, "SD"));
				break;
			case 1:
				fail_unless(stringEqualToAscii(parsingData.eventCode, "SE"));
				fail_unless(stringEqualToAscii(parsingData.uri, "urn:foo"));
				fail_unless(stringEqualToAscii(parsingData.localName, "AB"));
				break;
			case 2:
				fail_unless(stringEqualToAscii(parsingData.eventCode, "CH"));
				break;
			case 3:
				fail_unless(stringEqualToAscii(parsingData.eventCode, "EE"));
				break;
			case 4:
				fail_unless(stringEqualToAscii(parsingData.eventCode, "ED"));
				break;
			default:
				// Unexpected event count caught below.
				break;
		}

		tmp_err_code = parseNext(&testParser);
		parsingData.eventCount++;
	}
	
	fail_unless(stringEqualToAscii(parsingData.eventCode, "ED"));

	fail_unless(parsingData.eventCount == 4,
	            "Unexpected event count: %u", parsingData.eventCount);

	// VI: Free the memory allocated by the parser object
	freeAllocList(&parsingData.allocList);
	destroyParser(&testParser);
	fclose(infile);
	fail_unless (tmp_err_code == EXIP_PARSING_COMPLETE, "Error during parsing of the EXI body %d", tmp_err_code);
}