| 1 |
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the libqxp project. |
| 4 |
* |
| 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/. |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <string> |
| 11 |
|
| 12 |
#include <cppunit/TestFixture.h> |
| 13 |
#include <cppunit/extensions/HelperMacros.h> |
| 14 |
|
| 15 |
#include <librevenge-stream/librevenge-stream.h> |
| 16 |
|
| 17 |
#include <libqxp/libqxp.h> |
| 18 |
|
| 19 |
#if !defined DETECTION_TEST_DIR |
| 20 |
#error DETECTION_TEST_DIR not defined, cannot test |
| 21 |
#endif |
| 22 |
|
| 23 |
namespace test |
| 24 |
{ |
| 25 |
|
| 26 |
using libqxp::QXPDocument; |
| 27 |
|
| 28 |
using std::string; |
| 29 |
|
| 30 |
namespace |
| 31 |
{ |
| 32 |
|
| 33 |
QXPDocument::Type assertDetection(const string &name, const bool expectedSupported) |
| 34 |
{ |
| 35 |
librevenge::RVNGFileStream input((string(DETECTION_TEST_DIR) + "/" + name).c_str()); |
| 36 |
QXPDocument::Type type = QXPDocument::TYPE_UNKNOWN; |
| 37 |
const bool supported = QXPDocument::isSupported(&input, &type); |
| 38 |
CPPUNIT_ASSERT_EQUAL_MESSAGE(name, expectedSupported, supported); |
| 39 |
return type; |
| 40 |
} |
| 41 |
|
| 42 |
void assertSupported(const string &name) |
| 43 |
{ |
| 44 |
auto type = assertDetection(name, true); |
| 45 |
CPPUNIT_ASSERT_EQUAL_MESSAGE(name, QXPDocument::TYPE_DOCUMENT, type); |
| 46 |
} |
| 47 |
|
| 48 |
void assertUnsupported(const string &name) |
| 49 |
{ |
| 50 |
assertDetection(name, false); |
| 51 |
} |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
class QXPDocumentTest : public CPPUNIT_NS::TestFixture |
| 56 |
{ |
| 57 |
public: |
| 58 |
virtual void setUp() override; |
| 59 |
virtual void tearDown() override; |
| 60 |
|
| 61 |
private: |
| 62 |
CPPUNIT_TEST_SUITE(QXPDocumentTest); |
| 63 |
CPPUNIT_TEST(testDetectQXP); |
| 64 |
CPPUNIT_TEST(testUnsupported); |
| 65 |
CPPUNIT_TEST_SUITE_END(); |
| 66 |
|
| 67 |
private: |
| 68 |
void testDetectQXP(); |
| 69 |
void testUnsupported(); |
| 70 |
}; |
| 71 |
|
| 72 |
void QXPDocumentTest::setUp() |
| 73 |
{ |
| 74 |
} |
| 75 |
|
| 76 |
void QXPDocumentTest::tearDown() |
| 77 |
{ |
| 78 |
} |
| 79 |
|
| 80 |
void QXPDocumentTest::testDetectQXP() |
| 81 |
{ |
| 82 |
assertSupported("qxp1.zip"); |
| 83 |
assertSupported("qxp31mac"); |
| 84 |
assertSupported("qxp31win.qxd"); |
| 85 |
assertSupported("qxp33mac"); |
| 86 |
assertSupported("qxp33win.qxd"); |
| 87 |
assertSupported("qxp4mac"); |
| 88 |
assertSupported("qxp4win.qxd"); |
| 89 |
} |
| 90 |
|
| 91 |
void QXPDocumentTest::testUnsupported() |
| 92 |
{ |
| 93 |
assertUnsupported("unsupported.zip"); |
| 94 |
assertUnsupported("qxp5.qxd"); |
| 95 |
assertUnsupported("qxp6.qxd"); |
| 96 |
} |
| 97 |
|
| 98 |
CPPUNIT_TEST_SUITE_REGISTRATION(QXPDocumentTest); |
| 99 |
|
| 100 |
} |
| 101 |
|
| 102 |
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ |