Beispiel #1
0
void Qtilities::Testing::TestObserver::testOwnershipManual() {
    LOG_INFO("TestObserver::testOwnershipManual() start:");

    // Create the observer
    Observer* observerA = new Observer("Observer A");

    // Create the objects
    QPointer<QObject> object1 = new QObject();
    object1->setObjectName("Object 1");
    QPointer<QObject> object2 = new QObject();
    object2->setObjectName("Object 2");

    // Attach objects to observers
    observerA->attachSubject(object1,Observer::ManualOwnership);
    observerA->attachSubject(object2,Observer::ManualOwnership);

    // Now delete observers
    delete observerA;

    // Check the validity of the objects:
    QVERIFY(object1 != 0);
    QVERIFY(object2 != 0);

    delete object1;
    delete object2;

    LOG_INFO("TestObserver::testOwnershipManual() end.");
 }
Beispiel #2
0
void Qtilities::Testing::TestObserver::testOwnershipSpecificObserver() {
    LOG_INFO("TestObserver::testOwnershipSpecificObserver() start:");

    // Create the observer
    Observer* observerA = new Observer("Observer A");

    // Create the objects
    QPointer<QObject> object1 = new QObject();
    object1->setObjectName("Object 1");
    QPointer<QObject> object2 = new QObject();
    object2->setObjectName("Object 2");

    // Attach objects to observers
    observerA->attachSubject(object1,Observer::SpecificObserverOwnership);
    observerA->attachSubject(object2,Observer::SpecificObserverOwnership);

    // Now delete observer
    delete observerA;
    QApplication::processEvents();

    // Check the validity of the objects:
    QVERIFY(object1 == 0);
    QVERIFY(object2 == 0);

    LOG_INFO("TestObserver::testOwnershipSpecificObserver() end.");
}