1 /* 2 KStars UI tests for verifying correct counting of the capture module 3 4 SPDX-FileCopyrightText: 2020 Wolfgang Reissenberger <sterne-jaeger@openfuture.de> 5 6 SPDX-License-Identifier: GPL-2.0-or-later 7 */ 8 9 #pragma once 10 11 #include <QObject> 12 #include <QQueue> 13 14 #include "config-kstars.h" 15 #include "test_ekos_debug.h" 16 17 #if defined(HAVE_INDI) 18 #include "ekos/ekos.h" 19 #include "ekos/capture/sequencejob.h" 20 #include "test_ekos_capture_helper.h" 21 22 class TestEkosCaptureCount : public QObject 23 { 24 Q_OBJECT 25 public: 26 explicit TestEkosCaptureCount(QObject *parent = nullptr); 27 28 protected: 29 30 /** 31 * @brief Setup capturing 32 * @return true iff preparation was successful 33 */ 34 bool prepareCapture(); 35 36 /** 37 * @brief Setup capturing for tests with the scheduler 38 * @param completionCondition completion condition for the scheduler 39 * @return true iff preparation was successful 40 */ 41 bool prepareScheduledCapture(SchedulerJob::CompletionCondition completionCondition); 42 43 /** 44 * @brief Prepare the scheduler for the test. 45 * @param sequenceFile File name of the capture sequence file 46 * @param sequence filter and count as QString("<filter>:<count"), ... list 47 * @param capturedFramesMap mapping from filter to existing frames per filter as QString("<filter>:<count"), ... list 48 * @param completionCondition completion condition for the scheduler 49 * @param iterations number of iterations to be executed (only relevant if completionCondition == FINISH_REPEAT) 50 * @param rememberJobProgress should the scheduler use the option "Remember job progress" 51 * @param exptime exposure time (identical for all frames) 52 * @return true iff preparation was successful 53 */ 54 bool setupScheduler(QString sequenceFile, QString sequence, QString capturedFramesMap, SchedulerJob::CompletionCondition completionCondition, 55 int iterations, bool rememberJobProgress, double exptime); 56 57 /** 58 * @brief Verify the counts that the scheduler displays in the job table 59 * @param sequence filter and count as QString("<filter>:<count"), ... list 60 * @param capturedFramesMap mapping from filter to existing frames per filter as QString("<filter>:<count"), ... list 61 * @param completionCondition completion condition for the scheduler 62 * @param iterations number of iterations to be executed (only relevant if completionCondition == FINISH_REPEAT) 63 * @param rememberJobProgress should the scheduler use the option "Remember job progress" 64 * @param exptime exposure time (identical for all frames) 65 * @return true iff the displayed counts match the specification 66 */ 67 bool verifySchedulerCounting(QString sequence, QString capturedFramesMap, SchedulerJob::CompletionCondition completionCondition, 68 int iterations, bool rememberJobProgress, double exptime); 69 70 /** 71 * @brief Execute capturing 72 * @return true iff exactly the expected frames have been taken 73 */ 74 bool executeCapturing(); 75 76 /** 77 * @brief Helper function translating simple QString input into QTest test data rows 78 * @param exptime exposure time of the sequence 79 * @param sequence filter and count as QString("<filter>:<count"), ... list 80 * @param capturedFramesMap mapping from filter to existing frames per filter as QString("<filter>:<count"), ... list 81 * @param expectedFrames expected number of frames per filter as QString("<filter>:<count"), ... list 82 * @param iterations number of iterations the capture sequence should be repeated 83 */ 84 void prepareTestData(double exptime, QString sequence, QString capturedFramesMap, QString expectedFrames, int iterations = 1); 85 86 // mapping between image signature and number of images expected to be captured for this signature 87 QMap<QString, int> m_expectedImages; 88 /** 89 * @brief Register that a new image has been captured 90 */ 91 void captureComplete(const QString &filename, double exposureSeconds, const QString &filter, double hfr); 92 93 // sequence of scheduler states that are expected 94 QQueue<Ekos::SchedulerState> expectedSchedulerStates; 95 /** 96 * @brief Slot to receive a new scheduler state 97 * @param status new capture status 98 */ 99 void schedulerStateChanged(Ekos::SchedulerState status); 100 101 // current scheduler status 102 Ekos::SchedulerState m_SchedulerStatus; 103 104 /** 105 * @brief Retrieve the current capture status. 106 */ getSchedulerStatus()107 inline Ekos::SchedulerState getSchedulerStatus() {return m_SchedulerStatus;} 108 109 110 protected slots: 111 void initTestCase(); 112 void cleanupTestCase(); 113 114 void init(); 115 void cleanup(); 116 117 private: 118 // current capture status 119 Ekos::CaptureState m_CaptureStatus; 120 121 // helper class 122 TestEkosCaptureHelper *m_CaptureHelper = nullptr; 123 124 QString target = "test"; 125 126 /** 127 * @brief Fill the map of frames that have already been captured 128 * @param expectedFrames comma separated list of <filter>:<count> 129 * @return true if everything was successful 130 */ 131 bool fillCapturedFramesMap(QString capturedFramesMap); 132 133 /** 134 * @brief Determine the total count from a comma separated sequence of <filter>:<count> 135 * @return sum of <count> 136 */ 137 int totalCount(QString sequence); 138 139 /** 140 * @brief Determine the map filter --> counts from a comma separated sequence of <filter>:<count> 141 * @param sequence 142 * @return 143 */ 144 QMap<QString, uint16_t> framesMap(QString sequence); 145 146 /** 147 * @brief Fill the map of frames that are expected to be captured 148 * @param expectedFrames comma separated list of <filter>:<count> 149 * @return true if everything was successful 150 */ 151 bool setExpectedFrames(QString expectedFrames); 152 153 154 /** 155 * @brief Check if the expected number of frames are captured 156 * @return true if yes 157 */ 158 bool checkCapturedFrames(); 159 160 private slots: 161 /** 162 * @brief Test whether the capture module produces exactly the diff between the capture frames map and the defined frame counts. 163 */ 164 void testCaptureWithCaptureFramesMap(); 165 166 /** @brief Test data for @see testCaptureWithCaptureFramesMap() */ 167 void testCaptureWithCaptureFramesMap_data(); 168 169 /** 170 * @brief Test of appropriate captures controlled by the scheduler for fixed 171 * number of iterations. 172 */ 173 void testSchedulerCapture(); 174 175 /** @brief Test data for @see testSchedulerCapture() */ 176 void testSchedulerCapture_data(); 177 178 /** 179 * @brief Test of appropriate capturing for the scheduler using the 180 * "Repeat until terminated" option. 181 */ 182 void testSchedulerCaptureInfiteLooping(); 183 184 /** @brief Test data for @see testSchedulerCaptureInfiteLooping() */ 185 void testSchedulerCaptureInfiteLooping_data(); 186 }; 187 188 #endif // HAVE_INDI 189