Something went wrong. Try again.
[Mirror] Libreopolis is a cross-platform city simulation game fully compatible with SimCity 2000. gitlab.com/conasg/libreopolis
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162// Tests for the .SC2 RLE codec: exact decoder framing (vs the verified spec) + round-trip.#include "sc2k/io/sc2_rle.hpp"#include <cstdio>#include <vector>#include <cstdint>
#include "test_harness.hpp"
int main() { using namespace sc2k::io; using V = std::vector<std::uint8_t>;
// Decoder framing vs the spec: // 0x82,0xAA -> run of 3 x 0xAA ; 0x02,0x01,0x02 -> literal {0x01,0x02} { V enc = {0x82, 0xAA, 0x02, 0x01, 0x02}; V dec = rle_decode(enc, 5); V want = {0xAA, 0xAA, 0xAA, 0x01, 0x02}; CHECK(dec == want); } // Run of 128 (max): 0xFF, b -> 128 copies. { V enc = {0xFF, 0x7E}; V dec = rle_decode(enc, 128); CHECK(dec.size() == 128); bool all = true; for (auto x : dec) all &= (x == 0x7E); CHECK(all); } // Decoder stops at out_size even if more input remains. { V enc = {0x82, 0xAA, 0x82, 0xBB}; V dec = rle_decode(enc, 3); CHECK((dec == V{0xAA, 0xAA, 0xAA})); }
// Round-trip on varied data (runs, literals, mixed, map-sized). auto roundtrip = [&](const V& data) { V enc = rle_encode(data); V dec = rle_decode(enc, data.size()); CHECK(dec == data); }; roundtrip({}); roundtrip({0x05}); roundtrip({1, 2, 3, 4, 5, 6, 7}); roundtrip({9, 9, 9, 9, 9, 9, 9, 9, 9, 9}); roundtrip({1, 1, 2, 3, 3, 3, 4, 5, 5}); { V big; big.reserve(0x4000); // a 128x128 layer's worth for (int i = 0; i < 0x4000; ++i) big.push_back(static_cast<std::uint8_t>((i / 37) % 7 == 0 ? 0 : i)); roundtrip(big); }
if (failures == 0) { std::printf("rle: all tests passed\n"); return 0; } std::printf("rle: %d failure(s)\n", failures); return 1;}