Skip to content
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

#2917 Added Point locator test fields validation in Modbus IP #2919

Conversation

Patrykb0802
Copy link
Contributor

Added integer/byte validation for fields:

  • slave ID (int)
  • offset (int)
  • bit (byte)
  • register count (int)

inside point locator test for modbus ip data source.

Added integer/byte validation for fields:
 - slave ID (int)
 - offset (int)
 - bit (byte)
 - register count (int)

inside point locator test for modbus ip data source.
@Patrykb0802 Patrykb0802 requested review from Limraj and SoftQ as code owners June 8, 2024 12:34
Copy link

github-actions bot commented Jun 8, 2024

Java Script Mocha Unit Test Results

268 tests  ±0   268 ✅ ±0   4s ⏱️ ±0s
 70 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit d2ee637. ± Comparison against base commit 4c38bf6.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jun 8, 2024

Java JUnit Test Results

2 089 tests  +39   2 089 ✅ +39   26s ⏱️ ±0s
  107 suites + 2       0 💤 ± 0 
  107 files   + 2       0 ❌ ± 0 

Results for commit d2ee637. ± Comparison against base commit 4c38bf6.

♻️ This comment has been updated with latest results.

let num = Number(value);

if (!isNaN(num) && Number.isInteger(num)) {
if (num >= -128 && num <= 127) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be a negative value?
You always try to follow what already exists, look at how it works and what the isInt32 function checks. You're not reinventing the wheel.

} else if(!isValid($get("test_bit"))) {
let bitMessage = createValidationMessage("test_bit", "<fmt:message key='badIntegerFormat'/>");
showDwrMessages([bitMessage]);
} else if(!isByte($get("test_bit"))) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the value is a byte, it also meets the isValid condition.
In the function that checks isByte, you can first check whether isValid is present and then add a limit on the value.

@@ -1123,3 +1123,8 @@ function trim(value) {
return result;
}

function isByte(value) {
let num = Number(value);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if an alphanumeric character enters here?

let registerCountMessage = createValidationMessage("test_registerCount", "<fmt:message key='badIntegerFormat'/>");
showDwrMessages([registerCountMessage]);
} else {
var locator = {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let :)

- changed how variables are stored inside locatorTest() function
- Added createAndDisplayValidationMessage function for showing validation message on chosen node
- Added catching exception for invalid end offset for Modbus IP data source
@Patrykb0802 Patrykb0802 requested a review from Limraj June 14, 2024 15:17
@@ -532,7 +532,10 @@ private void testModbusPointLocator(ModbusMaster modbusMaster,
} catch (IllegalCharsetNameException e) {
response.addMessage(new LocalizableMessage(
"validate.invalidCharset"));
} finally {
} catch (ModbusIdException e) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exception

let locator = {};
locator.slaveId = parseInt(slaveId);
locator.range = range
locator.modbusDataType = modbusDataType;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't modbusDataType and range numeric types?

@Limraj Limraj added this to the 2.7.8 milestone Jun 14, 2024
@Patrykb0802 Patrykb0802 requested a review from Limraj June 20, 2024 14:18

locatorTestImpl(locator);

let temp = createTempLocator();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createLocatorConfigTemp

locatorTestImpl(locator);

let temp = createTempLocator();
let tempModbusData = createTempModbusData();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createModbusConfigTemp


function createTempModbusData(){

let dataSourceName = $get("dataSourceName");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no point in creating additional variables here, you get and immediately set them in the temp structure, you don't parse here, etc.

let messages = validateModbusProperties(temp);

if(messages.length > 0) {
showDwrMessages(messages);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatting needs to be improved

hideContextualMessages("locatorTestDiv");
hideContextualMessages("dataSourceProperties");

let messagesModbus = validateModbusProperties(tempModbusData);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modbusMessages, validateModbusConfig

@@ -65,20 +65,80 @@
setDisabled("scanBtn", scanning);
setDisabled("scanCancelBtn", !scanning);
}

function validateLocatorTest(temp){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

temp -> locator

let encapsulated = $get("encapsulated");
let createSocketMonitorPoint = $get("createSocketMonitorPoint");

let temp = {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

temp -> modbus

@Patrykb0802 Patrykb0802 requested a review from Limraj June 21, 2024 10:13
}

function createLocatorConfigTemp(){
let slaveId = $get("test_slaveId");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly to the previously submitted suggestion, this is unnecessary.
You should apply a given note to all changes you make so that you don't have to point out the same things one after the other.

- Optimized createLocatorConfigTemp() code
locator.charset = $get("test_charset");

locatorTestImpl(locator);
setDisabled("locatorTestBtn", true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to remove this line:

let messages = validateModbusConfig(temp);

if(messages.length > 0) {
showDwrMessages(messages);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stopImageFader("dsSaveImg");

let messages = modbusMessages.concat(messagesLocator);

if(messages.length > 0) {
showDwrMessages(messages);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stopImageFader("dsSaveImg");

- Added validation for Modbus read data table
@Limraj Limraj merged commit ac392df into release/2.7.8 Jul 2, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants