summaryrefslogtreecommitdiff
path: root/cpp/test
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2002-11-29 01:18:03 +0000
committerMichi Henning <michi@zeroc.com>2002-11-29 01:18:03 +0000
commit404a9441f45ac9ca1ba39f04c7f8d1f9fc79de5b (patch)
tree12023d167f8ab1b161aaec017a206863f4888bbf /cpp/test
parentfixing potential deadlock with ObjectAdapter (diff)
downloadice-404a9441f45ac9ca1ba39f04c7f8d1f9fc79de5b.tar.bz2
ice-404a9441f45ac9ca1ba39f04c7f8d1f9fc79de5b.tar.xz
ice-404a9441f45ac9ca1ba39f04c7f8d1f9fc79de5b.zip
Added ThreadControl::detach().
Diffstat (limited to 'cpp/test')
-rw-r--r--cpp/test/IceUtil/thread/DetachTest.cpp97
-rw-r--r--cpp/test/IceUtil/thread/DetachTest.h31
-rw-r--r--cpp/test/IceUtil/thread/Makefile1
-rw-r--r--cpp/test/IceUtil/thread/TestSuite.cpp2
4 files changed, 131 insertions, 0 deletions
diff --git a/cpp/test/IceUtil/thread/DetachTest.cpp b/cpp/test/IceUtil/thread/DetachTest.cpp
new file mode 100644
index 00000000000..bd7a5499f99
--- /dev/null
+++ b/cpp/test/IceUtil/thread/DetachTest.cpp
@@ -0,0 +1,97 @@
+// **********************************************************************
+//
+// Copyright (c) 2002
+// ZeroC, Inc.
+// Billerica, MA, USA
+//
+// All Rights Reserved.
+//
+// Ice is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation.
+//
+// **********************************************************************
+
+#include <IceUtil/IceUtil.h>
+
+#include <stdio.h>
+
+#include <DetachTest.h>
+#include <TestCommon.h>
+
+using namespace std;
+using namespace IceUtil;
+
+static const string createTestName("thread detach");
+
+class DetachTestThread : public Thread
+{
+public:
+
+ DetachTestThread()
+ {
+ }
+
+ virtual void run()
+ {
+ }
+};
+
+typedef Handle<DetachTestThread> DetachTestThreadPtr;
+
+DetachTest::DetachTest() :
+ TestBase(createTestName)
+{
+}
+
+void
+DetachTest::run()
+{
+ //
+ // Check that calling join() more than once raises ThreadSyscallException.
+ //
+ DetachTestThreadPtr t = new DetachTestThread();
+ ThreadControl control = t->start();
+ control.join();
+ bool gotException = false;
+ try {
+ control.join();
+ }
+ catch(const ThreadSyscallException&)
+ {
+ gotException = true;
+ }
+ test(gotException);
+
+ //
+ // Check that calling detach() more than once raises ThreadSyscallException.
+ //
+ t = new DetachTestThread();
+ control = t->start();
+ control.detach();
+ gotException = false;
+ try {
+ control.detach();
+ }
+ catch(const ThreadSyscallException&)
+ {
+ gotException = true;
+ }
+ test(gotException);
+
+ //
+ // Check that calling join() after detach() raises ThreadSyscallException.
+ //
+ t = new DetachTestThread();
+ control = t->start();
+ control.detach();
+ gotException = false;
+ try {
+ control.join();
+ }
+ catch(const ThreadSyscallException&)
+ {
+ gotException = true;
+ }
+ test(gotException);
+}
diff --git a/cpp/test/IceUtil/thread/DetachTest.h b/cpp/test/IceUtil/thread/DetachTest.h
new file mode 100644
index 00000000000..b7b844ad9b4
--- /dev/null
+++ b/cpp/test/IceUtil/thread/DetachTest.h
@@ -0,0 +1,31 @@
+// **********************************************************************
+//
+// Copyright (c) 2002
+// ZeroC, Inc.
+// Billerica, MA, USA
+//
+// All Rights Reserved.
+//
+// Ice is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation.
+//
+// **********************************************************************
+
+#ifndef DETACH_TEST_H
+#define DETACH_TEST_H
+
+#include <TestBase.h>
+
+class DetachTest : public TestBase
+{
+public:
+
+ DetachTest();
+
+private:
+
+ virtual void run();
+};
+
+#endif
diff --git a/cpp/test/IceUtil/thread/Makefile b/cpp/test/IceUtil/thread/Makefile
index 6beeb239e7c..ad5fa17752b 100644
--- a/cpp/test/IceUtil/thread/Makefile
+++ b/cpp/test/IceUtil/thread/Makefile
@@ -20,6 +20,7 @@ TARGETS = $(CLIENT)
OBJS = TestBase.o \
CreateTest.o \
+ DetachTest.o \
RWRecMutexTest.o \
RecMutexTest.o \
MutexTest.o \
diff --git a/cpp/test/IceUtil/thread/TestSuite.cpp b/cpp/test/IceUtil/thread/TestSuite.cpp
index 582509f9c9f..09d4e82fff6 100644
--- a/cpp/test/IceUtil/thread/TestSuite.cpp
+++ b/cpp/test/IceUtil/thread/TestSuite.cpp
@@ -17,6 +17,7 @@
#include <RecMutexTest.h>
#include <RWRecMutexTest.h>
#include <CreateTest.h>
+#include <DetachTest.h>
#include <MonitorMutexTest.h>
#include <MonitorRecMutexTest.h>
@@ -26,6 +27,7 @@ void
initializeTestSuite()
{
allTests.push_back(new CreateTest);
+ allTests.push_back(new DetachTest);
allTests.push_back(new MutexTest);
allTests.push_back(new RecMutexTest);
allTests.push_back(new RWRecMutexTest);