Kaydet (Commit) 4f4bed9b authored tarafından Fridrich Štrba's avatar Fridrich Štrba

Test also the IStream part

Change-Id: If36de8daffb547b07d1417863ccc1a7904b379a5
üst a25778ab
......@@ -26,6 +26,7 @@ $(eval $(call gb_CppunitTest_use_externals,zip,\
))
$(eval $(call gb_CppunitTest_use_system_win32_libs,zip, \
ole32 \
kernel32 \
msvcprt \
))
......
......@@ -17,13 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#define DLLIMPLEMENTATION
#include "testzipimpl.hxx"
vector<string> expectedContents;
TestZipImpl::TestZipImpl(StreamInterface *stream) :
zipFile(ZipFile(stream))
zipFile(ZipFile(stream)), expectedContents()
{
expectedContents.push_back("mimetype");
expectedContents.push_back("Configurations2/statusbar/");
......
......@@ -22,20 +22,16 @@
#include <vector>
#include <algorithm>
#include "sal/types.h"
#if defined(DLLIMPLEMENTATION)
#define DLLPUBLIC SAL_DLLPUBLIC_EXPORT
#else
#define DLLPUBLIC SAL_DLLPUBLIC_IMPORT
#endif
using namespace std;
class DLLPUBLIC TestZipImpl
class TestZipImpl
{
private:
ZipFile zipFile;
vector<string> expectedContents;
public:
TestZipImpl(StreamInterface *stream);
TestZipImpl(StreamInterface *stream);
~TestZipImpl();
bool test_directory();
bool test_hasContentCaseInSensitive();
......
......@@ -17,6 +17,16 @@
* 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"
......@@ -30,6 +40,7 @@ class Test : public CppUnit::TestFixture
{
private:
string documentName;
LPSTREAM pStream;
public:
Test();
void setUp() {}
......@@ -37,16 +48,22 @@ public:
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()
Test::Test() : documentName(), pStream(NULL)
{
const char* pSrcRoot = getenv( "SRC_ROOT" );
if (pSrcRoot)
......@@ -55,6 +72,20 @@ Test::Test() : documentName()
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);
GlobalUnlock(hGlobal);
CloseHandle(hFile);
HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);
}
void Test::test_file_directory()
......@@ -62,7 +93,7 @@ void Test::test_file_directory()
FileStream stream(documentName.c_str());
TestZipImpl testImpl(&stream);
bool isPassed = testImpl.test_directory();
CPPUNIT_ASSERT_MESSAGE("Content does not match with expected directory names.", isPassed);
CPPUNIT_ASSERT_MESSAGE("FileStream: Content does not match with expected directory names.", isPassed);
}
void Test::test_file_hasContentCaseInSensitive()
......@@ -70,7 +101,7 @@ void Test::test_file_hasContentCaseInSensitive()
FileStream stream(documentName.c_str());
TestZipImpl testImpl(&stream);
bool isPassed = testImpl.test_hasContentCaseInSensitive();
CPPUNIT_ASSERT_MESSAGE("Content in zip file was not found.", isPassed);
CPPUNIT_ASSERT_MESSAGE("FileStream: Content in zip file was not found.", isPassed);
}
void Test::test_file_getContent()
......@@ -78,7 +109,31 @@ void Test::test_file_getContent()
FileStream stream(documentName.c_str());
TestZipImpl testImpl(&stream);
bool isPassed = testImpl.test_getContent();
CPPUNIT_ASSERT_MESSAGE("Couldn't receive content buffer form zipfile.", isPassed);
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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment