int uriTestMemoryManager()

in cpp/src/arrow/vendored/uriparser/UriMemory.c [288:457]


int uriTestMemoryManager(UriMemoryManager * memory) {
	const size_t mallocSize = 7;
	const size_t callocNmemb = 3;
	const size_t callocSize = 5;
	const size_t callocTotalSize = callocNmemb * callocSize;
	const size_t reallocSize = 11;
	const size_t reallocarrayNmemb = 5;
	const size_t reallocarraySize = 7;
	const size_t reallocarrayTotal = reallocarrayNmemb * reallocarraySize;
	size_t index;
	char * buffer;

	if (memory == NULL) {
		return URI_ERROR_NULL;
	}

	if (uriMemoryManagerIsComplete(memory) != URI_TRUE) {
		return URI_ERROR_MEMORY_MANAGER_INCOMPLETE;
	}

	/* malloc + free*/
	buffer = memory->malloc(memory, mallocSize);
	if (buffer == NULL) {
		return URI_ERROR_MEMORY_MANAGER_FAULTY;
	}
	buffer[mallocSize - 1] = '\xF1';
	memory->free(memory, buffer);
	buffer = NULL;

	/* calloc + free */
	buffer = memory->calloc(memory, callocNmemb, callocSize);
	if (buffer == NULL) {
		return URI_ERROR_MEMORY_MANAGER_FAULTY;
	}
	for (index = 0; index < callocTotalSize; index++) {  /* all zeros? */
		if (buffer[index] != '\0') {
			return URI_ERROR_MEMORY_MANAGER_FAULTY;
		}
	}
	buffer[callocTotalSize - 1] = '\xF2';
	memory->free(memory, buffer);
	buffer = NULL;

	/* malloc + realloc + free */
	buffer = memory->malloc(memory, mallocSize);
	if (buffer == NULL) {
		return URI_ERROR_MEMORY_MANAGER_FAULTY;
	}
	for (index = 0; index < mallocSize; index++) {
		buffer[index] = '\xF3';
	}
	buffer = memory->realloc(memory, buffer, reallocSize);
	if (buffer == NULL) {
		return URI_ERROR_MEMORY_MANAGER_FAULTY;
	}
	for (index = 0; index < mallocSize; index++) {  /* previous content? */
		if (buffer[index] != '\xF3') {
			return URI_ERROR_MEMORY_MANAGER_FAULTY;
		}
	}
	buffer[reallocSize - 1] = '\xF4';
	memory->free(memory, buffer);
	buffer = NULL;

	/* malloc + realloc ptr!=NULL size==0 (equals free) */
	buffer = memory->malloc(memory, mallocSize);
	if (buffer == NULL) {
		return URI_ERROR_MEMORY_MANAGER_FAULTY;
	}
	buffer[mallocSize - 1] = '\xF5';
	memory->realloc(memory, buffer, 0);
	buffer = NULL;

	/* realloc ptr==NULL size!=0 (equals malloc) + free */
	buffer = memory->realloc(memory, NULL, mallocSize);
	if (buffer == NULL) {
		return URI_ERROR_MEMORY_MANAGER_FAULTY;
	}
	buffer[mallocSize - 1] = '\xF6';
	memory->free(memory, buffer);
	buffer = NULL;

	/* realloc ptr==NULL size==0 (equals malloc) + free */
	buffer = memory->realloc(memory, NULL, 0);
	if (buffer != NULL) {
		memory->free(memory, buffer);
		buffer = NULL;
	}

	/* malloc + reallocarray + free */
	buffer = memory->malloc(memory, mallocSize);
	if (buffer == NULL) {
		return URI_ERROR_MEMORY_MANAGER_FAULTY;
	}
	for (index = 0; index < mallocSize; index++) {
		buffer[index] = '\xF7';
	}
	buffer = memory->reallocarray(memory, buffer, reallocarrayNmemb,
			reallocarraySize);
	if (buffer == NULL) {
		return URI_ERROR_MEMORY_MANAGER_FAULTY;
	}
	for (index = 0; index < mallocSize; index++) {  /* previous content? */
		if (buffer[index] != '\xF7') {
			return URI_ERROR_MEMORY_MANAGER_FAULTY;
		}
	}
	buffer[reallocarrayTotal - 1] = '\xF8';
	memory->free(memory, buffer);
	buffer = NULL;

	/* malloc + reallocarray ptr!=NULL nmemb==0 size!=0 (equals free) */
	buffer = memory->malloc(memory, mallocSize);
	if (buffer == NULL) {
		return URI_ERROR_MEMORY_MANAGER_FAULTY;
	}
	buffer[mallocSize - 1] = '\xF9';
	memory->reallocarray(memory, buffer, 0, reallocarraySize);
	buffer = NULL;

	/* malloc + reallocarray ptr!=NULL nmemb!=0 size==0 (equals free) */
	buffer = memory->malloc(memory, mallocSize);
	if (buffer == NULL) {
		return URI_ERROR_MEMORY_MANAGER_FAULTY;
	}
	buffer[mallocSize - 1] = '\xFA';
	memory->reallocarray(memory, buffer, reallocarrayNmemb, 0);
	buffer = NULL;

	/* malloc + reallocarray ptr!=NULL nmemb==0 size==0 (equals free) */
	buffer = memory->malloc(memory, mallocSize);
	if (buffer == NULL) {
		return URI_ERROR_MEMORY_MANAGER_FAULTY;
	}
	buffer[mallocSize - 1] = '\xFB';
	memory->reallocarray(memory, buffer, 0, 0);
	buffer = NULL;

	/* reallocarray ptr==NULL nmemb!=0 size!=0 (equals malloc) + free */
	buffer = memory->reallocarray(memory, NULL, callocNmemb, callocSize);
	if (buffer == NULL) {
		return URI_ERROR_MEMORY_MANAGER_FAULTY;
	}
	buffer[callocTotalSize - 1] = '\xFC';
	memory->free(memory, buffer);
	buffer = NULL;

	/* reallocarray ptr==NULL nmemb==0 size!=0 (equals malloc) + free */
	buffer = memory->reallocarray(memory, NULL, 0, callocSize);
	if (buffer != NULL) {
		memory->free(memory, buffer);
		buffer = NULL;
	}

	/* reallocarray ptr==NULL nmemb!=0 size==0 (equals malloc) + free */
	buffer = memory->reallocarray(memory, NULL, callocNmemb, 0);
	if (buffer != NULL) {
		memory->free(memory, buffer);
		buffer = NULL;
	}

	/* reallocarray ptr==NULL nmemb==0 size==0 (equals malloc) + free */
	buffer = memory->reallocarray(memory, NULL, 0, 0);
	if (buffer != NULL) {
		memory->free(memory, buffer);
		buffer = NULL;
	}

	return URI_SUCCESS;
}