-
Notifications
You must be signed in to change notification settings - Fork 550
Fix Module copy assignment #1734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,63 @@ | |
|
|
||
| BOOST_FIXTURE_TEST_SUITE(suite_Module, ModuleFixture) | ||
|
|
||
| BOOST_FIXTURE_TEST_CASE(Module_copy_assignment_copies_spi_config_without_mutating_source, ModuleFixture) | ||
| { | ||
| BOOST_TEST_MESSAGE("--- Test Module copy assignment copies SPI config correctly ---"); | ||
|
|
||
| Module other(hal, EMULATED_RADIO_NSS_PIN, EMULATED_RADIO_IRQ_PIN, EMULATED_RADIO_RST_PIN, EMULATED_RADIO_GPIO_PIN); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you really want to ensure the source is unchanged, you have to set different pins and check them. |
||
|
|
||
| mod->spiConfig.stream = true; | ||
| mod->spiConfig.err = 123; | ||
| mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_READ] = 0x42; | ||
| mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_WRITE] = 0x99; | ||
| mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR] = Module::BITS_16; | ||
| mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD] = Module::BITS_8; | ||
| mod->spiConfig.statusPos = 7; | ||
| mod->spiConfig.timeout = 4321; | ||
| mod->rfSwitchPins[0] = 1001; | ||
| mod->rfSwitchPins[1] = 1002; | ||
| mod->rfSwitchTable = reinterpret_cast<const Module::RfSwitchMode_t*>(0x1234); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you reusing the module fixture to do this? It seems prone to breaking in the future if the approach to its setup/teardown changes. Especially since |
||
|
|
||
| other.spiConfig.stream = false; | ||
| other.spiConfig.err = -77; | ||
| other.spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_READ] = 0x11; | ||
| other.spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_WRITE] = 0x22; | ||
| other.spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR] = Module::BITS_24; | ||
| other.spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD] = Module::BITS_16; | ||
| other.spiConfig.statusPos = 3; | ||
| other.spiConfig.timeout = 555; | ||
| other.rfSwitchPins[0] = 2001; | ||
| other.rfSwitchPins[1] = 2002; | ||
| other.rfSwitchTable = reinterpret_cast<const Module::RfSwitchMode_t*>(0x5678); | ||
|
|
||
| other = *mod; | ||
|
|
||
| BOOST_TEST(other.spiConfig.stream == mod->spiConfig.stream); | ||
| BOOST_TEST(other.spiConfig.err == mod->spiConfig.err); | ||
| BOOST_TEST(other.spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_READ] == mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_READ]); | ||
| BOOST_TEST(other.spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_WRITE] == mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_WRITE]); | ||
| BOOST_TEST(other.spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR] == mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR]); | ||
| BOOST_TEST(other.spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD] == mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD]); | ||
| BOOST_TEST(other.spiConfig.statusPos == mod->spiConfig.statusPos); | ||
| BOOST_TEST(other.spiConfig.timeout == mod->spiConfig.timeout); | ||
| BOOST_TEST(other.rfSwitchPins[0] == mod->rfSwitchPins[0]); | ||
| BOOST_TEST(other.rfSwitchPins[1] == mod->rfSwitchPins[1]); | ||
| BOOST_TEST(other.rfSwitchTable == mod->rfSwitchTable); | ||
|
|
||
| BOOST_TEST(mod->spiConfig.stream == true); | ||
| BOOST_TEST(mod->spiConfig.err == 123); | ||
| BOOST_TEST(mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_READ] == 0x42); | ||
| BOOST_TEST(mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_WRITE] == 0x99); | ||
| BOOST_TEST(mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR] == Module::BITS_16); | ||
| BOOST_TEST(mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD] == Module::BITS_8); | ||
| BOOST_TEST(mod->spiConfig.statusPos == 7); | ||
| BOOST_TEST(mod->spiConfig.timeout == 4321); | ||
| BOOST_TEST(mod->rfSwitchPins[0] == 1001); | ||
| BOOST_TEST(mod->rfSwitchPins[1] == 1002); | ||
| BOOST_TEST(mod->rfSwitchTable == reinterpret_cast<const Module::RfSwitchMode_t*>(0x1234)); | ||
| } | ||
|
|
||
| BOOST_FIXTURE_TEST_CASE(Module_SPIgetRegValue_reg, ModuleFixture) | ||
| { | ||
| BOOST_TEST_MESSAGE("--- Test Module::SPIgetRegValue register access ---"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,11 +25,20 @@ Module::Module(const Module& mod) { | |
| } | ||
|
|
||
| Module& Module::operator=(const Module& mod) { | ||
| memcpy(reinterpret_cast<void*>(&(const_cast<Module&>(mod)).spiConfig), &this->spiConfig, sizeof(SPIConfig_t)); | ||
| this->hal = mod.hal; | ||
| memcpy(&this->spiConfig, &mod.spiConfig, sizeof(SPIConfig_t)); | ||
| this->csPin = mod.csPin; | ||
| this->irqPin = mod.irqPin; | ||
| this->rstPin = mod.rstPin; | ||
| this->gpioPin = mod.gpioPin; | ||
| memcpy(this->rfSwitchPins, mod.rfSwitchPins, sizeof(this->rfSwitchPins)); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is size of this copy not checked against |
||
| this->rfSwitchTable = mod.rfSwitchTable; | ||
|
|
||
| #if RADIOLIB_INTERRUPT_TIMING | ||
| this->TimerSetupCb = mod.TimerSetupCb; | ||
| this->TimerFlag = mod.TimerFlag; | ||
| this->prevTimingLen = mod.prevTimingLen; | ||
| #endif | ||
| return(*this); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No human in the history of the world would ever name a test case like this. Why is
Module_copy_assignmentinsufficient?