1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include "basictest.hxx"
11 #include <osl/file.hxx>
12 #include <basic/sbmod.hxx>
13 #include <basic/sbmeth.hxx>
14 #include <i18nlangtag/languagetag.hxx>
15 #include <unotools/syslocaleoptions.hxx>
20 class Coverage
: public test::BootstrapFixture
24 OUString m_sCurrentTest
;
25 void process_directory(const OUString
& sDirName
);
26 void run_test(const OUString
& sFileName
);
29 std::vector
< OUString
> get_subdirnames( const OUString
& sDirName
);
33 virtual ~Coverage() override
;
35 void Coverage_Iterator();
37 // Adds code needed to register the test suite
38 CPPUNIT_TEST_SUITE(Coverage
);
40 // Declares the method as a test to call
41 CPPUNIT_TEST(Coverage_Iterator
);
43 // End of test suite definition
44 CPPUNIT_TEST_SUITE_END();
48 : BootstrapFixture(true, false)
55 fprintf(stderr
,"basic coverage Summary : pass:%d\n", m_nb_tests_ok
);
58 void Coverage::test_failed()
61 OUStringToOString(m_sCurrentTest
, RTL_TEXTENCODING_UTF8
).getStr());
64 void Coverage::test_success()
67 fprintf(stderr
,"%s,PASS\n", OUStringToOString( m_sCurrentTest
, RTL_TEXTENCODING_UTF8
).getStr() );
70 void Coverage::run_test(const OUString
& sFileURL
)
72 m_sCurrentTest
= sFileURL
;
74 MacroSnippet testMacro
;
75 testMacro
.LoadSourceFromFile( sFileURL
);
77 if( !testMacro
.HasError() )
79 SbxVariableRef pResult
= testMacro
.Run();
80 if( pResult
.Is() && pResult
->GetInteger() == 1 )
95 std::vector
< OUString
> Coverage::get_subdirnames( const OUString
& sDirName
)
97 std::vector
< OUString
> sSubDirNames
;
98 osl::Directory
aDir(sDirName
);
99 osl::DirectoryItem aItem
;
100 osl::FileStatus
aFileStatus(osl_FileStatus_Mask_FileURL
|osl_FileStatus_Mask_Type
);
102 if(osl::FileBase::E_None
== aDir
.open())
104 while (aDir
.getNextItem(aItem
) == osl::FileBase::E_None
)
106 aItem
.getFileStatus(aFileStatus
);
107 if(aFileStatus
.isDirectory())
108 sSubDirNames
.push_back( aFileStatus
.getFileURL() );
113 void Coverage::process_directory(const OUString
& sDirName
)
115 osl::Directory
aDir(sDirName
);
116 osl::DirectoryItem aItem
;
117 osl::FileStatus
aFileStatus(osl_FileStatus_Mask_FileURL
|osl_FileStatus_Mask_Type
);
119 if(osl::FileBase::E_None
== aDir
.open())
121 while (aDir
.getNextItem(aItem
) == osl::FileBase::E_None
)
123 aItem
.getFileStatus(aFileStatus
);
124 if(aFileStatus
.isRegular())
126 run_test(aFileStatus
.getFileURL());
133 fprintf(stderr
,"end process directory\n");
136 void Coverage::Coverage_Iterator()
138 OUString sDirName
= m_directories
.getURLFromSrc("/basic/qa/basic_coverage/");
140 CPPUNIT_ASSERT(!sDirName
.isEmpty());
141 process_directory(sDirName
); // any files in the root test dir are run in test harness default locale ( en-US )
142 std::vector
< OUString
> sLangDirs
= get_subdirnames( sDirName
);
144 for ( std::vector
< OUString
>::iterator it
= sLangDirs
.begin(), it_end
= sLangDirs
.end(); it
!= it_end
; ++it
)
146 OUString
sDir( *it
);
147 sal_Int32 nSlash
= (*it
).lastIndexOf('/');
150 OUString sLangISO
= sDir
.copy( nSlash
+ 1 );
151 LanguageTag
aLocale( sLangISO
);
152 if ( aLocale
.isValidBcp47() )
154 SvtSysLocaleOptions aLocalOptions
;
155 // set locale for test dir
156 aLocalOptions
.SetLocaleConfigString( sLangISO
);
157 process_directory(sDir
);
163 CPPUNIT_TEST_SUITE_REGISTRATION(Coverage
);
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */