Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
ce7dc95f
Commit
ce7dc95f
authored
Dec 19, 2014
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(test): добавил тесты для части вспомогательных функций Modbus
parent
6d776e79
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
2 deletions
+93
-2
ModbusTypes.cc
src/Communications/Modbus/ModbusTypes.cc
+0
-1
test_modbustypes.cc
tests/test_modbustypes.cc
+91
-1
testsuite-coverage-common.mk
testsuite/testsuite-coverage-common.mk
+2
-0
No files found.
src/Communications/Modbus/ModbusTypes.cc
View file @
ce7dc95f
...
@@ -2806,7 +2806,6 @@ float ModbusRTU::dat2f( const ModbusData dat1, const ModbusData dat2 )
...
@@ -2806,7 +2806,6 @@ float ModbusRTU::dat2f( const ModbusData dat1, const ModbusData dat2 )
{
{
ModbusData
d
[
2
]
=
{
dat1
,
dat2
};
ModbusData
d
[
2
]
=
{
dat1
,
dat2
};
float
f
=
0
;
float
f
=
0
;
assert
(
sizeof
(
f
)
>=
sizeof
(
d
));
assert
(
sizeof
(
f
)
>=
sizeof
(
d
));
memcpy
(
&
f
,
d
,
sizeof
(
d
));
memcpy
(
&
f
,
d
,
sizeof
(
d
));
return
f
;
return
f
;
...
...
tests/test_modbustypes.cc
View file @
ce7dc95f
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
#include "modbus/ModbusTypes.h"
#include "modbus/ModbusTypes.h"
using
namespace
std
;
using
namespace
std
;
TEST_CASE
(
"
Modbus Types"
,
"[modbus][modbus types]"
)
TEST_CASE
(
"
WriteOutputMessage"
,
"[modbus][WriteOutputMessage]"
)
{
{
SECTION
(
"WriteOutputMessage: limit the amount of data verification"
)
SECTION
(
"WriteOutputMessage: limit the amount of data verification"
)
{
{
...
@@ -18,3 +18,93 @@ TEST_CASE("Modbus Types", "[modbus][modbus types]" )
...
@@ -18,3 +18,93 @@ TEST_CASE("Modbus Types", "[modbus][modbus types]" )
WARN
(
"Tests for 'Modbus types' incomplete.."
);
WARN
(
"Tests for 'Modbus types' incomplete.."
);
}
}
TEST_CASE
(
"Modbus helpers"
,
"[modbus][helpers]"
)
{
using
namespace
ModbusRTU
;
SECTION
(
"str2mbAddr"
)
{
REQUIRE
(
str2mbAddr
(
"0x01"
)
==
0x01
);
REQUIRE
(
str2mbAddr
(
"255"
)
==
255
);
REQUIRE
(
str2mbAddr
(
"2"
)
==
2
);
REQUIRE
(
str2mbAddr
(
"-1"
)
==
255
);
REQUIRE
(
str2mbAddr
(
""
)
==
0
);
REQUIRE
(
str2mbAddr
(
"4"
)
==
0x04
);
REQUIRE
(
str2mbAddr
(
"0xA"
)
==
10
);
REQUIRE
(
str2mbAddr
(
"10"
)
==
0xA
);
}
SECTION
(
"str2mbAddr"
)
{
REQUIRE
(
str2mbData
(
""
)
==
0
);
REQUIRE
(
str2mbData
(
"0x01"
)
==
0x01
);
REQUIRE
(
str2mbData
(
"10"
)
==
0xA
);
REQUIRE
(
str2mbData
(
"65535"
)
==
65535
);
REQUIRE
(
str2mbData
(
"-1"
)
==
65535
);
}
SECTION
(
"dat2str"
)
{
REQUIRE
(
dat2str
(
0
)
==
"0"
);
REQUIRE
(
dat2str
(
10
)
==
"0xa"
);
REQUIRE
(
dat2str
(
2
)
==
"0x2"
);
REQUIRE
(
dat2str
(
65535
)
==
"0xffff"
);
REQUIRE
(
dat2str
(
-
1
)
==
"0xffff"
);
}
SECTION
(
"addr2str"
)
{
REQUIRE
(
addr2str
(
0x1
)
==
"0x01"
);
REQUIRE
(
addr2str
(
10
)
==
"0x0a"
);
// ожидаемо ли? что dat2str = 0xa.. а addr2str = 0x0a
REQUIRE
(
addr2str
(
255
)
==
"0xff"
);
REQUIRE
(
addr2str
(
-
1
)
==
"0xff"
);
}
SECTION
(
"b2str"
)
{
REQUIRE
(
b2str
(
0x1
)
==
"01"
);
REQUIRE
(
b2str
(
10
)
==
"0a"
);
REQUIRE
(
b2str
(
255
)
==
"ff"
);
REQUIRE
(
b2str
(
-
1
)
==
"ff"
);
}
}
#if 0
Надо ещё подумать как тут протестировать
TEST_CASE("dat2f", "[modbus]" )
{
using namespace ModbusRTU;
REQUIRE( dat2f(0,0) == 0.0f );
// REQUIRE( dat2f(1,0) == 0.0f );
// REQUIRE( dat2f(0xff,0xff) == 0.0f );
}
#endif
TEST_CASE
(
"isWriteFunction"
,
"[modbus][isWriteFunction]"
)
{
using
namespace
ModbusRTU
;
CHECK_FALSE
(
isWriteFunction
(
fnUnknown
)
);
CHECK_FALSE
(
isWriteFunction
(
fnReadCoilStatus
)
);
CHECK_FALSE
(
isWriteFunction
(
fnReadInputStatus
)
);
CHECK_FALSE
(
isWriteFunction
(
fnReadOutputRegisters
)
);
CHECK_FALSE
(
isWriteFunction
(
fnReadInputRegisters
)
);
CHECK
(
isWriteFunction
(
fnForceSingleCoil
)
);
CHECK
(
isWriteFunction
(
fnWriteOutputSingleRegister
)
);
CHECK_FALSE
(
isWriteFunction
(
fnDiagnostics
)
);
CHECK
(
isWriteFunction
(
fnForceMultipleCoils
)
);
CHECK
(
isWriteFunction
(
fnWriteOutputRegisters
)
);
CHECK_FALSE
(
isWriteFunction
(
fnReadFileRecord
)
);
CHECK_FALSE
(
isWriteFunction
(
fnWriteFileRecord
)
);
CHECK_FALSE
(
isWriteFunction
(
fnMEI
)
);
CHECK_FALSE
(
isWriteFunction
(
fnSetDateTime
)
);
CHECK_FALSE
(
isWriteFunction
(
fnRemoteService
)
);
CHECK_FALSE
(
isWriteFunction
(
fnJournalCommand
)
);
CHECK_FALSE
(
isWriteFunction
(
fnFileTransfer
)
);
}
TEST_CASE
(
"checkCRC"
,
"[modbus][checkCRC]"
)
{
// ModbusCRC checkCRC( ModbusByte* start, int len );
}
testsuite/testsuite-coverage-common.mk
View file @
ce7dc95f
COVERAGE_REPORT_DIR=$(abs_srcdir)/coverage-report
COVERAGE_REPORT_DIR=$(abs_srcdir)/coverage-report
cov: all
cov: all
make clean
make
$(LCOV) --directory $(abs_srcdir) --zerocounters
$(LCOV) --directory $(abs_srcdir) --zerocounters
$(LCOV) -c -i -d $(abs_srcdir) -o $(abs_srcdir)/.coverage.base
$(LCOV) -c -i -d $(abs_srcdir) -o $(abs_srcdir)/.coverage.base
make check
make check
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment