Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / shell / qa / zip / ziptest.cxx
blobf76acf7c916c48e17b3ed38487a994ed8e8b27f3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #if !defined WIN32_LEAN_AND_MEAN
21 # define WIN32_LEAN_AND_MEAN
22 #endif
23 #include <windows.h>
24 #include <ole2.h>
25 #include <stdio.h>
27 #include <cppunit/TestAssert.h>
28 #include <cppunit/TestFixture.h>
29 #include <cppunit/extensions/HelperMacros.h>
30 #include <cppunit/plugin/TestPlugIn.h>
31 #include <string>
32 #include <stream_helper.hxx>
33 #include "testzipimpl.hxx"
34 using namespace std;
36 class Test : public CppUnit::TestFixture
38 private:
39 wstring documentName;
40 LPSTREAM pStream;
41 public:
42 Test();
43 void test_file_directory();
44 void test_file_hasContentCaseInSensitive();
45 void test_file_getContent();
46 void test_stream_directory();
47 void test_stream_hasContentCaseInSensitive();
48 void test_stream_getContent();
49 CPPUNIT_TEST_SUITE(Test);
50 CPPUNIT_TEST(test_file_directory);
51 CPPUNIT_TEST(test_file_hasContentCaseInSensitive);
52 CPPUNIT_TEST(test_file_getContent);
53 CPPUNIT_TEST(test_stream_directory);
54 CPPUNIT_TEST(test_stream_hasContentCaseInSensitive);
55 CPPUNIT_TEST(test_stream_getContent);
56 CPPUNIT_TEST_SUITE_END();
59 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
61 Test::Test() : documentName(), pStream(nullptr)
63 const wchar_t* pSrcRoot = _wgetenv(L"SRC_ROOT");
64 if (pSrcRoot)
66 documentName.append(pSrcRoot);
67 documentName.append(L"/");
69 documentName.append(L"shell/qa/zip/simpledocument.odt");
71 // Create an IStream pointer from the file
72 HANDLE hFile = CreateFileW(documentName.c_str(), GENERIC_READ, 0, nullptr, OPEN_EXISTING, 0, nullptr);
74 DWORD dwFileSize = GetFileSize(hFile, nullptr);
75 HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
77 LPVOID pvData = GlobalLock(hGlobal);
78 DWORD dwBytesRead = 0;
79 BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, nullptr);
80 CPPUNIT_ASSERT_MESSAGE("FileStream: ReadFile error.", bRead);
81 GlobalUnlock(hGlobal);
82 CloseHandle(hFile);
84 HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);
85 CPPUNIT_ASSERT_EQUAL_MESSAGE("FileStream: CreateStreamOnHGlobal failure.", S_OK, hr);
88 void Test::test_file_directory()
90 FileStream stream(documentName.c_str());
91 TestZipImpl testImpl(&stream);
92 bool isPassed = testImpl.test_directory();
93 CPPUNIT_ASSERT_MESSAGE("FileStream: Content does not match with expected directory names.", isPassed);
96 void Test::test_file_hasContentCaseInSensitive()
98 FileStream stream(documentName.c_str());
99 TestZipImpl testImpl(&stream);
100 bool isPassed = testImpl.test_hasContentCaseInSensitive();
101 CPPUNIT_ASSERT_MESSAGE("FileStream: Content in zip file was not found.", isPassed);
104 void Test::test_file_getContent()
106 FileStream stream(documentName.c_str());
107 TestZipImpl testImpl(&stream);
108 bool isPassed = testImpl.test_getContent();
109 CPPUNIT_ASSERT_MESSAGE("FileStream: Couldn't receive content buffer from zipfile.", isPassed);
112 void Test::test_stream_directory()
114 BufferStream stream(pStream);
115 TestZipImpl testImpl(&stream);
116 bool isPassed = testImpl.test_directory();
117 CPPUNIT_ASSERT_MESSAGE("BufferStream: Content does not match with expected directory names.", isPassed);
120 void Test::test_stream_hasContentCaseInSensitive()
122 BufferStream stream(pStream);
123 TestZipImpl testImpl(&stream);
124 bool isPassed = testImpl.test_hasContentCaseInSensitive();
125 CPPUNIT_ASSERT_MESSAGE("BufferStream: Content in zip file was not found.", isPassed);
128 void Test::test_stream_getContent()
130 BufferStream stream(pStream);
131 TestZipImpl testImpl(&stream);
132 bool isPassed = testImpl.test_getContent();
133 CPPUNIT_ASSERT_MESSAGE("BufferStream: Couldn't receive content buffer from zipfile.", isPassed);
136 CPPUNIT_PLUGIN_IMPLEMENT();
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */