Cannot load image in Google Test

Viewed 24

I'm trying to do unit testing with Google Test for a university project, and I created a test with a tile (I'm making a platform game with a tileMap) and a player to check if the player collides with it. The test passed, but the texture of the tile was not loaded ("Failed to load "../images/wall.png". Reason: unable to open file). I also tried to set the directory of my project as the working directory in Google Test, but nothing changed. It works only if the image is loaded directly in the constructor of the test. How could I fix this? Here is the method I use to load the texture:

bool LevelTile::setupSprite(char tile) {

    std::string textureName;

    switch(tile){

        case '2':
            textureName = "../images/door.png";
            exit = true;
            tileType = DOOR;
            break;
        case '0':
            textureName = "../images/Ground.jpg";
            tileType = GROUND;
            break;
        case '1':
            textureName = "../images/wall.png";
            tileType = WALL;
            break;
        default:
            textureName = "";

    }

    if(!texture.loadFromFile(textureName))
        return false;

    texture.setSmooth(true);
    body.setFillColor(sf:: Color::White);
    body.setTexture(&texture);
    //temporary texture cut for testing
    body.setTextureRect(sf::IntRect(0,0,50,50));
    return true;

0 Answers
Related