summary refs log tree commit diff stats
path: root/tests/stdlib/tposix.nim
diff options
context:
space:
mode:
authorn5m <72841454+n5m@users.noreply.github.com>2022-11-05 05:31:19 +0000
committerGitHub <noreply@github.com>2022-11-05 06:31:19 +0100
commit51bef9b4a8b0dab065470d9c224c20ac21e72275 (patch)
tree470bf75a2a570b712673a800421aad055be9c366 /tests/stdlib/tposix.nim
parent4491da4c4d090406987650ffd6eb7cea5ded9a19 (diff)
downloadNim-51bef9b4a8b0dab065470d9c224c20ac21e72275.tar.gz
fix posix.mq_receive compilation with cpp backend (#20710)
* fix posix.mq_receive compilation with cpp backend

* only enable runnableExample on posix

* linux, not posix

* simplify example

* add test

* mqueue.h does not exist on MacOS

* place test case in own block

* drop runnableExamples
Diffstat (limited to 'tests/stdlib/tposix.nim')
-rw-r--r--tests/stdlib/tposix.nim45
1 files changed, 44 insertions, 1 deletions
diff --git a/tests/stdlib/tposix.nim b/tests/stdlib/tposix.nim
index ea0472c31..d06c5cd56 100644
--- a/tests/stdlib/tposix.nim
+++ b/tests/stdlib/tposix.nim
@@ -7,7 +7,7 @@ outputsub: ""
 when not defined(windows):
 
   import posix
-  import std/syncio
+  import std/[assertions, syncio]
 
   var
     u: Utsname
@@ -18,3 +18,46 @@ when not defined(windows):
   writeLine(stdout, u.nodename)
   writeLine(stdout, u.release)
   writeLine(stdout, u.machine)
+
+  when not (defined(nintendoswitch) or defined(macos) or defined(macosx)):
+    block:
+      type Message = object
+        value: int
+
+      const MQ_PATH: cstring = "/top_level_file"
+      const MQ_PRIORITY: cuint = 170
+      const MQ_MESSAGE_SIZE: csize_t = csize_t(sizeof(Message))
+
+      let mqd_a: posix.MqAttr = MqAttr(mq_maxmsg: 10, mq_msgsize: clong(MQ_MESSAGE_SIZE))
+      let writable: posix.Mqd = posix.mq_open(
+        MQ_PATH,
+        posix.O_CREAT or posix.O_WRONLY or posix.O_NONBLOCK,
+        posix.S_IRWXU,
+        addr(mqd_a)
+      )
+      let readable: posix.Mqd = posix.mq_open(
+        MQ_PATH,
+        posix.O_RDONLY or posix.O_NONBLOCK,
+        posix.S_IRWXU,
+        addr(mqd_a)
+      )
+
+      let sent: Message = Message(value: 88)
+      block:
+        let success: int = writable.mq_send(
+          cast[cstring](sent.addr),
+          MQ_MESSAGE_SIZE,
+          MQ_PRIORITY
+        )
+        doAssert success == 0, $success
+
+      block:
+        var buffer: Message
+        var priority: cuint
+        let bytesRead: int = readable.mq_receive(
+          cast[cstring](buffer.addr),
+          MQ_MESSAGE_SIZE,
+          priority
+        )
+        doAssert buffer == sent
+        doAssert bytesRead == int(MQ_MESSAGE_SIZE)