xref: /haiku/headers/tools/cppunit/ThreadedTestCase.h (revision 893988af824e65e49e55f517b157db8386e8002b)
1 #ifndef _beos_threaded_test_case_h_
2 #define _beos_threaded_test_case_h_
3 
4 #include <Locker.h>
5 #include <OS.h>
6 #include <TestCase.h>
7 #include <map>
8 #include <string>
9 #include <vector>
10 
11 //! Base class for single threaded unit tests
12 class CPPUNIT_API BThreadedTestCase : public BTestCase {
13 public:
14 	BThreadedTestCase(std::string Name = "", std::string progressSeparator = ".");
15 	virtual ~BThreadedTestCase();
16 
17 	/*! \brief Displays the next sub test progress indicator for the
18 		thread in which it's called (i.e. [A.0][B.0][A.1][A.2][B.1]...). */
19 	virtual void NextSubTest();
20 
21 	/*! \brief Prints to standard out just like printf, except shell verbosity
22 		settings are honored, and output from threads other than the main thread
23 		happens before the test is over.
24 
25 		\note Currently your output is limited to a length of 1024 characters. If
26 		you really need to print a single string that's long than that, fix the
27 		function yourself :-).
28 	*/
29 	virtual void Outputf(const char *str, ...);
30 
31 	//! Saves the location of the current working directory.
32 	void SaveCWD();
33 
34 	//! Restores the current working directory to last directory saved by a	call to SaveCWD().
35 	void RestoreCWD(const char *alternate = NULL);
36 	void InitThreadInfo(thread_id id, std::string threadName);
37 	bool RegisterForUse();
38 	void UnregisterForUse();
39 
40 	std::vector<std::string>& AcquireUpdateList();
41 	void ReleaseUpdateList();
42 protected:
43 	bool fInUse;
44 
45 //	friend class ThreadManager<BThreadedTestCase>;
46 	std::string fProgressSeparator;
47 
48 	struct ThreadSubTestInfo {
49 		std::string name;
50 		int32 subTestNum;
51 	};
52 	std::map<thread_id, ThreadSubTestInfo*> fNumberMap;
53 	std::vector<std::string> fUpdateList;
54 	BLocker *fUpdateLock;
55 
56 };
57 
58 #endif // _beos_threaded_test_case_h_
59