API unit tests from Maemo API test team.

A large number of tweaks and changes to original tests, and refactor
a lot of the mock backends to reduce duplication.

Changed viewfinder test case to use mock service and provider so
that it matches the image capture test case.

Reviewed-by: Jonas Rabbe
(cherry picked from commit e40bef5508a4165cec4a46b97115aed461027fa5)

Also licence header fix:
(cherry picked from commit e9ee9e8c48b45b97d62ee4a82e400fa9d8ea8107)

Change-Id: Ic59891d75563bb2e008a336eea859e8c44d8d831
Reviewed-on: http://codereview.qt.nokia.com/2078
Reviewed-by: Jonas Rabbe <jonas.rabbe@nokia.com>
This commit is contained in:
Michael Goddard
2011-07-25 15:02:51 +10:00
committed by Qt by Nokia
parent 1e4dda9710
commit a6128410da
94 changed files with 8814 additions and 2396 deletions

View File

@@ -54,17 +54,6 @@ QT_BEGIN_NAMESPACE
class QtTestMediaService;
class tst_QMediaService : public QObject
{
Q_OBJECT
private slots:
void initTestCase();
void control_iid();
void control();
};
class QtTestMediaControlA : public QMediaControl
{
Q_OBJECT
@@ -98,23 +87,31 @@ class QtTestMediaControlD : public QMediaControl
#define QtTestMediaControlD_iid "com.nokia.QtTestMediaControlD"
Q_MEDIA_DECLARE_CONTROL(QtTestMediaControlD, QtTestMediaControlD_iid)
//unimplemented service
#define QtTestMediaControlE_iid "com.nokia.QtTestMediaControlF"
class QtTestMediaControlE : public QMediaControl
{
Q_OBJECT
};
/* implementation of child class by inheriting The QMediaService base class for media service implementations. */
class QtTestMediaService : public QMediaService
{
Q_OBJECT
public:
QtTestMediaService()
: QMediaService(0)
, refA(0)
, refB(0)
, refC(0)
int refA;
int refB;
int refC;
QtTestMediaControlA controlA;
QtTestMediaControlB controlB;
QtTestMediaControlC controlC;
//constructor
QtTestMediaService(): QMediaService(0), refA(0), refB(0), refC(0)
{
}
//requestControl() pure virtual function of QMediaService class.
QMediaControl *requestControl(const char *name)
{
if (strcmp(name, QtTestMediaControlA_iid) == 0) {
@@ -134,6 +131,7 @@ public:
}
}
//releaseControl() pure virtual function of QMediaService class.
void releaseControl(QMediaControl *control)
{
if (control == &controlA)
@@ -144,20 +142,107 @@ public:
refC -= 1;
}
//requestControl() function of QMediaService class.
using QMediaService::requestControl;
int refA;
int refB;
int refC;
QtTestMediaControlA controlA;
QtTestMediaControlB controlB;
QtTestMediaControlC controlC;
};
void tst_QMediaService::initTestCase()
{
/* Test case implementation for QMediaService class which provides a common base class for media service implementations.*/
class tst_QMediaService : public QObject
{
Q_OBJECT
private slots:
void tst_destructor();
void tst_releaseControl();
void tst_requestControl();
void tst_requestControlTemplate();
void initTestCase();
void control_iid();
void control();
};
/*MaemoAPI-1668 :destructor property test. */
void tst_QMediaService::tst_destructor()
{
QtTestMediaService *service = new QtTestMediaService;
delete service;
}
void tst_QMediaService::initTestCase()
{
}
/*MaemoAPI-1669 :releaseControl() API property test. */
void tst_QMediaService::tst_releaseControl()
{
//test class instance creation
QtTestMediaService service;
//Get a pointer to the media control implementing interface and verify.
QMediaControl* controlA = service.requestControl(QtTestMediaControlA_iid);
QCOMPARE(controlA, &service.controlA);
service.releaseControl(controlA); //Controls must be returned to the service when no longer needed
QVERIFY(service.refA == 0);
//Get a pointer to the media control implementing interface and verify.
QMediaControl* controlB = service.requestControl(QtTestMediaControlB_iid);
QCOMPARE(controlB, &service.controlB);
service.releaseControl(controlB); //Controls must be returned to the service when no longer needed
QVERIFY(service.refB == 0);
}
/*MaemoAPI-1670 :requestControl() API property test. */
void tst_QMediaService::tst_requestControl()
{
//test class instance creation
QtTestMediaService service;
//Get a pointer to the media control implementing interface and verify.
QMediaControl* controlA = service.requestControl(QtTestMediaControlA_iid);
QCOMPARE(controlA, &service.controlA);
service.releaseControl(controlA); //Controls must be returned to the service when no longer needed
//Get a pointer to the media control implementing interface and verify.
QMediaControl* controlB = service.requestControl(QtTestMediaControlB_iid);
QCOMPARE(controlB, &service.controlB);
service.releaseControl(controlB); //Controls must be returned to the service when no longer needed
//If the service does not implement the control, a null pointer is returned instead.
QMediaControl* controlE = service.requestControl(QtTestMediaControlE_iid);
QVERIFY(!controlE); //should return null pointer
service.releaseControl(controlE); //Controls must be returned to the service when no longer needed
//If the service is unavailable a null pointer is returned instead.
QMediaControl* control = service.requestControl("");
QVERIFY(!control); //should return null pointer
service.releaseControl(control); //Controls must be returned to the service when no longer needed
}
/*MaemoAPI-1671 :requestControl() API property test. */
void tst_QMediaService::tst_requestControlTemplate()
{
//test class instance creation
QtTestMediaService service;
//Get a pointer to the media control of type T implemented by a media service.
QtTestMediaControlA *controlA = service.requestControl<QtTestMediaControlA *>();
QCOMPARE(controlA, &service.controlA);
service.releaseControl(controlA);
//Get a pointer to the media control of type T implemented by a media service.
QtTestMediaControlB *controlB = service.requestControl<QtTestMediaControlB *>();
QCOMPARE(controlB, &service.controlB);
service.releaseControl(controlB);
QVERIFY(!service.requestControl<QtTestMediaControlC *>()); // Faulty implementation returns A.
QCOMPARE(service.refA, 0); // Verify the control was released.
QVERIFY(!service.requestControl<QtTestMediaControlD *>()); // No control of that type.
}
void tst_QMediaService::control_iid()
{
const char *nullString = 0;
@@ -181,7 +266,7 @@ void tst_QMediaService::control()
QCOMPARE(controlB, &service.controlB);
service.releaseControl(controlB);
QVERIFY(!service.requestControl<QtTestMediaControlC *>()); // Faulty implementation returns A.
QVERIFY(!service.requestControl<QtTestMediaControlC *>()); // Faulty implementation returns A, but is wrong class
QCOMPARE(service.refA, 0); // Verify the control was released.
QVERIFY(!service.requestControl<QtTestMediaControlD *>()); // No control of that type.