Revert "Revert "Revert "stronger typing for SwClient::GetRegisteredIn"" and fix SwIte...
[LibreOffice.git] / shell / qa / zip / ziptest.cxx
blobc2eb74222429b80b5e941804aa24cece8008b34b
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"
35 class Test : public CppUnit::TestFixture
37 private:
38 std::wstring documentName;
39 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()
62 : documentName()
63 , pStream(nullptr)
65 const wchar_t* pSrcRoot = _wgetenv(L"SRC_ROOT");
66 if (pSrcRoot)
68 documentName.append(pSrcRoot);
69 documentName.append(L"/");
71 documentName.append(L"shell/qa/zip/simpledocument.odt");
73 // Create an IStream pointer from the file
74 HANDLE hFile
75 = CreateFileW(documentName.c_str(), GENERIC_READ, 0, nullptr, OPEN_EXISTING, 0, nullptr);
77 DWORD dwFileSize = GetFileSize(hFile, nullptr);
78 HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
80 LPVOID pvData = GlobalLock(hGlobal);
81 DWORD dwBytesRead = 0;
82 bool bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, nullptr);
83 CPPUNIT_ASSERT_MESSAGE("FileStream: ReadFile error.", bRead);
84 GlobalUnlock(hGlobal);
85 CloseHandle(hFile);
87 HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);
88 CPPUNIT_ASSERT_EQUAL_MESSAGE("FileStream: CreateStreamOnHGlobal failure.", S_OK, hr);
91 void Test::test_file_directory()
93 FileStream stream(documentName.c_str());
94 TestZipImpl testImpl(&stream);
95 bool isPassed = testImpl.test_directory();
96 CPPUNIT_ASSERT_MESSAGE("FileStream: Content does not match with expected directory names.",
97 isPassed);
100 void Test::test_file_hasContentCaseInSensitive()
102 FileStream stream(documentName.c_str());
103 TestZipImpl testImpl(&stream);
104 bool isPassed = testImpl.test_hasContentCaseInSensitive();
105 CPPUNIT_ASSERT_MESSAGE("FileStream: Content in zip file was not found.", isPassed);
108 void Test::test_file_getContent()
110 FileStream stream(documentName.c_str());
111 TestZipImpl testImpl(&stream);
112 bool isPassed = testImpl.test_getContent();
113 CPPUNIT_ASSERT_MESSAGE("FileStream: Couldn't receive content buffer from zipfile.", isPassed);
116 void Test::test_stream_directory()
118 BufferStream stream(pStream);
119 TestZipImpl testImpl(&stream);
120 bool isPassed = testImpl.test_directory();
121 CPPUNIT_ASSERT_MESSAGE("BufferStream: Content does not match with expected directory names.",
122 isPassed);
125 void Test::test_stream_hasContentCaseInSensitive()
127 BufferStream stream(pStream);
128 TestZipImpl testImpl(&stream);
129 bool isPassed = testImpl.test_hasContentCaseInSensitive();
130 CPPUNIT_ASSERT_MESSAGE("BufferStream: Content in zip file was not found.", isPassed);
133 void Test::test_stream_getContent()
135 BufferStream stream(pStream);
136 TestZipImpl testImpl(&stream);
137 bool isPassed = testImpl.test_getContent();
138 CPPUNIT_ASSERT_MESSAGE("BufferStream: Couldn't receive content buffer from zipfile.", isPassed);
141 CPPUNIT_PLUGIN_IMPLEMENT();
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */