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/.
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
27 #include <cppunit/TestAssert.h>
28 #include <cppunit/TestFixture.h>
29 #include <cppunit/extensions/HelperMacros.h>
30 #include <cppunit/plugin/TestPlugIn.h>
32 #include <stream_helper.hxx>
33 #include "testzipimpl.hxx"
36 class Test
: public CppUnit::TestFixture
44 void test_file_directory();
45 void test_file_hasContentCaseInSensitive();
46 void test_file_getContent();
47 void test_stream_directory();
48 void test_stream_hasContentCaseInSensitive();
49 void test_stream_getContent();
50 CPPUNIT_TEST_SUITE(Test
);
51 CPPUNIT_TEST(test_file_directory
);
52 CPPUNIT_TEST(test_file_hasContentCaseInSensitive
);
53 CPPUNIT_TEST(test_file_getContent
);
54 CPPUNIT_TEST(test_stream_directory
);
55 CPPUNIT_TEST(test_stream_hasContentCaseInSensitive
);
56 CPPUNIT_TEST(test_stream_getContent
);
57 CPPUNIT_TEST_SUITE_END();
60 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
66 const wchar_t* pSrcRoot
= _wgetenv(L
"SRC_ROOT");
69 documentName
.append(pSrcRoot
);
70 documentName
.append(L
"/");
72 documentName
.append(L
"shell/qa/zip/simpledocument.odt");
74 // Create an IStream pointer from the file
76 = CreateFileW(documentName
.c_str(), GENERIC_READ
, 0, nullptr, OPEN_EXISTING
, 0, nullptr);
78 DWORD dwFileSize
= GetFileSize(hFile
, nullptr);
79 HGLOBAL hGlobal
= GlobalAlloc(GMEM_MOVEABLE
, dwFileSize
);
81 LPVOID pvData
= GlobalLock(hGlobal
);
82 DWORD dwBytesRead
= 0;
83 bool bRead
= ReadFile(hFile
, pvData
, dwFileSize
, &dwBytesRead
, nullptr);
84 CPPUNIT_ASSERT_MESSAGE("FileStream: ReadFile error.", bRead
);
85 GlobalUnlock(hGlobal
);
88 HRESULT hr
= CreateStreamOnHGlobal(hGlobal
, TRUE
, &pStream
);
89 CPPUNIT_ASSERT_EQUAL_MESSAGE("FileStream: CreateStreamOnHGlobal failure.", S_OK
, hr
);
92 void Test::test_file_directory()
94 FileStream
stream(documentName
.c_str());
95 TestZipImpl
testImpl(&stream
);
96 bool isPassed
= testImpl
.test_directory();
97 CPPUNIT_ASSERT_MESSAGE("FileStream: Content does not match with expected directory names.",
101 void Test::test_file_hasContentCaseInSensitive()
103 FileStream
stream(documentName
.c_str());
104 TestZipImpl
testImpl(&stream
);
105 bool isPassed
= testImpl
.test_hasContentCaseInSensitive();
106 CPPUNIT_ASSERT_MESSAGE("FileStream: Content in zip file was not found.", isPassed
);
109 void Test::test_file_getContent()
111 FileStream
stream(documentName
.c_str());
112 TestZipImpl
testImpl(&stream
);
113 bool isPassed
= testImpl
.test_getContent();
114 CPPUNIT_ASSERT_MESSAGE("FileStream: Couldn't receive content buffer from zipfile.", isPassed
);
117 void Test::test_stream_directory()
119 BufferStream
stream(pStream
);
120 TestZipImpl
testImpl(&stream
);
121 bool isPassed
= testImpl
.test_directory();
122 CPPUNIT_ASSERT_MESSAGE("BufferStream: Content does not match with expected directory names.",
126 void Test::test_stream_hasContentCaseInSensitive()
128 BufferStream
stream(pStream
);
129 TestZipImpl
testImpl(&stream
);
130 bool isPassed
= testImpl
.test_hasContentCaseInSensitive();
131 CPPUNIT_ASSERT_MESSAGE("BufferStream: Content in zip file was not found.", isPassed
);
134 void Test::test_stream_getContent()
136 BufferStream
stream(pStream
);
137 TestZipImpl
testImpl(&stream
);
138 bool isPassed
= testImpl
.test_getContent();
139 CPPUNIT_ASSERT_MESSAGE("BufferStream: Couldn't receive content buffer from zipfile.", isPassed
);
142 CPPUNIT_PLUGIN_IMPLEMENT();
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */