diff --git a/src/tests/kits/app/Jamfile b/src/tests/kits/app/Jamfile index 6516f4048c..5b7bbfbb4e 100644 --- a/src/tests/kits/app/Jamfile +++ b/src/tests/kits/app/Jamfile @@ -161,3 +161,4 @@ SubInclude OBOS_TOP src tests kits app bcursor ; SubInclude OBOS_TOP src tests kits app bmessenger ; SubInclude OBOS_TOP src tests kits app broster ; SubInclude OBOS_TOP src tests kits app common ; +SubInclude OBOS_TOP src tests kits app messaging ; diff --git a/src/tests/kits/app/messaging/Jamfile b/src/tests/kits/app/messaging/Jamfile new file mode 100644 index 0000000000..2221e178b1 --- /dev/null +++ b/src/tests/kits/app/messaging/Jamfile @@ -0,0 +1,24 @@ +SubDir OBOS_TOP src tests kits app messaging ; + +UsePrivateHeaders app ; +UsePrivateHeaders interface ; + +SimpleTest PortLinkTest : + PortLinkTest.cpp + PortLink.cpp + LinkMsgReader.cpp + LinkMsgSender.cpp + + # PortLink accesses some private stuff directly + Shape.cpp + Region.cpp + RegionSupport.cpp + + : be + ; + +SEARCH on [ FGristFiles PortLink.cpp LinkMsgReader.cpp LinkMsgSender.cpp ] + = [ FDirName $(OBOS_TOP) src kits app ] ; + +SEARCH on [ FGristFiles Shape.cpp Region.cpp RegionSupport.cpp ] + = [ FDirName $(OBOS_TOP) src kits interface ] ; diff --git a/src/tests/kits/app/messaging/PortLinkTest.cpp b/src/tests/kits/app/messaging/PortLinkTest.cpp new file mode 100644 index 0000000000..51f4a085d4 --- /dev/null +++ b/src/tests/kits/app/messaging/PortLinkTest.cpp @@ -0,0 +1,75 @@ +#include + +#include +#include +#include + + +int +main() +{ + port_id port = create_port(100, "portlink"); + + BPortLink sender(port, -1); + BPortLink receiver(-1, port); + + sender.StartMessage('tst1'); + sender.Attach(42); + + sender.StartMessage('tst2'); + sender.AttachString(NULL); + sender.AttachString(""); + sender.AttachString("Gurkensalat"); + + status_t status = sender.Flush(); + if (status != B_OK) { + fprintf(stderr, "flushing messages failed: %ld, %s!\n", + status, strerror(status)); + return -1; + } + + int32 code; + if (receiver.GetNextReply(&code) != B_OK) { + fprintf(stderr, "get message failed!\n"); + return -1; + } + if (code != 'tst1') + fprintf(stderr, "code is wrong (%ld)!\n", code); + + int32 value; + if (receiver.Read(&value) != B_OK) { + fprintf(stderr, "reading message failed!\n"); + return -1; + } + + if (value != 42) + fprintf(stderr, "value is wrong: %ld!\n", value); + + if (receiver.GetNextReply(&code) != B_OK) { + fprintf(stderr, "get message failed!\n"); + return -1; + } + if (code != 'tst2') + fprintf(stderr, "code is wrong (%ld)!\n", code); + + for (int32 i = 0; i < 4; i++) { + char *string; + if (receiver.ReadString(&string) != B_OK) { + if (i == 3) + continue; + + fprintf(stderr, "reading string failed!\n"); + return -1; + } else if (i == 3) { + fprintf(stderr, "reading string succeeded, but shouldn't!\n"); + return -1; + } + free(string); + } + + status = receiver.GetNextReply(&code, 0); + if (status != B_WOULD_BLOCK) + fprintf(stderr, "reading would not block!\n"); + + return 0; +}