Browse Source

Merge branch '0.2'

Julius Pfrommer 7 years ago
parent
commit
3a5f02db05
4 changed files with 37 additions and 29 deletions
  1. 1 0
      CMakeLists.txt
  2. 23 0
      include/ua_config.h.in
  3. 1 1
      src/server/ua_services_attribute.c
  4. 12 28
      tests/check_chunking.c

+ 1 - 0
CMakeLists.txt

@@ -698,6 +698,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
     install(FILES "${PROJECT_BINARY_DIR}/src_generated/open62541.pc"
             DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 endif()
+
 # export amalgamated header open62541.h which is generated due to build of open62541-object
 if(UA_ENABLE_AMALGAMATION)
     install(FILES ${PROJECT_BINARY_DIR}/open62541.h DESTINATION include/open62541)

+ 23 - 0
include/ua_config.h.in

@@ -307,6 +307,29 @@ extern "C" {
 # define UA_TYPENAME(name)
 #endif
 
+/**
+ * Static Assert
+ * ^^^^^^^^^^^^^
+ * Outputs an error message at compile time if the assert fails.
+ * Example usage:
+ * UA_STATIC_ASSERT(sizeof(long)==7, use_another_compiler_luke)
+ * See: https://stackoverflow.com/a/4815532/869402 */
+#if defined(__cplusplus) && __cplusplus >= 201103L /* C++11 or above */
+# define UA_STATIC_ASSERT(cond,msg) static_assert(cond, #msg)
+#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L /* C11 or above */
+# define UA_STATIC_ASSERT(cond,msg) _Static_assert(cond, #msg)
+#elif defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) /* GCC, Clang, MSC */
+# define UA_CTASTR2(pre,post) pre ## post
+# define UA_CTASTR(pre,post) UA_CTASTR2(pre,post)
+# define UA_STATIC_ASSERT(cond,msg)                             \
+    typedef struct {                                            \
+        int UA_CTASTR(static_assertion_failed_,msg) : !!(cond); \
+    } UA_CTASTR(static_assertion_failed_,__COUNTER__)
+#else /* Everybody else */
+# define UA_STATIC_ASSERT(cond,msg) \
+    typedef char static_assertion_##msg[(cond)?1:-1]
+#endif
+
 #ifdef __cplusplus
 } // extern "C"
 #endif

+ 1 - 1
src/server/ua_services_attribute.c

@@ -399,7 +399,7 @@ __UA_Server_read(UA_Server *server, const UA_NodeId *nodeId,
     /* Check the return value */
     UA_StatusCode retval = UA_STATUSCODE_GOOD;
     if(dv.hasStatus)
-        retval = dv.hasStatus;
+        retval = dv.status;
     else if(!dv.hasValue)
         retval = UA_STATUSCODE_BADUNEXPECTEDERROR;
     if(retval != UA_STATUSCODE_GOOD) {

+ 12 - 28
tests/check_chunking.c

@@ -26,6 +26,7 @@ sendChunkMockUp(UA_ChunkInfo *ci, UA_Byte **bufPos, const UA_Byte **bufEnd) {
     dataCount += offset;
     return UA_STATUSCODE_GOOD;
 }
+
 START_TEST(encodeArrayIntoFiveChunksShallWork) {
     size_t arraySize = 30; //number of elements within the array which should be encoded
     size_t chunkCount = 6; // maximum chunk count
@@ -34,20 +35,19 @@ START_TEST(encodeArrayIntoFiveChunksShallWork) {
     bufIndex = 0;
     counter = 0;
     dataCount = 0;
-    UA_Int32 *ar = (UA_Int32*)UA_Array_new(arraySize,&UA_TYPES[UA_TYPES_INT32]);
     buffers = (UA_ByteString*)UA_Array_new(chunkCount, &UA_TYPES[UA_TYPES_BYTESTRING]);
     for(size_t i=0;i<chunkCount;i++){
         UA_ByteString_allocBuffer(&buffers[i],chunkSize);
     }
 
-    UA_ByteString workingBuffer=buffers[0];
+    UA_Int32 *ar = (UA_Int32*)UA_Array_new(arraySize,&UA_TYPES[UA_TYPES_INT32]);
+    for(size_t i = 0; i < arraySize; i++)
+        ar[i] = (UA_Int32)i;
 
-    for(size_t i=0;i<arraySize;i++){
-        ar[i]=(UA_Int32)i;
-    }
     UA_Variant v;
-    UA_Variant_setArrayCopy(&v,ar,arraySize,&UA_TYPES[UA_TYPES_INT32]);
+    UA_Variant_setArrayCopy(&v, ar, arraySize, &UA_TYPES[UA_TYPES_INT32]);
 
+    UA_ByteString workingBuffer = buffers[0];
     UA_Byte *pos = workingBuffer.data;
     const UA_Byte *end = &workingBuffer.data[workingBuffer.length];
     UA_StatusCode retval = UA_encodeBinary(&v,&UA_TYPES[UA_TYPES_VARIANT], &pos, &end,
@@ -62,12 +62,9 @@ START_TEST(encodeArrayIntoFiveChunksShallWork) {
     UA_Variant_deleteMembers(&v);
     UA_Array_delete(buffers, chunkCount, &UA_TYPES[UA_TYPES_BYTESTRING]);
     UA_Array_delete(ar, arraySize, &UA_TYPES[UA_TYPES_INT32]);
-
-}
-END_TEST
+} END_TEST
 
 START_TEST(encodeStringIntoFiveChunksShallWork) {
-
     size_t stringLength = 120; //number of elements within the array which should be encoded
     size_t chunkCount = 6; // maximum chunk count
     size_t chunkSize = 30; //size in bytes of each chunk
@@ -110,11 +107,9 @@ START_TEST(encodeStringIntoFiveChunksShallWork) {
     UA_Variant_deleteMembers(&v);
     UA_Array_delete(buffers, chunkCount, &UA_TYPES[UA_TYPES_BYTESTRING]);
     UA_String_deleteMembers(&string);
-}
-END_TEST
+} END_TEST
 
 START_TEST(encodeTwoStringsIntoTenChunksShallWork) {
-
     size_t stringLength = 143; //number of elements within the array which should be encoded
     size_t chunkCount = 10; // maximum chunk count
     size_t chunkSize = 30; //size in bytes of each chunk
@@ -158,31 +153,20 @@ START_TEST(encodeTwoStringsIntoTenChunksShallWork) {
 
     UA_Array_delete(buffers, chunkCount, &UA_TYPES[UA_TYPES_BYTESTRING]);
     UA_String_deleteMembers(&string);
-}
-END_TEST
+} END_TEST
 
-
-static Suite *testSuite_builtin(void) {
+int main(void) {
     Suite *s = suite_create("Chunked encoding");
     TCase *tc_message = tcase_create("encode chunking");
     tcase_add_test(tc_message,encodeArrayIntoFiveChunksShallWork);
     tcase_add_test(tc_message,encodeStringIntoFiveChunksShallWork);
     tcase_add_test(tc_message,encodeTwoStringsIntoTenChunksShallWork);
     suite_add_tcase(s, tc_message);
-    return s;
-}
-
-
-int main(void) {
-    int      number_failed = 0;
-    Suite   *s;
-    SRunner *sr;
 
-    s  = testSuite_builtin();
-    sr = srunner_create(s);
+    SRunner *sr = srunner_create(s);
     srunner_set_fork_status(sr, CK_NOFORK);
     srunner_run_all(sr, CK_NORMAL);
-    number_failed += srunner_ntests_failed(sr);
+    int number_failed = srunner_ntests_failed(sr);
     srunner_free(sr);
 
     return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;