1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: testshl_test.cxx,v $
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"
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>
42 #include <tools/postsys.h>
44 #define VCL_NEED_BASETSD
46 #endif /* UNDER_WINDOWS_DEBUGGING */
57 #ifndef _TESTSHL_TSTMGR_H_
61 #ifndef _RTL_STRING_HXX_
62 #include <rtl/string.hxx>
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
;
94 retflags
|= rtl_tres_Flag_LOG
;
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
;
114 sal_uInt32
createFlags(int argc
, char* argv
[])
116 vector
< sal_Char
* > cmdln
;
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
135 "USAGE: testshl shlname scename [-boom][-verbose][-log][-his][-msg]\n" );
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
;
160 m_pStr
= new rtl::OString("test1");
161 // throw std::exception("initialization failed.");
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" );
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" );
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 ));
205 // -----------------------------------------------------------------------------
207 class ASimpleTest
: public CppUnit::TestCase
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
));
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() );
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);
264 // ----------------------------------- Main -----------------------------------
265 #if (defined UNX) || (defined OS2)
266 int main( int argc
, char* argv
[] )
268 int _cdecl
main( int argc
, char* argv
[] )
273 tslTestManager hMgr
= 0;
275 /* show usage screen if too less parameters */
279 #ifdef UNDER_WINDOWS_DEBUGGING
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
);