summaryrefslogtreecommitdiff
path: root/shell/qa/zip/ziptest.cxx
blob: e89d2e8cfd03bdca2ff66738bbe2ec8304bc1d17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* -*- 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 _MSC_VER
#pragma warning(push, 1)
#endif
#include <windows.h>
#if defined _MSC_VER
#pragma warning(pop)
#endif
#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:
    string 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(NULL)
{
    const char* pSrcRoot = getenv( "SRC_ROOT" );
    if (pSrcRoot)
    {
        documentName.append(pSrcRoot);
        documentName.append("/");
    }
    documentName.append("shell/qa/zip/simpledocument.odt");

    // Create an IStream pointer from the file
    HANDLE hFile = CreateFileA(documentName.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);

    DWORD dwFileSize = GetFileSize(hFile, NULL);
    HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);

    LPVOID pvData = GlobalLock(hGlobal);
    DWORD dwBytesRead = 0;
    BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, NULL);
    CPPUNIT_ASSERT_MESSAGE("FileStream: ReadFile error.", bRead);
    GlobalUnlock(hGlobal);
    CloseHandle(hFile);

    HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);
    CPPUNIT_ASSERT_MESSAGE("FileStream: CreateStreamOnHGlobal failure.", hr == S_OK);
}

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 form 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 form zipfile.", isPassed);
}

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */