- Three source trees: core/ (shared C++ engine, moved from ios/core), app/ (Android UI), ios/app/ (iOS UI) - Android plays through core/ via JNI (EngineHost, jni_engine.cpp): the Oboe callback renders natively; the Kotlin model is mirrored as project text and applied as a diff, so playback continues through edits - The Kotlin engine moves to the unit tests as ReferenceEngine (golden reference) - Shared MasterRecorder in core/src/host, used by both apps; host_test - versions.properties: one versionName/versionCode for both platforms, continuing Android's numbering (iOS 0.6.0/11 -> 0.37.0/71) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
55 lines
2.4 KiB
C++
55 lines
2.4 KiB
C++
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
// io/Zip: round trips, damage, unsafe names; argv[1]: an archive java.util.zip wrote
|
|
// (with data descriptors, as Android's ZipOutputStream does), holding a.txt = "hello\n"
|
|
// and dir/b.bin; argv[2]: where to write an archive for `unzip -t`.
|
|
|
|
#include "io/Zip.hpp"
|
|
|
|
#include <cstdio>
|
|
#include <fstream>
|
|
#include <iterator>
|
|
|
|
using namespace sizzle::io;
|
|
|
|
static int failures = 0;
|
|
#define CHECK(c) do { if (!(c)) { std::printf("FAIL %s:%d %s\n", __FILE__, __LINE__, #c); ++failures; } } while (0)
|
|
|
|
int main(int argc, char **argv) {
|
|
std::vector<zip::Entry> in = {{"project.szg", std::vector<uint8_t>(5000, 'x')}, {"empty", {}},
|
|
{"samples/0.wav", {}}};
|
|
for (int i = 0; i < 3000; ++i) in[2].data.push_back((uint8_t)(i * 7919 >> 3));
|
|
auto bytes = zip::write(in);
|
|
std::vector<zip::Entry> out;
|
|
CHECK(zip::read(bytes.data(), bytes.size(), out));
|
|
CHECK(out.size() == 3 && out[0].name == "project.szg" && out[0].data == in[0].data && out[1].data.empty() && out[2].data == in[2].data);
|
|
CHECK(bytes.size() < 5000); // deflated
|
|
|
|
auto bad = bytes;
|
|
bad[50] ^= 0xFF; // inside the first entry's data
|
|
CHECK(!zip::read(bad.data(), bad.size(), out) && out.empty());
|
|
CHECK(!zip::read(bytes.data(), bytes.size() - 10, out));
|
|
CHECK(!zip::read(bytes.data(), bytes.size(), out, 1000)); // over the size budget
|
|
CHECK(!zip::read(bytes.data(), bytes.size(), out, 1 << 30, 2));
|
|
|
|
CHECK(zip::safeName("songs/a b.szg") && zip::safeName("x"));
|
|
CHECK(!zip::safeName("../x") && !zip::safeName("a/../../x") && !zip::safeName("/etc/x") && !zip::safeName("a\\b") && !zip::safeName(""));
|
|
|
|
if (argc > 1) {
|
|
std::ifstream f(argv[1], std::ios::binary);
|
|
std::vector<uint8_t> j((std::istreambuf_iterator<char>(f)), {});
|
|
CHECK(zip::read(j.data(), j.size(), out));
|
|
bool a = false, b = false;
|
|
for (auto &e : out) {
|
|
if (e.name == "a.txt") a = std::string(e.data.begin(), e.data.end()) == "hello\n";
|
|
if (e.name == "dir/b.bin") b = e.data.size() == 4096;
|
|
}
|
|
CHECK(a && b);
|
|
}
|
|
if (argc > 2) { std::ofstream o(argv[2], std::ios::binary); o.write((const char *)bytes.data(), (std::streamsize)bytes.size()); }
|
|
|
|
std::printf(failures ? "zip_test: %d failure(s)\n" : "zip_test: ok\n", failures);
|
|
return failures ? 1 : 0;
|
|
}
|