Skip to content

Commit

Permalink
Enforces limit on SMS messages. Also added regression test. Addresses #…
Browse files Browse the repository at this point in the history
  • Loading branch information
hmatuschek authored Sep 30, 2024
1 parent 57282f7 commit 60440ed
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/d868uv_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2158,7 +2158,8 @@ D868UVCodeplug::allocateSMSMessages() {
bool
D868UVCodeplug::encodeSMSMessages(const Flags &flags, Context &ctx, const ErrorStack &err) {
Q_UNUSED(flags); Q_UNUSED(err)
for (unsigned int i=0; i<ctx.count<SMSTemplate>(); i++) {
unsigned int num_sms_messages = std::min(Limit::numMessages(), ctx.count<SMSTemplate>());
for (unsigned int i=0; i<num_sms_messages; i++) {
unsigned int bank = i/Limit::numMessagePerBank(), msg_idx = i % Limit::numMessagePerBank();
unsigned int addr = Offset::messageBanks() + bank*Offset::betweenMessageBanks() + msg_idx*MessageElement::size();
MessageElement message(data(addr));
Expand Down
20 changes: 20 additions & 0 deletions test/d868uve_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,5 +213,25 @@ D868UVETest::testRegressionSMSTemplateOffset() {
}


void
D868UVETest::testRegressionSMSCount() {
// Regression test for issue #482 (tries to encode too many SMS)
Config config;
config.radioIDs()->add(new DMRRadioID("ID", 1234567));
for (int i=0; i<101; i++) {
SMSTemplate *sms = new SMSTemplate(); sms->setName(QString("SMS%1").arg(i)); sms->setMessage("ABC");
config.smsExtension()->smsTemplates()->add(sms);
}

ErrorStack err;
D868UVCodeplug codeplug;
Codeplug::Flags flags; flags.updateCodePlug=false;
if (! codeplug.encode(&config, flags, err)) {
QFAIL(QString("Cannot encode codeplug for AnyTone AT-D868UVE: %1")
.arg(err.format()).toStdString().c_str());
}
}


QTEST_GUILESS_MAIN(D868UVETest)

1 change: 1 addition & 0 deletions test/d868uve_test.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ private slots:
void testDTMFContacts();
void testSMSTemplates();
void testRegressionSMSTemplateOffset();
void testRegressionSMSCount();
};

#endif // D878UV2TEST_HH

0 comments on commit 60440ed

Please sign in to comment.