xref: /aoo42x/main/soltools/testSHL/util/tstMgr.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_soltools.hxx"
30 #include "tstMgr.hxx"
31 #include <osl/module.hxx>
32 #include <rtl/tres.hxx>
33 
34 #ifndef _SOLTOOLS_TESTSHL_TLOG_HXX_
35 #include "tlog.hxx"
36 #endif
37 
38 #ifndef _SOLTOOLS_TESTSHL_TUTIL_HXX_
39 #include "tutil.hxx"
40 #endif
41 
42 using namespace rtl;
43 
44 // <namespace_tstutl>
45 namespace tstutl {
46 
47 typedef void* ( tstFunc )( TestResult* );
48 void test_Entry_Impl( ::osl::Module& oMod, TestResult* oRes );
49 
50 // <private_members>
51 struct tstMgr::tstMgr_Impl {
52     ::osl::Module m_tstmodule;
53     sal_Bool m_boom;
54 };
55 // </private_members>
56 
57 // <method_initialize>
58 sal_Bool tstMgr::initialize( sal_Char* modName, sal_Bool boom ) {
59 
60     ::rtl::OUString tstMod( ::rtl::OUString::createFromAscii( modName ) );
61     pImpl = new tstMgr_Impl;
62     pImpl->m_boom = boom;
63     return ( pImpl->m_tstmodule.load( tstMod ) );
64 } // <method_initialize>
65 
66 // <method_test_Entries>
67 sal_Bool tstMgr::test_Entries( vector< sal_Char* > entries,
68                                                         sal_Char* logName ) {
69 
70     sal_Bool bOK = sal_False;
71     if ( ! entries.empty() ) {
72 
73         bOK = sal_True;
74         vector< sal_Char* >::iterator iter = entries.begin();
75 
76         tLog log( logName );
77         // open testLog
78         log.open();
79             while ( iter != entries.end() ) {
80                 if ( *iter[0] != '#' ) {
81                     ::rtl::TestResult oRes( *iter, pImpl->m_boom );
82                     test_Entry_Impl( pImpl->m_tstmodule, &oRes );
83                     bOK &= oRes.getState();
84                     log.writeRes( oRes );
85                 }
86 				iter++;
87             }
88         log.close();
89     }
90     return ( bOK );
91 } // </method_test_Entries>
92 
93 // <method_test_Entry>
94 sal_Bool tstMgr::test_Entry( sal_Char* entry, sal_Char* logName ) {
95 
96     tLog log( logName );
97     // open testLog
98     log.open();
99     ::rtl::TestResult oRes( entry, pImpl->m_boom );
100     test_Entry_Impl( pImpl->m_tstmodule, &oRes );
101     log.writeRes( oRes, sal_True );
102     log.close();
103     return ( oRes.getState() );
104 } // </method_test_Entry>
105 
106 // <method_test_EntriesFromFile>
107 sal_Bool tstMgr::test_EntriesFromFile( sal_Char* fName, sal_Char* logName ) {
108 
109     sal_Bool bOK = sal_False;
110     vector< sal_Char* > entries;
111 
112     if ( getEntriesFromFile( fName, entries ) ) {
113         sal_Bool bOK = test_Entries( entries, logName );
114 
115         vector< sal_Char* >::iterator iter =  entries.begin();
116         while ( iter != entries.end() ) {
117             if ( *iter ) {
118                 delete [] *iter;
119             }
120             iter++;
121         }
122     }
123     else  {
124         bOK = test_Entry( fName );
125     }
126     return ( bOK );
127 
128 } // </method_test_EntriesFromFile>
129 
130 // <method_cleanup>
131 void tstMgr::cleanup() {
132     if ( pImpl ) {
133         delete pImpl;
134     }
135 } // </method_cleanup>
136 
137 
138 // <function_test_Entry_Impl>
139 void test_Entry_Impl( ::osl::Module& oMod, ::rtl::TestResult* oRes ) {
140 
141     tstFunc* pFunc;                             // entry pointer
142     ::rtl::OString entryName( "test_" );        // entryname prefix
143 
144     // prefix entryname
145     entryName += oRes->getName();
146 
147     // get entry pointer
148     pFunc = (tstFunc*) oMod.getSymbol(
149                     ::rtl::OUString::createFromAscii( entryName.getStr() ) );
150 
151     if ( pFunc ) {
152         // call entry
153         pFunc( oRes );
154         oRes->end();
155     }
156     else  {
157         oRes->end("symbol not found");
158     }
159     // return
160     return;
161 
162 } // </function_test_Entry_Impl>
163 
164 } // </namespace_tstutl>
165