Changeset 8
- Timestamp:
- 04/10/06 12:49:58 (3 years ago)
- Location:
- trunk
- Files:
-
- 6 modified
-
src/Document.cxx (modified) (3 diffs)
-
src/Document.h (modified) (2 diffs)
-
src/epdfview.h (modified) (1 diff)
-
tests/DocumentTest.cxx (modified) (2 diffs)
-
tests/DocumentTest.h (modified) (2 diffs)
-
tests/Makefile.am (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Document.cxx
r6 r8 24 24 using namespace ePDFView; 25 25 26 /// This is the error domain that will be used to report Document's errors. 27 GQuark Document::errorQuark = 0; 28 29 /// 30 /// @brief Gets the Document's error quark. 31 /// 32 /// The first time it's called will create the new quark value for the 33 /// document class. Successive calls will just return the previously created 34 /// quark value. 35 /// 36 /// @return The Document's quark. 37 /// 38 GQuark 39 Document::getErrorQuark () 40 { 41 if ( 0 == Document::errorQuark ) 42 Document::errorQuark = g_quark_from_static_string ("epdfview-document"); 43 44 return Document::errorQuark; 45 } 46 47 /// 48 /// @brief Gives the error's description. 49 /// 50 /// This function looks the error at @a errorCode and gives an human 51 /// readable error string. 52 /// 53 /// The error message must be freed using g_free(). 54 /// 55 /// @param errorCode The error code to get the string from. 56 /// 57 /// @return An human readable error message. 58 /// 59 gchar * 60 Document::getErrorMessage (DocumentError errorCode) 61 { 62 gchar *errorMessage = NULL; 63 switch (errorCode) 64 { 65 case DocumentErrorNone: 66 errorMessage = g_strdup (_("No error")); 67 break; 68 case DocumentErrorOpenFile: 69 errorMessage = g_strdup (_("File not found.")); 70 break; 71 case DocumentErrorBadCatalog: 72 errorMessage = g_strdup (_("Couldn't read the page catalog.")); 73 break; 74 case DocumentErrorDamaged: 75 errorMessage = g_strdup (_("The PDF file is damaged and can't be repaired.")); 76 break; 77 case DocumentErrorEncrypted: 78 errorMessage = g_strdup (_("The file is encrypted and the password was incorrect or not supplied.")); 79 break; 80 case DocumentErrorHighlightFile: 81 errorMessage = g_strdup (_("Nonexistent or invlid highlight file.")); 82 break; 83 case DocumentErrorBadPrinter: 84 errorMessage = g_strdup (_("Invalid printer.")); 85 break; 86 case DocumentErrorPrinting: 87 errorMessage = g_strdup (_("Error during printing.")); 88 break; 89 case DocumentErrorPermission: 90 errorMessage = g_strdup (_("The PDF file doesn't allow that operation.")); 91 break; 92 case DocumentErrorBadPageNumber: 93 errorMessage = g_strdup (_("Invalid page number.")); 94 break; 95 case DocumentErrorFileIO: 96 errorMessage = g_strdup (_("File I/O error.")); 97 break; 98 default: 99 errorMessage = g_strdup_printf (_("Unknown error (%d)"), errorCode); 100 } 101 102 g_assert (NULL != errorMessage && "The error message is NULL"); 103 return errorMessage; 104 } 105 26 106 /// 27 107 /// @brief Constructs a new Document object. … … 65 145 Document::loadFile (const gchar *filename, GError **error) 66 146 { 67 assert (NULL != filename && "Tried to load a NULL filename");147 g_assert (NULL != filename && "Tried to load a NULL filename"); 68 148 69 149 // The poppler library has a GLOBAL file for parameters. … … 85 165 if ( !newDocument->isOk() ) 86 166 { 87 gint errorCode =newDocument->getErrorCode ();167 DocumentError errorCode = (DocumentError)newDocument->getErrorCode (); 88 168 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 } 169 gchar *errorMessage = Document::getErrorMessage (errorCode); 170 g_set_error (error, 171 EPDFVIEW_DOCUMENT_ERROR, errorCode, 172 _("Failed to load document '%s'.\n%s\n"), 173 filename, errorMessage); 174 g_free (errorMessage); 101 175 102 176 return false; -
trunk/src/Document.h
r6 r8 19 19 #define __DOCUMENT_H__ 20 20 21 /// This is the definition of the GQuark used for Document's errors. 22 #define EPDFVIEW_DOCUMENT_ERROR ePDFView::Document::getErrorQuark () 23 21 24 namespace ePDFView 22 25 { 26 /// 27 /// @brief Defines the possible errors loading a document. 28 /// 29 /// This enumeration matches the definitions at ErrorCodes.h of Poppler. 30 /// 31 typedef enum 32 { 33 /// No error. 34 DocumentErrorNone = 0, 35 /// Couldn't open the PDF file. 36 DocumentErrorOpenFile = 1, 37 /// Coudln't read the page catalog. 38 DocumentErrorBadCatalog = 2, 39 /// PDF file is damaged and couldn't be repaired. 40 DocumentErrorDamaged = 3, 41 /// The file is encrypted and the password was incorrect 42 /// or not supplied. 43 DocumentErrorEncrypted = 4, 44 /// Nonexistent or invalid highlight file. 45 DocumentErrorHighlightFile = 5, 46 /// Invalid printer. 47 DocumentErrorBadPrinter = 6, 48 /// Error during printing. 49 DocumentErrorPrinting = 7, 50 /// PDF File doesn't allow that operation. 51 DocumentErrorPermission = 8, 52 /// Invalid page number. 53 DocumentErrorBadPageNumber = 9, 54 /// File I/O Error. 55 DocumentErrorFileIO = 10 56 } DocumentError; 57 23 58 /// 24 59 /// @brief Defines the document's page mode. … … 71 106 DocumentIndex &getDocumentIndex (void); 72 107 108 static GQuark getErrorQuark (void); 109 static gchar *getErrorMessage (DocumentError errorCode); 110 73 111 protected: 74 112 PDFDoc *m_Document; 113 114 static GQuark errorQuark; 75 115 }; 76 116 } -
trunk/src/epdfview.h
r6 r8 19 19 #define __E_PDF_VIEW_H__ 20 20 21 #include <assert.h>22 21 #include <gettext.h> 23 22 #include <glib.h> -
trunk/tests/DocumentTest.cxx
r6 r8 93 93 DocumentTest::fileNotFound (void) 94 94 { 95 gchar *error_message;96 95 GError *error = NULL; 97 96 … … 99 98 CPPUNIT_ASSERT (!m_Document->isLoaded ()); 100 99 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, 100 DocumentError errorCode = (DocumentError)error->code; 101 gchar *documentError = Document::getErrorMessage(errorCode); 102 gchar *errorMessage = g_strdup_printf ( 103 "Failed to load document '%sNoFile.pdf'.\n%s\n", 104 TEST_DATA_DIR, documentError); 105 g_free(documentError); 106 CPPUNIT_ASSERT_EQUAL (DocumentErrorOpenFile, errorCode); 107 CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp (errorMessage, 104 108 error->message)); 109 g_free (errorMessage); 110 g_error_free (error); 105 111 } 112 113 /// 114 /// @brief Test that loading an invalid file fails. 115 /// 116 /// This test checks the second load failure: the file is not a PDF or 117 /// is malformed. 118 /// 119 void 120 DocumentTest::invalidFile (void) 121 { 122 gchar *error_message; 123 GError *error = NULL; 124 125 CPPUNIT_ASSERT (!m_Document->loadFile (TEST_DATA_DIR "DocumentTest.cxx", 126 &error)); 127 CPPUNIT_ASSERT (!m_Document->isLoaded ()); 128 129 DocumentError errorCode = (DocumentError)error->code; 130 gchar *documentError = Document::getErrorMessage(errorCode); 131 gchar *errorMessage = g_strdup_printf ( 132 "Failed to load document '%sDocumentTest.cxx'.\n%s\n", 133 TEST_DATA_DIR, documentError); 134 g_free(documentError); 135 CPPUNIT_ASSERT_EQUAL (DocumentErrorDamaged, errorCode); 136 CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp (errorMessage, 137 error->message)); 138 g_free (errorMessage); 139 g_error_free (error); 140 } -
trunk/tests/DocumentTest.h
r6 r8 28 28 CPPUNIT_TEST (emptyDocument); 29 29 CPPUNIT_TEST (fileNotFound); 30 CPPUNIT_TEST (invalidFile); 30 31 CPPUNIT_TEST_SUITE_END (); 31 32 … … 36 37 void emptyDocument (void); 37 38 void fileNotFound (void); 38 39 void invalidFile (void); 40 39 41 private: 40 42 Document *m_Document; -
trunk/tests/Makefile.am
r7 r8 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) \15 $(POPPLER_CFLAGS) \11 test_epdfview_CXXFLAGS = \ 12 -DTEST_DATA_DIR='"$(top_srcdir)/tests/"' \ 13 -I$(top_srcdir)/src \ 14 $(GLIB_CFLAGS) \ 15 $(POPPLER_CFLAGS) \ 16 16 $(CPPUNIT_CFLAGS) 17 17
