view tests/tools/tileset/main.cpp @ 99:0addfab87b17

Common: implement basic tilesets, closes #664
author David Demelier <markand@malikania.fr>
date Fri, 18 Aug 2017 18:45:07 +0200
parents
children 119bcc5a727e
line wrap: on
line source

/*
 * main.cpp -- test tileset
 *
 * Copyright (c) 2013-2017 Malikania Authors
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <vector>
#include <string>

#define BOOST_TEST_MODULE "mlk-tileset"
#include <boost/test/unit_test.hpp>

#include <malikania/locator.hpp>
#include <malikania/loader.hpp>
#include <malikania/tileset.hpp>

class test_tileset {
protected:
    mlk::directory_locator locator_{CMAKE_CURRENT_BINARY_DIR};
    mlk::loader loader_{locator_};
};

BOOST_FIXTURE_TEST_SUITE(test_tileset_suite, test_tileset)

BOOST_AUTO_TEST_CASE(tileset)
{
    const std::vector<std::string> list{
        "tileset.json",
        "tileset_embedded.json",
        "tileset_external.json"
    };

    for (const auto& t : list) {
        auto tileset = loader_.load_tileset(t);

        BOOST_REQUIRE_EQUAL("worldmapchip5fo.png", tileset.image());
        BOOST_REQUIRE_EQUAL(32U, tileset.cell().width());
        BOOST_REQUIRE_EQUAL(32U, tileset.cell().height());
        BOOST_REQUIRE_EQUAL(3U, tileset.tile_properties().size());

        auto tp = tileset.tile_properties();

        // Index 8.
        BOOST_REQUIRE_EQUAL("value", tp[8]["test"]);

        // TODO: postpone collisions once made.
    }
}

BOOST_AUTO_TEST_SUITE_END()