update dev300-m58
[ooovba.git] / testshl2 / workben / examples / testshl_test.cxx
bloba2acc68b4a08c7ab5ee5cac2f5d1348408a9a416
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: testshl_test.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_testshl2.hxx"
34 #include <stdio.h>
36 #ifdef WNT
37 // #define UNDER_WINDOWS_DEBUGGING
38 // Nice feature, to debug under windows, install msdev locally and use DebugBreak() to stop a new process at a point you want.
39 #ifdef UNDER_WINDOWS_DEBUGGING
40 #include <tools/presys.h>
41 #include <windows.h>
42 #include <tools/postsys.h>
44 #define VCL_NEED_BASETSD
46 #endif /* UNDER_WINDOWS_DEBUGGING */
47 #endif /* WNT */
50 #include <vector>
53 #ifndef _SAL_TRES_H_
54 #include <rtl/tres.h>
55 #endif
57 #ifndef _TESTSHL_TSTMGR_H_
58 #include "tstmgr.h"
59 #endif
61 #ifndef _RTL_STRING_HXX_
62 #include <rtl/string.hxx>
63 #endif
65 #include <osl/time.h>
67 using namespace std;
70 /**
71 * create bitmap of comandline parameters
73 sal_uInt32 createFlags( vector< sal_Char* > const& cmdln )
75 sal_uInt32 retflags = rtl_tres_Flag_OK;
77 vector< sal_Char* >::const_iterator iter = cmdln.begin();
78 while( iter != cmdln.end() )
80 fprintf( stderr, "%s\n", *iter );
81 if ( *iter[0] == '-' )
83 rtl::OString item( *iter );
84 if ( item == "-boom" )
85 retflags |= rtl_tres_Flag_BOOM;
87 if ( item == "-verbose" )
88 retflags |= rtl_tres_Flag_VERBOSE;
90 if ( item == "-skip" )
91 retflags |= rtl_tres_Flag_SKIP;
93 if ( item == "-log" )
94 retflags |= rtl_tres_Flag_LOG;
96 if ( item == "-his" )
97 retflags |= rtl_tres_Flag_HIS;
99 if ( item == "-time" )
100 retflags |= rtl_tres_Flag_TIME;
102 if ( item == "-msg" )
103 retflags |= rtl_tres_Flag_MSG;
105 if ( item == "-quiet" )
106 retflags |= rtl_tres_Flag_QUIET;
108 iter++;
111 return retflags;
114 sal_uInt32 createFlags(int argc, char* argv[])
116 vector< sal_Char* > cmdln;
117 sal_Int32 i;
119 /* collect comandline */
120 for ( i = 1; i < argc; i++ )
121 cmdln.push_back( argv[i] );
123 return createFlags(cmdln);
126 // -----------------------------------------------------------------------------
129 * display usage screen
132 void usage()
134 fprintf( stdout,
135 "USAGE: testshl shlname scename [-boom][-verbose][-log][-his][-msg]\n" );
136 exit(0);
140 #include <fstream>
141 #include <cppunit/TestFixture.h>
142 #include <cppunit/TestCaller.h>
143 #include <cppunit/TestSuite.h>
144 #include <cppunit/TestAssert.h>
145 #include <cppunit/result/TestResult.h>
146 #include <cppunit/result/TestResultCollector.h>
147 #include <cppunit/result/TextTestResult.h>
149 namespace CppunitTest
151 class AStringTest : public CppUnit::TestCase
153 rtl::OString *m_pStr;
154 public:
155 AStringTest()
156 :m_pStr(NULL) {}
158 void setUp()
160 m_pStr = new rtl::OString("test1");
161 // throw std::exception("initialization failed.");
164 void tearDown()
166 delete m_pStr;
169 void testEquality()
171 CPPUNIT_ASSERT( *m_pStr == "test1" );
172 CPPUNIT_ASSERT( (*m_pStr).equalsIgnoreAsciiCase("Test1") );
173 CPPUNIT_ASSERT( (*m_pStr).equalsIgnoreAsciiCase("Test2") );
174 CPPUNIT_ASSERT( *m_pStr == "test1" );
175 CPPUNIT_ASSERT( *m_pStr == "must also fail" );
177 void testEquality2()
179 rtl::OString aStr("test2");
180 CPPUNIT_ASSERT( aStr == "test2" );
181 CPPUNIT_ASSERT_MESSAGE("ein vergleichstest", aStr == "test2");
182 CPPUNIT_ASSERT( aStr == "must also fail" );
184 void testThrow()
186 throw std::exception("an own exception!");
187 CPPUNIT_ASSERT( *m_pStr == "test2" );
191 CppUnit::TestSuite *suite1()
193 CppUnit::TestSuite *suite = new CppUnit::TestSuite( "AStringTest" );
195 // CppUnit::TestSuite suite;
196 // CppUnit::TextTestResult result;
198 suite->addTest( new CppUnit::TestCaller<AStringTest>( "throw test", &AStringTest::testThrow ));
199 // suite->addTest( new CppUnit::TestCaller<AStringTest>( "test op eq", &AStringTest::testEquality ));
200 // suite->addTest( new CppUnit::TestCaller<AStringTest>( "test op eq", &AStringTest::testEquality2 ));
202 return suite;
205 // -----------------------------------------------------------------------------
207 class ASimpleTest : public CppUnit::TestCase
209 public:
210 void testEqual()
212 CPPUNIT_ASSERT( 1 == 1 );
216 CppUnit::TestSuite *suite2()
218 CppUnit::TestSuite *suite = new CppUnit::TestSuite( "A simple test" );
220 // CppUnit::TestSuite suite;
221 // CppUnit::TextTestResult result;
223 suite->addTest( new CppUnit::TestCaller<ASimpleTest>( "1 == 1", &ASimpleTest::testEqual ));
225 return suite;
228 // -----------------------------------------------------------------------------
230 CppUnit::TestSuite *suite()
232 CppUnit::TestSuite *suite = new CppUnit::TestSuite( "A simple test" );
234 // CppUnit::TestSuite suite;
235 // CppUnit::TextTestResult result;
237 suite->addTest( suite1() );
238 // suite->addTest( suite2() );
240 return suite;
244 void cppunitbased_test()
247 // ofstream out("c:\\temp\\output.txt", ios::out);
248 CppUnit::TextTestResult aResult;
250 CppUnit::TestSuite* pSuite = CppunitTest::suite();
252 int nTests = pSuite->countTestCases();
253 pSuite->run(&aResult);
255 // aResult.print(out);
256 cout << aResult;
258 delete pSuite;
261 exit(1);
264 // ----------------------------------- Main -----------------------------------
265 #if (defined UNX) || (defined OS2)
266 int main( int argc, char* argv[] )
267 #else
268 int _cdecl main( int argc, char* argv[] )
269 #endif
271 cppunitbased_test();
273 tslTestManager hMgr = 0;
275 /* show usage screen if too less parameters */
276 if ( argc < 3 )
277 usage();
279 #ifdef UNDER_WINDOWS_DEBUGGING
280 DebugBreak();
281 #endif
283 sal_uInt32 nCmdlinebitflags = createFlags( argc, argv );
285 hMgr = tsl_TestManager_create( argv, argc, nCmdlinebitflags );
286 tsl_TestManager_run( hMgr );
287 tsl_TestManager_destroy( hMgr );
288 return 0;