67 lines
2.4 KiB
C++
67 lines
2.4 KiB
C++
// Gitea #15: gamepad/extra action slots 120..359 survive relog via the client-local store.
|
|
#include "../native/extended_action_bars.hpp"
|
|
|
|
#include <cassert>
|
|
#include <cstdio>
|
|
|
|
using namespace gateway;
|
|
namespace eab = gateway::extended_action_bars;
|
|
|
|
static Bytes request(uint64_t packed, uint16_t index) {
|
|
Bytes b;
|
|
le(b, packed, 8);
|
|
le(b, index, 2);
|
|
return b;
|
|
}
|
|
|
|
int main() {
|
|
auto root = std::filesystem::temp_directory_path() / ("gw-eab-test-" + std::to_string(::getpid()));
|
|
std::filesystem::remove_all(root);
|
|
Guid128 guid{};
|
|
guid[0] = 0x2a;
|
|
guid[15] = 0x08;
|
|
auto file = eab::path(7, guid, root);
|
|
assert(!file.empty());
|
|
assert(eab::path(0, guid, root).empty());
|
|
assert(eab::path(7, Guid128{}, root).empty());
|
|
|
|
// Missing file = empty bars.
|
|
for (auto v : eab::load(file)) assert(v == 0);
|
|
|
|
// Source-range slots are not ours; gamepad slot 180 and last slot 359 are stored.
|
|
assert(!eab::store_request(file, request(133, 119)));
|
|
assert(eab::store_request(file, request(133, 180)));
|
|
assert(eab::store_request(file, request(0x80000000000000ULL | 6948, 359)));
|
|
assert(eab::store_request(file, request(0x40000000000000ULL | 3, 200))); // macro
|
|
bool threw = false;
|
|
try { eab::store_request(file, request(1, 360)); } catch (...) { threw = true; }
|
|
assert(!threw); // index 360 is outside, returns false
|
|
assert(!eab::store_request(file, request(1, 360)));
|
|
|
|
// Native login list as forever_action_buttons builds it: 360 x uint64 + uint8 reason.
|
|
Bytes buttons(eab::NativeSlots * 8 + 1, 0);
|
|
buttons[0] = 78; // slot 0 = Heroic Strike (source slot, untouched by merge)
|
|
eab::merge(buttons, eab::load(file));
|
|
auto slot = [&](unsigned i) {
|
|
uint64_t v = 0;
|
|
for (unsigned b = 0; b < 8; ++b) v |= uint64_t(buttons[i * 8 + b]) << (8 * b);
|
|
return v;
|
|
};
|
|
assert(slot(0) == 78);
|
|
assert(slot(180) == 133);
|
|
assert(slot(359) == (0x80000000000000ULL | 6948));
|
|
assert(slot(200) == (0x40000000000000ULL | 3));
|
|
assert(slot(181) == 0);
|
|
|
|
// Clearing a slot persists.
|
|
assert(eab::store_request(file, request(0, 180)));
|
|
assert(eab::load(file)[60] == 0);
|
|
|
|
// Damaged file reads as empty, never throws.
|
|
{ std::ofstream(file, std::ios::binary | std::ios::trunc) << "GWAB\x01"; }
|
|
for (auto v : eab::load(file)) assert(v == 0);
|
|
|
|
std::filesystem::remove_all(root);
|
|
std::puts("extended action bars: ok");
|
|
}
|