[netinstall] Expand tests to include group-checking

- Check groups
- Check whole treemodels recursively (this is not in PackageTreeItem,
  because that explicitly ignores the tree structure).
- Also a stub of checking example files (from the src dir)
This commit is contained in:
Adriaan de Groot 2020-03-23 12:53:35 +01:00
parent 025ab8b524
commit f592a3f373
2 changed files with 94 additions and 5 deletions

View File

@ -66,6 +66,8 @@ public:
PackageTreeItem::List getItemPackages( PackageTreeItem* item ) const; PackageTreeItem::List getItemPackages( PackageTreeItem* item ) const;
private: private:
friend class ItemTests;
void setupModelData( const YAML::Node& data, PackageTreeItem* parent ); void setupModelData( const YAML::Node& data, PackageTreeItem* parent );
void setupModelData( const QVariantList& l, PackageTreeItem* parent ); void setupModelData( const QVariantList& l, PackageTreeItem* parent );

View File

@ -16,6 +16,7 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>. * along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "PackageModel.h"
#include "PackageTreeItem.h" #include "PackageTreeItem.h"
#include "utils/Logger.h" #include "utils/Logger.h"
@ -31,6 +32,10 @@ public:
ItemTests(); ItemTests();
virtual ~ItemTests() {} virtual ~ItemTests() {}
private:
void checkAllSelected( PackageTreeItem* p );
void recursiveCompare( PackageTreeItem*, PackageTreeItem* );
private Q_SLOTS: private Q_SLOTS:
void initTestCase(); void initTestCase();
@ -38,6 +43,8 @@ private Q_SLOTS:
void testPackage(); void testPackage();
void testGroup(); void testGroup();
void testCompare(); void testCompare();
void testModel();
void testExampleFiles();
}; };
ItemTests::ItemTests() {} ItemTests::ItemTests() {}
@ -106,6 +113,15 @@ static const char doc_no_packages[] =
"- name: \"CCR\"\n" "- name: \"CCR\"\n"
" description: \"Tools for the Chakra Community Repository\"\n" " description: \"Tools for the Chakra Community Repository\"\n"
" packages: []\n"; " packages: []\n";
static const char doc_with_expanded[] =
"- name: \"CCR\"\n"
" description: \"Tools for the Chakra Community Repository\"\n"
" expanded: true\n"
" packages:\n"
" - ccr\n"
" - base-devel\n"
" - bash\n";
// *INDENT-ON* // *INDENT-ON*
// clang-format on // clang-format on
@ -177,20 +193,91 @@ ItemTests::testCompare()
QVERIFY( p3 == p4 ); QVERIFY( p3 == p4 );
PackageTreeItem p5( CalamaresUtils::yamlSequenceToVariant( YAML::Load( doc_no_packages ) )[ 0 ].toMap(), nullptr ); PackageTreeItem p5( CalamaresUtils::yamlSequenceToVariant( YAML::Load( doc_no_packages ) )[ 0 ].toMap(), nullptr );
QVERIFY( p3 == p5 ); QVERIFY( p3 == p5 );
}
#if 0 void
ItemTests::checkAllSelected( PackageTreeItem* p )
{
QVERIFY( p->isSelected() );
for ( int i = 0; i < p->childCount(); ++i )
{
checkAllSelected( p->child( i ) );
}
}
void
ItemTests::recursiveCompare( PackageTreeItem* l, PackageTreeItem* r )
{
QVERIFY( l && r );
QVERIFY( *l == *r );
QCOMPARE( l->childCount(), r->childCount() );
for ( int i = 0; i < l->childCount(); ++i )
{
QCOMPARE( l->childCount(), r->childCount() );
recursiveCompare( l->child( i ), r->child( i ) );
}
}
void
ItemTests::testModel()
{
YAML::Node yamldoc = YAML::Load( doc ); // See testGroup()
QVariantList yamlContents = CalamaresUtils::yamlSequenceToVariant( yamldoc );
QCOMPARE( yamlContents.length(), 1 );
PackageModel m0( yamlContents, nullptr );
PackageModel m1( yamldoc, nullptr );
QCOMPARE( m0.rowCount(), m1.rowCount() );
QCOMPARE( m0.m_hiddenItems.count(), 0 ); // Nothing hidden
QCOMPARE( m1.m_hiddenItems.count(), 0 );
QCOMPARE( m0.rowCount(), 1 ); // Group, the packages are invisible
QCOMPARE( m0.rowCount( m0.index( 0, 0 ) ), 3 ); // The packages
QCOMPARE( m1.rowCount( m1.index( 0, 0 ) ), 3 ); // The packages
checkAllSelected( m0.m_rootItem );
checkAllSelected( m1.m_rootItem );
PackageModel m2( YAML::Load( doc_with_expanded ), nullptr );
QCOMPARE( m2.m_hiddenItems.count(), 0 );
QCOMPARE( m2.rowCount(), 1 ); // Group, now the packages expanded but not counted
QCOMPARE( m2.rowCount( m2.index( 0, 0 ) ), 3 ); // The packages
checkAllSelected( m2.m_rootItem );
PackageTreeItem r;
QVERIFY( r == *m0.m_rootItem );
QVERIFY( r == *m1.m_rootItem );
QCOMPARE( m0.m_rootItem->childCount(), 1 );
PackageTreeItem* group = m0.m_rootItem->child( 0 );
QVERIFY( group->isGroup() );
QCOMPARE( group->name(), QStringLiteral( "CCR" ) );
QCOMPARE( group->childCount(), 3 );
PackageTreeItem bash( "bash", nullptr );
// Check that the sub-packages loaded correctly // Check that the sub-packages loaded correctly
bool found_one_bash = false; bool found_one_bash = false;
for ( int i = 0; i < p3.childCount(); ++i ) for ( int i = 0; i < group->childCount(); ++i )
{ {
QVERIFY( p3.child( i )->isPackage() ); QVERIFY( group->child( i )->isPackage() );
if ( p0 == *p3.child( i ) ) if ( bash == *( group->child( i ) ) )
{ {
found_one_bash = true; found_one_bash = true;
} }
} }
QVERIFY( found_one_bash ); QVERIFY( found_one_bash );
#endif
recursiveCompare( m0.m_rootItem, m1.m_rootItem );
// But m2 has "expanded" set which the others do no
QVERIFY( *( m2.m_rootItem->child( 0 ) ) != *group );
}
void
ItemTests::testExampleFiles()
{
} }