~baltix/+junk/irrlicht-test

« back to all changes in this revision

Viewing changes to tests/disambiguateTextures.cpp

  • Committer: Mantas Kriaučiūnas
  • Date: 2011-07-18 13:06:25 UTC
  • Revision ID: mantas@akl.lt-20110718130625-c5pvifp61e7kj1ol
Included whole irrlicht SVN libraries to work around launchpad recipe issue with quilt, see https://answers.launchpad.net/launchpad/+question/165193

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2008-2011 Colin MacDonald
 
2
// No rights reserved: this software is in the public domain.
 
3
 
 
4
#include "testUtils.h"
 
5
 
 
6
using namespace irr;
 
7
using namespace core;
 
8
using namespace scene;
 
9
using namespace video;
 
10
using namespace io;
 
11
using namespace gui;
 
12
 
 
13
/** This tests verifies that textures opened from different places in the filesystem
 
14
        can be distinguished, even if they have the same filename. */
 
15
bool disambiguateTextures(void)
 
16
{
 
17
        IrrlichtDevice *device =
 
18
                createDevice( video::EDT_NULL, dimension2d<u32>(640, 480));
 
19
 
 
20
        if (!device)
 
21
        {
 
22
                logTestString("Unable to create EDT_NULL device\n");
 
23
                return false;
 
24
        }
 
25
 
 
26
        // Expects an empty tmp/tmp directory under this app's wd and
 
27
        // a media directory under this apps' directory with tools.png in it.
 
28
        stringc wd = device->getFileSystem()->getWorkingDirectory();
 
29
 
 
30
        if(-1 == wd.find("/tests") && -1 == wd.find("\\tests"))
 
31
        {
 
32
                logTestString("The tests must be run from the /tests directory, regardless of where\n"\
 
33
                        "the test executable was built.\n");
 
34
                device->drop();
 
35
                return false;
 
36
        }
 
37
 
 
38
        IVideoDriver * driver = device->getVideoDriver();
 
39
 
 
40
        ITexture * tex1 = driver->getTexture("../media/tools.png");
 
41
        assert(tex1);
 
42
        if(!tex1)
 
43
                logTestString("Unable to open ../media/tools.png\n");
 
44
 
 
45
        ITexture * tex2 = driver->getTexture("../media/tools.png");
 
46
        assert(tex2);
 
47
        if(!tex2)
 
48
                logTestString("Unable to open ../media/tools.png\n");
 
49
 
 
50
        IReadFile * readFile = device->getFileSystem()->createAndOpenFile("../media/tools.png");
 
51
        assert(readFile);
 
52
        if(!readFile)
 
53
                logTestString("Unable to open ../media/tools.png\n");
 
54
 
 
55
        ITexture * tex3 = driver->getTexture(readFile);
 
56
        assert(tex3);
 
57
        if(!readFile)
 
58
                logTestString("Unable to create texture from ../media/tools.png\n");
 
59
 
 
60
        readFile->drop();
 
61
 
 
62
        // All 3 of the above textures should be identical.
 
63
        assert(tex1 == tex2);
 
64
        assert(tex1 == tex3);
 
65
 
 
66
        stringc newWd = wd + "/empty/empty";
 
67
        bool changed = device->getFileSystem()->changeWorkingDirectoryTo(newWd.c_str());
 
68
        assert(changed);
 
69
        ITexture * tex4 = driver->getTexture("../../media/tools.png");
 
70
        assert(tex4);
 
71
        if(!tex4)
 
72
                logTestString("Unable to open ../../media/tools.png\n");
 
73
        assert(tex1 != tex4);
 
74
 
 
75
        // The working directory must be restored for the other tests to work.
 
76
        changed &= device->getFileSystem()->changeWorkingDirectoryTo(wd.c_str());
 
77
 
 
78
        device->closeDevice();
 
79
        device->run();
 
80
        device->drop();
 
81
 
 
82
        return (changed && tex1 == tex2 && tex1 == tex3 && tex1 != tex4) ? true : false;
 
83
}
 
84