MCPcopy Create free account
hub / github.com/cneben/QuickQanava / testContainerModelStdWeakQObject

Function testContainerModelStdWeakQObject

tests/containers_test.cpp:626–676  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

624
625template <class C>
626void testContainerModelStdWeakQObject(C& container)
627{
628 auto model = container.getModel();
629 ASSERT_TRUE( model != nullptr );
630
631 using T = typename C::Item_type;
632
633 auto so1{std::make_shared<QObject>()};
634 auto so2{std::make_shared<QObject>()};
635 auto o1 = T{so1};
636 auto o2 = T{so2};
637
638 // qcm::ContainerModel::append()
639 auto so3 = std::make_shared<QObject>();
640 ASSERT_EQ( 0, model->getLength() );
641 container.append( o1 );
642 ASSERT_EQ( 1, model->getLength() );
643 container.append(so3);
644 container.append( o2 );
645 ASSERT_EQ( 3, model->getLength() );
646
647 // qcm::ContainerModel::at()
648 ASSERT_TRUE( ( model->at(0) != nullptr ) );
649 EXPECT_TRUE( ( model->at(0) == o1.lock().get() ) );
650 EXPECT_TRUE( ( model->at(2) == o2.lock().get() ) );
651 ASSERT_TRUE( ( model->at(3) == nullptr ) ); // Overflow
652
653 // qcm::ContainerModel::at()
654 QObject* o3{new QObject()};
655 ASSERT_EQ( -1, model->indexOf(nullptr) ); // Invalid input
656 ASSERT_EQ( -1, model->indexOf(o3) ); // Invalid input, o3 is not inserted
657 EXPECT_EQ( 0, model->indexOf(o1.lock().get()) );
658 EXPECT_EQ( 2, model->indexOf(o2.lock().get()) );
659
660 // qcm::ContainerModel::remove()
661 model->remove(nullptr); // Invalid input
662 model->remove(o3); // Invalid input (o3 is not inserted)
663 model->remove(o1.lock().get());
664 ASSERT_EQ( 2, model->getLength() );
665
666 // qcm::ContainerModel::contains()
667 ASSERT_FALSE( model->contains(nullptr) ); // Invalid input
668 ASSERT_FALSE( model->contains(o3) ); // Invalid input o3 is not inserted
669 ASSERT_FALSE( model->contains(o1.lock().get()) ); // o1 has been removce
670 ASSERT_TRUE( model->contains(o2.lock().get()) );
671
672 // qcm::ContainerModel::clear()
673 model->clear();
674 ASSERT_TRUE( model->at(0) == nullptr );
675 ASSERT_EQ( 0, model->getLength() );
676}
677
678TEST(qpsContainerModel, qVectorStdWeakQObject)
679{

Callers

nothing calls this directly

Calls 8

getModelMethod · 0.80
getLengthMethod · 0.80
appendMethod · 0.45
atMethod · 0.45
indexOfMethod · 0.45
removeMethod · 0.45
containsMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected