summaryrefslogtreecommitdiffstats
path: root/shell/qa
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /shell/qa
parentInitial commit. (diff)
downloadlibreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz
libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--shell/qa/zip/simpledocument.odtbin0 -> 16259 bytes
-rw-r--r--shell/qa/zip/testzipimpl.cxx69
-rw-r--r--shell/qa/zip/testzipimpl.hxx46
-rw-r--r--shell/qa/zip/ziptest.cxx138
4 files changed, 253 insertions, 0 deletions
diff --git a/shell/qa/zip/simpledocument.odt b/shell/qa/zip/simpledocument.odt
new file mode 100644
index 000000000..bf83a648b
--- /dev/null
+++ b/shell/qa/zip/simpledocument.odt
Binary files differ
diff --git a/shell/qa/zip/testzipimpl.cxx b/shell/qa/zip/testzipimpl.cxx
new file mode 100644
index 000000000..8fe27d9ca
--- /dev/null
+++ b/shell/qa/zip/testzipimpl.cxx
@@ -0,0 +1,69 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "testzipimpl.hxx"
+
+TestZipImpl::TestZipImpl(StreamInterface *stream) :
+ zipFile(ZipFile(stream)), expectedContents()
+{
+ expectedContents.push_back("mimetype");
+ expectedContents.push_back("Configurations2/statusbar/");
+ expectedContents.push_back("Configurations2/accelerator/current.xml");
+ expectedContents.push_back("Configurations2/floater/");
+ expectedContents.push_back("Configurations2/popupmenu/");
+ expectedContents.push_back("Configurations2/progressbar/");
+ expectedContents.push_back("Configurations2/toolpanel/");
+ expectedContents.push_back("Configurations2/menubar/");
+ expectedContents.push_back("Configurations2/toolbar/");
+ expectedContents.push_back("Configurations2/images/Bitmaps/");
+ expectedContents.push_back("content.xml");
+ expectedContents.push_back("manifest.rdf");
+ expectedContents.push_back("styles.xml");
+ expectedContents.push_back("meta.xml");
+ expectedContents.push_back("Thumbnails/thumbnail.png");
+ expectedContents.push_back("settings.xml");
+ expectedContents.push_back("META-INF/manifest.xml");
+ sort(expectedContents.begin(), expectedContents.end());
+}
+
+TestZipImpl::~TestZipImpl()
+{
+}
+
+bool TestZipImpl::test_directory()
+{
+ ZipFile::DirectoryPtr_t contents = zipFile.GetDirectory();
+ vector<string> &stringVector = *contents;
+ sort(stringVector.begin(), stringVector.end());
+ return expectedContents == stringVector;
+}
+
+bool TestZipImpl::test_hasContentCaseInSensitive()
+{
+ return zipFile.HasContent("mimetype");
+}
+
+bool TestZipImpl::test_getContent()
+{
+ ZipFile::ZipContentBuffer_t contentBuf;
+ zipFile.GetUncompressedContent("content.xml", contentBuf);
+ return !contentBuf.empty();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/qa/zip/testzipimpl.hxx b/shell/qa/zip/testzipimpl.hxx
new file mode 100644
index 000000000..b0f4b91b1
--- /dev/null
+++ b/shell/qa/zip/testzipimpl.hxx
@@ -0,0 +1,46 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_SHELL_QA_ZIP_TESTZIPIMPL_HXX
+#define INCLUDED_SHELL_QA_ZIP_TESTZIPIMPL_HXX
+
+#include <zipfile.hxx>
+#include <string>
+#include <vector>
+#include <algorithm>
+#include <sal/types.h>
+
+using namespace std;
+
+class TestZipImpl
+{
+ private:
+ ZipFile zipFile;
+ vector<string> expectedContents;
+ public:
+ explicit TestZipImpl(StreamInterface *stream);
+ ~TestZipImpl();
+ bool test_directory();
+ bool test_hasContentCaseInSensitive();
+ bool test_getContent();
+};
+
+#endif // INCLUDED_SHELL_QA_ZIP_TESTZIPIMPL_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/qa/zip/ziptest.cxx b/shell/qa/zip/ziptest.cxx
new file mode 100644
index 000000000..7af18912a
--- /dev/null
+++ b/shell/qa/zip/ziptest.cxx
@@ -0,0 +1,138 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#if !defined WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+#endif
+#include <windows.h>
+#include <ole2.h>
+#include <stdio.h>
+
+#include <cppunit/TestAssert.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+#include <string>
+#include <stream_helper.hxx>
+#include "testzipimpl.hxx"
+using namespace std;
+
+class Test : public CppUnit::TestFixture
+{
+private:
+ wstring documentName;
+ LPSTREAM pStream;
+public:
+ Test();
+ void test_file_directory();
+ void test_file_hasContentCaseInSensitive();
+ void test_file_getContent();
+ void test_stream_directory();
+ void test_stream_hasContentCaseInSensitive();
+ void test_stream_getContent();
+ CPPUNIT_TEST_SUITE(Test);
+ CPPUNIT_TEST(test_file_directory);
+ CPPUNIT_TEST(test_file_hasContentCaseInSensitive);
+ CPPUNIT_TEST(test_file_getContent);
+ CPPUNIT_TEST(test_stream_directory);
+ CPPUNIT_TEST(test_stream_hasContentCaseInSensitive);
+ CPPUNIT_TEST(test_stream_getContent);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(Test);
+
+Test::Test() : documentName(), pStream(nullptr)
+{
+ const wchar_t* pSrcRoot = _wgetenv(L"SRC_ROOT");
+ if (pSrcRoot)
+ {
+ documentName.append(pSrcRoot);
+ documentName.append(L"/");
+ }
+ documentName.append(L"shell/qa/zip/simpledocument.odt");
+
+ // Create an IStream pointer from the file
+ HANDLE hFile = CreateFileW(documentName.c_str(), GENERIC_READ, 0, nullptr, OPEN_EXISTING, 0, nullptr);
+
+ DWORD dwFileSize = GetFileSize(hFile, nullptr);
+ HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
+
+ LPVOID pvData = GlobalLock(hGlobal);
+ DWORD dwBytesRead = 0;
+ bool bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, nullptr);
+ CPPUNIT_ASSERT_MESSAGE("FileStream: ReadFile error.", bRead);
+ GlobalUnlock(hGlobal);
+ CloseHandle(hFile);
+
+ HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("FileStream: CreateStreamOnHGlobal failure.", S_OK, hr);
+}
+
+void Test::test_file_directory()
+{
+ FileStream stream(documentName.c_str());
+ TestZipImpl testImpl(&stream);
+ bool isPassed = testImpl.test_directory();
+ CPPUNIT_ASSERT_MESSAGE("FileStream: Content does not match with expected directory names.", isPassed);
+}
+
+void Test::test_file_hasContentCaseInSensitive()
+{
+ FileStream stream(documentName.c_str());
+ TestZipImpl testImpl(&stream);
+ bool isPassed = testImpl.test_hasContentCaseInSensitive();
+ CPPUNIT_ASSERT_MESSAGE("FileStream: Content in zip file was not found.", isPassed);
+}
+
+void Test::test_file_getContent()
+{
+ FileStream stream(documentName.c_str());
+ TestZipImpl testImpl(&stream);
+ bool isPassed = testImpl.test_getContent();
+ CPPUNIT_ASSERT_MESSAGE("FileStream: Couldn't receive content buffer from zipfile.", isPassed);
+}
+
+void Test::test_stream_directory()
+{
+ BufferStream stream(pStream);
+ TestZipImpl testImpl(&stream);
+ bool isPassed = testImpl.test_directory();
+ CPPUNIT_ASSERT_MESSAGE("BufferStream: Content does not match with expected directory names.", isPassed);
+}
+
+void Test::test_stream_hasContentCaseInSensitive()
+{
+ BufferStream stream(pStream);
+ TestZipImpl testImpl(&stream);
+ bool isPassed = testImpl.test_hasContentCaseInSensitive();
+ CPPUNIT_ASSERT_MESSAGE("BufferStream: Content in zip file was not found.", isPassed);
+}
+
+void Test::test_stream_getContent()
+{
+ BufferStream stream(pStream);
+ TestZipImpl testImpl(&stream);
+ bool isPassed = testImpl.test_getContent();
+ CPPUNIT_ASSERT_MESSAGE("BufferStream: Couldn't receive content buffer from zipfile.", isPassed);
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */