|
@@ -539,33 +539,30 @@ END_TEST
|
|
|
|
|
|
START_TEST(UA_Byte_encode_test) {
|
|
START_TEST(UA_Byte_encode_test) {
|
|
// given
|
|
// given
|
|
- UA_Byte src;
|
|
|
|
|
|
+ UA_Byte src = 8;
|
|
UA_Byte data[] = { 0x00, 0xFF };
|
|
UA_Byte data[] = { 0x00, 0xFF };
|
|
UA_ByteString dst = { 2, data };
|
|
UA_ByteString dst = { 2, data };
|
|
-
|
|
|
|
- UA_Int32 retval = 0;
|
|
|
|
- size_t pos = 0;
|
|
|
|
-
|
|
|
|
ck_assert_uint_eq(dst.data[1], 0xFF);
|
|
ck_assert_uint_eq(dst.data[1], 0xFF);
|
|
|
|
|
|
- src = 8;
|
|
|
|
- retval = UA_Byte_encodeBinary(&src, &dst, &pos);
|
|
|
|
|
|
+ UA_Byte *pos = dst.data;
|
|
|
|
+ const UA_Byte *end = &dst.data[dst.length];
|
|
|
|
+ UA_StatusCode retval = UA_Byte_encodeBinary(&src, &pos, &end);
|
|
|
|
|
|
ck_assert_uint_eq(dst.data[0], 0x08);
|
|
ck_assert_uint_eq(dst.data[0], 0x08);
|
|
ck_assert_uint_eq(dst.data[1], 0xFF);
|
|
ck_assert_uint_eq(dst.data[1], 0xFF);
|
|
- ck_assert_int_eq(pos, 1);
|
|
|
|
|
|
+ ck_assert_int_eq((uintptr_t)(pos - dst.data), 1);
|
|
ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
|
|
ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
|
|
|
// Test2
|
|
// Test2
|
|
// given
|
|
// given
|
|
src = 0xFF;
|
|
src = 0xFF;
|
|
dst.data[1] = 0x00;
|
|
dst.data[1] = 0x00;
|
|
- pos = 0;
|
|
|
|
- retval = UA_Byte_encodeBinary(&src, &dst, &pos);
|
|
|
|
|
|
+ pos = dst.data;
|
|
|
|
+ retval = UA_Byte_encodeBinary(&src, &pos, &end);
|
|
|
|
|
|
ck_assert_int_eq(dst.data[0], 0xFF);
|
|
ck_assert_int_eq(dst.data[0], 0xFF);
|
|
ck_assert_int_eq(dst.data[1], 0x00);
|
|
ck_assert_int_eq(dst.data[1], 0x00);
|
|
- ck_assert_int_eq(pos, 1);
|
|
|
|
|
|
+ ck_assert_int_eq((uintptr_t)(pos - dst.data), 1);
|
|
ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
|
|
ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
|
|
|
}
|
|
}
|
|
@@ -573,27 +570,25 @@ END_TEST
|
|
|
|
|
|
START_TEST(UA_UInt16_encodeNegativeShallEncodeLittleEndian) {
|
|
START_TEST(UA_UInt16_encodeNegativeShallEncodeLittleEndian) {
|
|
// given
|
|
// given
|
|
- UA_UInt16 src;
|
|
|
|
|
|
+ UA_UInt16 src = -1;
|
|
UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55 };
|
|
UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55 };
|
|
UA_ByteString dst = { 4, data };
|
|
UA_ByteString dst = { 4, data };
|
|
-
|
|
|
|
- UA_StatusCode retval = 0;
|
|
|
|
- size_t pos = 0;
|
|
|
|
|
|
+ UA_Byte *pos = dst.data;
|
|
|
|
+ const UA_Byte *end = &dst.data[dst.length];
|
|
|
|
|
|
// when test 1
|
|
// when test 1
|
|
- src = -1;
|
|
|
|
- retval = UA_UInt16_encodeBinary(&src, &dst, &pos);
|
|
|
|
|
|
+ UA_StatusCode retval = UA_UInt16_encodeBinary(&src, &pos, &end);
|
|
// then test 1
|
|
// then test 1
|
|
- ck_assert_int_eq(pos, 2);
|
|
|
|
|
|
+ ck_assert_int_eq((uintptr_t)(pos - dst.data), 2);
|
|
ck_assert_int_eq(dst.data[0], 0xFF);
|
|
ck_assert_int_eq(dst.data[0], 0xFF);
|
|
ck_assert_int_eq(dst.data[1], 0xFF);
|
|
ck_assert_int_eq(dst.data[1], 0xFF);
|
|
ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
|
|
ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
|
|
|
// when test 2
|
|
// when test 2
|
|
src = -32768;
|
|
src = -32768;
|
|
- retval = UA_UInt16_encodeBinary(&src, &dst, &pos);
|
|
|
|
|
|
+ retval = UA_UInt16_encodeBinary(&src, &pos, &end);
|
|
// then test 2
|
|
// then test 2
|
|
- ck_assert_int_eq(pos, 4);
|
|
|
|
|
|
+ ck_assert_int_eq((uintptr_t)(pos - dst.data), 4);
|
|
ck_assert_int_eq(dst.data[2], 0x00);
|
|
ck_assert_int_eq(dst.data[2], 0x00);
|
|
ck_assert_int_eq(dst.data[3], 0x80);
|
|
ck_assert_int_eq(dst.data[3], 0x80);
|
|
ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
|
|
ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
|
|
@@ -602,28 +597,25 @@ END_TEST
|
|
|
|
|
|
START_TEST(UA_UInt16_encodeShallEncodeLittleEndian) {
|
|
START_TEST(UA_UInt16_encodeShallEncodeLittleEndian) {
|
|
// given
|
|
// given
|
|
- UA_UInt16 src;
|
|
|
|
- UA_Byte data[] = { 0x55, 0x55,
|
|
|
|
- 0x55, 0x55 };
|
|
|
|
|
|
+ UA_UInt16 src = 0;
|
|
|
|
+ UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55 };
|
|
UA_ByteString dst = { 4, data };
|
|
UA_ByteString dst = { 4, data };
|
|
-
|
|
|
|
- UA_StatusCode retval = 0;
|
|
|
|
- size_t pos = 0;
|
|
|
|
|
|
+ UA_Byte *pos = dst.data;
|
|
|
|
+ const UA_Byte *end = &dst.data[dst.length];
|
|
|
|
|
|
// when test 1
|
|
// when test 1
|
|
- src = 0;
|
|
|
|
- retval = UA_UInt16_encodeBinary(&src, &dst, &pos);
|
|
|
|
|
|
+ UA_StatusCode retval = UA_UInt16_encodeBinary(&src, &pos, &end);
|
|
// then test 1
|
|
// then test 1
|
|
- ck_assert_int_eq(pos, 2);
|
|
|
|
|
|
+ ck_assert_int_eq((uintptr_t)(pos - dst.data), 2);
|
|
ck_assert_int_eq(dst.data[0], 0x00);
|
|
ck_assert_int_eq(dst.data[0], 0x00);
|
|
ck_assert_int_eq(dst.data[1], 0x00);
|
|
ck_assert_int_eq(dst.data[1], 0x00);
|
|
ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
|
|
ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
|
|
|
// when test 2
|
|
// when test 2
|
|
src = 32767;
|
|
src = 32767;
|
|
- retval = UA_UInt16_encodeBinary(&src, &dst, &pos);
|
|
|
|
|
|
+ retval = UA_UInt16_encodeBinary(&src, &pos, &end);
|
|
// then test 2
|
|
// then test 2
|
|
- ck_assert_int_eq(pos, 4);
|
|
|
|
|
|
+ ck_assert_int_eq((uintptr_t)(pos - dst.data), 4);
|
|
ck_assert_int_eq(dst.data[2], 0xFF);
|
|
ck_assert_int_eq(dst.data[2], 0xFF);
|
|
ck_assert_int_eq(dst.data[3], 0x7F);
|
|
ck_assert_int_eq(dst.data[3], 0x7F);
|
|
ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
|
|
ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
|
|
@@ -632,18 +624,16 @@ END_TEST
|
|
|
|
|
|
START_TEST(UA_UInt32_encodeShallEncodeLittleEndian) {
|
|
START_TEST(UA_UInt32_encodeShallEncodeLittleEndian) {
|
|
// given
|
|
// given
|
|
- UA_UInt32 src;
|
|
|
|
|
|
+ UA_UInt32 src = -1;
|
|
UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
|
|
UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
|
|
UA_ByteString dst = { 8, data };
|
|
UA_ByteString dst = { 8, data };
|
|
-
|
|
|
|
- UA_StatusCode retval = 0;
|
|
|
|
- size_t pos = 0;
|
|
|
|
|
|
+ UA_Byte *pos = dst.data;
|
|
|
|
+ const UA_Byte *end = &dst.data[dst.length];
|
|
|
|
|
|
// when test 1
|
|
// when test 1
|
|
- src = -1;
|
|
|
|
- retval = UA_UInt32_encodeBinary(&src, &dst, &pos);
|
|
|
|
|
|
+ UA_StatusCode retval = UA_UInt32_encodeBinary(&src, &pos, &end);
|
|
// then test 1
|
|
// then test 1
|
|
- ck_assert_int_eq(pos, 4);
|
|
|
|
|
|
+ ck_assert_int_eq((uintptr_t)(pos - dst.data), 4);
|
|
ck_assert_int_eq(dst.data[0], 0xFF);
|
|
ck_assert_int_eq(dst.data[0], 0xFF);
|
|
ck_assert_int_eq(dst.data[1], 0xFF);
|
|
ck_assert_int_eq(dst.data[1], 0xFF);
|
|
ck_assert_int_eq(dst.data[2], 0xFF);
|
|
ck_assert_int_eq(dst.data[2], 0xFF);
|
|
@@ -652,9 +642,9 @@ START_TEST(UA_UInt32_encodeShallEncodeLittleEndian) {
|
|
|
|
|
|
// when test 2
|
|
// when test 2
|
|
src = 0x0101FF00;
|
|
src = 0x0101FF00;
|
|
- retval = UA_UInt32_encodeBinary(&src, &dst, &pos);
|
|
|
|
|
|
+ retval = UA_UInt32_encodeBinary(&src, &pos, &end);
|
|
// then test 2
|
|
// then test 2
|
|
- ck_assert_int_eq(pos, 8);
|
|
|
|
|
|
+ ck_assert_int_eq((uintptr_t)(pos - dst.data), 8);
|
|
ck_assert_int_eq(dst.data[4], 0x00);
|
|
ck_assert_int_eq(dst.data[4], 0x00);
|
|
ck_assert_int_eq(dst.data[5], 0xFF);
|
|
ck_assert_int_eq(dst.data[5], 0xFF);
|
|
ck_assert_int_eq(dst.data[6], 0x01);
|
|
ck_assert_int_eq(dst.data[6], 0x01);
|
|
@@ -665,18 +655,16 @@ END_TEST
|
|
|
|
|
|
START_TEST(UA_Int32_encodeShallEncodeLittleEndian) {
|
|
START_TEST(UA_Int32_encodeShallEncodeLittleEndian) {
|
|
// given
|
|
// given
|
|
- UA_Int32 src;
|
|
|
|
|
|
+ UA_Int32 src = 1;
|
|
UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
|
|
UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
|
|
UA_ByteString dst = { 8, data };
|
|
UA_ByteString dst = { 8, data };
|
|
-
|
|
|
|
- UA_Int32 retval = 0;
|
|
|
|
- size_t pos = 0;
|
|
|
|
|
|
+ UA_Byte *pos = dst.data;
|
|
|
|
+ const UA_Byte *end = &dst.data[dst.length];
|
|
|
|
|
|
// when test 1
|
|
// when test 1
|
|
- src = 1;
|
|
|
|
- retval = UA_Int32_encodeBinary(&src, &dst, &pos);
|
|
|
|
|
|
+ UA_StatusCode retval = UA_Int32_encodeBinary(&src, &pos, &end);
|
|
// then test 1
|
|
// then test 1
|
|
- ck_assert_int_eq(pos, 4);
|
|
|
|
|
|
+ ck_assert_int_eq((uintptr_t)(pos - dst.data), 4);
|
|
ck_assert_int_eq(dst.data[0], 0x01);
|
|
ck_assert_int_eq(dst.data[0], 0x01);
|
|
ck_assert_int_eq(dst.data[1], 0x00);
|
|
ck_assert_int_eq(dst.data[1], 0x00);
|
|
ck_assert_int_eq(dst.data[2], 0x00);
|
|
ck_assert_int_eq(dst.data[2], 0x00);
|
|
@@ -685,9 +673,9 @@ START_TEST(UA_Int32_encodeShallEncodeLittleEndian) {
|
|
|
|
|
|
// when test 2
|
|
// when test 2
|
|
src = 0x7FFFFFFF;
|
|
src = 0x7FFFFFFF;
|
|
- retval = UA_Int32_encodeBinary(&src, &dst, &pos);
|
|
|
|
|
|
+ retval = UA_Int32_encodeBinary(&src, &pos, &end);
|
|
// then test 2
|
|
// then test 2
|
|
- ck_assert_int_eq(pos, 8);
|
|
|
|
|
|
+ ck_assert_int_eq((uintptr_t)(pos - dst.data), 8);
|
|
ck_assert_int_eq(dst.data[4], 0xFF);
|
|
ck_assert_int_eq(dst.data[4], 0xFF);
|
|
ck_assert_int_eq(dst.data[5], 0xFF);
|
|
ck_assert_int_eq(dst.data[5], 0xFF);
|
|
ck_assert_int_eq(dst.data[6], 0xFF);
|
|
ck_assert_int_eq(dst.data[6], 0xFF);
|
|
@@ -698,19 +686,16 @@ END_TEST
|
|
|
|
|
|
START_TEST(UA_Int32_encodeNegativeShallEncodeLittleEndian) {
|
|
START_TEST(UA_Int32_encodeNegativeShallEncodeLittleEndian) {
|
|
// given
|
|
// given
|
|
- UA_Int32 src;
|
|
|
|
- UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55,
|
|
|
|
- 0x55, 0x55, 0x55, 0x55 };
|
|
|
|
|
|
+ UA_Int32 src = -1;
|
|
|
|
+ UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
|
|
UA_ByteString dst = { 8, data };
|
|
UA_ByteString dst = { 8, data };
|
|
-
|
|
|
|
- UA_Int32 retval = 0;
|
|
|
|
- size_t pos = 0;
|
|
|
|
|
|
+ UA_Byte *pos = dst.data;
|
|
|
|
+ const UA_Byte *end = &dst.data[dst.length];
|
|
|
|
|
|
// when test 1
|
|
// when test 1
|
|
- src = -1;
|
|
|
|
- retval = UA_Int32_encodeBinary(&src, &dst, &pos);
|
|
|
|
|
|
+ UA_StatusCode retval = UA_Int32_encodeBinary(&src, &pos, &end);
|
|
// then test 1
|
|
// then test 1
|
|
- ck_assert_int_eq(pos, 4);
|
|
|
|
|
|
+ ck_assert_int_eq((uintptr_t)(pos - dst.data), 4);
|
|
ck_assert_int_eq(dst.data[0], 0xFF);
|
|
ck_assert_int_eq(dst.data[0], 0xFF);
|
|
ck_assert_int_eq(dst.data[1], 0xFF);
|
|
ck_assert_int_eq(dst.data[1], 0xFF);
|
|
ck_assert_int_eq(dst.data[2], 0xFF);
|
|
ck_assert_int_eq(dst.data[2], 0xFF);
|
|
@@ -721,19 +706,17 @@ END_TEST
|
|
|
|
|
|
START_TEST(UA_UInt64_encodeShallWorkOnExample) {
|
|
START_TEST(UA_UInt64_encodeShallWorkOnExample) {
|
|
// given
|
|
// given
|
|
- UA_UInt64 src;
|
|
|
|
|
|
+ UA_UInt64 src = -1;
|
|
UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
|
UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
|
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
|
|
UA_ByteString dst = { 16, data };
|
|
UA_ByteString dst = { 16, data };
|
|
-
|
|
|
|
- UA_StatusCode retval = 0;
|
|
|
|
- size_t pos = 0;
|
|
|
|
|
|
+ UA_Byte *pos = dst.data;
|
|
|
|
+ const UA_Byte *end = &dst.data[dst.length];
|
|
|
|
|
|
// when test 1
|
|
// when test 1
|
|
- src = -1;
|
|
|
|
- retval = UA_UInt64_encodeBinary(&src, &dst, &pos);
|
|
|
|
|
|
+ UA_StatusCode retval = UA_UInt64_encodeBinary(&src, &pos, &end);
|
|
// then test 1
|
|
// then test 1
|
|
- ck_assert_int_eq(pos, 8);
|
|
|
|
|
|
+ ck_assert_int_eq((uintptr_t)(pos - dst.data), 8);
|
|
ck_assert_int_eq(dst.data[0], 0xFF);
|
|
ck_assert_int_eq(dst.data[0], 0xFF);
|
|
ck_assert_int_eq(dst.data[1], 0xFF);
|
|
ck_assert_int_eq(dst.data[1], 0xFF);
|
|
ck_assert_int_eq(dst.data[2], 0xFF);
|
|
ck_assert_int_eq(dst.data[2], 0xFF);
|
|
@@ -746,9 +729,9 @@ START_TEST(UA_UInt64_encodeShallWorkOnExample) {
|
|
|
|
|
|
// when test 2
|
|
// when test 2
|
|
src = 0x7F0033AA44EE6611;
|
|
src = 0x7F0033AA44EE6611;
|
|
- retval = UA_UInt64_encodeBinary(&src, &dst, &pos);
|
|
|
|
|
|
+ retval = UA_UInt64_encodeBinary(&src, &pos, &end);
|
|
// then test 2
|
|
// then test 2
|
|
- ck_assert_int_eq(pos, 16);
|
|
|
|
|
|
+ ck_assert_int_eq((uintptr_t)(pos - dst.data), 16);
|
|
ck_assert_int_eq(dst.data[8], 0x11);
|
|
ck_assert_int_eq(dst.data[8], 0x11);
|
|
ck_assert_int_eq(dst.data[9], 0x66);
|
|
ck_assert_int_eq(dst.data[9], 0x66);
|
|
ck_assert_int_eq(dst.data[10], 0xEE);
|
|
ck_assert_int_eq(dst.data[10], 0xEE);
|
|
@@ -763,19 +746,17 @@ END_TEST
|
|
|
|
|
|
START_TEST(UA_Int64_encodeShallEncodeLittleEndian) {
|
|
START_TEST(UA_Int64_encodeShallEncodeLittleEndian) {
|
|
// given
|
|
// given
|
|
- UA_Int64 src;
|
|
|
|
- UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
|
|
|
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
|
|
|
|
|
|
+ UA_Int64 src = 0x7F0033AA44EE6611;
|
|
|
|
+ UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
|
|
|
+ 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
|
|
UA_ByteString dst = { 16, data };
|
|
UA_ByteString dst = { 16, data };
|
|
-
|
|
|
|
- UA_Int32 retval = 0;
|
|
|
|
- size_t pos = 0;
|
|
|
|
|
|
+ UA_Byte *pos = dst.data;
|
|
|
|
+ const UA_Byte *end = &dst.data[dst.length];
|
|
|
|
|
|
// when test 1
|
|
// when test 1
|
|
- src = 0x7F0033AA44EE6611;
|
|
|
|
- retval = UA_Int64_encodeBinary(&src, &dst, &pos);
|
|
|
|
|
|
+ UA_StatusCode retval = UA_Int64_encodeBinary(&src, &pos, &end);
|
|
// then test 1
|
|
// then test 1
|
|
- ck_assert_int_eq(pos, 8);
|
|
|
|
|
|
+ ck_assert_int_eq((uintptr_t)(pos - dst.data), 8);
|
|
ck_assert_int_eq(dst.data[0], 0x11);
|
|
ck_assert_int_eq(dst.data[0], 0x11);
|
|
ck_assert_int_eq(dst.data[1], 0x66);
|
|
ck_assert_int_eq(dst.data[1], 0x66);
|
|
ck_assert_int_eq(dst.data[2], 0xEE);
|
|
ck_assert_int_eq(dst.data[2], 0xEE);
|
|
@@ -790,19 +771,17 @@ END_TEST
|
|
|
|
|
|
START_TEST(UA_Int64_encodeNegativeShallEncodeLittleEndian) {
|
|
START_TEST(UA_Int64_encodeNegativeShallEncodeLittleEndian) {
|
|
// given
|
|
// given
|
|
- UA_Int64 src;
|
|
|
|
- UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
|
|
|
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
|
|
|
|
|
|
+ UA_Int64 src = -1;
|
|
|
|
+ UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
|
|
|
+ 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
|
|
UA_ByteString dst = { 16, data };
|
|
UA_ByteString dst = { 16, data };
|
|
-
|
|
|
|
- UA_Int32 retval = 0;
|
|
|
|
- size_t pos = 0;
|
|
|
|
|
|
+ UA_Byte *pos = dst.data;
|
|
|
|
+ const UA_Byte *end = &dst.data[dst.length];
|
|
|
|
|
|
// when test 1
|
|
// when test 1
|
|
- src = -1;
|
|
|
|
- retval = UA_Int64_encodeBinary(&src, &dst, &pos);
|
|
|
|
|
|
+ UA_StatusCode retval = UA_Int64_encodeBinary(&src, &pos, &end);
|
|
// then test 1
|
|
// then test 1
|
|
- ck_assert_int_eq(pos, 8);
|
|
|
|
|
|
+ ck_assert_int_eq((uintptr_t)(pos - dst.data), 8);
|
|
ck_assert_int_eq(dst.data[0], 0xFF);
|
|
ck_assert_int_eq(dst.data[0], 0xFF);
|
|
ck_assert_int_eq(dst.data[1], 0xFF);
|
|
ck_assert_int_eq(dst.data[1], 0xFF);
|
|
ck_assert_int_eq(dst.data[2], 0xFF);
|
|
ck_assert_int_eq(dst.data[2], 0xFF);
|
|
@@ -834,11 +813,12 @@ START_TEST(UA_Float_encodeShallWorkOnExample) {
|
|
|
|
|
|
UA_Byte data[] = {0x55, 0x55, 0x55, 0x55};
|
|
UA_Byte data[] = {0x55, 0x55, 0x55, 0x55};
|
|
UA_ByteString dst = {4, data};
|
|
UA_ByteString dst = {4, data};
|
|
|
|
+ const UA_Byte *end = &dst.data[dst.length];
|
|
|
|
|
|
for(size_t i = 0; i < 7; i++) {
|
|
for(size_t i = 0; i < 7; i++) {
|
|
- size_t pos = 0;
|
|
|
|
- UA_Int32 retval = UA_Float_encodeBinary(&src[i], &dst, &pos);
|
|
|
|
- ck_assert_int_eq(pos, 4);
|
|
|
|
|
|
+ UA_Byte *pos = dst.data;
|
|
|
|
+ UA_Int32 retval = UA_Float_encodeBinary(&src[i], &pos, &end);
|
|
|
|
+ ck_assert_int_eq((uintptr_t)(pos - dst.data), 4);
|
|
ck_assert_int_eq(dst.data[0], result[i][0]);
|
|
ck_assert_int_eq(dst.data[0], result[i][0]);
|
|
ck_assert_int_eq(dst.data[1], result[i][1]);
|
|
ck_assert_int_eq(dst.data[1], result[i][1]);
|
|
ck_assert_int_eq(dst.data[2], result[i][2]);
|
|
ck_assert_int_eq(dst.data[2], result[i][2]);
|
|
@@ -848,27 +828,23 @@ START_TEST(UA_Float_encodeShallWorkOnExample) {
|
|
}
|
|
}
|
|
END_TEST
|
|
END_TEST
|
|
|
|
|
|
-START_TEST(UA_Double_encodeShallWorkOnExample)
|
|
|
|
- {
|
|
|
|
|
|
+START_TEST(UA_Double_encodeShallWorkOnExample) {
|
|
// given
|
|
// given
|
|
- UA_Double src;
|
|
|
|
- UA_Byte data[] = { 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
|
|
|
|
- 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
|
|
|
|
- };
|
|
|
|
|
|
+ UA_Double src = -6.5;
|
|
|
|
+ UA_Byte data[] = { 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
|
|
|
|
+ 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55 };
|
|
UA_ByteString dst = {16,data};
|
|
UA_ByteString dst = {16,data};
|
|
-
|
|
|
|
- UA_Int32 retval;
|
|
|
|
- size_t pos = 0;
|
|
|
|
|
|
+ UA_Byte *pos = dst.data;
|
|
|
|
+ const UA_Byte *end = &dst.data[dst.length];
|
|
|
|
|
|
// when test 1
|
|
// when test 1
|
|
- src = -6.5;
|
|
|
|
- retval = UA_Double_encodeBinary(&src, &dst, &pos);
|
|
|
|
|
|
+ UA_StatusCode retval = UA_Double_encodeBinary(&src, &pos, &end);
|
|
// then test 1
|
|
// then test 1
|
|
- ck_assert_int_eq(pos, 8);
|
|
|
|
|
|
+ ck_assert_int_eq((uintptr_t)(pos - dst.data), 8);
|
|
ck_assert_int_eq(dst.data[6], 0x1A);
|
|
ck_assert_int_eq(dst.data[6], 0x1A);
|
|
ck_assert_int_eq(dst.data[7], 0xC0);
|
|
ck_assert_int_eq(dst.data[7], 0xC0);
|
|
ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
|
|
ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
|
|
- }
|
|
|
|
|
|
+}
|
|
END_TEST
|
|
END_TEST
|
|
|
|
|
|
START_TEST(UA_String_encodeShallWorkOnExample) {
|
|
START_TEST(UA_String_encodeShallWorkOnExample) {
|
|
@@ -878,19 +854,18 @@ START_TEST(UA_String_encodeShallWorkOnExample) {
|
|
UA_Byte mem[11] = "ACPLT OPCUA";
|
|
UA_Byte mem[11] = "ACPLT OPCUA";
|
|
src.data = mem;
|
|
src.data = mem;
|
|
|
|
|
|
- UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
|
|
|
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
|
|
|
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
|
|
|
|
|
|
+ UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
|
|
|
+ 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
|
|
|
+ 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
|
|
UA_ByteString dst = { 24, data };
|
|
UA_ByteString dst = { 24, data };
|
|
-
|
|
|
|
- UA_Int32 retval = 0;
|
|
|
|
- size_t pos = 0;
|
|
|
|
|
|
+ UA_Byte *pos = dst.data;
|
|
|
|
+ const UA_Byte *end = &dst.data[dst.length];
|
|
|
|
|
|
// when
|
|
// when
|
|
- retval = UA_String_encodeBinary(&src, &dst, &pos);
|
|
|
|
|
|
+ UA_StatusCode retval = UA_String_encodeBinary(&src, &pos, &end);
|
|
// then
|
|
// then
|
|
- ck_assert_int_eq(pos, sizeof(UA_Int32)+11);
|
|
|
|
- ck_assert_uint_eq(pos, UA_calcSizeBinary(&src, &UA_TYPES[UA_TYPES_STRING]));
|
|
|
|
|
|
+ ck_assert_int_eq((uintptr_t)(pos - dst.data), sizeof(UA_Int32)+11);
|
|
|
|
+ ck_assert_uint_eq(sizeof(UA_Int32)+11, UA_calcSizeBinary(&src, &UA_TYPES[UA_TYPES_STRING]));
|
|
ck_assert_int_eq(dst.data[0], 11);
|
|
ck_assert_int_eq(dst.data[0], 11);
|
|
ck_assert_int_eq(dst.data[sizeof(UA_Int32)+0], 'A');
|
|
ck_assert_int_eq(dst.data[sizeof(UA_Int32)+0], 'A');
|
|
ck_assert_int_eq(dst.data[sizeof(UA_Int32)+1], 'C');
|
|
ck_assert_int_eq(dst.data[sizeof(UA_Int32)+1], 'C');
|
|
@@ -912,15 +887,15 @@ START_TEST(UA_ExpandedNodeId_encodeShallWorkOnExample) {
|
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
|
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
|
|
UA_ByteString dst = { 32, data };
|
|
UA_ByteString dst = { 32, data };
|
|
- UA_Int32 retval = 0;
|
|
|
|
- size_t pos = 0;
|
|
|
|
|
|
+ UA_Byte *pos = dst.data;
|
|
|
|
+ const UA_Byte *end = &dst.data[dst.length];
|
|
|
|
|
|
// when
|
|
// when
|
|
- retval = UA_ExpandedNodeId_encodeBinary(&src, &dst, &pos);
|
|
|
|
|
|
+ UA_StatusCode retval = UA_ExpandedNodeId_encodeBinary(&src, &pos, &end);
|
|
// then
|
|
// then
|
|
ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
|
|
ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
|
|
- ck_assert_int_eq(pos, 13);
|
|
|
|
- ck_assert_uint_eq(pos, UA_calcSizeBinary(&src, &UA_TYPES[UA_TYPES_EXPANDEDNODEID]));
|
|
|
|
|
|
+ ck_assert_int_eq((uintptr_t)(pos - dst.data), 13);
|
|
|
|
+ ck_assert_uint_eq(13, UA_calcSizeBinary(&src, &UA_TYPES[UA_TYPES_EXPANDEDNODEID]));
|
|
ck_assert_int_eq(dst.data[0], 0x80); // namespaceuri flag
|
|
ck_assert_int_eq(dst.data[0], 0x80); // namespaceuri flag
|
|
}
|
|
}
|
|
END_TEST
|
|
END_TEST
|
|
@@ -936,15 +911,14 @@ START_TEST(UA_DataValue_encodeShallWorkOnExampleWithoutVariant) {
|
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
|
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
|
|
UA_ByteString dst = { 24, data };
|
|
UA_ByteString dst = { 24, data };
|
|
-
|
|
|
|
- UA_Int32 retval = 0;
|
|
|
|
- size_t pos = 0;
|
|
|
|
|
|
+ UA_Byte *pos = dst.data;
|
|
|
|
+ const UA_Byte *end = &dst.data[dst.length];
|
|
|
|
|
|
// when
|
|
// when
|
|
- retval = UA_DataValue_encodeBinary(&src, &dst, &pos);
|
|
|
|
|
|
+ UA_StatusCode retval = UA_DataValue_encodeBinary(&src, &pos, &end);
|
|
// then
|
|
// then
|
|
- ck_assert_int_eq(pos, 9); // represents the length
|
|
|
|
- ck_assert_uint_eq(pos, UA_calcSizeBinary(&src, &UA_TYPES[UA_TYPES_DATAVALUE]));
|
|
|
|
|
|
+ ck_assert_int_eq((uintptr_t)(pos - dst.data), 9);
|
|
|
|
+ ck_assert_uint_eq(9, UA_calcSizeBinary(&src, &UA_TYPES[UA_TYPES_DATAVALUE]));
|
|
ck_assert_int_eq(dst.data[0], 0x08); // encodingMask
|
|
ck_assert_int_eq(dst.data[0], 0x08); // encodingMask
|
|
ck_assert_int_eq(dst.data[1], 80); // 8 Byte serverTimestamp
|
|
ck_assert_int_eq(dst.data[1], 80); // 8 Byte serverTimestamp
|
|
ck_assert_int_eq(dst.data[2], 0);
|
|
ck_assert_int_eq(dst.data[2], 0);
|
|
@@ -974,15 +948,14 @@ START_TEST(UA_DataValue_encodeShallWorkOnExampleWithVariant) {
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
UA_ByteString dst = { 24, data };
|
|
UA_ByteString dst = { 24, data };
|
|
-
|
|
|
|
- UA_Int32 retval = 0;
|
|
|
|
- size_t pos = 0;
|
|
|
|
|
|
+ UA_Byte *pos = dst.data;
|
|
|
|
+ const UA_Byte *end = &dst.data[dst.length];
|
|
|
|
|
|
// when
|
|
// when
|
|
- retval = UA_DataValue_encodeBinary(&src, &dst, &pos);
|
|
|
|
|
|
+ UA_StatusCode retval = UA_DataValue_encodeBinary(&src, &pos, &end);
|
|
// then
|
|
// then
|
|
- ck_assert_int_eq(pos, 1+(1+4)+8); // represents the length
|
|
|
|
- ck_assert_uint_eq(pos, UA_calcSizeBinary(&src, &UA_TYPES[UA_TYPES_DATAVALUE]));
|
|
|
|
|
|
+ ck_assert_int_eq((uintptr_t)(pos - dst.data), 1+(1+4)+8); // represents the length
|
|
|
|
+ ck_assert_uint_eq(1+(1+4)+8, UA_calcSizeBinary(&src, &UA_TYPES[UA_TYPES_DATAVALUE]));
|
|
ck_assert_int_eq(dst.data[0], 0x08 | 0x01); // encodingMask
|
|
ck_assert_int_eq(dst.data[0], 0x08 | 0x01); // encodingMask
|
|
ck_assert_int_eq(dst.data[1], 0x06); // Variant's Encoding Mask - INT32
|
|
ck_assert_int_eq(dst.data[1], 0x06); // Variant's Encoding Mask - INT32
|
|
ck_assert_int_eq(dst.data[2], 45); // the single value
|
|
ck_assert_int_eq(dst.data[2], 45); // the single value
|
|
@@ -1539,11 +1512,9 @@ static Suite *testSuite_builtin(void) {
|
|
tcase_add_test(tc_copy, UA_Array_copyByteArrayShallWorkOnExample);
|
|
tcase_add_test(tc_copy, UA_Array_copyByteArrayShallWorkOnExample);
|
|
tcase_add_test(tc_copy, UA_Array_copyUA_StringShallWorkOnExample);
|
|
tcase_add_test(tc_copy, UA_Array_copyUA_StringShallWorkOnExample);
|
|
tcase_add_test(tc_copy, UA_ExtensionObject_copyShallWorkOnExample);
|
|
tcase_add_test(tc_copy, UA_ExtensionObject_copyShallWorkOnExample);
|
|
-
|
|
|
|
tcase_add_test(tc_copy, UA_Variant_copyShallWorkOnSingleValueExample);
|
|
tcase_add_test(tc_copy, UA_Variant_copyShallWorkOnSingleValueExample);
|
|
tcase_add_test(tc_copy, UA_Variant_copyShallWorkOn1DArrayExample);
|
|
tcase_add_test(tc_copy, UA_Variant_copyShallWorkOn1DArrayExample);
|
|
tcase_add_test(tc_copy, UA_Variant_copyShallWorkOn2DArrayExample);
|
|
tcase_add_test(tc_copy, UA_Variant_copyShallWorkOn2DArrayExample);
|
|
-
|
|
|
|
tcase_add_test(tc_copy, UA_DiagnosticInfo_copyShallWorkOnExample);
|
|
tcase_add_test(tc_copy, UA_DiagnosticInfo_copyShallWorkOnExample);
|
|
tcase_add_test(tc_copy, UA_ApplicationDescription_copyShallWorkOnExample);
|
|
tcase_add_test(tc_copy, UA_ApplicationDescription_copyShallWorkOnExample);
|
|
tcase_add_test(tc_copy, UA_QualifiedName_copyShallWorkOnInputExample);
|
|
tcase_add_test(tc_copy, UA_QualifiedName_copyShallWorkOnInputExample);
|
|
@@ -1554,7 +1525,6 @@ static Suite *testSuite_builtin(void) {
|
|
return s;
|
|
return s;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
int main(void) {
|
|
int main(void) {
|
|
int number_failed = 0;
|
|
int number_failed = 0;
|
|
Suite *s;
|
|
Suite *s;
|