Changeset 6
- Timestamp:
- 04/10/06 11:11:30 (3 years ago)
- Location:
- trunk
- Files:
-
- 7 modified
-
src/Document.cxx (modified) (4 diffs)
-
src/Document.h (modified) (2 diffs)
-
src/Makefile.am (modified) (1 diff)
-
src/epdfview.h (modified) (1 diff)
-
tests/DocumentTest.cxx (modified) (3 diffs)
-
tests/DocumentTest.h (modified) (2 diffs)
-
tests/Makefile.am (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Document.cxx
r4 r6 16 16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 17 18 // Poppler headers. 19 #include <ErrorCodes.h> 20 #include <GlobalParams.h> 21 18 22 #include "epdfview.h" 19 23 … … 25 29 Document::Document () 26 30 { 31 this->m_Document = NULL; 27 32 } 28 33 … … 32 37 Document::~Document () 33 38 { 39 delete this->m_Document; 34 40 } 35 41 … … 43 49 { 44 50 return false; 51 } 52 53 /// 54 /// @brief Load a PDF file. 55 /// 56 /// Tries to open the PDF file @a filename. 57 /// 58 /// @param filename The name of the filename to open. 59 /// @param error Locatrion to store the error ocurringm or NULL to ignore 60 /// errors. 61 /// 62 /// @return True if the file could be opened, false otherwise. 63 /// 64 bool 65 Document::loadFile (const gchar *filename, GError **error) 66 { 67 assert (NULL != filename && "Tried to load a NULL filename"); 68 69 // The poppler library has a GLOBAL file for parameters. 70 // If this file isn't loaded then weird error happens. 71 if ( NULL == globalParams ) 72 { 73 globalParams = new GlobalParams ("/etc/xpdfrc"); 74 } 75 76 GooString *filename_g = new GooString (filename); 77 GooString *password_g = NULL; 78 // Try to open the PDF document. 79 PDFDoc *newDocument = new PDFDoc (filename_g, password_g, password_g); 80 delete password_g; 81 // The filename_g can't be deleted as PDFDoc saves the reference. 82 // deleting it will cause trouble when deleting the newDocument. 83 84 // Check if the document couldn't be opened sucessfully and why. 85 if ( !newDocument->isOk() ) 86 { 87 gint errorCode = newDocument->getErrorCode (); 88 delete newDocument; 89 90 if ( errEncrypted == errorCode ) 91 { 92 g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, 93 _("Document is encrypted.")); 94 } 95 else 96 { 97 g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, 98 _("Failed to load document '%s'. Error %d"), 99 filename, errorCode); 100 } 101 102 return false; 103 } 104 105 delete this->m_Document; 106 this->m_Document = newDocument; 107 108 return true; 45 109 } 46 110 -
trunk/src/Document.h
r4 r6 54 54 55 55 bool isLoaded (void); 56 bool loadFile (const gchar *filename, GError **error); 56 57 const gchar *getTitle (void); 57 58 const gchar *getAuthor (void); … … 69 70 gint getCurrentPageNum (void); 70 71 DocumentIndex &getDocumentIndex (void); 72 73 protected: 74 PDFDoc *m_Document; 71 75 }; 72 76 } -
trunk/src/Makefile.am
r4 r6 11 11 12 12 libepdfview_a_CXXFLAGS = \ 13 $(GLIB_CFLAGS) 13 $(GLIB_CFLAGS) \ 14 $(POPPLER_CFLAGS) -
trunk/src/epdfview.h
r4 r6 19 19 #define __E_PDF_VIEW_H__ 20 20 21 #include <assert.h> 21 22 #include <gettext.h> 22 23 #include <glib.h> 24 25 // Poppler headers. 26 #include <PDFDoc.h> 23 27 24 28 #include <DocumentIndex.h> -
trunk/tests/DocumentTest.cxx
r4 r6 30 30 DocumentTest::setUp () 31 31 { 32 m_Document = new Document (); 32 33 } 33 34 … … 38 39 DocumentTest::tearDown () 39 40 { 41 delete m_Document; 40 42 } 41 43 … … 51 53 DocumentTest::emptyDocument () 52 54 { 53 Document *doc = new Document (); 55 CPPUNIT_ASSERT (!m_Document->isLoaded ()); 56 CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("", m_Document->getTitle ())); 57 CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("", m_Document->getAuthor ())); 58 CPPUNIT_ASSERT_EQUAL (0, 59 g_ascii_strcasecmp ("", m_Document->getSubject ())); 60 CPPUNIT_ASSERT_EQUAL (0, 61 g_ascii_strcasecmp ("", m_Document->getKeywords ())); 62 CPPUNIT_ASSERT_EQUAL (0, 63 g_ascii_strcasecmp ("", m_Document->getCreator ())); 64 CPPUNIT_ASSERT_EQUAL (0, 65 g_ascii_strcasecmp ("", m_Document->getProducer ())); 66 CPPUNIT_ASSERT_EQUAL (0, 67 g_ascii_strcasecmp ("", m_Document->getFormat ())); 68 CPPUNIT_ASSERT_EQUAL (0, 69 g_ascii_strcasecmp ("", m_Document->getLinearized ())); 70 CPPUNIT_ASSERT_EQUAL (0, 71 g_ascii_strcasecmp ("", m_Document->getCreationDate ())); 72 CPPUNIT_ASSERT_EQUAL (0, 73 g_ascii_strcasecmp ("", m_Document->getModifiedDate ())); 74 CPPUNIT_ASSERT_EQUAL (PageModeUnset, m_Document->getPageMode ()); 75 CPPUNIT_ASSERT_EQUAL (PageLayoutUnset, m_Document->getPageLayout ()); 76 CPPUNIT_ASSERT_EQUAL (0, m_Document->getNumPages ()); 77 CPPUNIT_ASSERT_EQUAL (0, m_Document->getCurrentPageNum ()); 54 78 55 CPPUNIT_ASSERT (!doc->isLoaded ()); 56 CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("", doc->getTitle ())); 57 CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("", doc->getAuthor ())); 58 CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("", doc->getSubject ())); 59 CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("", doc->getKeywords ())); 60 CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("", doc->getCreator ())); 61 CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("", doc->getProducer ())); 62 CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("", doc->getFormat ())); 63 CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("", doc->getLinearized ())); 64 CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("", doc->getCreationDate ())); 65 CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("", doc->getModifiedDate ())); 66 CPPUNIT_ASSERT_EQUAL (PageModeUnset, doc->getPageMode ()); 67 CPPUNIT_ASSERT_EQUAL (PageLayoutUnset, doc->getPageLayout ()); 68 CPPUNIT_ASSERT_EQUAL (0, doc->getNumPages ()); 69 CPPUNIT_ASSERT_EQUAL (0, doc->getCurrentPageNum ()); 70 71 DocumentIndex &index = doc->getDocumentIndex (); 79 DocumentIndex &index = m_Document->getDocumentIndex (); 72 80 CPPUNIT_ASSERT_EQUAL (0, index.getNumChildren ()); 73 81 } 82 83 /// 84 /// @brief Tests that loading a file which does not exist fails. 85 /// 86 /// Loading a PDF can fail under three conditions: the file is not found, 87 /// the file is not a PDF (or a malformed PDF file) and the file is encrypted 88 /// but not password has been supplied. 89 /// 90 /// This test just check that loading a not existent file fails. 91 /// 92 void 93 DocumentTest::fileNotFound (void) 94 { 95 gchar *error_message; 96 GError *error = NULL; 97 98 CPPUNIT_ASSERT (!m_Document->loadFile (TEST_DATA_DIR "noFile.pdf", &error)); 99 CPPUNIT_ASSERT (!m_Document->isLoaded ()); 100 101 error_message = g_strdup_printf ( 102 "Failed to load document '%sNoFile.pdf'. Error 1", TEST_DATA_DIR); 103 CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp (error_message, 104 error->message)); 105 } -
trunk/tests/DocumentTest.h
r4 r6 27 27 CPPUNIT_TEST_SUITE (DocumentTest); 28 28 CPPUNIT_TEST (emptyDocument); 29 CPPUNIT_TEST (fileNotFound); 29 30 CPPUNIT_TEST_SUITE_END (); 30 31 … … 34 35 35 36 void emptyDocument (void); 37 void fileNotFound (void); 38 39 private: 40 Document *m_Document; 36 41 }; 37 42 } -
trunk/tests/Makefile.am
r5 r6 9 9 main.cxx 10 10 11 test_epdfview_CXXFLAGS = \ 12 -DTEST_DATA_DIR=$(top_srcdir)/src \ 13 -I$(top_srcdir)/src \ 14 $(GLIB_CFLAGS) \ 11 test_epdfview_CXXFLAGS = \ 12 -DTEST_DATA_DIR='"$(top_srcdir)/src/"' \ 13 -I$(top_srcdir)/src \ 14 $(GLIB_CFLAGS) \ 15 $(POPPLER_CFLAGS) \ 15 16 $(CPPUNIT_CFLAGS) 16 17 17 18 test_epdfview_LDFLAGS = \ 18 19 $(GLIB_LIBS) \ 20 $(POPPLER_LIBS) \ 19 21 $(CPPUNIT_LIBS) 20 22
