/* -*- 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/. */#include <cppunit/TestAssert.h>#include <cppunit/extensions/HelperMacros.h>#include <unotest/bootstrapfixturebase.hxx>#include <graphic/GraphicFormatDetector.hxx>#include <graphic/DetectorTools.hxx>#include <tools/stream.hxx>usingnamespacecss;namespace{classGraphicFormatDetectorTest:publictest::BootstrapFixtureBase{OUStringgetFullUrl(constOUString&sFileName){returnm_directories.getURLFromSrc("/vcl/qa/cppunit/data/")+sFileName;}voidtestDetectMET();voidtestDetectBMP();voidtestDetectWMF();voidtestDetectPCX();voidtestDetectJPG();voidtestDetectPNG();voidtestDetectGIF();voidtestDetectPSD();voidtestDetectTGA();voidtestDetectTIF();voidtestDetectXBM();voidtestDetectXPM();voidtestDetectSVG();voidtestDetectSVGZ();voidtestDetectPDF();voidtestDetectEPS();voidtestMatchArray();voidtestCheckArrayForMatchingStrings();CPPUNIT_TEST_SUITE(GraphicFormatDetectorTest);CPPUNIT_TEST(testDetectMET);CPPUNIT_TEST(testDetectBMP);CPPUNIT_TEST(testDetectWMF);CPPUNIT_TEST(testDetectPCX);CPPUNIT_TEST(testDetectJPG);CPPUNIT_TEST(testDetectPNG);CPPUNIT_TEST(testDetectGIF);CPPUNIT_TEST(testDetectPSD);CPPUNIT_TEST(testDetectTGA);CPPUNIT_TEST(testDetectTIF);CPPUNIT_TEST(testDetectXBM);CPPUNIT_TEST(testDetectXPM);CPPUNIT_TEST(testDetectSVG);CPPUNIT_TEST(testDetectSVGZ);CPPUNIT_TEST(testDetectPDF);CPPUNIT_TEST(testDetectEPS);CPPUNIT_TEST(testMatchArray);CPPUNIT_TEST(testCheckArrayForMatchingStrings);CPPUNIT_TEST_SUITE_END();};voidGraphicFormatDetectorTest::testDetectMET(){SvFileStreamaFileStream(getFullUrl("TypeDetectionExample.met"),StreamMode::READ);vcl::GraphicFormatDetectoraDetector(aFileStream,"MET");CPPUNIT_ASSERT(aDetector.detect());CPPUNIT_ASSERT(aDetector.checkMET());aFileStream.Seek(aDetector.mnStreamPosition);OUStringrFormatExtension;CPPUNIT_ASSERT(ImpPeekGraphicFormat(aFileStream,rFormatExtension,false));CPPUNIT_ASSERT_EQUAL(OUString("MET"),rFormatExtension);}voidGraphicFormatDetectorTest::testDetectBMP(){SvFileStreamaFileStream(getFullUrl("TypeDetectionExample.bmp"),StreamMode::READ);vcl::GraphicFormatDetectoraDetector(aFileStream,"BMP");CPPUNIT_ASSERT(aDetector.detect());CPPUNIT_ASSERT(aDetector.checkBMP());aFileStream.Seek(aDetector.mnStreamPosition);OUStringrFormatExtension;CPPUNIT_ASSERT(ImpPeekGraphicFormat(aFileStream,rFormatExtension,false));CPPUNIT_ASSERT_EQUAL(OUString("BMP"),rFormatExtension);}voidGraphicFormatDetectorTest::testDetectWMF(){SvFileStreamaFileStream(getFullUrl("TypeDetectionExample.wmf"),StreamMode::READ);vcl::GraphicFormatDetectoraDetector(aFileStream,"WMF");CPPUNIT_ASSERT(aDetector.detect());CPPUNIT_ASSERT(aDetector.checkWMForEMF());aFileStream.Seek(aDetector.mnStreamPosition);OUStringrFormatExtension;CPPUNIT_ASSERT(ImpPeekGraphicFormat(aFileStream,rFormatExtension,false));CPPUNIT_ASSERT_EQUAL(OUString("WMF"),rFormatExtension);}voidGraphicFormatDetectorTest::testDetectPCX(){SvFileStreamaFileStream(getFullUrl("TypeDetectionExample.pcx"),StreamMode::READ);vcl::GraphicFormatDetectoraDetector(aFileStream,"PCX");CPPUNIT_ASSERT(aDetector.detect());CPPUNIT_ASSERT(aDetector.checkPCX());aFileStream.Seek(aDetector.mnStreamPosition);OUStringrFormatExtension;CPPUNIT_ASSERT(ImpPeekGraphicFormat(aFileStream,rFormatExtension,false));CPPUNIT_ASSERT_EQUAL(OUString("PCX"),rFormatExtension);}voidGraphicFormatDetectorTest::testDetectJPG(){SvFileStreamaFileStream(getFullUrl("TypeDetectionExample.jpg"),StreamMode::READ);vcl::GraphicFormatDetectoraDetector(aFileStream,"JPG");CPPUNIT_ASSERT(aDetector.detect());CPPUNIT_ASSERT(aDetector.checkJPG());aFileStream.Seek(aDetector.mnStreamPosition);OUStringrFormatExtension;CPPUNIT_ASSERT(ImpPeekGraphicFormat(aFileStream,rFormatExtension,false));CPPUNIT_ASSERT_EQUAL(OUString("JPG"),rFormatExtension);}voidGraphicFormatDetectorTest::testDetectPNG(){SvFileStreamaFileStream(getFullUrl("TypeDetectionExample.png"),StreamMode::READ);vcl::GraphicFormatDetectoraDetector(aFileStream,"PNG");CPPUNIT_ASSERT(aDetector.detect());CPPUNIT_ASSERT(aDetector.checkPNG());aFileStream.Seek(aDetector.mnStreamPosition);OUStringrFormatExtension;CPPUNIT_ASSERT(ImpPeekGraphicFormat(aFileStream,rFormatExtension,false));CPPUNIT_ASSERT_EQUAL(OUString("PNG"),rFormatExtension);}voidGraphicFormatDetectorTest::testDetectGIF(){SvFileStreamaFileStream(getFullUrl("TypeDetectionExample.gif"),StreamMode::READ);vcl::GraphicFormatDetectoraDetector(aFileStream,"GIF");CPPUNIT_ASSERT(aDetector.detect());CPPUNIT_ASSERT(aDetector.checkGIF());aFileStream.Seek(aDetector.mnStreamPosition);OUStringrFormatExtension;CPPUNIT_ASSERT(ImpPeekGraphicFormat(aFileStream,rFormatExtension,false));CPPUNIT_ASSERT_EQUAL(OUString("GIF"),rFormatExtension);}voidGraphicFormatDetectorTest::testDetectPSD(){SvFileStreamaFileStream(getFullUrl("TypeDetectionExample.psd"),StreamMode::READ);vcl::GraphicFormatDetectoraDetector(aFileStream,"PSD");CPPUNIT_ASSERT(aDetector.detect());CPPUNIT_ASSERT(aDetector.checkPSD());aFileStream.Seek(aDetector.mnStreamPosition);OUStringrFormatExtension;CPPUNIT_ASSERT(ImpPeekGraphicFormat(aFileStream,rFormatExtension,false));CPPUNIT_ASSERT_EQUAL(OUString("PSD"),rFormatExtension);}voidGraphicFormatDetectorTest::testDetectTGA(){SvFileStreamaFileStream(getFullUrl("TypeDetectionExample.tga"),StreamMode::READ);vcl::GraphicFormatDetectoraDetector(aFileStream,"TGA");CPPUNIT_ASSERT(aDetector.detect());CPPUNIT_ASSERT(aDetector.checkTGA());aFileStream.Seek(aDetector.mnStreamPosition);OUStringrFormatExtension("TGA");// detection is based on extension onlyCPPUNIT_ASSERT(ImpPeekGraphicFormat(aFileStream,rFormatExtension,false));CPPUNIT_ASSERT_EQUAL(OUString("TGA"),rFormatExtension);}voidGraphicFormatDetectorTest::testDetectTIF(){SvFileStreamaFileStream(getFullUrl("TypeDetectionExample.tif"),StreamMode::READ);vcl::GraphicFormatDetectoraDetector(aFileStream,"TIF");CPPUNIT_ASSERT(aDetector.detect());CPPUNIT_ASSERT(aDetector.checkTIF());aFileStream.Seek(aDetector.mnStreamPosition);OUStringrFormatExtension;CPPUNIT_ASSERT(ImpPeekGraphicFormat(aFileStream,rFormatExtension,false));CPPUNIT_ASSERT_EQUAL(OUString("TIF"),rFormatExtension);}voidGraphicFormatDetectorTest::testDetectXBM(){SvFileStreamaFileStream(getFullUrl("TypeDetectionExample.xbm"),StreamMode::READ);vcl::GraphicFormatDetectoraDetector(aFileStream,"XBM");CPPUNIT_ASSERT(aDetector.detect());CPPUNIT_ASSERT(aDetector.checkXBM());aFileStream.Seek(aDetector.mnStreamPosition);OUStringrFormatExtension;CPPUNIT_ASSERT(ImpPeekGraphicFormat(aFileStream,rFormatExtension,false));CPPUNIT_ASSERT_EQUAL(OUString("XBM"),rFormatExtension);}voidGraphicFormatDetectorTest::testDetectXPM(){SvFileStreamaFileStream(getFullUrl("TypeDetectionExample.xpm"),StreamMode::READ);vcl::GraphicFormatDetectoraDetector(aFileStream,"XPM");CPPUNIT_ASSERT(aDetector.detect());CPPUNIT_ASSERT(aDetector.checkXPM());aFileStream.Seek(aDetector.mnStreamPosition);OUStringrFormatExtension;CPPUNIT_ASSERT(ImpPeekGraphicFormat(aFileStream,rFormatExtension,false));CPPUNIT_ASSERT_EQUAL(OUString("XPM"),rFormatExtension);}voidGraphicFormatDetectorTest::testDetectSVG(){SvFileStreamaFileStream(getFullUrl("TypeDetectionExample.svg"),StreamMode::READ);vcl::GraphicFormatDetectoraDetector(aFileStream,"SVG");CPPUNIT_ASSERT(aDetector.detect());CPPUNIT_ASSERT(aDetector.checkSVG());aFileStream.Seek(aDetector.mnStreamPosition);OUStringrFormatExtension;CPPUNIT_ASSERT(ImpPeekGraphicFormat(aFileStream,rFormatExtension,false));CPPUNIT_ASSERT_EQUAL(OUString("SVG"),rFormatExtension);}voidGraphicFormatDetectorTest::testDetectSVGZ(){SvFileStreamaFileStream(getFullUrl("TypeDetectionExample.svgz"),StreamMode::READ);vcl::GraphicFormatDetectoraDetector(aFileStream,"SVG");CPPUNIT_ASSERT(aDetector.detect());CPPUNIT_ASSERT(aDetector.checkSVG());aFileStream.Seek(aDetector.mnStreamPosition);OUStringrFormatExtension;CPPUNIT_ASSERT(ImpPeekGraphicFormat(aFileStream,rFormatExtension,false));CPPUNIT_ASSERT_EQUAL(OUString("SVG"),rFormatExtension);}voidGraphicFormatDetectorTest::testDetectPDF(){SvFileStreamaFileStream(getFullUrl("TypeDetectionExample.pdf"),StreamMode::READ);vcl::GraphicFormatDetectoraDetector(aFileStream,"PDF");CPPUNIT_ASSERT(aDetector.detect());CPPUNIT_ASSERT(aDetector.checkPDF());aFileStream.Seek(aDetector.mnStreamPosition);OUStringrFormatExtension;CPPUNIT_ASSERT(ImpPeekGraphicFormat(aFileStream,rFormatExtension,false));CPPUNIT_ASSERT_EQUAL(OUString("PDF"),rFormatExtension);}voidGraphicFormatDetectorTest::testDetectEPS(){SvFileStreamaFileStream(getFullUrl("TypeDetectionExample.eps"),StreamMode::READ);vcl::GraphicFormatDetectoraDetector(aFileStream,"EPS");CPPUNIT_ASSERT(aDetector.detect());CPPUNIT_ASSERT(aDetector.checkEPS());aFileStream.Seek(aDetector.mnStreamPosition);OUStringrFormatExtension;CPPUNIT_ASSERT(ImpPeekGraphicFormat(aFileStream,rFormatExtension,false));CPPUNIT_ASSERT_EQUAL(OUString("EPS"),rFormatExtension);}voidGraphicFormatDetectorTest::testMatchArray(){std::stringaString("<?xml version=\"1.0\" standalone=\"no\"?>\n""<svg width=\"5cm\" height=\"4cm\" version=\"1.1\"\n""xmlns=\"http://www.w3.org/2000/svg\">\n""</svg>");constchar*pCompleteStringPointer=aString.c_str();constchar*pMatchPointer;intnCheckSize=aString.size();// Check beginning of the input stringpMatchPointer=vcl::matchArrayWithString(pCompleteStringPointer,nCheckSize,"<?xml");<--- Assignment 'pMatchPointer=vcl::matchArrayWithString(pCompleteStringPointer,nCheckSize,"
CPPUNIT_ASSERT(pMatchPointer!=nullptr);<--- Assuming that condition 'pMatchPointer!=nullptr' is not redundantCPPUNIT_ASSERT_EQUAL(0,int(pMatchPointer-pCompleteStringPointer));<--- Null pointer subtractionCPPUNIT_ASSERT_EQUAL(true,OString(pMatchPointer).startsWith("<?xml"));// Check middle of the input stringpMatchPointer=vcl::matchArrayWithString(aString.c_str(),nCheckSize,"version");<--- Assignment 'pMatchPointer=vcl::matchArrayWithString(aString.c_str(),nCheckSize,"version")', assigned value is 0CPPUNIT_ASSERT(pMatchPointer!=nullptr);<--- Assuming that condition 'pMatchPointer!=nullptr' is not redundantCPPUNIT_ASSERT_EQUAL(6,int(pMatchPointer-pCompleteStringPointer));<--- Null pointer subtractionCPPUNIT_ASSERT_EQUAL(true,OString(pMatchPointer).startsWith("version"));pMatchPointer=vcl::matchArrayWithString(aString.c_str(),nCheckSize,"<svg");<--- Assignment 'pMatchPointer=vcl::matchArrayWithString(aString.c_str(),nCheckSize,"CPPUNIT_ASSERT(pMatchPointer!=nullptr);<--- Assuming that condition 'pMatchPointer!=nullptr' is not redundantCPPUNIT_ASSERT_EQUAL(38,int(pMatchPointer-pCompleteStringPointer));<--- Null pointer subtractionCPPUNIT_ASSERT_EQUAL(true,OString(pMatchPointer).startsWith("<svg"));// Check end of the input stringpMatchPointer=vcl::matchArrayWithString(aString.c_str(),nCheckSize,"/svg>");<--- Assignment 'pMatchPointer=vcl::matchArrayWithString(aString.c_str(),nCheckSize,"/svg>")', assigned value is 0CPPUNIT_ASSERT(pMatchPointer!=nullptr);<--- Assuming that condition 'pMatchPointer!=nullptr' is not redundantCPPUNIT_ASSERT_EQUAL(119,int(pMatchPointer-pCompleteStringPointer));<--- Null pointer subtractionCPPUNIT_ASSERT_EQUAL(true,OString(pMatchPointer).startsWith("/svg>"));// Check that non-existing search stringpMatchPointer=vcl::matchArrayWithString(aString.c_str(),nCheckSize,"none");CPPUNIT_ASSERT(pMatchPointer==nullptr);}voidGraphicFormatDetectorTest::testCheckArrayForMatchingStrings(){std::stringaString("<?xml version=\"1.0\" standalone=\"no\"?>\n""<svg width=\"5cm\" height=\"4cm\" version=\"1.1\"\n""xmlns=\"http://www.w3.org/2000/svg\">\n""</svg>");constchar*pCompleteStringPointer=aString.c_str();intnCheckSize=aString.size();boolbResult;// check beginning stringbResult=vcl::checkArrayForMatchingStrings(pCompleteStringPointer,nCheckSize,{"<?xml"});CPPUNIT_ASSERT_EQUAL(true,bResult);// check ending stringbResult=vcl::checkArrayForMatchingStrings(pCompleteStringPointer,nCheckSize,{"/svg>"});CPPUNIT_ASSERT_EQUAL(true,bResult);// check middle stringbResult=vcl::checkArrayForMatchingStrings(pCompleteStringPointer,nCheckSize,{"version"});CPPUNIT_ASSERT_EQUAL(true,bResult);// check beginning and then ending stringbResult=vcl::checkArrayForMatchingStrings(pCompleteStringPointer,nCheckSize,{"<?xml","/svg>"});CPPUNIT_ASSERT_EQUAL(true,bResult);// check ending and then beginning stringbResult=vcl::checkArrayForMatchingStrings(pCompleteStringPointer,nCheckSize,{"/svg>","<?xml"});CPPUNIT_ASSERT_EQUAL(false,bResult);// check middle stringsbResult=vcl::checkArrayForMatchingStrings(pCompleteStringPointer,nCheckSize,{"version","<svg"});CPPUNIT_ASSERT_EQUAL(true,bResult);// check beginning, middle and ending stringsbResult=vcl::checkArrayForMatchingStrings(pCompleteStringPointer,nCheckSize,{"<?xml","version","<svg","/svg>"});CPPUNIT_ASSERT_EQUAL(true,bResult);// check non-existingbResult=vcl::checkArrayForMatchingStrings(pCompleteStringPointer,nCheckSize,{"none"});CPPUNIT_ASSERT_EQUAL(false,bResult);// check non-existing on the beginningbResult=vcl::checkArrayForMatchingStrings(pCompleteStringPointer,nCheckSize,{"none","version","<svg","/svg>"});CPPUNIT_ASSERT_EQUAL(false,bResult);// check non-existing on the endbResult=vcl::checkArrayForMatchingStrings(pCompleteStringPointer,nCheckSize,{"<?xml","version","<svg","none"});CPPUNIT_ASSERT_EQUAL(false,bResult);// check non-existing after the endbResult=vcl::checkArrayForMatchingStrings(pCompleteStringPointer,nCheckSize,{"<?xml","/svg>","none"});CPPUNIT_ASSERT_EQUAL(false,bResult);}}// namespaceCPPUNIT_TEST_SUITE_REGISTRATION(GraphicFormatDetectorTest);/* vim:set shiftwidth=4 softtabstop=4 expandtab: */