From 41e5be37737b959c476275c6aa245b635b6e2a16 Mon Sep 17 00:00:00 2001 From: Antonis Tsiapaliokas Date: Tue, 16 Aug 2011 01:26:21 +0300 Subject: [PATCH] Add operator== and operator!= to qsqlerror class Merge-request: 44 Task-number: QTBUG-20543 Change-Id: I7b88985fe095ffd2e48ac05c82dc3f3a92dbb091 Reviewed-on: http://codereview.qt.nokia.com/3425 Reviewed-by: Charles Yin Reviewed-by: Qt Sanity Bot --- src/sql/kernel/qsqlerror.cpp | 20 ++++++++++++++++++++ src/sql/kernel/qsqlerror.h | 2 ++ tests/auto/qsqlerror/tst_qsqlerror.cpp | 16 ++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/src/sql/kernel/qsqlerror.cpp b/src/sql/kernel/qsqlerror.cpp index a8ffdff..fd731e4 100644 --- a/src/sql/kernel/qsqlerror.cpp +++ b/src/sql/kernel/qsqlerror.cpp @@ -124,6 +124,26 @@ QSqlError& QSqlError::operator=(const QSqlError& other) } /*! + Compare the \a other error's values to this error and returns true, if it equal. +*/ + +bool QSqlError::operator==(const QSqlError& other) +{ + return (errorType == other.errorType); +} + + +/*! + Compare the \a other error's values to this error and returns true if it is not equal. +*/ + +bool QSqlError::operator!=(const QSqlError& other) +{ + return (errorType != other.errorType); +} + + +/*! Destroys the object and frees any allocated resources. */ diff --git a/src/sql/kernel/qsqlerror.h b/src/sql/kernel/qsqlerror.h index fea3ca8..c1df370 100644 --- a/src/sql/kernel/qsqlerror.h +++ b/src/sql/kernel/qsqlerror.h @@ -66,6 +66,8 @@ public: int number = -1); QSqlError(const QSqlError& other); QSqlError& operator=(const QSqlError& other); + bool operator==(const QSqlError& other); + bool operator!=(const QSqlError& other); ~QSqlError(); QString driverText() const; diff --git a/tests/auto/qsqlerror/tst_qsqlerror.cpp b/tests/auto/qsqlerror/tst_qsqlerror.cpp index ad3ef05..d02b373 100644 --- a/tests/auto/qsqlerror/tst_qsqlerror.cpp +++ b/tests/auto/qsqlerror/tst_qsqlerror.cpp @@ -61,6 +61,7 @@ public: private slots: void getSetCheck(); void construction(); + void operators(); }; tst_QSqlError::tst_QSqlError() @@ -125,5 +126,20 @@ void tst_QSqlError::construction() QVERIFY(!obj4.isValid()); } +void tst_QSqlError::operators() +{ + QSqlError error1; + QSqlError error2; + QSqlError error3; + + error1.setType(QSqlError::NoError); + error2.setType(QSqlError::NoError); + error3.setType(QSqlError::UnknownError); + + QVERIFY(error1 == error2); + QVERIFY(error1 != error3); +} + + QTEST_MAIN(tst_QSqlError) #include "tst_qsqlerror.moc" -- 2.7.4