4 #include <gtest/gtest.h>
5 #include <gmock/gmock.h>
8 using ::testing::StrEq;
12 char _me[] =
"MockCCDSimDriver";
26 ASSERT_NE(p,
nullptr);
27 ASSERT_NE(p.findWidgetByName(
"SIM_XRES"),
nullptr);
28 ASSERT_NE(p.findWidgetByName(
"SIM_YRES"),
nullptr);
29 ASSERT_NE(p.findWidgetByName(
"SIM_XSIZE"),
nullptr);
30 ASSERT_NE(p.findWidgetByName(
"SIM_YSIZE"),
nullptr);
31 ASSERT_NE(p.findWidgetByName(
"SIM_MAXVAL"),
nullptr);
32 ASSERT_NE(p.findWidgetByName(
"SIM_SATURATION"),
nullptr);
33 ASSERT_NE(p.findWidgetByName(
"SIM_LIMITINGMAG"),
nullptr);
34 ASSERT_NE(p.findWidgetByName(
"SIM_NOISE"),
nullptr);
35 ASSERT_NE(p.findWidgetByName(
"SIM_SKYGLOW"),
nullptr);
36 ASSERT_NE(p.findWidgetByName(
"SIM_OAGOFFSET"),
nullptr);
37 ASSERT_NE(p.findWidgetByName(
"SIM_POLAR"),
nullptr);
38 ASSERT_NE(p.findWidgetByName(
"SIM_POLARDRIFT"),
nullptr);
44 EXPECT_TRUE(isnan(
currentRA)) <<
"Field 'currentRA' is undefined when initializing CCDSim.";
45 EXPECT_TRUE(isnan(
currentDE)) <<
"Field 'currentDEC' is undefined when initializing CCDSim.";
54 double const arcsec = 1.0 / 3600.0;
88 int const maxval = pow(2, 8) - 1;
92 ASSERT_NE(p,
nullptr);
93 p.findWidgetByName(
"SIM_XRES")->setValue((
double) xres);
94 p.findWidgetByName(
"SIM_YRES")->setValue((
double) yres);
96 p.findWidgetByName(
"SIM_MAXVAL")->setValue((
double) maxval);
97 p.findWidgetByName(
"SIM_XSIZE")->setValue(4.6);
98 p.findWidgetByName(
"SIM_YSIZE")->setValue(4.6);
101 p.findWidgetByName(
"SIM_SATURATION")->setValue(0.0);
102 p.findWidgetByName(
"SIM_LIMITINGMAG")->setValue(30.0);
105 p.findWidgetByName(
"SIM_SKYGLOW")->setValue(0.0);
106 p.findWidgetByName(
"SIM_NOISE")->setValue(0.0);
113 ASSERT_EQ(
PrimaryCCD.
getBPP(), 16) <<
"Simulator CCD depth is hardcoded at 16 bits";
121 EXPECT_EQ(this->
seeing, 1.0f);
143 int const center = xres / 2 + 1 + (yres / 2 + 1) * xres;
146 double const sigma = 1.0 / (2 * sqrt(2 * log(2)));
147 double const fa0 = 1.0 / (sigma * sqrt(2 * 3.1416));
150 uint16_t
const ADU_at_center =
static_cast<uint16_t
>(fa0 * maxval);
151 EXPECT_EQ(fb[center], ADU_at_center) <<
"Recorded flux of magnitude 0.0 for 1 second at center is " << ADU_at_center <<
155 uint16_t
const ADU_at_1pix =
static_cast<uint16_t
>(fa0 * maxval * exp(-(1 * 1 + 0 * 0) / (2 * sigma * sigma)));
156 EXPECT_EQ(fb[center - xres], ADU_at_1pix);
157 EXPECT_EQ(fb[center - 1], ADU_at_1pix);
158 EXPECT_EQ(fb[center + 1], ADU_at_1pix);
159 EXPECT_EQ(fb[center + xres], ADU_at_1pix);
162 uint16_t
const ADU_at_2pix =
static_cast<uint16_t
>(fa0 * maxval * exp(-(2 * 2 + 0 * 0) / (2 * sigma * sigma)));
163 EXPECT_EQ(fb[center - xres * 2], ADU_at_2pix);
164 EXPECT_EQ(fb[center - 1 * 2], ADU_at_2pix);
165 EXPECT_EQ(fb[center + 1 * 2], ADU_at_2pix);
166 EXPECT_EQ(fb[center + xres * 2], ADU_at_2pix);
169 uint16_t
const ADU_at_3pix =
static_cast<uint16_t
>(fa0 * maxval * exp(-(3 * 3 + 0 * 0) / (2 * sigma * sigma)));
170 EXPECT_EQ(fb[center - xres * 3], ADU_at_3pix);
171 EXPECT_EQ(fb[center - 1 * 3], ADU_at_3pix);
172 EXPECT_EQ(fb[center + 1 * 3], ADU_at_3pix);
173 EXPECT_EQ(fb[center + xres * 3], ADU_at_3pix);
176 EXPECT_EQ(fb[center - xres * 4], 0.0);
177 EXPECT_EQ(fb[center - 1 * 4], 0.0);
178 EXPECT_EQ(fb[center + 1 * 4], 0.0);
179 EXPECT_EQ(fb[center + xres * 4], 0.0);
182 auto const before = std::chrono::steady_clock::now();
183 int const loops = 200000;
184 for (
int i = 0; i < loops; i++)
186 float const m = (15.0f * rand()) / RAND_MAX;
187 float const x =
static_cast<float>(xres * rand()) / RAND_MAX;
188 float const y =
static_cast<float>(yres * rand()) / RAND_MAX;
189 float const e = (100.0f * rand()) / RAND_MAX;
192 auto const after = std::chrono::steady_clock::now();
193 auto const duration = std::chrono::duration_cast <std::chrono::nanoseconds> (after - before).count() / loops;
194 std::cout <<
"[ ] DrawStarImage - randomized no-noise no-skyglow benchmark: " << duration <<
"ns per call" <<
199 TEST(CCDSimulatorDriverTest, test_properties)
204 TEST(CCDSimulatorDriverTest, test_guide_api)
209 TEST(CCDSimulatorDriverTest, test_draw_star)
214 int main(
int argc,
char **argv)
219 ::testing::InitGoogleTest(&argc, argv);
220 ::testing::InitGoogleMock(&argc, argv);
221 return RUN_ALL_TESTS();
The CCDSim class provides an advanced simulator for a CCD that includes a dedicated on-board guide ch...
bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
virtual IPState GuideSouth(uint32_t) override
Guide southward for ms milliseconds.
float GuideRate
Guide rate is 7 arcseconds per second.
void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
int DrawImageStar(INDI::CCDChip *targetChip, float, float, float, float ExposureTime)
virtual IPState GuideEast(uint32_t) override
Guide easward for ms milliseconds.
double flux(double magnitude) const
virtual IPState GuideWest(uint32_t) override
Guide westward for ms milliseconds.
virtual IPState GuideNorth(uint32_t) override
Guide northward for ms milliseconds.
INDI::PropertyNumber getNumber(const char *name) const
uint8_t * getFrameBuffer()
getFrameBuffer Get raw frame buffer of the CCD chip.
float getPixelSizeY() const
getPixelSizeY Get vertical pixel size in microns.
int getBPP() const
getBPP Get CCD Chip depth (bits per pixel).
float getPixelSizeX() const
getPixelSizeX Get horizontal pixel size in microns.
int getXRes() const
getXRes Get the horizontal resolution in pixels of the CCD Chip.
int getYRes() const
Get the vertical resolution in pixels of the CCD Chip.
Implementations for common driver routines.
static const loggerConf file_off
void configure(const std::string &outputFile, const loggerConf configuration, const int fileVerbosityLevel, const int screenVerbosityLevel)
Method to configure the logger. Called by the DEBUG_CONF() macro. To make implementation easier,...
static Logger & getInstance()
Method to get a reference to the object (i.e., Singleton) It is a static method.
int main(int argc, char **argv)
TEST(CCDSimulatorDriverTest, test_properties)