From 62fbf00df821a2731f0a5847806eba0ac13052ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 7 Jun 2005 19:40:56 +0000 Subject: [PATCH] Added a simple mini test application for BPortLink. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12995 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/kits/app/Jamfile | 1 + src/tests/kits/app/messaging/Jamfile | 24 ++++++ src/tests/kits/app/messaging/PortLinkTest.cpp | 75 +++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 src/tests/kits/app/messaging/Jamfile create mode 100644 src/tests/kits/app/messaging/PortLinkTest.cpp 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; +}