File indexing completed on 2024-03-24 15:18:34

0001 /*
0002     KStars UI tests for verifying correct counting of the capture module
0003 
0004     SPDX-FileCopyrightText: 2020 Wolfgang Reissenberger <sterne-jaeger@openfuture.de>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #pragma once
0010 
0011 #include <QObject>
0012 #include <QQueue>
0013 
0014 #include "config-kstars.h"
0015 #include "test_ekos_debug.h"
0016 
0017 #if defined(HAVE_INDI)
0018 #include "ekos/ekos.h"
0019 #include "ekos/capture/sequencejob.h"
0020 #include "test_ekos_capture_helper.h"
0021 
0022 class TestEkosCaptureCount : public QObject
0023 {
0024     Q_OBJECT
0025 public:
0026     explicit TestEkosCaptureCount(QObject *parent = nullptr);
0027 
0028 protected:
0029 
0030     /**
0031      * @brief Setup capturing
0032      * @return true iff preparation was successful
0033      */
0034     bool prepareCapture();
0035 
0036     /**
0037      * @brief Setup capturing for tests with the scheduler
0038      * @param completionCondition completion condition for the scheduler
0039      * @return true iff preparation was successful
0040      */
0041     bool prepareScheduledCapture(Ekos::CompletionCondition completionCondition);
0042 
0043     /**
0044      * @brief Prepare the scheduler for the test.
0045      * @param sequenceFile File name of the capture sequence file
0046      * @param sequence filter and count as QString("<filter>:<count"), ... list
0047      * @param capturedFramesMap mapping from filter to existing frames per filter as QString("<filter>:<count"), ... list
0048      * @param completionCondition completion condition for the scheduler
0049      * @param iterations number of iterations to be executed (only relevant if completionCondition == FINISH_REPEAT)
0050      * @param rememberJobProgress should the scheduler use the option "Remember job progress"
0051      * @param exptime exposure time (identical for all frames)
0052      * @return true iff preparation was successful
0053      */
0054     bool setupScheduler(QString sequenceFile, QString sequence, QString capturedFramesMap, Ekos::CompletionCondition completionCondition,
0055                         int iterations, bool rememberJobProgress, double exptime);
0056 
0057     /**
0058      * @brief Verify the counts that the scheduler displays in the job table
0059      * @param sequence filter and count as QString("<filter>:<count"), ... list
0060      * @param capturedFramesMap mapping from filter to existing frames per filter as QString("<filter>:<count"), ... list
0061      * @param completionCondition completion condition for the scheduler
0062      * @param iterations number of iterations to be executed (only relevant if completionCondition == FINISH_REPEAT)
0063      * @param rememberJobProgress should the scheduler use the option "Remember job progress"
0064      * @param exptime exposure time (identical for all frames)
0065      * @return true iff the displayed counts match the specification
0066      */
0067     bool verifySchedulerCounting(QString sequence, QString capturedFramesMap, Ekos::CompletionCondition completionCondition,
0068                                  int iterations, bool rememberJobProgress, double exptime);
0069 
0070     /**
0071      * @brief Execute capturing
0072      * @return true iff exactly the expected frames have been taken
0073      */
0074     bool executeCapturing();
0075 
0076     /**
0077      * @brief Helper function translating simple QString input into QTest test data rows
0078      * @param exptime exposure time of the sequence
0079      * @param sequence filter and count as QString("<filter>:<count"), ... list
0080      * @param capturedFramesMap mapping from filter to existing frames per filter as QString("<filter>:<count"), ... list
0081      * @param expectedFrames expected number of frames per filter as QString("<filter>:<count"), ... list
0082      * @param iterations number of iterations the capture sequence should be repeated
0083      */
0084     void prepareTestData(double exptime, QString sequence, QString capturedFramesMap, QString expectedFrames, int iterations = 1);
0085 
0086     // mapping between image signature and number of images expected to be captured for this signature
0087     QMap<QString, int> m_expectedImages;
0088     /**
0089      * @brief Register that a new image has been captured
0090      */
0091     void captureComplete(const QVariantMap &metadata);
0092 
0093     // sequence of scheduler states that are expected
0094     QQueue<Ekos::SchedulerState> expectedSchedulerStates;
0095     /**
0096      * @brief Slot to receive a new scheduler state
0097      * @param status new capture status
0098      */
0099     void schedulerStateChanged(Ekos::SchedulerState status);
0100 
0101     // current scheduler status
0102     Ekos::SchedulerState m_SchedulerStatus;
0103 
0104     /**
0105      * @brief Retrieve the current capture status.
0106      */
0107     inline Ekos::SchedulerState getSchedulerStatus() {return m_SchedulerStatus;}
0108 
0109 
0110 protected slots:
0111     void initTestCase();
0112     void cleanupTestCase();
0113 
0114     void init();
0115     void cleanup();
0116 
0117 private:
0118     // current capture status
0119     Ekos::CaptureState m_CaptureStatus;
0120 
0121     // helper class
0122     TestEkosCaptureHelper *m_CaptureHelper = nullptr;
0123 
0124     QString target = "test";
0125 
0126     /**
0127      * @brief Fill the map of frames that have already been captured
0128      * @param expectedFrames comma separated list of <filter>:<count>
0129      * @param imagepath base directory holding all images
0130      * @return true if everything was successful
0131      */
0132     bool fillCapturedFramesMap(QString capturedFramesMap, QString imagepath);
0133 
0134     /**
0135      * @brief Determine the total count from a comma separated sequence of <filter>:<count>
0136      * @return sum of <count>
0137      */
0138     int totalCount(QString sequence);
0139 
0140     /**
0141      * @brief Determine the map filter --> counts from a comma separated sequence of <filter>:<count>
0142      * @param sequence
0143      * @return
0144      */
0145     QMap<QString, uint16_t> framesMap(QString sequence);
0146 
0147     /**
0148      * @brief Fill the map of frames that are expected to be captured
0149      * @param expectedFrames comma separated list of <filter>:<count>
0150      * @return true if everything was successful
0151      */
0152     bool setExpectedFrames(QString expectedFrames);
0153 
0154 
0155     /**
0156      * @brief Check if the expected number of frames are captured
0157      * @return true if yes
0158      */
0159     bool checkCapturedFrames();
0160 
0161 private slots:
0162     /**
0163      * @brief Test whether the capture module produces exactly the diff between the capture frames map and the defined frame counts.
0164      */
0165     void testCaptureWithCaptureFramesMap();
0166 
0167     /** @brief Test data for @see testCaptureWithCaptureFramesMap() */
0168     void testCaptureWithCaptureFramesMap_data();
0169 
0170     /**
0171      * @brief Test of appropriate captures controlled by the scheduler for fixed
0172      *        number of iterations.
0173      */
0174     void testSchedulerCapture();
0175 
0176     /** @brief Test data for @see testSchedulerCapture() */
0177     void testSchedulerCapture_data();
0178 
0179     /**
0180      * @brief Test of appropriate capturing for the scheduler using the
0181      *        "Repeat until terminated" option.
0182      */
0183     void testSchedulerCaptureInfiteLooping();
0184 
0185     /** @brief Test data for @see testSchedulerCaptureInfiteLooping() */
0186     void testSchedulerCaptureInfiteLooping_data();
0187 };
0188 
0189 #endif // HAVE_INDI