Esempio n. 1
0
void destroyProtoGrammar(ProtoGrammar* pg)
{
	Index i;
	for (i = 0; i < pg->count; i++)
	{
		destroyDynArray(&pg->rule[i].dynArray);
	}
	destroyDynArray(&pg->dynArray);
}
Esempio n. 2
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);
}
Esempio n. 3
0
END_TEST

START_TEST (test_addLnEntry)
{
	errorCode err = EXIP_UNEXPECTED_ERROR;
	LnTable lnTable;
	Index entryId = 55;
	String test_ln = {"test_ln_string", 14};

	err = createDynArray(&lnTable.dynArray, sizeof(LnEntry), DEFAULT_LN_ENTRIES_NUMBER);
	fail_if(err != EXIP_OK);

	err = addLnEntry(&lnTable, test_ln, &entryId);

	fail_unless (err == EXIP_OK, "addLnEntry returns error code %d", err);
	fail_unless (lnTable.dynArray.arrayEntries == DEFAULT_LN_ENTRIES_NUMBER,
				"addLnEntry changed the dynArray.arrayEntries unnecessary");
	fail_unless (lnTable.count == 1,
					"addLnEntry did not update rowCount properly");
	fail_unless (stringEqual(lnTable.ln[0].lnStr, test_ln) == 1,
						"addLnEntry changed the lnStr");
	fail_unless (entryId == 0,
				"addLnEntry returned wrong entryId: %d", entryId);

#if VALUE_CROSSTABLE_USE
	fail_if(lnTable.ln[0].vxTable != NULL);
#endif

	lnTable.count = DEFAULT_LN_ENTRIES_NUMBER;

	err = addLnEntry(&lnTable, test_ln, &entryId);

	fail_unless (err == EXIP_OK, "addLnEntry returns error code %d", err);
	fail_unless (lnTable.dynArray.arrayEntries == DEFAULT_LN_ENTRIES_NUMBER*2,
				"addLnEntry did not update the dynArray.arrayEntries properly");
	fail_unless (lnTable.count == DEFAULT_LN_ENTRIES_NUMBER + 1,
					"addLnEntry did not update count properly");
	fail_unless (stringEqual(lnTable.ln[DEFAULT_LN_ENTRIES_NUMBER].lnStr, test_ln) == 1,
						"addLnEntry changed the lnStr");
	fail_unless (entryId == DEFAULT_LN_ENTRIES_NUMBER,
				"addLnEntry returned wrong entryId: %d", entryId);
#if VALUE_CROSSTABLE_USE
	fail_if(lnTable.ln[DEFAULT_LN_ENTRIES_NUMBER].vxTable != NULL);
#endif
	destroyDynArray(&lnTable.dynArray);
}
Esempio n. 4
0
END_TEST

START_TEST (test_addUriEntry)
{
	errorCode err = EXIP_UNEXPECTED_ERROR;
	UriTable uriTable;
	SmallIndex entryId = 55;
	String test_uri = {"test_uri_string", 15};

	// Create the URI table
	err = createDynArray(&uriTable.dynArray, sizeof(UriEntry), DEFAULT_URI_ENTRIES_NUMBER);
	fail_if(err != EXIP_OK);

	err = addUriEntry(&uriTable, test_uri, &entryId);

	fail_unless (err == EXIP_OK, "addUriEntry returns error code %d", err);
	fail_unless (uriTable.dynArray.arrayEntries == DEFAULT_URI_ENTRIES_NUMBER,
				"addUriEntry changed the dynArray.arrayEntries unnecessary");
	fail_unless (uriTable.count == 1,
					"addUriEntry did not update count properly");
	fail_unless (stringEqual(uriTable.uri[0].uriStr, test_uri) == 1,
						"addUriEntry changed the uriStr");
	fail_unless (entryId == 0,
				"addUriEntry returned wrong entryId: %d", entryId);

	fail_if(uriTable.uri[0].lnTable.ln == NULL);

	uriTable.count = DEFAULT_URI_ENTRIES_NUMBER;

	err = addUriEntry(&uriTable, test_uri, &entryId);

	fail_unless (err == EXIP_OK, "addUriEntry returns error code %d", err);
	fail_unless (uriTable.dynArray.arrayEntries == DEFAULT_URI_ENTRIES_NUMBER*2,
				"addUriEntry did not update the dynArray.arrayEntries properly");
	fail_unless (uriTable.count == DEFAULT_URI_ENTRIES_NUMBER + 1,
					"addUriEntry did not update rowCount properly");
	fail_unless (stringEqual(uriTable.uri[DEFAULT_URI_ENTRIES_NUMBER].uriStr, test_uri) == 1,
						"addUriEntry changed the uriStr");
	fail_unless (entryId == DEFAULT_URI_ENTRIES_NUMBER,
				"addUriEntry returned wrong entryId: %d", entryId);

	fail_if(uriTable.uri[DEFAULT_URI_ENTRIES_NUMBER].lnTable.ln == NULL);

	destroyDynArray(&uriTable.dynArray);
}
Esempio n. 5
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));
}