summaryrefslogtreecommitdiffhomepage
path: root/test/wall-atlas.cpp
blob: b9ba2aec0a6132a5392514dfb9982df928c4d560 (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
#include "test/app.hpp"
#include "src/wall-atlas.hpp"
#include "serialize/wall-atlas.hpp"
#include "serialize/json-helper.hpp"
#include "loader/loader.hpp"
#include <algorithm>
#include <Corrade/Containers/PairStl.h>
#include <Corrade/Utility/Path.h>

namespace floormat {

using nlohmann::json;

namespace {

[[nodiscard]] Pair<wall_atlas_def, json> test_atlas_header(StringView path, StringView filename)
{
    auto j = json_helper::from_json_(Path::join(path, filename));
    wall_atlas_def def;
    test::read_atlas_header(j, def);

    fm_assert(def.info.name == "foo"_s);
    fm_assert(def.info.depth == 42);
    fm_assert(def.dir_count == 2);

    constexpr auto none = (uint8_t)-1;
    enum : uint8_t { N, E, S, W, };

    fm_assert(def.dir_indexes[N] == 0 || def.dir_indexes[N] == 1);
    fm_assert(def.dir_indexes[E] == none);
    fm_assert(def.dir_indexes[S] == none);

    if (def.dir_indexes[N] == 0)
        fm_assert(def.dir_indexes[W] == 1);
    else if (def.dir_indexes[N] == 1)
        fm_assert(def.dir_indexes[W] == 0);
    else
        fm_assert(false);

    return {std::move(def), std::move(j)};
}

} // namespace

void test_app::test_wall_atlas()
{
    fm_assert(Path::exists(Path::join(loader.TEMP_PATH, "CMakeCache.txt")));
    const auto path = Path::join(loader.TEMP_PATH, "test/json"_s);
    fm_assert(Path::isDirectory(path));

    (void)test_atlas_header(path, "frame_direction-header.json"_s);
}



} // namespace floormat