16#include <osl/file.hxx>
17#include <osl/thread.h>
18#include <rtl/cipher.h>
20#include <cppunit/TestAssert.h>
24static void decode(
const OUString& rIn,
const OUString &rOut)
26 rtlCipher cipher = rtl_cipher_create(rtl_Cipher_AlgorithmARCFOUR, rtl_Cipher_ModeStream);
27 CPPUNIT_ASSERT_MESSAGE(
"cipher creation failed", cipher !=
nullptr);
30 const sal_uInt8 aKey[3] = {
'C',
'V',
'E'};
32 rtlCipherError
result = rtl_cipher_init(cipher, rtl_Cipher_DirectionDecode, aKey, std::size(aKey),
nullptr, 0);
34 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"cipher init failed", rtl_Cipher_E_None,
result);
37 CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, aIn.open(osl_File_OpenFlag_Read));
40 CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, aOut.open(osl_File_OpenFlag_Write));
44 sal_uInt64 nBytesRead, nBytesWritten;
47 CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, aIn.read(
in,
sizeof(
in), nBytesRead));
50 CPPUNIT_ASSERT_EQUAL(rtl_Cipher_E_None, rtl_cipher_decode(cipher,
in, nBytesRead, out,
sizeof(out)));
51 CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, aOut.write(out, nBytesRead, nBytesWritten));
52 CPPUNIT_ASSERT_EQUAL(nBytesRead, nBytesWritten);
55 rtl_cipher_destroy(cipher);
59 const OUString &rFilter,
const OUString &rURL,
63 osl::Directory aDir(rURL);
65 CPPUNIT_ASSERT_EQUAL_MESSAGE(OUString(
"Failed to open directory " + rURL).toUtf8().getStr(), osl::FileBase::E_None, aDir.open());
66 osl::DirectoryItem aItem;
67 osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileURL|osl_FileStatus_Mask_Type);
68 std::set<OUString> dirs;
69 std::set<OUString> files;
70 while (aDir.getNextItem(aItem) == osl::FileBase::E_None)
72 aItem.getFileStatus(aFileStatus);
73 OUString sURL = aFileStatus.getFileURL();
74 if (aFileStatus.getFileType() == osl::FileStatus::Directory)
83 for (
auto const & sURL: dirs) {
85 nFilterFlags, nClipboardID, nFilterVersion, bExport);
87 for (
auto const & sURL: files) {
89 bool bEncrypted =
false;
91 sal_Int32 nLastSlash = sURL.lastIndexOf(
'/');
93 if ((nLastSlash != -1) && (nLastSlash+1 < sURL.getLength()))
96 if (sURL[nLastSlash+1] ==
'.')
100 (sURL.match(
"BID", nLastSlash+1)) ||
101 (sURL.match(
"CVE", nLastSlash+1)) ||
102 (sURL.match(
"EDB", nLastSlash+1)) ||
103 (sURL.match(
"RC4", nLastSlash+1))
111 OString::Concat(bExport ? std::string_view(
"save") : std::string_view(
"load")) +
" "
117 CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, osl::FileBase::createTempFile(
nullptr,
nullptr, &sTmpFile));
128 fprintf(stderr,
"Testing %s:\n", aRes.getStr());
129 sal_uInt32 nStartTime = osl_getGlobalTimer();
132 bRes =
load(rFilter, realUrl, rUserData, nFilterFlags,
133 nClipboardID, nFilterVersion);
135 bRes =
save(rFilter, realUrl, rUserData, nFilterFlags,
136 nClipboardID, nFilterVersion);
137 sal_uInt32 nEndTime = osl_getGlobalTimer();
140 CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, osl::File::remove(sTmpFile));
142 fprintf(stderr,
"Tested %s: %s (%" SAL_PRIuUINT32
"ms)\n",
143 aRes.getStr(), bRes?
"Pass":
"Fail", nEndTime-nStartTime);
147 CPPUNIT_ASSERT_EQUAL_MESSAGE(aRes.getStr(), nExpected, nResult);
149 CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, aDir.close());
153 std::u16string_view rURL,
const OUString &rUserData,
155 unsigned int nFilterVersion,
bool bExport)
158 OUString::Concat(rURL) +
"pass",
159 rUserData, nFilterFlags, nClipboardID, nFilterVersion, bExport);
161 OUString::Concat(rURL) +
"fail",
162 rUserData, nFilterFlags, nClipboardID, nFilterVersion, bExport);
164 OUString::Concat(rURL) +
"indeterminate",
165 rUserData, nFilterFlags, nClipboardID, nFilterVersion, bExport);
virtual bool save(const OUString &, const OUString &, const OUString &, SfxFilterFlags, SotClipboardFormatId, unsigned int)
void recursiveScan(filterStatus nExpected, const OUString &rFilter, const OUString &rURL, const OUString &rUserData, SfxFilterFlags nFilterFlags, SotClipboardFormatId nClipboardID, unsigned int nFilterVersion, bool bExport)
virtual bool load(const OUString &rFilter, const OUString &rURL, const OUString &rUserData, SfxFilterFlags nFilterFlags, SotClipboardFormatId nClipboardID, unsigned int nFilterVersion)=0
void testDir(const OUString &rFilter, std::u16string_view rURL, const OUString &rUserData=OUString(), SfxFilterFlags nFilterFlags=SfxFilterFlags::IMPORT, SotClipboardFormatId nClipboardID=SotClipboardFormatId::NONE, unsigned int nFilterVersion=0, bool bExport=false)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
static void decode(const OUString &rIn, const OUString &rOut)