Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
41 lines (34 loc) · 1.15 KB

File metadata and controls

41 lines (34 loc) · 1.15 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <gtest/gtest.h>
#include "modbus_test_utils.h"
#include "../src/modbus_request.h"
namespace testutils
{
void AssertPayloadError(const std::vector<uint8_t>* payload, modb::ResponseError expectedError)
{
ASSERT_NE(payload, nullptr);
ASSERT_EQ(payload->size(), 3);
ASSERT_EQ((*payload)[1] & modb::ERROR_FLAG, modb::ERROR_FLAG);
ASSERT_EQ((*payload)[2], static_cast<uint8_t>(expectedError));
}
bool IsEqualString(uint16_t* reg, const std::string& text)
{
return std::memcmp(reg, text.c_str(), text.length()) == 0;
}
bool IsEqualString(uint8_t* buf, const std::string& text)
{
return std::memcmp(buf, text.c_str(), text.length()) == 0;
}
bool IsEqualUint16(uint8_t* bufBigEndian, uint16_t valueLittleEndian)
{
// convert to little-endian
uint16_t bufValue = *(bufBigEndian + 1) + (*(bufBigEndian + 0) << 8);
return bufValue == valueLittleEndian;
}
// Use other conversion method for test
float ToFloatLittleEndian(uint16_t* reg)
{
// Note: cannot direct cast to float => wrong result!!
uint32_t tempUint32 = __builtin_bswap32(*(uint32_t*)reg);
return *(reinterpret_cast<float*>(&tempUint32));
}
} // namespace testutils
Morty Proxy This is a proxified and sanitized view of the page, visit original site.