File: test_zip.cpp

package info (click to toggle)
libtcod 1.24.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,728 kB
  • sloc: ansic: 46,186; cpp: 13,523; python: 4,814; makefile: 44; sh: 25
file content (39 lines) | stat: -rw-r--r-- 1,213 bytes parent folder | download | duplicates (2)
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
#ifndef TCOD_NO_ZLIB
#include <catch2/catch_all.hpp>
#include <filesystem>
#include <libtcod/zip.hpp>

TEST_CASE("TCODZip") {
  const auto temp_dir = std::filesystem::temp_directory_path();
  const auto zip_path = temp_dir / "saved.sav";
  {
    auto zip = TCODZip{};
    zip.put('c');
    zip.put(42);
    zip.put("Test");
    zip.put(std::optional<std::string>{});
    zip.put(tcod::ColorRGB{1, 2, 3});
    zip.put(TCODColor{4, 5, 6});
    zip.put(TCODImage{3, 2});
    zip.put(TCODRandom{42});
    zip.put(TCODConsole{3, 2});
    zip.put(tcod::Console{3, 2});

    zip.saveToFile(zip_path);
  }
  {
    auto zip = TCODZip{};
    zip.loadFromFile(zip_path);
    REQUIRE(zip.get<char>() == 'c');
    REQUIRE(zip.get<int>() == 42);
    REQUIRE(zip.get<std::string>() == "Test");
    REQUIRE_FALSE(zip.get<std::optional<std::string>>());
    REQUIRE(zip.get<tcod::ColorRGB>() == tcod::ColorRGB{1, 2, 3});
    REQUIRE(tcod::ColorRGB{zip.get<TCODColor>()} == tcod::ColorRGB{4, 5, 6});
    REQUIRE(zip.get<TCODImage>().getSize() == std::array{3, 2});
    zip.get<TCODRandom>();
    REQUIRE(zip.get<tcod::Console>().get_width() == 3);
    REQUIRE(zip.get<TCODConsole>().getWidth() == 3);
  }
}
#endif  // TCOD_NO_ZLIB