From 0a836c56cd7f80214efa91f0d6d506a6625eee66 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Wed, 25 Jan 2023 04:52:27 +0100 Subject: [PATCH] Test application for crystal bindings. --- .../crystal/some-crystal-app/src/test-app.cr | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 zig-impl/crystal/some-crystal-app/src/test-app.cr diff --git a/zig-impl/crystal/some-crystal-app/src/test-app.cr b/zig-impl/crystal/some-crystal-app/src/test-app.cr new file mode 100644 index 0000000..400fe16 --- /dev/null +++ b/zig-impl/crystal/some-crystal-app/src/test-app.cr @@ -0,0 +1,46 @@ +require "./some-crystal-app.cr" + +def test_high_level + ipc = IPC.new + fd = ipc.connect("pong") + ipc.write(fd, "hello this is some value") + event = ipc.wait() + + m = event.message + if m.nil? + puts "No message" + else + pp! String.new(m.to_unsafe, m.size) + end +end + +def test_loop + ipc = IPC.new + fd = ipc.connect("pong") + ipc.schedule(fd, "hello this is some value") + ipc.loop do |event| + case event.type + when LibIPC::EventType::MessageRx + m = event.message + if m.nil? + puts "No message" + else + pp! String.new(m.to_unsafe, m.size) + end + exit 0 + when LibIPC::EventType::MessageTx + puts "A message has been sent" + else + puts "Unexpected: #{event.type}" + exit 1 + end + end +end + +# TODO: Write documentation for `Some::Crystal::App` +module Some::Crystal::App + VERSION = "0.1.0" + + test_high_level + test_loop +end