Extract standalone Playground SDK source foundation
This commit is contained in:
commit
d49c22a06c
3567 changed files with 1657902 additions and 0 deletions
35
tests/core_synthetic.cpp
Normal file
35
tests/core_synthetic.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include "core/pfp.h"
|
||||
#include "core/save_snapshot.h"
|
||||
#include "core/vfs.h"
|
||||
#include "ui/controls.h"
|
||||
#include <cassert>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
int main() {
|
||||
const auto archive = std::filesystem::temp_directory_path() / "playground-sdk-synthetic.pfp";
|
||||
const char bytes[] = {'P','F','P','K', 1,0,0,0, 5,'a','.','t','x','t', 22,0,0,0, 3,0,0,0, 'a','b','c'};
|
||||
{ std::ofstream out(archive, std::ios::binary); out.write(bytes, sizeof(bytes)); }
|
||||
std::string error;
|
||||
auto fs = playground::openPfp(playground::pathToUtf8(archive), &error);
|
||||
assert(fs && error.empty());
|
||||
playground::Bytes content;
|
||||
assert(fs->read("A.TXT", content) && std::string(content.begin(), content.end()) == "abc");
|
||||
std::filesystem::remove(archive);
|
||||
|
||||
auto table = std::make_shared<playground::SaveTable>();
|
||||
table->entries.push_back({"score", 42.0});
|
||||
std::string encoded;
|
||||
assert(playground::encodeSave(table, encoded, &error));
|
||||
playground::SaveValue decoded;
|
||||
assert(playground::decodeSave(encoded, decoded, &error));
|
||||
assert(std::get<playground::SaveValue::Table>(decoded.data)->entries.size() == 1);
|
||||
auto truncated = encoded.substr(0, encoded.size() - 1);
|
||||
assert(!playground::decodeSave(truncated, decoded, &error));
|
||||
|
||||
playground::Rollover button({10, 20, 100, 40});
|
||||
assert(button.down(50, 40));
|
||||
assert(button.up(50, 40));
|
||||
assert(!button.down(200, 40));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue