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 .
21 #pragma warning(push, 1)
30 #include "cppunit/TestAssert.h"
31 #include "cppunit/TestFixture.h"
32 #include "cppunit/extensions/HelperMacros.h"
33 #include "cppunit/plugin/TestPlugIn.h"
35 #include "internal/stream_helper.hxx"
36 #include "testzipimpl.hxx"
39 class Test
: public CppUnit::TestFixture
48 void test_file_directory();
49 void test_file_hasContentCaseInSensitive();
50 void test_file_getContent();
51 void test_stream_directory();
52 void test_stream_hasContentCaseInSensitive();
53 void test_stream_getContent();
54 CPPUNIT_TEST_SUITE(Test
);
55 CPPUNIT_TEST(test_file_directory
);
56 CPPUNIT_TEST(test_file_hasContentCaseInSensitive
);
57 CPPUNIT_TEST(test_file_getContent
);
58 CPPUNIT_TEST(test_stream_directory
);
59 CPPUNIT_TEST(test_stream_hasContentCaseInSensitive
);
60 CPPUNIT_TEST(test_stream_getContent
);
61 CPPUNIT_TEST_SUITE_END();
64 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
66 Test::Test() : documentName(), pStream(NULL
)
68 const char* pSrcRoot
= getenv( "SRC_ROOT" );
71 documentName
.append(pSrcRoot
);
72 documentName
.append("/");
74 documentName
.append("shell/qa/zip/simpledocument.odt");
76 // Create an IStream pointer from the file
77 HANDLE hFile
= CreateFileA(documentName
.c_str(), GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
79 DWORD dwFileSize
= GetFileSize(hFile
, NULL
);
80 HGLOBAL hGlobal
= GlobalAlloc(GMEM_MOVEABLE
, dwFileSize
);
82 LPVOID pvData
= GlobalLock(hGlobal
);
83 DWORD dwBytesRead
= 0;
84 BOOL bRead
= ReadFile(hFile
, pvData
, dwFileSize
, &dwBytesRead
, NULL
);
85 CPPUNIT_ASSERT_MESSAGE("FileStream: ReadFile error.", bRead
);
86 GlobalUnlock(hGlobal
);
89 HRESULT hr
= CreateStreamOnHGlobal(hGlobal
, TRUE
, &pStream
);
90 CPPUNIT_ASSERT_MESSAGE("FileStream: CreateStreamOnHGlobal failure.", hr
== S_OK
);
93 void Test::test_file_directory()
95 FileStream
stream(documentName
.c_str());
96 TestZipImpl
testImpl(&stream
);
97 bool isPassed
= testImpl
.test_directory();
98 CPPUNIT_ASSERT_MESSAGE("FileStream: Content does not match with expected directory names.", isPassed
);
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 form 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.", 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 form zipfile.", isPassed
);
141 CPPUNIT_PLUGIN_IMPLEMENT();
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */