Commit 93a05986fc0fd352e054d1befead52d9bd2463c3
1 parent
b7ed06a4
Unit test for baud rate check and error message
Showing
2 changed files
with
5 additions
and
2 deletions
src/modbus-rtu.c
| ... | ... | @@ -1148,7 +1148,7 @@ modbus_t* modbus_new_rtu(const char *device, |
| 1148 | 1148 | |
| 1149 | 1149 | /* Check baud argument */ |
| 1150 | 1150 | if (baud == 0) { |
| 1151 | - fprintf(stderr, "baud must not be zero\n"); | |
| 1151 | + fprintf(stderr, "The baud rate value must not be zero\n"); | |
| 1152 | 1152 | errno = EINVAL; |
| 1153 | 1153 | return NULL; |
| 1154 | 1154 | } | ... | ... |
tests/unit-test-client.c
| ... | ... | @@ -590,7 +590,10 @@ int main(int argc, char *argv[]) |
| 590 | 590 | |
| 591 | 591 | /* Test init functions */ |
| 592 | 592 | printf("\nTEST INVALID INITIALIZATION:\n"); |
| 593 | - ctx = modbus_new_rtu(NULL, 0, 'A', 0, 0); | |
| 593 | + ctx = modbus_new_rtu(NULL, 1, 'A', 0, 0); | |
| 594 | + ASSERT_TRUE(ctx == NULL && errno == EINVAL, ""); | |
| 595 | + | |
| 596 | + ctx = modbus_new_rtu("/dev/dummy", 0, 'A', 0, 0); | |
| 594 | 597 | ASSERT_TRUE(ctx == NULL && errno == EINVAL, ""); |
| 595 | 598 | |
| 596 | 599 | ctx = modbus_new_tcp_pi(NULL, NULL); | ... | ... |