|
From: <mik...@us...> - 2003-12-24 13:03:59
|
Update of /cvsroot/sharedaemon/sharedaemon-ui-web/src/test
In directory sc8-pr-cvs1:/tmp/cvs-serv659/src/test
Modified Files:
TestException.cpp TestException.h TestHandler.h
Added Files:
TestThread.cpp TestThread.h
Log Message:
24/12/2003 Barbeaux
* Added simple test programs for Exceptions and Threads.
* Implemented Semaphore and Thread.
--- NEW FILE: TestThread.cpp ---
/*
* This file is part of webInterface.
* Copyright (C) 2003 Mikael Barbeaux <mik...@us...>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "TestThread.h"
#include <iostream>
using namespace std;
#include <stdio.h>
/**
* Constructor for TestThread.
*/
TestThread::TestThread() : TestHandler(), Thread() {
}
/**
* Destructor for TestThread.
*/
TestThread::~TestThread() throw (ThreadException) {
}
/**
* Runs the thread.
*/
void TestThread::run() {
cout << "I am the thread, running 5 seconds..." << endl;
for(int i=0;i<5;i++) {
cout << "Thread says : \"Hello world !\"" << endl;
Thread::sleep(1);
}
cout << "Thread has finished !" << endl;
}
/**
* Runs the tester.
*/
void TestThread::test() {
/** This test tries to launch a thread
* and goes on working. */
cout << endl;
cout << "ShareDaemon Web Interface - Test" << endl << endl;
cout << "Test for threads... " << endl;
cout << "A thread saying \"Hello world !\" will start to run for 5 seconds, " << endl;
cout << "while the main thread will display \"Tester is working\". After " << endl;
cout << "5 seconds, the thread should stop and the tester will goes" << endl;
cout << "on working for 5 others seconds before exiting." << endl;
cout << "Press enter to continue" << endl;
getchar();
cout << endl << endl;
try {
// Launching the thread
start();
// Goes on working
for(int i=0;i<10;i++) {
cout << "Tester is working..." << endl;
Thread::sleep(1);
}
cout << "Tester has finished !" << endl << endl;
}
catch(Exception& e) {
// display the exception message
cout << e.getMessage() << endl;
}
cout << "Did you see the thread working ?" << endl;
cout << " If no => VERY BAD :(" << endl;
cout << " If yes => Test worked !! :D" << endl << endl;
cout << "Press enter to continue" << endl;
getchar();
}
--- NEW FILE: TestThread.h ---
/*
* This file is part of webInterface.
* Copyright (C) 2003 Mikael Barbeaux <mik...@us...>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _TEST_THREAD_H_
#define _TEST_THREAD_H_
#include "TestHandler.h"
#include "../thread/Thread.h"
#include "../exceptions/ThreadException.h"
/**
* Defines a test class for threading.
* Herits from TestHandler ( it's a test class ) and from
* Thread ( this tester is itself a Thread ).
*/
class TestThread : public TestHandler, public Thread {
public:
/**
* Creates a test for threading.
*/
TestThread();
/**
* Destructor for TestThread
*/
~TestThread() throw (ThreadException);
/**
* Runs the thread.
*/
virtual void run();
/**
* Runs the tester.
*/
virtual void test();
};
#endif
Index: TestException.cpp
===================================================================
RCS file: /cvsroot/sharedaemon/sharedaemon-ui-web/src/test/TestException.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- TestException.cpp 24 Dec 2003 11:52:49 -0000 1.2
+++ TestException.cpp 24 Dec 2003 13:03:55 -0000 1.3
@@ -22,6 +22,7 @@
#include "../exceptions/ThreadException.h"
#include <iostream>
using namespace std;
+#include <stdio.h>
/**
* Creates a TestException object.
@@ -32,20 +33,29 @@
/**
* Runs the tester.
*/
-void TestException::run() {
+void TestException::test() {
/** This test tries to launch an exception
* and to catch it. Then it displays the message
* sent by the exception before exiting. */
- //cout << "Start of TestException" <<endl;
+ cout << endl;
+ cout << "ShareDaemon Web Interface - Test" << endl << endl;
+ cout << "Test for exceptions... " << endl;
+ cout << "The program will now try to throw an exception, and then" << endl;
+ cout << "will try to catch it. So don't worry if the console says an" <<endl;
+ cout << "exception occured, it's totally normal !!" << endl;
+ cout << "Press enter to continue" << endl;
+ getchar();
+ cout << endl << endl;
try {
- //cout << "Throws exception" << endl;
- throw ThreadException(MutexError, "MutexError test", "TestException::run");
- //cout << "Exception hasn't been thrown" << endl;
+ throw ThreadException(MutexExcp, "MutexError - Only a test !!", "TestException::run");
}
catch(Exception& e) {
- //cout << "Exception catched" << endl;
// display the exception message
cout << e.getMessage() << endl;
}
- //cout << "End of TestException" << endl;
+ cout << "Did you see the exception ?" << endl;
+ cout << " If no => VERY BAD :(" << endl;
+ cout << " If yes => Test worked !! :D" << endl << endl;
+ cout << "Press enter to continue" << endl;
+ getchar();
}
Index: TestException.h
===================================================================
RCS file: /cvsroot/sharedaemon/sharedaemon-ui-web/src/test/TestException.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- TestException.h 24 Dec 2003 10:49:48 -0000 1.1
+++ TestException.h 24 Dec 2003 13:03:55 -0000 1.2
@@ -40,7 +40,7 @@
/**
* Runs the tester.
*/
- virtual void run();
+ virtual void test();
};
#endif
Index: TestHandler.h
===================================================================
RCS file: /cvsroot/sharedaemon/sharedaemon-ui-web/src/test/TestHandler.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- TestHandler.h 24 Dec 2003 10:49:48 -0000 1.1
+++ TestHandler.h 24 Dec 2003 13:03:55 -0000 1.2
@@ -44,7 +44,7 @@
* Runs the test
* Needs to be implemented into subclasses.
*/
- virtual void run() = 0;
+ virtual void test() = 0;
};
|