Skip to content

Commit fecb748

Browse files
committed
improve testAstrometry searching of star catalog file for testing
1 parent 072d95d commit fecb748

1 file changed

Lines changed: 30 additions & 17 deletions

File tree

src/tests/testAstrometry.cpp

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,44 @@ QTEST_GUILESS_MAIN(TestAstrometry)
3333
void TestAstrometry::initTestCase()
3434
{
3535
// Define the directory to search in
36-
QDir dir("../../stars/hip_gaia3/");
37-
38-
// Make sure the directory exists
39-
if (!dir.exists()) {
40-
qDebug() << "Directory does not exist!";
41-
return;
42-
}
43-
36+
QDir dir(QDir::currentPath());
4437
// make a list of star catalog files stars_0_*.cat, stars_1_*.cat, stars_2_*.cat and stars_3_*.cat
4538
QStringList filters;
4639
filters << "stars_0_*.cat" << "stars_1_*.cat" << "stars_2_*.cat" << "stars_3_*.cat";
40+
QStringList files;
41+
QString file;
42+
43+
while (!dir.isRoot()) // check directory one by one if the current directory contains star catalog files
44+
{
45+
// check if at least one "stars_*.cat" file exist under the directory
46+
if (dir.exists("stars/hip_gaia3")) // check if the directory exists, if yes go in to check
47+
{
48+
dir.cd("stars/hip_gaia3");
49+
dir.setNameFilters(QStringList() << filters[0]);
50+
files = dir.entryList(QDir::Files);
51+
if (!files.isEmpty()) // in case the directory does not contains any star catalog file
52+
{
53+
break;
54+
}
55+
else
56+
{
57+
// go back to the parent directory and keep searching
58+
dir.cd("../../");
59+
}
60+
}
61+
dir.cdUp(); // one level up at a time
62+
}
63+
64+
// assert the directory exists
65+
QVERIFY2(dir.exists(), "Star catalog directory does not exist! Can't perform the rest of the tests.");
4766

4867
// loop through the filters and set the ZoneArray pointers
4968
for (int i = 0; i < filters.size(); i++)
5069
{
5170
dir.setNameFilters(QStringList() << filters[i]);
52-
QStringList files = dir.entryList(QDir::Files);
53-
QString file;
54-
55-
if (!files.isEmpty()) {
56-
qDebug() << "Found files:" << files[0];
57-
file = files[0];
58-
} else {
59-
qDebug() << "No matching files found.";
60-
}
71+
files = dir.entryList(QDir::Files); // get the list of files in the directory
72+
QVERIFY2(!files.isEmpty(), qPrintable(QString("No matching star catalog found at %1").arg(dir.path().toStdString().c_str())));
73+
file = files[0];
6174

6275
file = dir.path() + "/" + file;
6376
ZoneArray* z = ZoneArray::create(file, true);

0 commit comments

Comments
 (0)