[Ktutorial-commits] SF.net SVN: ktutorial:[196] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
|
From: <dan...@us...> - 2010-03-26 19:34:28
|
Revision: 196
http://ktutorial.svn.sourceforge.net/ktutorial/?rev=196&view=rev
Author: danxuliu
Date: 2010-03-26 19:34:21 +0000 (Fri, 26 Mar 2010)
Log Message:
-----------
Fix message of DeserializationException thrown by TutorialReader
Modified Paths:
--------------
trunk/ktutorial/ktutorial-editor/src/serialization/DeserializationException.cpp
trunk/ktutorial/ktutorial-editor/src/serialization/DeserializationException.h
trunk/ktutorial/ktutorial-editor/src/serialization/TutorialReader.cpp
trunk/ktutorial/ktutorial-editor/tests/unit/serialization/DeserializationExceptionTest.cpp
trunk/ktutorial/ktutorial-editor/tests/unit/serialization/TutorialReaderTest.cpp
Modified: trunk/ktutorial/ktutorial-editor/src/serialization/DeserializationException.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/serialization/DeserializationException.cpp 2010-03-26 08:49:10 UTC (rev 195)
+++ trunk/ktutorial/ktutorial-editor/src/serialization/DeserializationException.cpp 2010-03-26 19:34:21 UTC (rev 196)
@@ -31,3 +31,7 @@
const char* DeserializationException::what() const throw() {
return mMessage.toUtf8();
}
+
+QString DeserializationException::message() const throw() {
+ return mMessage;
+}
Modified: trunk/ktutorial/ktutorial-editor/src/serialization/DeserializationException.h
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/serialization/DeserializationException.h 2010-03-26 08:49:10 UTC (rev 195)
+++ trunk/ktutorial/ktutorial-editor/src/serialization/DeserializationException.h 2010-03-26 19:34:21 UTC (rev 196)
@@ -39,6 +39,13 @@
*/
virtual const char* what() const throw();
+ /**
+ * Returns the exception message.
+ *
+ * @return The exception message.
+ */
+ QString message() const throw();
+
private:
QString mMessage;
Modified: trunk/ktutorial/ktutorial-editor/src/serialization/TutorialReader.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/serialization/TutorialReader.cpp 2010-03-26 08:49:10 UTC (rev 195)
+++ trunk/ktutorial/ktutorial-editor/src/serialization/TutorialReader.cpp 2010-03-26 19:34:21 UTC (rev 196)
@@ -20,6 +20,8 @@
#include <QDomDocument>
+#include <KLocalizedString>
+
#include "../Reaction.h"
#include "../Step.h"
#include "../Tutorial.h"
@@ -41,11 +43,17 @@
int errorLine;
int errorColumn;
- if (!document.setContent(data, &errorMessage, &errorLine, &errorColumn) ||
- document.documentElement().tagName() != "tutorial") {
- throw DeserializationException(errorMessage);
+ if (!document.setContent(data, &errorMessage, &errorLine, &errorColumn)) {
+ throw DeserializationException(i18n("XML document is not well formed: "
+"%1, line %2, column %3", errorMessage, errorLine, errorColumn));
}
+ if (document.documentElement().tagName() != "tutorial") {
+ throw DeserializationException(i18n("Unknown root element, "
+"<emphasis>tutorial</emphasis> expected, got: %1",
+document.documentElement().tagName()));
+ }
+
return readTutorial(document.documentElement());
}
Modified: trunk/ktutorial/ktutorial-editor/tests/unit/serialization/DeserializationExceptionTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/serialization/DeserializationExceptionTest.cpp 2010-03-26 08:49:10 UTC (rev 195)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/serialization/DeserializationExceptionTest.cpp 2010-03-26 19:34:21 UTC (rev 196)
@@ -34,12 +34,14 @@
DeserializationException exception(QString("The message"));
QCOMPARE(exception.what(), "The message");
+ QCOMPARE(exception.message(), QString("The message"));
}
void DeserializationExceptionTest::testConstructorEmpty() {
DeserializationException exception;
QCOMPARE(exception.what(), "");
+ QCOMPARE(exception.message(), QString(""));
}
QTEST_MAIN(DeserializationExceptionTest)
Modified: trunk/ktutorial/ktutorial-editor/tests/unit/serialization/TutorialReaderTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/serialization/TutorialReaderTest.cpp 2010-03-26 08:49:10 UTC (rev 195)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/serialization/TutorialReaderTest.cpp 2010-03-26 19:34:21 UTC (rev 196)
@@ -20,6 +20,8 @@
#include "TutorialReader.h"
+#include <KLocalizedString>
+
#include "../Reaction.h"
#include "../Step.h"
#include "../Tutorial.h"
@@ -515,6 +517,7 @@
QScopedPointer<Tutorial> tutorial(reader.readTutorial(data));
QFAIL("Expected DeserializationException not thrown");
} catch (DeserializationException e) {
+ QVERIFY(e.message().contains(i18n("XML document is not well formed")));
}
}
@@ -529,6 +532,7 @@
QScopedPointer<Tutorial> tutorial(reader.readTutorial(data));
QFAIL("Expected DeserializationException not thrown");
} catch (DeserializationException e) {
+ QVERIFY(e.message().contains(i18n("Unknown root element")));
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|