From 9837f25ec6fed2ee4febfb0781cdda7a07db88b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 7 Feb 2006 16:54:21 +0000 Subject: [PATCH] Forgot to commit a simple test application for node monitoring. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16287 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/kits/storage/testapps/Jamfile | 10 +- .../kits/storage/testapps/NodeMonitorTest.cpp | 95 +++++++++++++++++++ 2 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 src/tests/kits/storage/testapps/NodeMonitorTest.cpp diff --git a/src/tests/kits/storage/testapps/Jamfile b/src/tests/kits/storage/testapps/Jamfile index bc7e2794c4..75925f601e 100644 --- a/src/tests/kits/storage/testapps/Jamfile +++ b/src/tests/kits/storage/testapps/Jamfile @@ -3,5 +3,11 @@ SubDir HAIKU_TOP src tests kits storage testapps ; SetSubDirSupportedPlatformsBeOSCompatible ; AddSubDirSupportedPlatforms libbe_test ; -SimpleTest clipboard : clipboard.cpp : be net ; -SimpleTest dump_mime_types : dump_mime_types.cpp : be net ; +SimpleTest clipboard + : clipboard.cpp : be ; + +SimpleTest dump_mime_types + : dump_mime_types.cpp : be ; + +SimpleTest NodeMonitorTest + : NodeMonitorTest.cpp : be ; diff --git a/src/tests/kits/storage/testapps/NodeMonitorTest.cpp b/src/tests/kits/storage/testapps/NodeMonitorTest.cpp new file mode 100644 index 0000000000..8784d48935 --- /dev/null +++ b/src/tests/kits/storage/testapps/NodeMonitorTest.cpp @@ -0,0 +1,95 @@ +/* + * Copyright 2006, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Axel Dörfler, axeld@pinc-software.de + */ + + +#include +#include +#include +#include + +#include +#include + + +class Looper : public BLooper { + public: + Looper(node_ref& nodeRef); + virtual ~Looper(); + + virtual void MessageReceived(BMessage* message); + + private: + node_ref fNodeRef; +}; + + +Looper::Looper(node_ref& nodeRef) + : + fNodeRef(nodeRef) +{ + status_t status = watch_node(&fNodeRef, B_WATCH_DIRECTORY, this); + if (status != B_OK) { + fprintf(stderr, "Could not watch file.\n"); + PostMessage(B_QUIT_REQUESTED); + } +} + + +Looper::~Looper() +{ + status_t status = watch_node(&fNodeRef, B_STOP_WATCHING, this); + if (status != B_OK) + fprintf(stderr, "Could not stop watching: %s\n", strerror(status)); +} + + +void +Looper::MessageReceived(BMessage* message) +{ + if (message->what == B_NODE_MONITOR) + message->PrintToStream(); +} + + +int +main() +{ + BEntry entry("/tmp", true); + node_ref nodeRef; + if (entry.GetNodeRef(&nodeRef) != B_OK) { + fprintf(stderr, "Could not open /tmp.\n"); + return -1; + } + + //printf("device: %ld, node: %Ld\n", nodeRef.device, nodeRef.node); + + // start looper + Looper& looper = *new Looper(nodeRef); + looper.Run(); + + // run tests + entry.SetTo("/tmp/_watch_test_"); + + BFile file; + status_t status = file.SetTo(&entry, B_CREATE_FILE | B_READ_WRITE); + if (status != B_OK) + fprintf(stderr, "could not create watch test.\n"); + file.Write("test", 4); + file.Unset(); + + if (entry.Remove() != B_OK) + fprintf(stderr, "could not remove watch test.\n"); + + snooze(500000LL); + + // quit looper + looper.PostMessage(B_QUIT_REQUESTED); + wait_for_thread(looper.Thread(), &status); + + return 0; +}