Ejemplo n.º 1
0
static void testAddResource() {
	ResourceManager * resourceManager;
	void * resource;
	
	loadResourceCalls = 0;
	unloadResourceCalls = 0;
	
	resourceManager = ResourceManager_create();
	TestCase_assert(resourceManager != NULL, "Expected non-NULL but got NULL");
	if (resourceManager == NULL) { return; } // Suppress clang warning
	
	resourceNameToLoad = "bar";
	resourceToLoad = "foo";
	resourceManager->addResource(resourceManager, "type", resourceNameToLoad, resourceToLoad);
	resource = resourceManager->referenceResource(resourceManager, "type", "resource");
	TestCase_assert(resource == NULL, "Expected NULL but got %p", resource);
	
	loadContext = NULL;
	resourceManager->addTypeHandler(resourceManager, "type", loadResource, unloadResource, loadContext);
	resourceManager->addResource(resourceManager, "type", resourceNameToLoad, resourceToLoad);
	resource = resourceManager->referenceResource(resourceManager, "type", resourceNameToLoad);
	TestCase_assert(resource == resourceToLoad, "Expected %p but got %p", resourceToLoad, resource);
	TestCase_assert(loadResourceCalls == 0, "Expected 0 but got %u", loadResourceCalls);
	
	resourceManager->releaseResource(resourceManager, "type", resourceNameToLoad);
	TestCase_assert(unloadResourceCalls == 0, "Expected 0 but got %u", unloadResourceCalls);
	
	resourceManager->releaseResource(resourceManager, "type", resourceNameToLoad);
	TestCase_assert(unloadResourceCalls == 1, "Expected 1 but got %u", unloadResourceCalls);
	
	resourceManager->dispose(resourceManager);
}
Ejemplo n.º 2
0
static void testOptionalityOfCallbacks() {
	ResourceManager * resourceManager;
	void * resource;
	
	resourceManager = ResourceManager_create();
	TestCase_assert(resourceManager != NULL, "Expected non-NULL but got NULL");
	if (resourceManager == NULL) { return; } // Suppress clang warning
	
	loadContext = NULL;
	loadResourceCalls = 0;
	unloadResourceCalls = 0;
	resourceManager->addTypeHandler(resourceManager, "load only", loadResource, NULL, NULL);
	resourceManager->addTypeHandler(resourceManager, "unload only", NULL, unloadResource, NULL);
	
	resource = resourceManager->referenceResource(resourceManager, "unload only", "foo");
	TestCase_assert(resource == NULL, "Expected NULL but got %p", resource);
	TestCase_assert(loadResourceCalls == 0, "Expected 0 but got %u", loadResourceCalls);
	
	resourceManager->addResource(resourceManager, "load only", "foo", "bar");
	resourceManager->releaseResource(resourceManager, "load only", "foo");
	TestCase_assert(unloadResourceCalls == 0, "Expected 0 but got %u", unloadResourceCalls);
	
	resourceManager->dispose(resourceManager);
}