summary refs log tree commit diff
path: root/src/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig58
1 files changed, 48 insertions, 10 deletions
diff --git a/src/main.zig b/src/main.zig
index fc13fa8..21e4f3a 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -18,7 +18,7 @@
 
 const al = @import("al.zig");
 const alc = @import("alc.zig");
-const expect = std.testing.expect;
+const expectEqual = std.testing.expectEqual;
 const eql = std.meta.eql;
 const std = @import("std");
 
@@ -73,34 +73,72 @@ pub const Listener = struct {
 
     pub fn setPosition(self: Listener, position: [3]f32) !void {
         try checkContext(self.context);
-        al.listener.set([3]f32, al.POSITION, position);
+        try al.listener.set(al.POSITION, position);
     }
 
     pub fn setOrientation(self: Listener, at: [3]f32, up: [3]f32) !void {
         try checkContext(self.context);
         const orientation = [_]f32{ at[0], at[1], at[2], up[0], up[1], up[2] };
-        al.listener.set(@TypeOf(orientation), al.ORIENTATION, orientation);
+        try al.listener.set(al.ORIENTATION, orientation);
     }
 };
 
-test "temporary" {
+pub const Buffer = struct {
+    context: Context,
+    reference: u32,
+
+    pub fn init(context: Context, name: []const u8) !Buffer {
+        try checkContext(context);
+        const reference = try al.genBuffer();
+        return Buffer{ .context = context, .reference = reference };
+    }
+
+    pub fn deinit(self: Buffer) !void {
+        try checkContext(self.context);
+        try al.deleteBuffer(&self.reference);
+    }
+};
+
+test "Device" {
     const device = try Device.init("OpenAL Soft");
+    try device.deinit();
+}
+
+test "Context" {
+    const device = try Device.init(null);
     defer device.deinit() catch unreachable;
     const context = try Context.init(device, &.{ alc.HRTF, alc.TRUE });
     defer context.deinit() catch unreachable;
 
-    try expect(null == try currentContext());
-    if (checkContext(context)) |_| unreachable else |err| switch (err) {
+    try expectEqual(try currentContext(), null);
+    if (checkContext(context)) unreachable else |err| switch (err) {
         error.UncurrentContext => {},
     }
 
     try useContext(context);
     const current_context = (try currentContext()).?;
-    try expect(eql(current_context, context));
-    try expect(eql(current_context.device, device));
+    try expectEqual(current_context, context);
+    try expectEqual(current_context.device, device);
     try checkContext(context);
+}
+
+test "Listener" {
+    const context = try Context.init(try Device.init(null), &.{});
+    defer context.device.deinit() catch unreachable;
+    defer context.deinit() catch unreachable;
 
+    try useContext(context);
     const listener = Listener{ .context = context };
-    try listener.setPosition(.{ 0, 0, 0 });
-    try listener.setOrientation(.{ 0, 0, 0 }, .{ 0, 0, 0 });
+    try listener.setPosition(.{ 1, 2, 3 });
+    try listener.setOrientation(.{ 4, 5, 6 }, .{ 7, 8, 9 });
+}
+
+test "Buffer" {
+    const context = try Context.init(try Device.init(null), &.{});
+    defer context.device.deinit() catch unreachable;
+    defer context.deinit() catch unreachable;
+
+    try useContext(context);
+    const buffer = try Buffer.init(context, "");
+    defer buffer.deinit() catch unreachable;
 }