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 <i18nlangtag/languagetag.hxx>
13 #include <unotools/syslocaleoptions.hxx>
18 class Coverage
: public test::BootstrapFixture
21 void process_directory(const OUString
& sDirName
);
22 std::vector
< OUString
> get_subdirnames( const OUString
& sDirName
);
27 void Coverage_Iterator();
29 // Adds code needed to register the test suite
30 CPPUNIT_TEST_SUITE(Coverage
);
32 // Declares the method as a test to call
33 CPPUNIT_TEST(Coverage_Iterator
);
35 // End of test suite definition
36 CPPUNIT_TEST_SUITE_END();
40 : BootstrapFixture(true, false)
44 std::vector
< OUString
> Coverage::get_subdirnames( const OUString
& sDirName
)
46 std::vector
< OUString
> sSubDirNames
;
47 osl::Directory
aDir(sDirName
);
48 osl::DirectoryItem aItem
;
49 osl::FileStatus
aFileStatus(osl_FileStatus_Mask_FileURL
|osl_FileStatus_Mask_Type
);
51 if(aDir
.open() == osl::FileBase::E_None
)
53 while (aDir
.getNextItem(aItem
) == osl::FileBase::E_None
)
55 aItem
.getFileStatus(aFileStatus
);
56 if(aFileStatus
.isDirectory())
57 sSubDirNames
.push_back( aFileStatus
.getFileURL() );
62 void Coverage::process_directory(const OUString
& sDirName
)
64 osl::Directory
aDir(sDirName
);
65 osl::DirectoryItem aItem
;
66 osl::FileStatus
aFileStatus(osl_FileStatus_Mask_FileURL
|osl_FileStatus_Mask_Type
);
67 OUString sMacroUtilsURL
= m_directories
.getURLFromSrc(u
"basic/qa/cppunit/_test_asserts.bas");
69 if(aDir
.open() == osl::FileBase::E_None
)
71 while (aDir
.getNextItem(aItem
) == osl::FileBase::E_None
)
73 aItem
.getFileStatus(aFileStatus
);
74 if(aFileStatus
.isRegular())
76 OUString sFileURL
= aFileStatus
.getFileURL();
77 if (sFileURL
.endsWith(".bas"))
79 MacroSnippet testMacro
;
80 testMacro
.LoadSourceFromFile("TestUtil", sMacroUtilsURL
);
81 testMacro
.LoadSourceFromFile("TestModule", sFileURL
);
82 SbxVariableRef pReturn
= testMacro
.Run();
83 CPPUNIT_ASSERT_MESSAGE("No return variable huh?", pReturn
.is());
84 fprintf(stderr
, "macro result for %s\n", OUStringToOString(sFileURL
,RTL_TEXTENCODING_UTF8
).getStr());
85 fprintf(stderr
, "macro returned:\n%s\n",
86 OUStringToOString(pReturn
->GetOUString(), RTL_TEXTENCODING_UTF8
).getStr());
87 CPPUNIT_ASSERT_EQUAL_MESSAGE("Result not as expected", OUString("OK"),
88 pReturn
->GetOUString());
93 fprintf(stderr
,"end process directory\n");
96 void Coverage::Coverage_Iterator()
98 OUString sDirName
= m_directories
.getURLFromSrc(u
"basic/qa/basic_coverage");
100 CPPUNIT_ASSERT(!sDirName
.isEmpty());
101 process_directory(sDirName
); // any files in the root test dir are run in test harness default locale ( en-US )
102 std::vector
< OUString
> sLangDirs
= get_subdirnames( sDirName
);
104 for (auto const& langDir
: sLangDirs
)
106 sal_Int32 nSlash
= langDir
.lastIndexOf('/');
109 OUString sLangISO
= langDir
.copy( nSlash
+ 1 );
110 LanguageTag
aLocale( sLangISO
);
111 if ( aLocale
.isValidBcp47() )
113 SvtSysLocaleOptions aLocalOptions
;
114 // set locale for test dir
115 aLocalOptions
.SetLocaleConfigString( sLangISO
);
116 process_directory(langDir
);
122 CPPUNIT_TEST_SUITE_REGISTRATION(Coverage
);
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */