iOS 0.6.0: milestone 5 (recording, MIDI, input bindings, themes, bundles, backups)
- Master recording (MasterSink ring + writer thread) and the sample recorder - CoreMIDI in/out: sound module, clock send/follow, virtual "Sizzle" ports; platform-free parser/module/clock in core (midi_test) - Hardware keyboard and gamepads via GameController; rebindable keyboard, gamepad and MIDI CC actions; per-parameter MIDI learn - Colour themes (.szt), project bundles (.szgz), backup & restore; ZIP in core with zlib (zip_test against jar and unzip) - Persistent app settings; audio pauses in the background unless sound module Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
435305e42a
commit
64e21e0bcc
@@ -0,0 +1,54 @@
|
||||
// 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;
|
||||
}
|
||||
Reference in New Issue
Block a user