aboutsummaryrefslogtreecommitdiff
path: root/tests/loadTextures.cpp
blob: 44f38b7d8668cabad4eb66479fee01875a08d5f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (C) 2008-2011 Colin MacDonald
// No rights reserved: this software is in the public domain.

#include "testUtils.h"

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

/** This tests verifies that textures opened from different places in the
	filesystem don't create duplicated textures. */
bool loadFromFileFolder(void)
{
	IrrlichtDevice *device =
		createDevice( video::EDT_NULL, dimension2du(160, 120));

	if (!device)
	{
		logTestString("Unable to create EDT_NULL device\n");
		return false;
	}

	IVideoDriver * driver = device->getVideoDriver();

	u32 numTexs = driver->getTextureCount();

	ITexture * tex1 = driver->getTexture("../media/tools.png");
	assert(tex1);
	if(!tex1)
		logTestString("Unable to open ../media/tools.png\n");
	if (driver->getTextureCount()!=numTexs+1)
	{
		logTestString("No additional texture in the texture cache %s:%d\n", __FILE__, __LINE__);
		return false;
	}

	IReadFile * readFile = device->getFileSystem()->createAndOpenFile("../media/tools.png");
	assert(readFile);
	if(!readFile)
		logTestString("Unable to open ../media/tools.png\n");
	if (driver->getTextureCount()!=numTexs+1)
	{
		logTestString("Additional texture in the texture cache %s:%d\n", __FILE__, __LINE__);
		return false;
	}

	ITexture * tex2 = driver->getTexture(readFile);
	assert(tex2);
	if(!readFile)
		logTestString("Unable to create texture from ../media/tools.png\n");
	if (driver->getTextureCount()!=numTexs+1)
	{
		logTestString("Additional texture in the texture cache %s:%d\n", __FILE__, __LINE__);
		return false;
	}

	readFile->drop();

	// adding  a folder archive
	device->getFileSystem()->addFileArchive( "../media/" );

	ITexture * tex3 = driver->getTexture("tools.png");
	assert(tex3);
	if(!tex3)
		logTestString("Unable to open tools.png\n");
	if (driver->getTextureCount()!=numTexs+1)
	{
		logTestString("Additional texture in the texture cache %s:%d\n", __FILE__, __LINE__);
		return false;
	}

	ITexture * tex4 = driver->getTexture("tools.png");
	assert(tex4);
	if(!tex4)
		logTestString("Unable to open tools.png\n");
	if (driver->getTextureCount()!=numTexs+1)
	{
		logTestString("Additional texture in the texture cache %s:%d\n", __FILE__, __LINE__);
		return false;
	}

	device->closeDevice();
	device->run();
	device->drop();
	return ((tex1 == tex2) && (tex1 == tex3) && (tex1 == tex4));
}

bool loadTextures()
{
	bool result = true;
	result &= loadFromFileFolder();
	return result;
}