zig build upgrade to 0.17 and removed a lot of ai generated tests
This commit is contained in:
parent
d86f81ce2c
commit
22dc0fb3eb
|
|
@ -1,6 +1,6 @@
|
|||
# Uhdk
|
||||
|
||||
A small desktop platform library written in Zig 0.16.0 with a C99 ABI.
|
||||
A small desktop platform library written in Zig 0.17.0 with a C99 ABI.
|
||||
It provides windows, input and IME, clipboard, file dialogs, drag and drop, menus, tray icons,
|
||||
async file operations, file watching, and OpenGL context creation. The macOS
|
||||
backend uses AppKit, OpenGL, and FSEvents through a private Objective-C bridge.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
.name = .uhdk,
|
||||
.fingerprint = 0xe0900359a69bf43d,
|
||||
.version = "0.1.0",
|
||||
.minimum_zig_version = "0.16.0",
|
||||
.minimum_zig_version = "0.17.0",
|
||||
.dependencies = .{},
|
||||
.paths = .{ "build.zig", "build.zig.zon", "src", "include", "README.md", "shell.nix" },
|
||||
}
|
||||
|
|
|
|||
126
src/Cycles.zig
126
src/Cycles.zig
|
|
@ -143,37 +143,6 @@ test "drag and capture share a cycle and late releases cannot revive it" {
|
|||
try std.testing.expect(event.cycle_id != drag);
|
||||
}
|
||||
|
||||
test "confinement keeps a pointer cycle alive across button releases" {
|
||||
var state: Cycles = .{};
|
||||
var next: u64 = 1;
|
||||
var event = std.mem.zeroes(c.z_event);
|
||||
event.type = c.UHDK_EVENT_POINTER_MODE_CHANGED;
|
||||
event.data.pointer_mode = c.UHDK_POINTER_CONFINED;
|
||||
_ = try state.apply(&next, &event);
|
||||
const cycle = event.cycle_id;
|
||||
try std.testing.expect(cycle != 0);
|
||||
|
||||
event.type = c.UHDK_EVENT_POINTER_BUTTON;
|
||||
event.data.pointer = std.mem.zeroes(c.uhdk_pointer_event);
|
||||
event.data.pointer.button = c.UHDK_BUTTON_PRIMARY;
|
||||
event.data.pointer.pressed = 1;
|
||||
_ = try state.apply(&next, &event);
|
||||
event.data.pointer.pressed = 0;
|
||||
try std.testing.expectEqual(@as(usize, 0), (try state.apply(&next, &event)).len);
|
||||
try std.testing.expectEqual(cycle, event.cycle_id);
|
||||
|
||||
event.type = c.UHDK_EVENT_POINTER_MODE_CHANGED;
|
||||
event.data.pointer_mode = c.UHDK_POINTER_NORMAL;
|
||||
event.cycle_end_reason = c.UHDK_CYCLE_CAPTURE_LOST;
|
||||
const ended = try state.apply(&next, &event);
|
||||
try std.testing.expectEqual(@as(usize, 1), ended.len);
|
||||
try std.testing.expectEqual(cycle, ended.ids[0]);
|
||||
try std.testing.expectEqual(@as(c.uhdk_cycle_end_reason, c.UHDK_CYCLE_CAPTURE_LOST), ended.reasons[0]);
|
||||
event.type = c.UHDK_EVENT_POINTER_MOVE;
|
||||
_ = try state.apply(&next, &event);
|
||||
try std.testing.expectEqual(@as(u64, 0), event.cycle_id);
|
||||
}
|
||||
|
||||
test "independent windows and kinds get distinct cycles and focus loss ends all" {
|
||||
var state: Cycles = .{};
|
||||
var other: Cycles = .{};
|
||||
|
|
@ -217,98 +186,3 @@ test "independent windows and kinds get distinct cycles and focus loss ends all"
|
|||
_ = try state.apply(&next, &event);
|
||||
try std.testing.expectEqual(@as(u64, 0), event.cycle_id);
|
||||
}
|
||||
|
||||
test "interleaved gestures finish independently and a chord ends on its last release" {
|
||||
var state: Cycles = .{};
|
||||
var next: u64 = 1;
|
||||
var event = std.mem.zeroes(c.z_event);
|
||||
event.type = c.UHDK_EVENT_POINTER_BUTTON;
|
||||
event.data.pointer.button = c.UHDK_BUTTON_PRIMARY;
|
||||
event.data.pointer.pressed = 1;
|
||||
_ = try state.apply(&next, &event);
|
||||
|
||||
const pointer = event.cycle_id;
|
||||
event.data.pointer.button = c.UHDK_BUTTON_SECONDARY;
|
||||
_ = try state.apply(&next, &event);
|
||||
try std.testing.expectEqual(pointer, event.cycle_id);
|
||||
event.type = c.UHDK_EVENT_SCROLL;
|
||||
event.data.scroll.phase = c.UHDK_SCROLL_BEGIN;
|
||||
_ = try state.apply(&next, &event);
|
||||
|
||||
const scroll = event.cycle_id;
|
||||
event.type = c.UHDK_EVENT_TEXT_PREEDIT;
|
||||
_ = try state.apply(&next, &event);
|
||||
|
||||
const composition = event.cycle_id;
|
||||
event.type = c.UHDK_EVENT_SCROLL;
|
||||
event.data.scroll.phase = c.UHDK_SCROLL_END;
|
||||
|
||||
const scroll_end = try state.apply(&next, &event);
|
||||
try std.testing.expectEqual(scroll, event.cycle_id);
|
||||
try std.testing.expectEqual(scroll, scroll_end.ids[0]);
|
||||
event.type = c.UHDK_EVENT_TEXT_COMPOSITION_END;
|
||||
|
||||
const ime_end = try state.apply(&next, &event);
|
||||
try std.testing.expectEqual(composition, event.cycle_id);
|
||||
try std.testing.expectEqual(composition, ime_end.ids[0]);
|
||||
event.type = c.UHDK_EVENT_POINTER_BUTTON;
|
||||
event.data.pointer = std.mem.zeroes(c.uhdk_pointer_event);
|
||||
event.data.pointer.button = c.UHDK_BUTTON_PRIMARY;
|
||||
try std.testing.expectEqual(@as(usize, 0), (try state.apply(&next, &event)).len);
|
||||
try std.testing.expectEqual(pointer, event.cycle_id);
|
||||
event.data.pointer.button = c.UHDK_BUTTON_SECONDARY;
|
||||
|
||||
const pointer_end = try state.apply(&next, &event);
|
||||
try std.testing.expectEqual(pointer, pointer_end.ids[0]);
|
||||
try std.testing.expectEqual(@as(usize, 0), state.endAll(c.UHDK_CYCLE_SHUTDOWN).len);
|
||||
}
|
||||
|
||||
test "cycle reasons distinguish release loss cancellation replacement and shutdown" {
|
||||
var state: Cycles = .{};
|
||||
var next: u64 = 1;
|
||||
var event = std.mem.zeroes(c.z_event);
|
||||
for ([_]c.uhdk_cycle_end_reason{ c.UHDK_CYCLE_CAPTURE_RELEASED, c.UHDK_CYCLE_CAPTURE_LOST, c.UHDK_CYCLE_FOCUS_LOST }) |reason| {
|
||||
event.type = c.UHDK_EVENT_POINTER_MODE_CHANGED;
|
||||
event.data.pointer_mode = c.UHDK_POINTER_CAPTURE;
|
||||
_ = try state.apply(&next, &event);
|
||||
event.data.pointer_mode = c.UHDK_POINTER_NORMAL;
|
||||
event.cycle_end_reason = reason;
|
||||
|
||||
const ended = try state.apply(&next, &event);
|
||||
try std.testing.expectEqual(@as(usize, 1), ended.len);
|
||||
try std.testing.expectEqual(reason, ended.reasons[0]);
|
||||
}
|
||||
|
||||
event.type = c.UHDK_EVENT_SCROLL;
|
||||
event.data.scroll.phase = c.UHDK_SCROLL_BEGIN;
|
||||
_ = try state.apply(&next, &event);
|
||||
|
||||
const superseded = try state.apply(&next, &event);
|
||||
try std.testing.expectEqual(@as(u32, c.UHDK_CYCLE_SUPERSEDED), superseded.reasons[0]);
|
||||
event.data.scroll.phase = c.UHDK_SCROLL_CANCEL;
|
||||
try std.testing.expectEqual(@as(u32, c.UHDK_CYCLE_CANCELLED), (try state.apply(&next, &event)).reasons[0]);
|
||||
for ([_]bool{ false, true }) |commit| {
|
||||
event.type = c.UHDK_EVENT_TEXT_PREEDIT;
|
||||
_ = try state.apply(&next, &event);
|
||||
if (commit) {
|
||||
event.type = c.UHDK_EVENT_TEXT_COMMIT;
|
||||
_ = try state.apply(&next, &event);
|
||||
}
|
||||
|
||||
event.type = c.UHDK_EVENT_TEXT_COMPOSITION_END;
|
||||
try std.testing.expectEqual(@as(u32, if (commit) c.UHDK_CYCLE_COMPLETED else c.UHDK_CYCLE_CANCELLED), (try state.apply(&next, &event)).reasons[0]);
|
||||
}
|
||||
|
||||
for ([_]bool{ false, true }) |hidden| {
|
||||
event.type = c.UHDK_EVENT_TEXT_PREEDIT;
|
||||
_ = try state.apply(&next, &event);
|
||||
event.type = c.UHDK_EVENT_WINDOW_METRICS;
|
||||
event.data.metrics = std.mem.zeroes(c.uhdk_window_metrics);
|
||||
event.data.metrics.visible = @intFromBool(!hidden);
|
||||
try std.testing.expectEqual(@as(u32, if (hidden) c.UHDK_CYCLE_HIDDEN else c.UHDK_CYCLE_FOCUS_LOST), (try state.apply(&next, &event)).reasons[0]);
|
||||
}
|
||||
|
||||
event.type = c.UHDK_EVENT_TEXT_PREEDIT;
|
||||
_ = try state.apply(&next, &event);
|
||||
try std.testing.expectEqual(@as(u32, c.UHDK_CYCLE_SHUTDOWN), state.endAll(c.UHDK_CYCLE_SHUTDOWN).reasons[0]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -288,87 +288,28 @@ pub fn PagedVectorAdvanced(comptime T: type, comptime growth: usize) type {
|
|||
};
|
||||
}
|
||||
|
||||
test "simple loading multiple pages." {
|
||||
const TestStruct = struct {
|
||||
lmao: usize,
|
||||
};
|
||||
test "paged storage preserves values and pointers across growth, removal and reset" {
|
||||
const gpa = std.testing.allocator;
|
||||
var vector = try PagedVectorAdvanced(u32, 4).init(gpa);
|
||||
defer vector.deinit(gpa);
|
||||
|
||||
const allocator = std.testing.allocator;
|
||||
var vector = try PagedVectorAdvanced(TestStruct, 1024).init(std.testing.allocator);
|
||||
defer vector.deinit(allocator);
|
||||
try vector.append(gpa, 0);
|
||||
const first = vector.get(0);
|
||||
for (1..13) |i| try vector.append(gpa, @intCast(i));
|
||||
try std.testing.expect(first == vector.get(0));
|
||||
for (0..13) |i| try std.testing.expectEqual(@as(u32, @intCast(i)), vector.get(i).*);
|
||||
|
||||
for (0..128) |j| {
|
||||
try vector.append(allocator, .{ .lmao = j });
|
||||
}
|
||||
|
||||
const ptr = vector.get(0);
|
||||
const mutable = vector.getMutable(127);
|
||||
|
||||
for (0..4096) |i| {
|
||||
try vector.append(allocator, .{ .lmao = i });
|
||||
}
|
||||
|
||||
// testing that pointers are not invalidated
|
||||
std.debug.assert(ptr == vector.get(0));
|
||||
std.debug.assert(mutable == vector.getMutable(127));
|
||||
|
||||
std.debug.assert(vector.getMutable(4092) == vector.getMutable(4092));
|
||||
|
||||
// 4096 + 128 = 4224 = 4 pages + 128 extra entries
|
||||
std.debug.assert(vector.pages.items.len == 5);
|
||||
std.debug.assert(vector.capacity() == 1024 * 5);
|
||||
std.debug.assert(vector.len() == 128 + 1024 * 4);
|
||||
|
||||
// 4092 - 3072 = offset of 1020 in the third page.
|
||||
const ptr4092 = vector.getMutable(4092);
|
||||
std.debug.assert(vector.getMutable(4092) == &vector.pages.items[3].data[1020]);
|
||||
|
||||
// lets try adding 1024 elements and see if pointers are still preserved.
|
||||
for (0..1024) |_| {
|
||||
try vector.append(allocator, .{ .lmao = 0 });
|
||||
}
|
||||
|
||||
std.debug.assert(vector.getMutable(4092) == ptr4092);
|
||||
std.debug.assert(vector.get(0).lmao == 0);
|
||||
std.debug.assert(vector.get(1).lmao == 1);
|
||||
std.debug.assert(vector.get(2).lmao == 2);
|
||||
|
||||
// testing the pop() function
|
||||
std.debug.assert(vector.len() == 128 + 1024 * 5);
|
||||
_ = try vector.pop();
|
||||
_ = try vector.pop();
|
||||
_ = try vector.pop();
|
||||
|
||||
// testing the swapRemove Functionality
|
||||
std.debug.assert(vector.len() == 128 + 1024 * 5 - 3);
|
||||
// Remove across a page boundary, checking values rather than page layout.
|
||||
try std.testing.expectEqual(@as(u32, 12), try vector.pop());
|
||||
vector.swapRemove(1);
|
||||
std.debug.assert(vector.len() == 128 + 1024 * 5 - 4);
|
||||
try std.testing.expectEqual(@as(u32, 11), vector.get(1).*);
|
||||
try std.testing.expectEqual(@as(usize, 11), vector.len());
|
||||
try std.testing.expectEqual(@as(u32, 0), first.*);
|
||||
|
||||
for (0..1024) |_| {
|
||||
vector.swapRemove(0);
|
||||
}
|
||||
|
||||
std.debug.assert(vector.len() == 128 + 1024 * 5 - 4 - 1024);
|
||||
}
|
||||
|
||||
test "reset retains pages and clears length" {
|
||||
const allocator = std.testing.allocator;
|
||||
|
||||
var vec = try PagedVectorAdvanced(u32, 4).init(allocator);
|
||||
defer vec.deinit(allocator);
|
||||
|
||||
for (0..10) |i| {
|
||||
try vec.append(allocator, @intCast(i));
|
||||
}
|
||||
|
||||
try std.testing.expect(vec.pages.items.len > 1);
|
||||
vec.reset(allocator);
|
||||
|
||||
try std.testing.expectEqual(@as(usize, 3), vec.pages.items.len);
|
||||
try std.testing.expectEqual(@as(usize, 0), vec.len());
|
||||
|
||||
try vec.append(allocator, 42);
|
||||
try std.testing.expectEqual(@as(u32, 42), vec.get(0).*);
|
||||
vector.reset(gpa);
|
||||
try std.testing.expectEqual(@as(usize, 0), vector.len());
|
||||
for (0..13) |_| try vector.append(gpa, 42);
|
||||
for (0..13) |i| try std.testing.expectEqual(@as(u32, 42), vector.get(i).*);
|
||||
}
|
||||
|
||||
fn exercise(gpa: std.mem.Allocator) !void {
|
||||
|
|
@ -400,7 +341,7 @@ fn exercise(gpa: std.mem.Allocator) !void {
|
|||
try std.testing.expectEqual(@as(usize, 0), arena.usage());
|
||||
|
||||
const reused = try a.alloc(u8, 4096);
|
||||
try std.testing.expectEqual(@intFromPtr(first.ptr), @intFromPtr(reused.ptr));
|
||||
@memset(reused, 31);
|
||||
for (0..12) |_| _ = try a.alloc(u8, 4096);
|
||||
arena.reset();
|
||||
for (0..12) |_| _ = try a.alloc(u8, 4096);
|
||||
|
|
|
|||
|
|
@ -27,33 +27,6 @@ test "function key policy holds through repeats and release in both directions"
|
|||
try std.testing.expectEqual(@as(u32, 0), state.suppress);
|
||||
}
|
||||
|
||||
test "function key policy preserves modified shortcuts and independent held keys" {
|
||||
const suppress = c.z_function_key_suppress;
|
||||
const application = c.UHDK_FUNCTION_KEYS_APPLICATION;
|
||||
var state = std.mem.zeroes(c.z_function_keys);
|
||||
for ([_]u32{ c.UHDK_MOD_SHIFT, c.UHDK_MOD_CONTROL, c.UHDK_MOD_ALT, c.UHDK_MOD_SUPER }) |mods| {
|
||||
try std.testing.expect(suppress(&state, application, c.UHDK_KEY_F4, mods, 1) == 0);
|
||||
// Releasing the modifier first must not steal the original shortcut's release.
|
||||
try std.testing.expect(suppress(&state, application, c.UHDK_KEY_F4, 0, 0) == 0);
|
||||
}
|
||||
const locks = c.UHDK_MOD_CAPS_LOCK | c.UHDK_MOD_NUM_LOCK;
|
||||
try std.testing.expect(suppress(&state, application, c.UHDK_KEY_F10, locks, 1) != 0);
|
||||
try std.testing.expect(suppress(&state, application, c.UHDK_KEY_F4, c.UHDK_MOD_ALT, 1) == 0);
|
||||
try std.testing.expect(suppress(&state, application, c.UHDK_KEY_F10, c.UHDK_MOD_ALT, 0) != 0);
|
||||
try std.testing.expect(suppress(&state, application, c.UHDK_KEY_F4, 0, 0) == 0);
|
||||
for ([_]u32{ c.UHDK_KEY_UNKNOWN, 'a', c.UHDK_KEY_ESCAPE, c.UHDK_KEY_F1 - 1, c.UHDK_KEY_F24 + 1 }) |key| {
|
||||
try std.testing.expect(suppress(&state, application, key, 0, 1) == 0);
|
||||
try std.testing.expect(suppress(&state, application, key, 0, 0) == 0);
|
||||
}
|
||||
try std.testing.expectEqual(@as(u32, 0), state.down);
|
||||
}
|
||||
|
||||
test "function key policy rejects invalid arguments" {
|
||||
const setPolicy = @import("api/input.zig").uhdk_window_set_function_key_policy;
|
||||
try std.testing.expectEqual(@as(abi.Status, abi.INVALID), setPolicy(null, c.UHDK_FUNCTION_KEYS_NATIVE));
|
||||
try std.testing.expectEqual(@as(abi.Status, abi.INVALID), setPolicy(null, 2));
|
||||
}
|
||||
|
||||
fn destroyApplication(application: *Application) void {
|
||||
runtime.destroyEvents(application.pending_head);
|
||||
runtime.destroyEvents(application.published);
|
||||
|
|
@ -86,50 +59,6 @@ test "all request construction failures release partial ownership" {
|
|||
try std.testing.checkAllAllocationFailures(std.testing.allocator, allocationLifecycle, .{});
|
||||
}
|
||||
|
||||
test "publication copies text and preserves batches across ordinary calls" {
|
||||
const application = try Application.create(std.testing.allocator, std.testing.io, "events");
|
||||
defer destroyApplication(application);
|
||||
|
||||
var source = [_]u8{ 'h', 'i' };
|
||||
var event = std.mem.zeroes(c.z_event);
|
||||
event.type = c.UHDK_EVENT_TEXT_COMMIT;
|
||||
event.data.text.text = .{ .ptr = &source, .len = source.len };
|
||||
runtime.emit(runtime.toAppHandle(application), &event);
|
||||
@memset(&source, '?');
|
||||
|
||||
const published = application.pending_head.?;
|
||||
try std.testing.expectEqualStrings("hi", abi.textBytes(published.event.data.text.text));
|
||||
runtime.simpleEvent(application, c.UHDK_EVENT_WAKE);
|
||||
runtime.simpleEvent(application, c.UHDK_EVENT_WAKE);
|
||||
try std.testing.expect(published.next != null);
|
||||
try std.testing.expect(published.next.?.next == null);
|
||||
try std.testing.expectEqualStrings("hi", abi.textBytes(published.event.data.text.text));
|
||||
}
|
||||
|
||||
test "accepted request gets one terminal result when cancellation wins" {
|
||||
const application = try Application.create(std.testing.allocator, std.testing.io, "requests");
|
||||
defer destroyApplication(application);
|
||||
application.running = true;
|
||||
|
||||
application.main_thread = std.Thread.getCurrentId();
|
||||
const command = try runtime.createCommand(application, c.Z_CLIP_READ, null);
|
||||
const request_id: u64 = 42;
|
||||
try std.testing.expectEqual(@as(u32, c.UHDK_STATUS_OK), runtime.submit(application, command, request_id));
|
||||
try std.testing.expect(request_id != 0);
|
||||
application.lock();
|
||||
command.cancelled = true;
|
||||
application.unlock();
|
||||
runtime.dispatch(runtime.toAppHandle(application));
|
||||
try std.testing.expect(application.requests == null);
|
||||
try std.testing.expect(application.queue_head == null);
|
||||
|
||||
const event = application.pending_head.?;
|
||||
try std.testing.expect(event.next == null);
|
||||
try std.testing.expectEqual(@as(u32, c.UHDK_EVENT_REQUEST_DONE), event.event.type);
|
||||
try std.testing.expectEqual(request_id, event.event.data.request.tag);
|
||||
try std.testing.expectEqual(@as(u32, c.UHDK_STATUS_CANCELLED), event.event.data.request.status);
|
||||
}
|
||||
|
||||
test "invalid UTF-8 spans and partial scalar ranges are rejected" {
|
||||
try std.testing.expect(!abi.validText(.{ .ptr = null, .len = 1 }, false));
|
||||
try std.testing.expect(!abi.validText(.{ .ptr = "\xff", .len = 1 }, false));
|
||||
|
|
@ -171,7 +100,6 @@ test "public payload scratch lifetime empty polls and resource pins" {
|
|||
try std.testing.expectEqual(@as(abi.Status, abi.OK), app_api.poll(handle, 0, &batch));
|
||||
try std.testing.expectEqual(@as(u64, 0), batch.len);
|
||||
try std.testing.expectEqual(@as(usize, 1), file.refs);
|
||||
try std.testing.expectEqual(@as(usize, 0), application.scratch.usage());
|
||||
}
|
||||
|
||||
test "poll allocation failure keeps queued terminal completion retryable" {
|
||||
|
|
@ -210,8 +138,6 @@ test "poll allocation failure keeps queued terminal completion retryable" {
|
|||
for (data.ptr[0..@intCast(data.len)]) |b| try std.testing.expectEqual(@as(u8, 42), b);
|
||||
try std.testing.expect(application.pending_head == null);
|
||||
|
||||
// Producer payload storage has been freed; the public copy is in scratch.
|
||||
try std.testing.expectEqual(@as(usize, 0), application.published.?.arena.queryCapacity());
|
||||
try std.testing.expectEqual(@as(abi.Status, abi.OK), app_api.poll(handle, 0, &batch));
|
||||
try std.testing.expectEqual(@as(u64, 0), batch.len);
|
||||
}
|
||||
|
|
@ -220,41 +146,6 @@ test {
|
|||
_ = @import("linux/WindowState.zig");
|
||||
}
|
||||
|
||||
test "desktop edit defaults preserve modifiers and selection intent" {
|
||||
const ctrl = c.UHDK_MOD_CONTROL;
|
||||
const shift = c.UHDK_MOD_SHIFT;
|
||||
const cases = [_][3]u32{
|
||||
.{ c.UHDK_KEY_BACKSPACE, ctrl, c.UHDK_EDIT_DELETE_WORD_BACKWARD },
|
||||
.{ c.UHDK_KEY_DELETE, ctrl, c.UHDK_EDIT_DELETE_WORD_FORWARD },
|
||||
.{ c.UHDK_KEY_DELETE, shift, c.UHDK_EDIT_CUT },
|
||||
.{ c.UHDK_KEY_INSERT, ctrl, c.UHDK_EDIT_COPY },
|
||||
.{ c.UHDK_KEY_INSERT, shift, c.UHDK_EDIT_PASTE },
|
||||
.{ 'v', ctrl, c.UHDK_EDIT_PASTE },
|
||||
.{ 'z', ctrl | shift, c.UHDK_EDIT_REDO },
|
||||
.{ c.UHDK_KEY_UP, ctrl | shift, c.UHDK_EDIT_PARAGRAPH_START },
|
||||
.{ c.UHDK_KEY_DOWN, ctrl, c.UHDK_EDIT_PARAGRAPH_END },
|
||||
.{ c.UHDK_KEY_PAGE_UP, shift, c.UHDK_EDIT_PAGE_UP },
|
||||
.{ c.UHDK_KEY_PAGE_DOWN, 0, c.UHDK_EDIT_PAGE_DOWN },
|
||||
.{ c.UHDK_KEY_TAB, shift, c.UHDK_EDIT_BACKTAB },
|
||||
.{ c.UHDK_KEY_ENTER, shift, c.UHDK_EDIT_LINE_BREAK },
|
||||
.{ c.UHDK_KEY_ESCAPE, 0, c.UHDK_EDIT_CANCEL },
|
||||
.{ c.UHDK_KEY_TAB, ctrl, 0 },
|
||||
.{ c.UHDK_KEY_PAGE_DOWN, ctrl, 0 },
|
||||
.{ 'v', ctrl | shift, 0 },
|
||||
};
|
||||
|
||||
for (cases) |item| {
|
||||
try std.testing.expectEqual(item[2], c.z_edit_key(item[0], item[1]));
|
||||
try std.testing.expectEqual(@as(u32, 0), c.z_edit_key(item[0], item[1] | c.UHDK_MOD_ALT));
|
||||
try std.testing.expectEqual(@as(u32, 0), c.z_edit_key(item[0], item[1] | c.UHDK_MOD_SUPER));
|
||||
}
|
||||
|
||||
try std.testing.expect(c.z_edit_extends_selection(c.UHDK_EDIT_WORD_LEFT, shift) != 0);
|
||||
try std.testing.expect(c.z_edit_extends_selection(c.UHDK_EDIT_PAGE_DOWN, shift) != 0);
|
||||
for ([_]u32{ c.UHDK_EDIT_BACKTAB, c.UHDK_EDIT_LINE_BREAK, c.UHDK_EDIT_CUT, c.UHDK_EDIT_DELETE_WORD_FORWARD, c.UHDK_EDIT_REDO }) |command|
|
||||
try std.testing.expectEqual(@as(c_int, 0), c.z_edit_extends_selection(command, shift));
|
||||
}
|
||||
|
||||
const IoGate = struct {
|
||||
io: std.Io,
|
||||
entered: std.Io.Event = .unset,
|
||||
|
|
@ -336,26 +227,6 @@ test "blocked file execution leaves event polling live and cancellation drains o
|
|||
}
|
||||
}
|
||||
|
||||
test "file queue saturation rejects without reserving a tag" {
|
||||
const application = try Application.create(std.testing.allocator, std.testing.io, "io limit");
|
||||
defer destroyApplication(application);
|
||||
application.running = true;
|
||||
|
||||
application.main_thread = std.Thread.getCurrentId();
|
||||
const file = try runtime.createObject(application, c.Z_KIND_FILE);
|
||||
defer runtime.release(file);
|
||||
for (0..64) |i| {
|
||||
const command = try runtime.createCommand(application, abi.IO_INFO, file);
|
||||
try std.testing.expectEqual(@as(u32, abi.OK), runtime.submit(application, command, i + 1));
|
||||
}
|
||||
|
||||
const excess = try runtime.createCommand(application, abi.IO_INFO, file);
|
||||
try std.testing.expectEqual(@as(u32, c.UHDK_STATUS_BUSY), runtime.submit(application, excess, 65));
|
||||
application.stopping = true;
|
||||
while (application.requests != null) runtime.dispatch(runtime.toAppHandle(application));
|
||||
try std.testing.expectEqual(@as(usize, 0), application.io_pending);
|
||||
}
|
||||
|
||||
test "fatal native failure persists and wakes subsequent polls" {
|
||||
const app_api = @import("api/app.zig");
|
||||
const application = try Application.create(std.testing.allocator, std.testing.io, "native failure");
|
||||
|
|
@ -417,32 +288,6 @@ test "caller tags remain reserved until delivery and isolate late native complet
|
|||
try std.testing.expectEqual(@as(u64, 1), events.len);
|
||||
}
|
||||
|
||||
test "error messages and diagnostics need no session and preserve native details" {
|
||||
const app_api = @import("api/app.zig");
|
||||
for (0..13) |status| {
|
||||
const message = app_api.uhdk_status_message(@intCast(status));
|
||||
try std.testing.expect(message.len > 0);
|
||||
try std.testing.expect(abi.validText(message, true));
|
||||
}
|
||||
|
||||
try std.testing.expect(app_api.uhdk_status_message(std.math.maxInt(u32)).len > 0);
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
|
||||
var event = std.mem.zeroes(c.z_event);
|
||||
event.type = c.UHDK_EVENT_REQUEST_DONE;
|
||||
event.data.request.status = c.UHDK_STATUS_PERMISSION_DENIED;
|
||||
|
||||
const converted = try @import("EventPayload.zig").pack(arena.allocator(), event);
|
||||
const result: *const c.uhdk_request_result = @ptrCast(@alignCast(converted.data.?));
|
||||
try std.testing.expectEqualStrings(abi.textBytes(app_api.uhdk_status_message(c.UHDK_STATUS_PERMISSION_DENIED)), abi.textBytes(result.diagnostic));
|
||||
event.data.request.diagnostic = abi.textSpan("Native context detail");
|
||||
|
||||
const detailed = try @import("EventPayload.zig").pack(arena.allocator(), event);
|
||||
const with_detail: *const c.uhdk_request_result = @ptrCast(@alignCast(detailed.data.?));
|
||||
try std.testing.expectEqualStrings("Native context detail", abi.textBytes(with_detail.diagnostic));
|
||||
}
|
||||
|
||||
test "cycle end markers survive public event batching" {
|
||||
const app_api = @import("api/app.zig");
|
||||
const application = try Application.create(std.testing.allocator, std.testing.io, "cycles");
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ const shm_listener: c.struct_wl_shm_listener = .{ .format = format };
|
|||
pub fn initialize() void {
|
||||
const token = c.getenv("XDG_ACTIVATION_TOKEN");
|
||||
if (token != null and token[0] != 0) {
|
||||
desktopState().launch = backend().app.gpa.dupeZ(u8, std.mem.span(token)) catch null;
|
||||
desktopState().launch = backend().app.gpa.dupeSentinel(u8, std.mem.span(token), 0) catch null;
|
||||
_ = c.unsetenv("XDG_ACTIVATION_TOKEN");
|
||||
}
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ pub fn initialize() void {
|
|||
// A tray host supplies provenance that a hidden application's own seat lacks.
|
||||
// Consume it once, promptly, without modifying the process environment.
|
||||
pub fn trayToken(token: []const u8) !void {
|
||||
const copy = if (token.len != 0) try backend().app.gpa.dupeZ(u8, token) else null;
|
||||
const copy = if (token.len != 0) try backend().app.gpa.dupeSentinel(u8, token, 0) else null;
|
||||
if (desktopState().tray_token) |old| backend().app.gpa.free(old);
|
||||
desktopState().tray_token = copy;
|
||||
desktopState().tray_token_deadline = runtime.now(backend().app.io) + 5 * std.time.ns_per_s;
|
||||
|
|
@ -115,7 +115,7 @@ pub fn focus(w: *native.Window, id: u64) u32 {
|
|||
c.xdg_activation_token_v1_set_serial(token, input.serial, input.seat);
|
||||
c.xdg_activation_token_v1_set_surface(token, input.key_focus.?.surface);
|
||||
|
||||
const app_id = backend().app.gpa.dupeZ(u8, backend().app.application_id) catch {
|
||||
const app_id = backend().app.gpa.dupeSentinel(u8, backend().app.application_id, 0) catch {
|
||||
finish(p, abi.OOM);
|
||||
return n.Z_DEFERRED;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ pub fn proc(ptr: ?*anyopaque, name: n.uhdk_text, out: [*c]n.uhdk_gl_proc) u32 {
|
|||
if (frame != ctx or c.z_eglGetCurrentContext.?() != ctx.context) return n.UHDK_STATUS_BUSY;
|
||||
|
||||
const allocator = ctx.window.owner.gpa;
|
||||
const terminated = allocator.dupeZ(u8, abi.textBytes(name)) catch return abi.OOM;
|
||||
const terminated = allocator.dupeSentinel(u8, abi.textBytes(name), 0) catch return abi.OOM;
|
||||
defer allocator.free(terminated);
|
||||
|
||||
const address = c.z_eglGetProcAddress.?(terminated) orelse return n.UHDK_STATUS_NOT_FOUND;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ pub fn activate(window: *native.Window, item: *const n.uhdk_menu_item, input_id:
|
|||
}
|
||||
|
||||
pub fn keyName(key: u32, buffer: *[32]u8) ?[:0]const u8 {
|
||||
if (key >= n.UHDK_KEY_F1 and key < n.UHDK_KEY_F1 + 24) return std.fmt.bufPrintZ(buffer, "F{d}", .{key - n.UHDK_KEY_F1 + 1}) catch unreachable;
|
||||
if (key >= n.UHDK_KEY_F1 and key < n.UHDK_KEY_F1 + 24) return std.mem.printSentinel(buffer, "F{d}", .{key - n.UHDK_KEY_F1 + 1}, 0) catch unreachable;
|
||||
|
||||
switch (key) {
|
||||
n.UHDK_KEY_ESCAPE => return "Escape",
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ fn setOwner(message: *Bus.Message) !void {
|
|||
const sender = c.z_dbus_message_get_sender.?(message);
|
||||
if (sender == null) return;
|
||||
if (portalState().owner) |old| backend().app.gpa.free(old);
|
||||
portalState().owner = try backend().app.gpa.dupeZ(u8, std.mem.span(sender));
|
||||
portalState().owner = try backend().app.gpa.dupeSentinel(u8, std.mem.span(sender), 0);
|
||||
}
|
||||
|
||||
fn process(message: *Bus.Message) !void {
|
||||
|
|
@ -192,7 +192,7 @@ fn process(message: *Bus.Message) !void {
|
|||
return;
|
||||
}
|
||||
|
||||
portalState().unique = try backend().app.gpa.dupeZ(u8, Bus.str(&args).?);
|
||||
portalState().unique = try backend().app.gpa.dupeSentinel(u8, Bus.str(&args).?, 0);
|
||||
try addMatches();
|
||||
return;
|
||||
}
|
||||
|
|
@ -273,7 +273,7 @@ fn process(message: *Bus.Message) !void {
|
|||
|
||||
if (new.len != 0) {
|
||||
if (portalState().owner) |owner| backend().app.gpa.free(owner);
|
||||
portalState().owner = try backend().app.gpa.dupeZ(u8, new);
|
||||
portalState().owner = try backend().app.gpa.dupeSentinel(u8, new, 0);
|
||||
try discover();
|
||||
}
|
||||
|
||||
|
|
@ -296,7 +296,7 @@ fn process(message: *Bus.Message) !void {
|
|||
return;
|
||||
}
|
||||
|
||||
const handle = try backend().app.gpa.dupeZ(u8, Bus.str(&args).?);
|
||||
const handle = try backend().app.gpa.dupeSentinel(u8, Bus.str(&args).?, 0);
|
||||
backend().app.gpa.free(pending.handle);
|
||||
pending.handle = handle;
|
||||
if (pending.id == 0) {
|
||||
|
|
@ -442,7 +442,7 @@ fn submit(p: *Pending, parent: [*:0]const u8, activation_token: ?[*:0]const u8)
|
|||
const gpa = arena.allocator();
|
||||
var args = Bus.append(message);
|
||||
try Bus.string(&args, parent);
|
||||
try Bus.string(&args, try gpa.dupeZ(u8, abi.textBytes(if (dialog) cmd.dialog.title else cmd.text)));
|
||||
try Bus.string(&args, try gpa.dupeSentinel(u8, abi.textBytes(if (dialog) cmd.dialog.title else cmd.text), 0));
|
||||
|
||||
var options = try Bus.open(&args, c.DBUS_TYPE_ARRAY, "{sv}");
|
||||
errdefer c.z_dbus_message_iter_abandon_container_if_open.?(&args, &options);
|
||||
|
|
@ -455,8 +455,8 @@ fn submit(p: *Pending, parent: [*:0]const u8, activation_token: ?[*:0]const u8)
|
|||
try Bus.option(&options, "directory", "b", @as(u32, @intFromBool(cmd.dialog.kind == n.UHDK_DIALOG_OPEN_DIRECTORY)));
|
||||
}
|
||||
|
||||
if (cmd.dialog.accept_label.len != 0) try Bus.option(&options, "accept_label", "s", (try gpa.dupeZ(u8, abi.textBytes(cmd.dialog.accept_label))).ptr);
|
||||
if (cmd.dialog.suggested_name.len != 0 and cmd.dialog.kind == n.UHDK_DIALOG_SAVE_FILE) try Bus.option(&options, "current_name", "s", (try gpa.dupeZ(u8, abi.textBytes(cmd.dialog.suggested_name))).ptr);
|
||||
if (cmd.dialog.accept_label.len != 0) try Bus.option(&options, "accept_label", "s", (try gpa.dupeSentinel(u8, abi.textBytes(cmd.dialog.accept_label), 0)).ptr);
|
||||
if (cmd.dialog.suggested_name.len != 0 and cmd.dialog.kind == n.UHDK_DIALOG_SAVE_FILE) try Bus.option(&options, "current_name", "s", (try gpa.dupeSentinel(u8, abi.textBytes(cmd.dialog.suggested_name), 0)).ptr);
|
||||
if (cmd.dialog.initial_directory != null) {
|
||||
const directory = abi.bytes(n.z_file_path(cmd.dialog.initial_directory));
|
||||
var entry = try Bus.open(&options, c.DBUS_TYPE_DICT_ENTRY, null);
|
||||
|
|
@ -495,7 +495,7 @@ fn filters(options: *Bus.Iter, desc: n.uhdk_file_dialog_desc, gpa: std.mem.Alloc
|
|||
for (desc.filters[0..@intCast(desc.filters_len)]) |filter| {
|
||||
var pair = try Bus.open(&list, c.DBUS_TYPE_STRUCT, null);
|
||||
errdefer c.z_dbus_message_iter_abandon_container_if_open.?(&list, &pair);
|
||||
try Bus.string(&pair, try gpa.dupeZ(u8, abi.textBytes(filter.label)));
|
||||
try Bus.string(&pair, try gpa.dupeSentinel(u8, abi.textBytes(filter.label), 0));
|
||||
|
||||
var patterns = try Bus.open(&pair, c.DBUS_TYPE_ARRAY, "(us)");
|
||||
errdefer c.z_dbus_message_iter_abandon_container_if_open.?(&pair, &patterns);
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ For distribution on conventional glibc systems, build the application explicitly
|
|||
for the chosen baseline, for example:
|
||||
|
||||
```sh
|
||||
zig build -Dtarget=x86_64-linux-gnu.2.35 -Dcpu=baseline -Doptimize=ReleaseSafe
|
||||
zig build -Dtarget=x86_64-linux-gnu.2.35 -Dcpu=baseline -Doptimize=safe
|
||||
python3 src/linux/tools/audit-elf.py /path/to/application
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ fn publish(w: *native.Window) u32 {
|
|||
|
||||
const range = crop(t.surrounding, @intCast(t.snapshot.selection_start), @intCast(t.snapshot.selection_len));
|
||||
const sent = w.owner.gpa.create(Sent) catch return abi.OOM;
|
||||
const bytes = w.owner.gpa.dupeZ(u8, if (range) |r| t.surrounding[r.start..r.end] else "") catch {
|
||||
const bytes = w.owner.gpa.dupeSentinel(u8, if (range) |r| t.surrounding[r.start..r.end] else "", 0) catch {
|
||||
w.owner.gpa.destroy(sent);
|
||||
return abi.OOM;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ pub fn ready() !void {
|
|||
}
|
||||
|
||||
fn setOwner(owner: []const u8) !void {
|
||||
const copied = if (owner.len != 0) try backend().app.gpa.dupeZ(u8, owner) else null;
|
||||
const copied = if (owner.len != 0) try backend().app.gpa.dupeSentinel(u8, owner, 0) else null;
|
||||
if (state().owner) |old| backend().app.gpa.free(old);
|
||||
state().owner = copied;
|
||||
state().host_query = 0;
|
||||
|
|
|
|||
|
|
@ -20,13 +20,13 @@ fn backend() *native.Backend {
|
|||
}
|
||||
|
||||
pub fn prepare(root: ?*n.uhdk_file, handle: ?*n.uhdk_watch, out: *?*anyopaque) u32 {
|
||||
const path = backend().app.gpa.dupeZ(u8, abi.bytes(n.z_file_path(root))) catch return abi.OOM;
|
||||
const path = backend().app.gpa.dupeSentinel(u8, abi.bytes(n.z_file_path(root)), 0) catch return abi.OOM;
|
||||
defer backend().app.gpa.free(path);
|
||||
|
||||
const kind = c.z_linux_is_directory(path);
|
||||
if (kind < 0 and c.z_linux_errno() != c.ENOENT) return n.UHDK_STATUS_OS_ERROR;
|
||||
|
||||
const directory = backend().app.gpa.dupeZ(u8, if (kind == 1) path else std.fs.path.dirname(path) orelse "/") catch return abi.OOM;
|
||||
const directory = backend().app.gpa.dupeSentinel(u8, if (kind == 1) path else std.fs.path.dirname(path) orelse "/", 0) catch return abi.OOM;
|
||||
defer backend().app.gpa.free(directory);
|
||||
|
||||
const fd = c.inotify_init1(c.IN_NONBLOCK | c.IN_CLOEXEC);
|
||||
|
|
|
|||
|
|
@ -565,10 +565,10 @@ fn createWindow(b: *Backend, command: *const n.z_command, id: u64) u32 {
|
|||
}
|
||||
|
||||
fn setupWindow(b: *Backend, w: *Window, desc: n.z_window_desc) u32 {
|
||||
const title = b.app.gpa.dupeZ(u8, abi.textBytes(desc.title)) catch return abi.OOM;
|
||||
const title = b.app.gpa.dupeSentinel(u8, abi.textBytes(desc.title), 0) catch return abi.OOM;
|
||||
defer b.app.gpa.free(title);
|
||||
|
||||
const app_id = b.app.gpa.dupeZ(u8, b.app.application_id) catch return abi.OOM;
|
||||
const app_id = b.app.gpa.dupeSentinel(u8, b.app.application_id, 0) catch return abi.OOM;
|
||||
defer b.app.gpa.free(app_id);
|
||||
w.surface = c.wl_compositor_create_surface(b.compositor) orelse return abi.OOM;
|
||||
if (c.wl_surface_add_listener(w.surface, &wl_surface_listener, w) != 0) return abi.OOM;
|
||||
|
|
@ -702,7 +702,7 @@ export fn z_native_execute(_: ?*n.uhdk_session, raw: [*c]const n.z_command, id:
|
|||
switch (cmd.op) {
|
||||
n.Z_WINDOW_MENU => return KdeAppMenu.attach(w, cmd.other),
|
||||
n.Z_TITLE => {
|
||||
const title = b.app.gpa.dupeZ(u8, abi.textBytes(cmd.text)) catch return abi.OOM;
|
||||
const title = b.app.gpa.dupeSentinel(u8, abi.textBytes(cmd.text), 0) catch return abi.OOM;
|
||||
defer b.app.gpa.free(title);
|
||||
c.xdg_toplevel_set_title(w.top, title);
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue