├── .clang-format ├── .github ├── linters │ └── .yaml-lint.yml └── workflows │ ├── ClangRelWithDebInfoAsan.yml │ ├── GccDebugMemcheck.yml │ ├── GccIntegrationTest.yml │ ├── Linter.yml │ └── windows.yml ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── README.md ├── backends ├── CMakeLists.txt ├── open62541 │ ├── CMakeLists.txt │ ├── examples │ │ ├── CMakeLists.txt │ │ ├── dataTypeImport.c │ │ ├── iterate.c │ │ └── server.c │ ├── include │ │ └── NodesetLoader │ │ │ ├── backendOpen62541.h │ │ │ └── dataTypes.h │ ├── src │ │ ├── DataTypeImporter.c │ │ ├── DataTypeImporter.h │ │ ├── RefServiceImpl.c │ │ ├── RefServiceImpl.h │ │ ├── ServerContext.c │ │ ├── ServerContext.h │ │ ├── Value.c │ │ ├── Value.h │ │ ├── conversion.h │ │ ├── customDataType.c │ │ ├── customDataType.h │ │ ├── import.c │ │ ├── nodeset_base64.h │ │ └── padding.h │ └── tests │ │ ├── CMakeLists.txt │ │ ├── basestruct.xml │ │ ├── basicNodeClasses.c │ │ ├── basicNodeClasses.xml │ │ ├── conversion.c │ │ ├── cornerCases.c │ │ ├── cornerCases.xml │ │ ├── customTypesWithValues.c │ │ ├── customTypesWithValues.xml │ │ ├── dataTypeImport │ │ ├── CMakeLists.txt │ │ ├── abstractdatatypemember.bsd │ │ ├── abstractdatatypemember.csv │ │ ├── abstractdatatypemember.xml │ │ ├── bytestring.c │ │ ├── bytestring.xml │ │ ├── compareAbstractDataTypeMember.c │ │ ├── compareDITypes.c │ │ ├── compareOptionset.c │ │ ├── compareStructExtended.c │ │ ├── compareStructSpecialized.c │ │ ├── compareStructTypes.c │ │ ├── compareUnion.c │ │ ├── enum.c │ │ ├── enum.xml │ │ ├── optionalStruct.c │ │ ├── optionalstruct.bsd │ │ ├── optionalstruct.csv │ │ ├── optionalstruct.xml │ │ ├── optionset.bsd │ │ ├── optionset.csv │ │ ├── optionset.xml │ │ ├── padding.c │ │ ├── specializedstruct.bsd │ │ ├── specializedstruct.csv │ │ ├── specializedstruct.xml │ │ ├── struct.bsd │ │ ├── struct.csv │ │ ├── struct.xml │ │ ├── structExtended.bsd │ │ ├── structExtended.csv │ │ ├── structExtended.xml │ │ ├── subDataType.c │ │ ├── subDataType.xml │ │ ├── union.bsd │ │ ├── union.csv │ │ └── union.xml │ │ ├── extendedstruct.xml │ │ ├── extension.c │ │ ├── extension.xml │ │ ├── import.c │ │ ├── integration │ │ ├── CMakeLists.txt │ │ ├── client │ │ │ ├── CMakeLists.txt │ │ │ ├── browse_utils.cpp │ │ │ ├── browse_utils.h │ │ │ ├── client.cpp │ │ │ ├── common_defs.h │ │ │ ├── operator_ov.cpp │ │ │ ├── operator_ov.h │ │ │ ├── sort_utils.cpp │ │ │ ├── sort_utils.h │ │ │ ├── utils.cpp │ │ │ ├── utils.h │ │ │ ├── value_utils.cpp │ │ │ ├── value_utils.h │ │ │ └── value_utils_mock.cpp │ │ ├── reference_server │ │ │ ├── CMakeLists.txt │ │ │ └── server.cpp │ │ ├── start_test.sh │ │ └── test_server │ │ │ ├── CMakeLists.txt │ │ │ └── server.cpp │ │ ├── issue266_TestData.NodeSet2.xml │ │ ├── issue_201.c │ │ ├── issue_201.xml │ │ ├── issue_241.c │ │ ├── issue_241.xml │ │ ├── issue_246.c │ │ ├── issue_246.xml │ │ ├── issue_246_2.c │ │ ├── issue_246_2.xml │ │ ├── issue_266_testdata.c │ │ ├── multipleNamespaces.c │ │ ├── multipleNamespaces.xml │ │ ├── namespaceZeroValues.c │ │ ├── namespaceZeroValues.xml │ │ ├── newHierachicalRef.c │ │ ├── newHierachicalRef.xml │ │ ├── newHierachicalRef2.xml │ │ ├── nodeAttributes.c │ │ ├── nodeAttributes.xml │ │ ├── orderingStringNodeIds.c │ │ ├── orderingStringNodeIds.xml │ │ ├── primitiveValues.c │ │ ├── primitiveValues.xml │ │ ├── references.c │ │ ├── references.xml │ │ ├── stringNodeId_issue_224.c │ │ ├── stringNodeId_issue_224.xml │ │ ├── structMultipleNamespaces.c │ │ ├── structwitharray.c │ │ ├── structwitharray.xml │ │ ├── subDataTypes.c │ │ ├── subDataTypes.xml │ │ ├── testHelper.h │ │ ├── valueRank.c │ │ └── valueRank.xml └── stdout │ ├── CMakeLists.txt │ └── examples │ ├── CMakeLists.txt │ ├── backend.h │ ├── csv.c │ ├── dump.c │ └── main.c ├── cmake └── FindCheck.cmake ├── conanfile.txt ├── coverage └── CMakeLists.txt ├── include └── NodesetLoader │ ├── Extension.h │ ├── Logger.h │ ├── NodesetLoader.h │ ├── ReferenceService.h │ └── arch.h ├── nodesetloader-config.cmake ├── nodesets ├── Opc.Ua.Di.NodeSet2.xml ├── Opc.Ua.NodeSet2.xml ├── Opc.Ua.Plc.NodeSet2.xml ├── euromap │ ├── Opc.Ua.PlasticsRubber.GeneralTypes.NodeSet2.bsd │ ├── Opc.Ua.PlasticsRubber.GeneralTypes.NodeSet2.csv │ ├── Opc.Ua.PlasticsRubber.GeneralTypes.NodeSet2.xml │ ├── Opc.Ua.PlasticsRubber.IMM2MES.NodeSet2.bsd │ ├── Opc.Ua.PlasticsRubber.IMM2MES.NodeSet2.csv │ └── Opc.Ua.PlasticsRubber.IMM2MES.NodeSet2.xml ├── euromap_instances │ ├── euromapinstances.csv │ ├── euromapinstances.tt2pro │ └── euromapinstances.xml ├── open62541 │ ├── Opc.Ua.Di.NodeSet2_invalid_ordering.xml │ └── testnodeset.xml ├── struct_union_optionset │ ├── structtest.bsd │ ├── structtest.csv │ ├── structtest.tt2pro │ ├── structtest.xml │ └── structtest.xsd ├── testNodeset.xml └── testNodeset100nodes.xml ├── runCppcheck.sh ├── runLcov.sh ├── src ├── AliasList.c ├── AliasList.h ├── CharAllocator.c ├── CharAllocator.h ├── InternalLogger.h ├── InternalRefService.c ├── InternalRefService.h ├── NamespaceList.c ├── NamespaceList.h ├── Nodeset.c ├── Nodeset.h ├── NodesetLoader.c ├── Parser.c ├── Parser.h ├── PrintfLogger.c ├── Sort.c ├── Sort.h ├── Value.c ├── Value.h └── nodes │ ├── DataTypeNode.c │ ├── DataTypeNode.h │ ├── InstanceNode.c │ ├── Node.c │ ├── Node.h │ ├── NodeContainer.c │ └── NodeContainer.h └── tests ├── CMakeLists.txt ├── NodeContainer.c ├── ValueTest.c ├── allocator.c ├── basicNodeClasses.xml ├── invalidNodeDefinitions.xml ├── parser.c └── sort.c /.github/linters/.yaml-lint.yml: -------------------------------------------------------------------------------- 1 | --- 2 | ########################################### 3 | # These are the rules used for # 4 | # linting all the yaml files in the stack # 5 | # NOTE: # 6 | # You can disable line with: # 7 | # # yamllint disable-line # 8 | ########################################### 9 | rules: 10 | braces: 11 | level: warning 12 | min-spaces-inside: 0 13 | max-spaces-inside: 0 14 | min-spaces-inside-empty: 1 15 | max-spaces-inside-empty: 5 16 | brackets: 17 | level: warning 18 | min-spaces-inside: 0 19 | max-spaces-inside: 0 20 | min-spaces-inside-empty: 1 21 | max-spaces-inside-empty: 5 22 | colons: 23 | level: warning 24 | max-spaces-before: 0 25 | max-spaces-after: 1 26 | commas: 27 | level: warning 28 | max-spaces-before: 0 29 | min-spaces-after: 1 30 | max-spaces-after: 1 31 | comments: disable 32 | comments-indentation: disable 33 | document-end: disable 34 | document-start: 35 | level: warning 36 | present: true 37 | empty-lines: 38 | level: warning 39 | max: 2 40 | max-start: 0 41 | max-end: 0 42 | hyphens: 43 | level: warning 44 | max-spaces-after: 1 45 | indentation: 46 | level: warning 47 | spaces: consistent 48 | indent-sequences: true 49 | check-multi-line-strings: false 50 | key-duplicates: enable 51 | line-length: 52 | level: warning 53 | max: 80 54 | allow-non-breakable-words: true 55 | allow-non-breakable-inline-mappings: true 56 | new-line-at-end-of-file: disable 57 | new-lines: 58 | type: unix 59 | trailing-spaces: disable -------------------------------------------------------------------------------- /.github/workflows/ClangRelWithDebInfoAsan.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Clang RelWithDebInfoAsan 3 | 4 | on: 5 | push: 6 | branches: 7 | - master 8 | pull_request: 9 | 10 | permissions: read-all 11 | 12 | env: 13 | # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) 14 | BUILD_TYPE: RelWithDebInfo 15 | CC: clang 16 | CXX: clang 17 | 18 | jobs: 19 | build: 20 | # yamllint disable rule:line-length 21 | # The CMake configure and build commands are platform agnostic and should 22 | # work equally well on Windows or Mac. You can convert this to a matrix 23 | # build if you need cross-platform coverage. 24 | # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix 25 | # yamllint enable rule:line-length 26 | runs-on: ubuntu-latest 27 | 28 | steps: 29 | - uses: actions/checkout@v4 30 | - uses: actions/setup-python@v5 31 | with: 32 | python-version: '3.x' 33 | # Version range or exact version of a Python version to use, 34 | # using SemVer's version range syntax 35 | 36 | - name: Update package lists 37 | run: sudo apt-get update 38 | 39 | - name: Install check 40 | run: sudo apt-get install check 41 | 42 | - name: Install Valgrind 43 | run: sudo apt-get install valgrind 44 | 45 | - name: Install conan 46 | run: pip3 install conan 47 | 48 | - name: Create Build Environment 49 | # Some projects don't allow in-source building, so create a separate 50 | # build directory We'll use this as our working directory for all 51 | # subsequent commands 52 | shell: bash 53 | run: cmake -E make_directory ${{ runner.temp }}/build 54 | 55 | - name: Configure CMake 56 | # Use a bash shell so we can use the same syntax for environment 57 | # variable access regardless of the host operating system 58 | shell: bash 59 | working-directory: ${{ runner.temp }}/build 60 | # Note the current convention is to use the -S and -B options here 61 | # to specify source and build directories, but this is only 62 | # available with CMake 3.13 and higher. The CMake binaries on the 63 | # Github Actions machines are (as of this writing) 3.28 64 | run: | 65 | cmake "$GITHUB_WORKSPACE" \ 66 | -DCMAKE_BUILD_TYPE=RelWithDebInfo \ 67 | -DENABLE_TESTING=ON \ 68 | -DBUILD_SHARED_LIBS=ON \ 69 | -DENABLE_ASAN=ON .. 70 | 71 | - name: Build 72 | shell: bash 73 | working-directory: ${{ runner.temp }}/build 74 | # Execute the build. You can specify a specific target 75 | # with "--target " 76 | run: cmake --build . --config "$BUILD_TYPE" 77 | 78 | - name: Test 79 | shell: bash 80 | working-directory: ${{ runner.temp }}/build 81 | # Execute tests defined by the CMake configuration. 82 | # See https://cmake.org/cmake/help/latest/manual/ctest.1.html 83 | # for more detail 84 | run: ctest 85 | -------------------------------------------------------------------------------- /.github/workflows/Linter.yml: -------------------------------------------------------------------------------- 1 | --- 2 | ########################### 3 | ########################### 4 | ## Linter GitHub Actions ## 5 | ########################### 6 | ########################### 7 | name: Lint Code Base 8 | 9 | # 10 | # Documentation: 11 | # https://help.github.com/en/articles/workflow-syntax-for-github-actions 12 | # 13 | 14 | ############################# 15 | # Start the job on all push # 16 | ############################# 17 | on: 18 | push: 19 | branches: 20 | - master 21 | pull_request: 22 | 23 | permissions: read-all 24 | 25 | ############### 26 | # Set the Job # 27 | ############### 28 | jobs: 29 | build: 30 | # Name the Job 31 | name: Lint Code Base 32 | # Set the agent to run on 33 | runs-on: ubuntu-latest 34 | 35 | ################## 36 | # Load all steps # 37 | ################## 38 | steps: 39 | ########################## 40 | # Checkout the code base # 41 | ########################## 42 | - name: Checkout Code 43 | uses: actions/checkout@v4 44 | with: 45 | # Full git history is needed to get a proper 46 | # list of changed files within `super-linter` 47 | fetch-depth: 0 48 | 49 | ################################ 50 | # Run Linter against code base # 51 | ################################ 52 | - name: Lint Code Base 53 | uses: super-linter/super-linter@v6 54 | env: 55 | VALIDATE_ALL_CODEBASE: false 56 | DEFAULT_BRANCH: master 57 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /.github/workflows/windows.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: WindowsBuildOnly 3 | 4 | on: 5 | push: 6 | branches: 7 | - master 8 | pull_request: 9 | workflow_dispatch: 10 | 11 | permissions: read-all 12 | 13 | env: 14 | # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) 15 | BUILD_TYPE: Release 16 | 17 | jobs: 18 | build: 19 | # yamllint disable rule:line-length 20 | # The CMake configure and build commands are platform agnostic and should 21 | # work equally well on Windows or Mac. You can convert this to a matrix 22 | # build if you need cross-platform coverage. 23 | # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix 24 | # yamllint enable rule:line-length 25 | runs-on: windows-2019 26 | 27 | steps: 28 | - name: Install conan 29 | run: pip install conan && conan profile detect 30 | 31 | - uses: actions/checkout@v4 32 | with: 33 | submodules: recursive 34 | path: ./nodesetLoader 35 | 36 | - uses: ilammy/msvc-dev-cmd@v1 37 | - name: Build nodesetLoader 38 | run: | 39 | cd ./nodesetLoader && cmake "-DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=./cmake-conan/conan_provider.cmake" -DCMAKE_BUILD_TYPE=Debug ` 40 | -DUA_NAMESPACE_ZERO=FULL ` 41 | -DENABLE_TESTING=ON . && ` 42 | cmake --build . 43 | 44 | - name: Test 45 | shell: cmd 46 | # Execute tests defined by the CMake configuration. 47 | # See https://cmake.org/cmake/help/latest/manual/ctest.1.html 48 | # for more detail 49 | run: cd ./nodesetLoader && ctest -E issue_241_Test -C Debug --verbose 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | build/ 3 | Testing/ 4 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "cmake-conan"] 2 | path = cmake-conan 3 | url = https://github.com/conan-io/cmake-conan.git 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nodesetLoader ![IntegrationTests](https://github.com/matkonnerth/nodesetLoader/workflows/IntegrationTests/badge.svg) [![codecov](https://codecov.io/gh/matkonnerth/nodesetLoader/branch/master/graph/badge.svg?token=2VCWKLKFJL)](https://codecov.io/gh/matkonnerth/nodesetLoader) 2 | nodesetLoader is a library written in C99 for the purpose of loading OPC UA nodesets from xml and sorting the nodes based on their hierachical references. 3 | 4 | ## License 5 | MPL2.0 https://github.com/matkonnerth/nodesetLoader/blob/master/LICENSE 6 | 7 | # Current status 8 | Official release v0.4.0 is tagged. Please be aware that interface may change in future releases. 9 | 10 | Supported operating systems: Linux, Windows (rudimentary) 11 | 12 | #### Backend open62541 13 | 14 | Supported open62541 version: 1.3.x 15 | Support for loading values with datatypes from namespace 0 or custom namespaces 16 | Support parsing of extensions (via a callback interface) 17 | 18 | ## Contribution 19 | Feel free to work on issues or providing further tests to improve the quality of this library. You can start by forking this repository and opening pull requests on it. 20 | 21 | ## dependencies 22 | xmlImport: libXml (http://www.xmlsoft.org/) for parsing the nodeset xml \ 23 | unit testing: libcheck 24 | 25 | ## Design goals 26 | 1) performance 27 | 2) memory overhead 28 | 29 | ## Build 30 | mkdir build \ 31 | cd build \ 32 | cmake .. \ 33 | make 34 | 35 | ## Running the demo 36 | ./parserDemo pathToNodesetFile1 pathToNodesetFile2 37 | 38 | ## Integration with open62541 39 | 40 | ### example 41 | 42 | ```c 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | static volatile UA_Boolean running = true; 50 | static void stopHandler(int sign) { 51 | UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c"); 52 | running = false; 53 | } 54 | 55 | int main(int argc, const char *argv[]) { 56 | UA_Server *server = UA_Server_new(); 57 | UA_ServerConfig_setDefault(UA_Server_getConfig(server)); 58 | //provide the server and the path to nodeset 59 | //returns true in case of successful import 60 | if(!NodesetLoader_loadFile(server, "../Opc.Ua.Di.NodeSet2.xml", NULL)) 61 | { 62 | UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "importing the xml nodeset failed"); 63 | } 64 | UA_StatusCode retval = UA_Server_run(server, &running); 65 | //NodesetLoader is allocating memory for custom dataTypes, user has to manually clean up 66 | const UA_DataTypeArray *customTypes = 67 | UA_Server_getConfig(server)->customDataTypes; 68 | UA_Server_delete(server); 69 | NodesetLoader_cleanupCustomDataTypes(customTypes); 70 | return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE; 71 | } 72 | ``` 73 | 74 | ### status 75 | * :heavy_check_mark: import of multiple nodeset files 76 | * :heavy_check_mark: nodesetLoader uses the logger from the server configuration 77 | * :heavy_check_mark: DataType import: custom datatypes 78 | * :heavy_check_mark: DataType import: optionset, union, structs with optional members supported 79 | * :heavy_check_mark: Value import: for variables with datatypes from namespace 0 and custom data types 80 | 81 | ### build 82 | 83 | Build with cmake. 84 | 85 | There is an example in the open backend, can be started with 86 | backends/open62541/examples/server 87 | 88 | Here's an example repo, consuming open62541 and NodesetLoader via cmake find_package: 89 | https://github.com/matkonnerth/nodesetLoader_usage 90 | -------------------------------------------------------------------------------- /backends/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # set backend variables in current scope 2 | set(NODESETLOADER_BACKEND_SOURCES "") 3 | set(NODESETLOADER_BACKEND_PUBLIC_INCLUDES "") 4 | set(NODESETLOADER_BACKEND_PRIVATE_INCLUDES "") 5 | set(NODESETLOADER_BACKEND_DEPS_LIBS "") 6 | set(NODESETLOADER_BACKEND_PUBLIC_HEADERS "") 7 | set(NODESETLOADER_BACKEND_PRIVATE_HEADERS "") 8 | 9 | if(${ENABLE_BACKEND_STDOUT}) 10 | add_subdirectory(stdout) 11 | endif() 12 | 13 | add_subdirectory(open62541) 14 | list(APPEND NODESETLOADER_BACKEND_SOURCES 15 | ${NODESETLOADER_BACKEND_OPEN62541_SOURCES}) 16 | list(APPEND NODESETLOADER_BACKEND_PUBLIC_INCLUDES 17 | ${NODESETLOADER_BACKEND_OPEN62541_PUBLIC_INCLUDES}) 18 | list(APPEND NODESETLOADER_BACKEND_PRIVATE_INCLUDES 19 | ${NODESETLOADER_BACKEND_OPEN62541_PRIVATE_INCLUDES}) 20 | list(APPEND NODESETLOADER_BACKEND_DEPS_LIBS 21 | ${NODESETLOADER_BACKEND_OPEN62541_DEPS_LIBS}) 22 | list(APPEND NODESETLOADER_BACKEND_PUBLIC_HEADERS 23 | ${NODESETLOADER_BACKEND_OPEN62541_PUBLIC_HEADERS}) 24 | list(APPEND NODESETLOADER_BACKEND_PRIVATE_HEADERS 25 | ${NODESETLOADER_BACKEND_OPEN62541_PRIVATE_HEADERS}) 26 | 27 | # export backend variables in parent scope 28 | set(NODESETLOADER_BACKEND_SOURCES 29 | ${NODESETLOADER_BACKEND_SOURCES} 30 | PARENT_SCOPE) 31 | set(NODESETLOADER_BACKEND_PUBLIC_INCLUDES 32 | ${NODESETLOADER_BACKEND_PUBLIC_INCLUDES} 33 | PARENT_SCOPE) 34 | set(NODESETLOADER_BACKEND_PRIVATE_INCLUDES 35 | ${NODESETLOADER_BACKEND_PRIVATE_INCLUDES} 36 | PARENT_SCOPE) 37 | set(NODESETLOADER_BACKEND_DEPS_LIBS 38 | ${NODESETLOADER_BACKEND_DEPS_LIBS} 39 | PARENT_SCOPE) 40 | set(NODESETLOADER_BACKEND_PUBLIC_HEADERS 41 | ${NODESETLOADER_BACKEND_PUBLIC_HEADERS} 42 | PARENT_SCOPE) 43 | set(NODESETLOADER_BACKEND_PRIVATE_HEADERS 44 | ${NODESETLOADER_BACKEND_PRIVATE_HEADERS} 45 | PARENT_SCOPE) 46 | -------------------------------------------------------------------------------- /backends/open62541/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(NODESETLOADER_BACKEND_OPEN62541_SOURCES 2 | ${CMAKE_CURRENT_SOURCE_DIR}/src/customDataType.c 3 | ${CMAKE_CURRENT_SOURCE_DIR}/src/DataTypeImporter.c 4 | ${CMAKE_CURRENT_SOURCE_DIR}/src/ServerContext.c 5 | ${CMAKE_CURRENT_SOURCE_DIR}/src/Value.c 6 | ${CMAKE_CURRENT_SOURCE_DIR}/src/RefServiceImpl.c 7 | ${CMAKE_CURRENT_SOURCE_DIR}/src/import.c 8 | PARENT_SCOPE) 9 | 10 | set(NODESETLOADER_BACKEND_OPEN62541_PUBLIC_INCLUDES 11 | $ 12 | $ 13 | PARENT_SCOPE) 14 | 15 | set(NODESETLOADER_BACKEND_OPEN62541_PRIVATE_INCLUDES 16 | ${CMAKE_CURRENT_SOURCE_DIR}/src 17 | PARENT_SCOPE) 18 | 19 | set(NODESETLOADER_BACKEND_OPEN62541_DEPS_LIBS "" PARENT_SCOPE) 20 | 21 | set(NODESETLOADER_BACKEND_OPEN62541_PUBLIC_HEADERS 22 | ${CMAKE_CURRENT_SOURCE_DIR}/include/NodesetLoader/backendOpen62541.h 23 | ${CMAKE_CURRENT_SOURCE_DIR}/include/NodesetLoader/dataTypes.h 24 | PARENT_SCOPE) 25 | 26 | set(NODESETLOADER_BACKEND_OPEN62541_PRIVATE_HEADERS 27 | ${CMAKE_CURRENT_SOURCE_DIR}/src/DataTypeImporter.h 28 | ${CMAKE_CURRENT_SOURCE_DIR}/src/conversion.h 29 | ${CMAKE_CURRENT_SOURCE_DIR}/src/customDataType.h 30 | ${CMAKE_CURRENT_SOURCE_DIR}/src/padding.h 31 | ${CMAKE_CURRENT_SOURCE_DIR}/src/ServerContext.h 32 | ${CMAKE_CURRENT_SOURCE_DIR}/src/Value.h 33 | ${CMAKE_CURRENT_SOURCE_DIR}/src/nodeset_base64.h 34 | ${CMAKE_CURRENT_SOURCE_DIR}/src/RefServiceImpl.h 35 | PARENT_SCOPE) 36 | 37 | if(${ENABLE_TESTING}) 38 | add_subdirectory(tests) 39 | endif() 40 | if(${ENABLE_EXAMPLES}) 41 | add_subdirectory(examples) 42 | endif() -------------------------------------------------------------------------------- /backends/open62541/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(server server.c) 2 | target_link_libraries(server PRIVATE NodesetLoader open62541::open62541) 3 | 4 | add_executable(dataTypeImport dataTypeImport.c) 5 | target_link_libraries(dataTypeImport PRIVATE NodesetLoader open62541::open62541) 6 | 7 | add_executable(iterate iterate.c) 8 | target_link_libraries(iterate PRIVATE NodesetLoader open62541::open62541) 9 | -------------------------------------------------------------------------------- /backends/open62541/examples/iterate.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | static volatile UA_Boolean running = true; 13 | static void stopHandler(int sig) 14 | { 15 | UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "received ctrl-c"); 16 | running = false; 17 | } 18 | 19 | void iterate(UA_Server* server, const UA_NodeId* id) 20 | { 21 | UA_BrowseDescription bd; 22 | UA_BrowseDescription_init(&bd); 23 | bd.browseDirection = UA_BROWSEDIRECTION_FORWARD; 24 | bd.includeSubtypes = true; 25 | bd.referenceTypeId = UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE); 26 | //bd.resultMask = UA_BROWSERESULTMASK_ALL; 27 | bd.resultMask = UA_BROWSERESULTMASK_BROWSENAME; 28 | bd.nodeId = *id; 29 | bd.nodeClassMask = UA_NODECLASS_REFERENCETYPE; 30 | //bd.nodeClassMask 31 | UA_BrowseResult br = UA_Server_browse(server, 100, &bd); 32 | if(br.statusCode == UA_STATUSCODE_GOOD) 33 | { 34 | for(UA_ReferenceDescription* rd = br.references; rd != br.references+br.referencesSize; rd++) 35 | { 36 | printf("found :printf %.*s\n", UA_PRINTF_STRING_DATA( rd->browseName.name ) ); 37 | 38 | /* 39 | const char* bn = "PublishedEventsType"; 40 | if (strlen(bn) == rd->browseName.name.length && 41 | !strncmp(bn, rd->browseName.name.data, 42 | strlen(bn))) 43 | { 44 | printf("found :printf %.*s\n", rd->browseName.name.length, 45 | rd->browseName.name.data); 46 | } 47 | */ 48 | 49 | iterate(server, &rd->nodeId.nodeId); 50 | } 51 | } 52 | UA_BrowseResult_clear(&br); 53 | } 54 | 55 | int main(int argc, const char *argv[]) 56 | { 57 | UA_Server *server = UA_Server_new(); 58 | UA_ServerConfig_setDefault(UA_Server_getConfig(server)); 59 | 60 | for (int cnt = 1; cnt < argc; cnt++) 61 | { 62 | if (!NodesetLoader_loadFile(server, argv[cnt], NULL)) 63 | { 64 | printf("nodeset could not be loaded, exit\n"); 65 | return 1; 66 | } 67 | } 68 | 69 | UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "start hierachicalrefs"); 70 | UA_NodeId startId = UA_NODEID_NUMERIC(0, UA_NS0ID_HIERARCHICALREFERENCES); 71 | iterate(server, &startId); 72 | UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, 73 | "start nonHierachicalRefs"); 74 | startId = UA_NODEID_NUMERIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES); 75 | iterate(server, &startId); 76 | UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, 77 | "finished"); 78 | 79 | UA_Server_run(server, &running); 80 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 81 | const UA_DataTypeArray *customTypes = 82 | UA_Server_getConfig(server)->customDataTypes; 83 | #endif 84 | UA_Server_delete(server); 85 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 86 | NodesetLoader_cleanupCustomDataTypes(customTypes); 87 | #endif 88 | } 89 | -------------------------------------------------------------------------------- /backends/open62541/examples/server.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | static volatile UA_Boolean running = true; 12 | static void stopHandler(int sig) 13 | { 14 | UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "received ctrl-c"); 15 | running = false; 16 | } 17 | 18 | int main(int argc, const char *argv[]) 19 | { 20 | UA_Server *server = UA_Server_new(); 21 | UA_ServerConfig_setDefault(UA_Server_getConfig(server)); 22 | 23 | for (int cnt = 1; cnt < argc; cnt++) 24 | { 25 | if (!NodesetLoader_loadFile(server, argv[cnt], NULL)) 26 | { 27 | printf("nodeset could not be loaded, exit\n"); 28 | return 1; 29 | } 30 | } 31 | 32 | UA_Server_run(server, &running); 33 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 34 | const UA_DataTypeArray *customTypes = 35 | UA_Server_getConfig(server)->customDataTypes; 36 | #endif 37 | UA_Server_delete(server); 38 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 39 | NodesetLoader_cleanupCustomDataTypes(customTypes); 40 | #endif 41 | } 42 | -------------------------------------------------------------------------------- /backends/open62541/include/NodesetLoader/backendOpen62541.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2019 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef __NODESETLOADER_BACKEND_OPEN62541_H__ 9 | #define __NODESETLOADER_BACKEND_OPEN62541_H__ 10 | 11 | #include 12 | #include "NodesetLoader/Extension.h" 13 | 14 | #include 15 | #include 16 | 17 | #if defined(_WIN32) 18 | #ifdef __GNUC__ 19 | #define LOADER_EXPORT __attribute__((dllexport)) 20 | #else 21 | #define LOADER_EXPORT __declspec(dllexport) 22 | #endif 23 | #else /* non win32 */ 24 | #if __GNUC__ || __clang__ 25 | #define LOADER_EXPORT __attribute__((visibility("default"))) 26 | #endif 27 | #endif 28 | #ifndef LOADER_EXPORT 29 | #define LOADER_EXPORT /* fallback to default */ 30 | #endif 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | LOADER_EXPORT bool NodesetLoader_loadFile(struct UA_Server *, const char *path, 37 | NodesetLoader_ExtensionInterface *extensionHandling); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | #endif 43 | -------------------------------------------------------------------------------- /backends/open62541/include/NodesetLoader/dataTypes.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef __NODESETLOADER_BACKEND_OPEN62541_DATATYPES_H__ 9 | #define __NODESETLOADER_BACKEND_OPEN62541_DATATYPES_H__ 10 | #include 11 | 12 | #if defined(_WIN32) 13 | #ifdef __GNUC__ 14 | #define LOADER_EXPORT __attribute__((dllexport)) 15 | #else 16 | #define LOADER_EXPORT __declspec(dllexport) 17 | #endif 18 | #else /* non win32 */ 19 | #if __GNUC__ || __clang__ 20 | #define LOADER_EXPORT __attribute__((visibility("default"))) 21 | #endif 22 | #endif 23 | #ifndef LOADER_EXPORT 24 | #define LOADER_EXPORT /* fallback to default */ 25 | #endif 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | LOADER_EXPORT const struct UA_DataType * 32 | NodesetLoader_getCustomDataType(struct UA_Server *server, 33 | const UA_NodeId *typeId); 34 | LOADER_EXPORT void 35 | NodesetLoader_cleanupCustomDataTypes(const UA_DataTypeArray *customTypes); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /backends/open62541/src/DataTypeImporter.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef DATATYPEIMPORTER_H 9 | #define DATATYPEIMPORTER_H 10 | 11 | #include 12 | 13 | #include "NodesetLoader/NodesetLoader.h" 14 | 15 | struct DataTypeImporter; 16 | typedef struct DataTypeImporter DataTypeImporter; 17 | 18 | DataTypeImporter *DataTypeImporter_new(struct UA_Server *server); 19 | void DataTypeImporter_addCustomDataType(DataTypeImporter *importer, 20 | const NL_DataTypeNode *node, const UA_NodeId parentId); 21 | // has to be called after all dependent types where added 22 | void DataTypeImporter_initMembers(DataTypeImporter *importer); 23 | void DataTypeImporter_delete(DataTypeImporter *importer); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /backends/open62541/src/RefServiceImpl.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef REFSERVICEIMPL_H 9 | #define REFSERVICEIMPL_H 10 | 11 | #include 12 | #include "NodesetLoader/ReferenceService.h" 13 | 14 | NL_ReferenceService *RefServiceImpl_new(struct UA_Server *server); 15 | void RefServiceImpl_delete(NL_ReferenceService *service); 16 | #endif 17 | -------------------------------------------------------------------------------- /backends/open62541/src/ServerContext.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2021 (c) Jan Murzyn 6 | */ 7 | 8 | #include "ServerContext.h" 9 | #include 10 | 11 | struct ServerContext 12 | { 13 | UA_Server *server; 14 | size_t namespaceCnt; 15 | UA_UInt16 *namespaceIdxMapping; 16 | }; 17 | 18 | ServerContext *ServerContext_new(UA_Server *server) 19 | { 20 | ServerContext *serverContext = (ServerContext *)calloc(1, sizeof(ServerContext)); 21 | if (serverContext) 22 | { 23 | serverContext->server = server; 24 | serverContext->namespaceCnt = 0; 25 | serverContext->namespaceIdxMapping = NULL; 26 | } 27 | 28 | return serverContext; 29 | } 30 | 31 | void ServerContext_delete(ServerContext *serverContext) 32 | { 33 | free(serverContext->namespaceIdxMapping); 34 | free(serverContext); 35 | } 36 | 37 | UA_Server *ServerContext_getServerObject(const ServerContext *serverContext) 38 | { 39 | if (!serverContext) 40 | return NULL; 41 | 42 | return serverContext->server; 43 | } 44 | 45 | // Adding server side namespace indices to an array of UA_UInt16. 46 | // Position in the array (minus 1) corresponds to the namespace index in the nodeset file. 47 | // E.g. 48 | // namespaceIdxMapping [0] = x 49 | // [1] = y 50 | // [2] = z 51 | // ... 52 | // y is a server side namespace index of the namespace that in the nodeset file has index 2. 53 | void ServerContext_addNamespaceIdx(ServerContext *serverContext, UA_UInt16 serverIdx) 54 | { 55 | if (!serverContext) 56 | return; 57 | 58 | void *newNamespaceIdxMapping = 59 | realloc(serverContext->namespaceIdxMapping, sizeof(UA_UInt16) * (serverContext->namespaceCnt + 1)); 60 | 61 | if (newNamespaceIdxMapping) 62 | { 63 | serverContext->namespaceIdxMapping = (UA_UInt16 *)newNamespaceIdxMapping; 64 | serverContext->namespaceCnt++; 65 | serverContext->namespaceIdxMapping[serverContext->namespaceCnt - 1] = serverIdx; 66 | } 67 | } 68 | 69 | // See the comment above ServerContext_addNamespaceIdx 70 | UA_UInt16 ServerContext_translateToServerIdx(const ServerContext *serverContext, UA_UInt16 nodesetIdx) 71 | { 72 | if (!serverContext) 73 | return UA_UINT16_MAX; 74 | 75 | if (nodesetIdx == 0) 76 | { 77 | // Zero is always 0, no need for translation 78 | return 0; 79 | } 80 | else if ((nodesetIdx > 0) && ((size_t)nodesetIdx <= serverContext->namespaceCnt)) 81 | { 82 | return serverContext->namespaceIdxMapping[nodesetIdx - 1]; 83 | } 84 | else 85 | { 86 | // Error case. Should it rather be handled by assert(false)? 87 | return UA_UINT16_MAX; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /backends/open62541/src/ServerContext.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2021 (c) Jan Murzyn 6 | */ 7 | 8 | #ifndef SERVERCONTEXT_H 9 | #define SERVERCONTEXT_H 10 | 11 | #include 12 | 13 | // ServerContext struct bundles the open62541's UA_Server object 14 | // and a table that maps indices used in the nodeset file to indices used in the server. 15 | struct ServerContext; 16 | typedef struct ServerContext ServerContext; 17 | 18 | // ServerContext_new allocates memory that has to released by ServerContext_delete 19 | ServerContext *ServerContext_new(struct UA_Server *server); 20 | 21 | // Releases memory allocated by ServerContext_new 22 | void ServerContext_delete(ServerContext *serverContext); 23 | 24 | // Gets pointer to the UA_Server object 25 | struct UA_Server *ServerContext_getServerObject(const ServerContext *serverContext); 26 | 27 | // Use ServerContext_addNamespaceIdx to sequentially add namespaces as they appear in the 28 | // nodeset file. 29 | void ServerContext_addNamespaceIdx(ServerContext *serverContext, UA_UInt16 serverIdx); 30 | 31 | // Translates from an index used in the nodeset file to an index used in the server 32 | UA_UInt16 ServerContext_translateToServerIdx(const ServerContext *serverContext, UA_UInt16 nodesetIdx); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /backends/open62541/src/Value.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef VALUE_H 9 | #define VALUE_H 10 | 11 | #include 12 | 13 | #include "NodesetLoader/NodesetLoader.h" 14 | 15 | struct ServerContext; 16 | 17 | struct RawData; 18 | struct RawData 19 | { 20 | void *mem; 21 | size_t offset; 22 | struct RawData* next; 23 | }; 24 | typedef struct RawData RawData; 25 | RawData *RawData_new(RawData *old); 26 | void RawData_delete(RawData *data); 27 | 28 | void Value_getData(RawData *outData, const NL_Value *value, const UA_DataType* type, const UA_DataType* customTypes, const struct ServerContext *serverContext); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /backends/open62541/src/conversion.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef CONVERSION_H 9 | #define CONVERSION_H 10 | #include 11 | 12 | #include "NodesetLoader/NodesetLoader.h" 13 | 14 | #include 15 | 16 | static inline UA_Boolean isNodeId(const char *s) 17 | { 18 | if (!s) 19 | { 20 | return UA_FALSE; 21 | } 22 | if (!strncmp(s, "ns=", 3) || !strncmp(s, "i=", 2) || !strncmp(s, "s=", 2) || 23 | !strncmp(s, "g=", 2) || !strncmp(s, "b=", 2)) 24 | { 25 | return UA_TRUE; 26 | } 27 | return UA_FALSE; 28 | } 29 | 30 | static inline UA_Boolean isValTrue(const char *s) 31 | { 32 | if (!s) 33 | { 34 | return UA_FALSE; 35 | } 36 | if (strcmp(s, "true")) 37 | { 38 | return UA_FALSE; 39 | } 40 | return UA_TRUE; 41 | } 42 | 43 | static inline UA_NodeId extractNodeId(char *s) 44 | { 45 | UA_NodeId id = UA_NODEID_NULL; 46 | if(!s) 47 | { 48 | return id; 49 | } 50 | UA_String idString; 51 | idString.length=strlen(s); 52 | idString.data = (UA_Byte*)s; 53 | UA_StatusCode result = UA_NodeId_parse(&id, idString); 54 | if(result!=UA_STATUSCODE_GOOD) 55 | { 56 | return id; 57 | } 58 | return id; 59 | } 60 | 61 | static inline UA_DateTime UA_DateTime_fromString(const char *dateString) 62 | { 63 | UA_DateTimeStruct dt; 64 | memset(&dt, 0, sizeof(UA_DateTimeStruct)); 65 | sscanf(dateString, "%hi-%hu-%huT%hu:%hu:%huZ", 66 | &dt.year, &dt.month, &dt.day, &dt.hour, &dt.min, &dt.sec); 67 | UA_DateTime dateTime = UA_DateTime_fromStruct(dt); 68 | return dateTime; 69 | } 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /backends/open62541/src/customDataType.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include "customDataType.h" 12 | 13 | const struct UA_DataType *findCustomDataType(const UA_NodeId *typeId, 14 | const UA_DataTypeArray *types) 15 | { 16 | while (types) 17 | { 18 | const UA_DataTypeArray *next = types->next; 19 | if (types->types) 20 | { 21 | for (const UA_DataType *type = types->types; 22 | type != types->types + types->typesSize; type++) 23 | { 24 | if (UA_NodeId_equal(&type->typeId, typeId)) 25 | { 26 | return type; 27 | } 28 | } 29 | } 30 | types = next; 31 | } 32 | return NULL; 33 | } 34 | 35 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 36 | static void cleanupCustomTypes(const UA_DataTypeArray *types) 37 | { 38 | while (types) 39 | { 40 | const UA_DataTypeArray *next = types->next; 41 | if (types->types) 42 | { 43 | for (const UA_DataType *type = types->types; 44 | type != types->types + types->typesSize; type++) 45 | { 46 | free((void*)(uintptr_t)type->typeName); 47 | for (UA_DataTypeMember *m = type->members; 48 | m != type->members + type->membersSize; m++) 49 | { 50 | free((void*)(uintptr_t)m->memberName); 51 | m->memberName = NULL; 52 | } 53 | free((void*)type->members); 54 | } 55 | } 56 | free((void*)(uintptr_t)types->types); 57 | free((void*)(uintptr_t)types); 58 | types = next; 59 | } 60 | } 61 | #endif 62 | 63 | const struct UA_DataType * 64 | NodesetLoader_getCustomDataType(struct UA_Server *server, 65 | const UA_NodeId *typeId) 66 | { 67 | UA_ServerConfig *config = UA_Server_getConfig(server); 68 | const UA_DataTypeArray *types = config->customDataTypes; 69 | return findCustomDataType(typeId, types); 70 | } 71 | 72 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 73 | void 74 | NodesetLoader_cleanupCustomDataTypes(const UA_DataTypeArray *customTypes) 75 | { 76 | cleanupCustomTypes(customTypes); 77 | } 78 | #endif 79 | -------------------------------------------------------------------------------- /backends/open62541/src/customDataType.h: -------------------------------------------------------------------------------- 1 | #ifndef CUSTOMDATATYPE_H 2 | #define CUSTOMDATATYPE_H 3 | const struct UA_DataType *findCustomDataType(const UA_NodeId *typeId, 4 | const UA_DataTypeArray *types); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /backends/open62541/src/padding.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef PADDING_H 9 | #define PADDING_H 10 | 11 | #include 12 | 13 | static inline UA_Byte getPadding(int alignment, int offset) 14 | { 15 | assert(alignment != 0); 16 | return (UA_Byte)((alignment - (offset % alignment)) % alignment); 17 | } 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /backends/open62541/tests/basicNodeClasses.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include "check.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "testHelper.h" 13 | 14 | UA_Server *server; 15 | char *nodesetPath = NULL; 16 | 17 | static void setup(void) 18 | { 19 | printf("path to testnodesets %s\n", nodesetPath); 20 | server = UA_Server_new(); 21 | UA_ServerConfig *config = UA_Server_getConfig(server); 22 | UA_ServerConfig_setDefault(config); 23 | } 24 | 25 | static void teardown(void) 26 | { 27 | UA_Server_run_shutdown(server); 28 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 29 | const UA_DataTypeArray *customTypes = 30 | UA_Server_getConfig(server)->customDataTypes; 31 | #endif 32 | UA_Server_delete(server); 33 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 34 | NodesetLoader_cleanupCustomDataTypes(customTypes); 35 | #endif 36 | } 37 | 38 | START_TEST(Server_ImportBasicNodeClassTest) 39 | { 40 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL)); 41 | } 42 | END_TEST 43 | 44 | static Suite *testSuite_Client(void) 45 | { 46 | Suite *s = suite_create("server nodeset import"); 47 | TCase *tc_server = tcase_create("server nodeset import"); 48 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 49 | tcase_add_test(tc_server, Server_ImportBasicNodeClassTest); 50 | suite_add_tcase(s, tc_server); 51 | return s; 52 | } 53 | 54 | int main(int argc, char *argv[]) 55 | { 56 | printf("%s", argv[0]); 57 | if (!(argc > 1)) 58 | return 1; 59 | nodesetPath = argv[1]; 60 | Suite *s = testSuite_Client(); 61 | SRunner *sr = srunner_create(s); 62 | srunner_set_fork_status(sr, CK_NOFORK); 63 | srunner_run_all(sr, CK_NORMAL); 64 | int number_failed = srunner_ntests_failed(sr); 65 | srunner_free(sr); 66 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 67 | } 68 | -------------------------------------------------------------------------------- /backends/open62541/tests/conversion.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include "../src/conversion.h" 6 | #include "check.h" 7 | #include 8 | 9 | #include "testHelper.h" 10 | 11 | static void setup(void) 12 | { 13 | 14 | } 15 | 16 | static void teardown(void) 17 | { 18 | 19 | } 20 | 21 | START_TEST(dateTime) 22 | { 23 | UA_DateTime dt = UA_DateTime_fromString("1970-01-01T00:00:00Z"); 24 | ck_assert_int_eq(dt, UA_DATETIME_UNIX_EPOCH); 25 | } 26 | END_TEST 27 | 28 | START_TEST(dateTime2022) 29 | { 30 | UA_DateTime dt = UA_DateTime_fromString("2022-02-11T19:02:01Z"); 31 | UA_DateTime fromUnix = UA_DateTime_fromUnixTime(1644606121LL); 32 | ck_assert_int_eq(dt, fromUnix); 33 | } 34 | END_TEST 35 | 36 | static Suite *testSuite_Client(void) 37 | { 38 | Suite *s = suite_create("conversion"); 39 | TCase *tc_server = tcase_create("conversion"); 40 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 41 | tcase_add_test(tc_server, dateTime); 42 | tcase_add_test(tc_server, dateTime2022); 43 | suite_add_tcase(s, tc_server); 44 | return s; 45 | } 46 | 47 | int main(int argc, char *argv[]) 48 | { 49 | Suite *s = testSuite_Client(); 50 | SRunner *sr = srunner_create(s); 51 | srunner_set_fork_status(sr, CK_NOFORK); 52 | srunner_run_all(sr, CK_NORMAL); 53 | int number_failed = srunner_ntests_failed(sr); 54 | srunner_free(sr); 55 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 56 | } 57 | -------------------------------------------------------------------------------- /backends/open62541/tests/cornerCases.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include "check.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "testHelper.h" 13 | 14 | UA_Server *server; 15 | char *nodesetPath = NULL; 16 | 17 | static void setup(void) 18 | { 19 | printf("path to testnodesets %s\n", nodesetPath); 20 | server = UA_Server_new(); 21 | UA_ServerConfig *config = UA_Server_getConfig(server); 22 | UA_ServerConfig_setDefault(config); 23 | } 24 | 25 | static void teardown(void) 26 | { 27 | UA_Server_run_shutdown(server); 28 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 29 | const UA_DataTypeArray *customTypes = 30 | UA_Server_getConfig(server)->customDataTypes; 31 | #endif 32 | UA_Server_delete(server); 33 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 34 | NodesetLoader_cleanupCustomDataTypes(customTypes); 35 | #endif 36 | } 37 | 38 | START_TEST(Server_ImportCornerCases) 39 | { 40 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL)); 41 | } 42 | END_TEST 43 | 44 | static Suite *testSuite_Client(void) 45 | { 46 | Suite *s = suite_create("server nodeset import"); 47 | TCase *tc_server = tcase_create("server nodeset import"); 48 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 49 | tcase_add_test(tc_server, Server_ImportCornerCases); 50 | suite_add_tcase(s, tc_server); 51 | return s; 52 | } 53 | 54 | int main(int argc, char *argv[]) 55 | { 56 | printf("%s", argv[0]); 57 | if (!(argc > 1)) 58 | return 1; 59 | nodesetPath = argv[1]; 60 | Suite *s = testSuite_Client(); 61 | SRunner *sr = srunner_create(s); 62 | srunner_set_fork_status(sr, CK_NOFORK); 63 | srunner_run_all(sr, CK_NORMAL); 64 | int number_failed = srunner_ntests_failed(sr); 65 | srunner_free(sr); 66 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 67 | } 68 | -------------------------------------------------------------------------------- /backends/open62541/tests/cornerCases.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | http://open62541.com/tests/CornerCasesTests/ 5 | 6 | 7 | i=11 8 | i=12 9 | i=15 10 | i=35 11 | i=37 12 | i=38 13 | i=39 14 | i=40 15 | i=45 16 | i=46 17 | i=47 18 | 19 | 20 | VariableWithoutVariableTypeDefinition 21 | 22 | i=85 23 | 24 | 25 | 26 | ObjectWithoutTypeDefinition 27 | 28 | i=85 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /backends/open62541/tests/customTypesWithValues.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "check.h" 10 | 11 | #include "testHelper.h" 12 | #include 13 | #include 14 | 15 | UA_Server *server; 16 | char *nodesetPath = NULL; 17 | 18 | static void setup(void) 19 | { 20 | printf("path to testnodesets %s\n", nodesetPath); 21 | server = UA_Server_new(); 22 | UA_ServerConfig *config = UA_Server_getConfig(server); 23 | UA_ServerConfig_setDefault(config); 24 | } 25 | 26 | static void teardown(void) 27 | { 28 | UA_Server_run_shutdown(server); 29 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 30 | const UA_DataTypeArray *customTypes = 31 | UA_Server_getConfig(server)->customDataTypes; 32 | #endif 33 | UA_Server_delete(server); 34 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 35 | NodesetLoader_cleanupCustomDataTypes(customTypes); 36 | #endif 37 | } 38 | 39 | struct Point 40 | { 41 | UA_Int32 x; 42 | UA_Int32 y; 43 | }; 44 | 45 | struct PointWithOffset 46 | { 47 | struct Point offset; 48 | UA_Int32 x; 49 | UA_Int32 y; 50 | }; 51 | 52 | START_TEST(Server_ReadPoint) 53 | { 54 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL)); 55 | 56 | UA_Variant var; 57 | UA_Variant_init(&var); 58 | // Point with offset 59 | UA_StatusCode retval = 60 | UA_Server_readValue(server, UA_NODEID_NUMERIC(2, 6019), &var); 61 | ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD); 62 | 63 | struct Point *p = (struct Point *)var.data; 64 | ck_assert(p->x == 20); 65 | ck_assert(p->y == 30); 66 | 67 | UA_Variant_clear(&var); 68 | } 69 | END_TEST 70 | 71 | START_TEST(Server_ReadPointWithOffset) 72 | { 73 | 74 | UA_Variant var; 75 | UA_Variant_init(&var); 76 | // Point with offset 77 | UA_StatusCode retval = 78 | UA_Server_readValue(server, UA_NODEID_NUMERIC(2, 6018), &var); 79 | ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD); 80 | 81 | struct PointWithOffset *p = (struct PointWithOffset *)var.data; 82 | ck_assert(p->x == 20); 83 | ck_assert(p->y == 30); 84 | ck_assert(p->offset.x == 1); 85 | ck_assert(p->offset.y == 2); 86 | 87 | UA_Variant_clear(&var); 88 | } 89 | END_TEST 90 | 91 | static Suite *testSuite_Client(void) 92 | { 93 | Suite *s = suite_create("server nodeset import"); 94 | TCase *tc_server = tcase_create("server nodeset import"); 95 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 96 | tcase_add_test(tc_server, Server_ReadPoint); 97 | tcase_add_test(tc_server, Server_ReadPointWithOffset); 98 | suite_add_tcase(s, tc_server); 99 | return s; 100 | } 101 | 102 | int main(int argc, char *argv[]) 103 | { 104 | printf("%s", argv[0]); 105 | if (!(argc > 1)) 106 | return 1; 107 | nodesetPath = argv[1]; 108 | Suite *s = testSuite_Client(); 109 | SRunner *sr = srunner_create(s); 110 | srunner_set_fork_status(sr, CK_NOFORK); 111 | srunner_run_all(sr, CK_NORMAL); 112 | int number_failed = srunner_ntests_failed(sr); 113 | srunner_free(sr); 114 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 115 | } 116 | -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/abstractdatatypemember.bsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/abstractdatatypemember.csv: -------------------------------------------------------------------------------- 1 | StructWithAbstractMember,3002,DataType 2 | StructWithAbstractMember_Encoding_DefaultBinary,5001,Object 3 | StructWithAbstractMember_Encoding_DefaultXml,5002,Object 4 | StructWithAbstractMember_Encoding_DefaultJson,5003,Object 5 | BinarySchema_TypeDictionary_BinarySchema,6001,Variable 6 | BinarySchema_TypeDictionary_BinarySchema_NamespaceUri,6002,Variable 7 | XmlSchema_TypeDictionary_XmlSchema,6003,Variable 8 | XmlSchema_TypeDictionary_XmlSchema_NamespaceUri,6004,Variable 9 | BinarySchema_TypeDictionary_BinarySchema_StructWithAbstractMember,6005,Variable 10 | XmlSchema_TypeDictionary_XmlSchema_StructWithAbstractMember,6006,Variable 11 | -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/bytestring.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "check.h" 10 | 11 | #include 12 | 13 | #include "../testHelper.h" 14 | #include 15 | #include 16 | 17 | UA_Server *server; 18 | char *nodesetPath = NULL; 19 | 20 | static void setup(void) 21 | { 22 | printf("path to testnodesets %s\n", nodesetPath); 23 | server = UA_Server_new(); 24 | UA_ServerConfig *config = UA_Server_getConfig(server); 25 | UA_ServerConfig_setDefault(config); 26 | } 27 | 28 | static void teardown(void) 29 | { 30 | UA_Server_run_shutdown(server); 31 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 32 | const UA_DataTypeArray *customTypes = 33 | UA_Server_getConfig(server)->customDataTypes; 34 | #endif 35 | UA_Server_delete(server); 36 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 37 | NodesetLoader_cleanupCustomDataTypes(customTypes); 38 | #endif 39 | } 40 | 41 | START_TEST(TestByteString) 42 | { 43 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL)); 44 | } 45 | END_TEST 46 | 47 | static Suite *testSuite_Client(void) 48 | { 49 | Suite *s = suite_create("datatype Import"); 50 | TCase *tc_server = tcase_create("server nodeset import"); 51 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 52 | tcase_add_test(tc_server, TestByteString); 53 | suite_add_tcase(s, tc_server); 54 | return s; 55 | } 56 | 57 | int main(int argc, char *argv[]) 58 | { 59 | printf("%s", argv[0]); 60 | if (!(argc > 1)) 61 | return 1; 62 | nodesetPath = argv[1]; 63 | Suite *s = testSuite_Client(); 64 | SRunner *sr = srunner_create(s); 65 | srunner_set_fork_status(sr, CK_NOFORK); 66 | srunner_run_all(sr, CK_NORMAL); 67 | int number_failed = srunner_ntests_failed(sr); 68 | srunner_free(sr); 69 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 70 | } 71 | -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/compareAbstractDataTypeMember.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "check.h" 10 | 11 | #include "../testHelper.h" 12 | #include "open62541/types_abstractdatatypemember_generated.h" 13 | #include 14 | #include 15 | 16 | UA_Server *server; 17 | char *nodesetPath = NULL; 18 | 19 | static void setup(void) 20 | { 21 | printf("path to testnodesets %s\n", nodesetPath); 22 | server = UA_Server_new(); 23 | UA_ServerConfig *config = UA_Server_getConfig(server); 24 | UA_ServerConfig_setDefault(config); 25 | } 26 | 27 | static void teardown(void) 28 | { 29 | 30 | UA_Server_run_shutdown(server); 31 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 32 | const UA_DataTypeArray *customTypes = 33 | UA_Server_getConfig(server)->customDataTypes; 34 | #endif 35 | UA_Server_delete(server); 36 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 37 | NodesetLoader_cleanupCustomDataTypes(customTypes); 38 | #endif 39 | } 40 | 41 | START_TEST(compareAbstractDataTypeMember) 42 | { 43 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL)); 44 | 45 | setNamespaceIndexOfGeneratedStruct( 46 | server, "http://yourorganisation.org/AbstractDataTypeMember/", 47 | UA_TYPES_ABSTRACTDATATYPEMEMBER, UA_TYPES_ABSTRACTDATATYPEMEMBER_COUNT); 48 | 49 | UA_ServerConfig *config = UA_Server_getConfig(server); 50 | ck_assert(config->customDataTypes); 51 | 52 | ck_assert(config->customDataTypes->typesSize == 53 | UA_TYPES_ABSTRACTDATATYPEMEMBER_COUNT); 54 | 55 | for (const UA_DataType *generatedType = UA_TYPES_ABSTRACTDATATYPEMEMBER; 56 | generatedType != UA_TYPES_ABSTRACTDATATYPEMEMBER + 57 | UA_TYPES_ABSTRACTDATATYPEMEMBER_COUNT; 58 | generatedType++) 59 | { 60 | const UA_DataType *importedType = 61 | NodesetLoader_getCustomDataType(server, &generatedType->typeId); 62 | ck_assert(importedType != NULL); 63 | typesAreMatching(generatedType, importedType, 64 | &UA_TYPES_ABSTRACTDATATYPEMEMBER[0], 65 | config->customDataTypes->types); 66 | } 67 | } 68 | END_TEST 69 | 70 | static Suite *testSuite_Client(void) 71 | { 72 | Suite *s = suite_create("datatype Import"); 73 | TCase *tc_server = tcase_create("server nodeset import"); 74 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 75 | tcase_add_test(tc_server, compareAbstractDataTypeMember); 76 | suite_add_tcase(s, tc_server); 77 | return s; 78 | } 79 | 80 | int main(int argc, char *argv[]) 81 | { 82 | printf("%s", argv[0]); 83 | if (!(argc > 1)) 84 | return 1; 85 | nodesetPath = argv[1]; 86 | Suite *s = testSuite_Client(); 87 | SRunner *sr = srunner_create(s); 88 | srunner_set_fork_status(sr, CK_NOFORK); 89 | srunner_run_all(sr, CK_NORMAL); 90 | int number_failed = srunner_ntests_failed(sr); 91 | srunner_free(sr); 92 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 93 | } -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/compareDITypes.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "check.h" 10 | 11 | #include "../testHelper.h" 12 | #include "open62541/types_di_generated.h" 13 | #include 14 | #include 15 | 16 | UA_Server *server; 17 | char *nodesetPath = NULL; 18 | 19 | static void setup(void) 20 | { 21 | printf("path to testnodesets %s\n", nodesetPath); 22 | server = UA_Server_new(); 23 | UA_ServerConfig *config = UA_Server_getConfig(server); 24 | UA_ServerConfig_setDefault(config); 25 | } 26 | 27 | static void teardown(void) 28 | { 29 | 30 | UA_Server_run_shutdown(server); 31 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 32 | const UA_DataTypeArray *customTypes = 33 | UA_Server_getConfig(server)->customDataTypes; 34 | #endif 35 | UA_Server_delete(server); 36 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 37 | NodesetLoader_cleanupCustomDataTypes(customTypes); 38 | #endif 39 | } 40 | 41 | START_TEST(compareDI) 42 | { 43 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL)); 44 | 45 | UA_ServerConfig* config = UA_Server_getConfig(server); 46 | ck_assert(config->customDataTypes); 47 | 48 | ck_assert(config->customDataTypes->typesSize == UA_TYPES_DI_COUNT); 49 | 50 | for(const UA_DataType* generatedType = UA_TYPES_DI; generatedType!= UA_TYPES_DI + UA_TYPES_DI_COUNT; generatedType++) 51 | { 52 | const UA_DataType* importedType = NodesetLoader_getCustomDataType(server, &generatedType->typeId); 53 | ck_assert(importedType!=NULL); 54 | typesAreMatching(generatedType, importedType, 55 | &UA_TYPES_DI[0], config->customDataTypes->types); 56 | } 57 | } 58 | END_TEST 59 | 60 | 61 | static Suite *testSuite_Client(void) 62 | { 63 | Suite *s = suite_create("datatype Import"); 64 | TCase *tc_server = tcase_create("server nodeset import"); 65 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 66 | tcase_add_test(tc_server, compareDI); 67 | suite_add_tcase(s, tc_server); 68 | return s; 69 | } 70 | 71 | int main(int argc, char *argv[]) 72 | { 73 | printf("%s", argv[0]); 74 | if (!(argc > 1)) 75 | return 1; 76 | nodesetPath = argv[1]; 77 | Suite *s = testSuite_Client(); 78 | SRunner *sr = srunner_create(s); 79 | srunner_set_fork_status(sr, CK_NOFORK); 80 | srunner_run_all(sr, CK_NORMAL); 81 | int number_failed = srunner_ntests_failed(sr); 82 | srunner_free(sr); 83 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 84 | } -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/compareOptionset.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "check.h" 10 | 11 | #include "../testHelper.h" 12 | #include "open62541/types_optionsetgen_generated.h" 13 | #include 14 | #include 15 | 16 | UA_Server *server; 17 | char *nodesetPath = NULL; 18 | 19 | static void setup(void) 20 | { 21 | printf("path to testnodesets %s\n", nodesetPath); 22 | server = UA_Server_new(); 23 | UA_ServerConfig *config = UA_Server_getConfig(server); 24 | UA_ServerConfig_setDefault(config); 25 | } 26 | 27 | static void teardown(void) 28 | { 29 | 30 | UA_Server_run_shutdown(server); 31 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 32 | const UA_DataTypeArray *customTypes = 33 | UA_Server_getConfig(server)->customDataTypes; 34 | #endif 35 | UA_Server_delete(server); 36 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 37 | NodesetLoader_cleanupCustomDataTypes(customTypes); 38 | #endif 39 | } 40 | 41 | START_TEST(compareOptionSet) 42 | { 43 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL)); 44 | 45 | setNamespaceIndexOfGeneratedStruct( 46 | server, "http://yourorganisation.org/optionSet/", 47 | UA_TYPES_OPTIONSETGEN, UA_TYPES_OPTIONSETGEN_COUNT); 48 | 49 | UA_ServerConfig *config = UA_Server_getConfig(server); 50 | ck_assert(config->customDataTypes); 51 | 52 | ck_assert(config->customDataTypes->typesSize == UA_TYPES_OPTIONSETGEN_COUNT); 53 | 54 | for (const UA_DataType *generatedType = UA_TYPES_OPTIONSETGEN; 55 | generatedType != 56 | UA_TYPES_OPTIONSETGEN + UA_TYPES_OPTIONSETGEN_COUNT; 57 | generatedType++) 58 | { 59 | const UA_DataType *importedType = 60 | NodesetLoader_getCustomDataType(server, &generatedType->typeId); 61 | ck_assert(importedType != NULL); 62 | typesAreMatching(generatedType, importedType, &UA_TYPES_OPTIONSETGEN[0], 63 | config->customDataTypes->types); 64 | } 65 | } 66 | END_TEST 67 | 68 | static Suite *testSuite_Client(void) 69 | { 70 | Suite *s = suite_create("datatype Import"); 71 | TCase *tc_server = tcase_create("server nodeset import"); 72 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 73 | tcase_add_test(tc_server, compareOptionSet); 74 | suite_add_tcase(s, tc_server); 75 | return s; 76 | } 77 | 78 | int main(int argc, char *argv[]) 79 | { 80 | printf("%s", argv[0]); 81 | if (!(argc > 1)) 82 | return 1; 83 | nodesetPath = argv[1]; 84 | Suite *s = testSuite_Client(); 85 | SRunner *sr = srunner_create(s); 86 | srunner_set_fork_status(sr, CK_NOFORK); 87 | srunner_run_all(sr, CK_NORMAL); 88 | int number_failed = srunner_ntests_failed(sr); 89 | srunner_free(sr); 90 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 91 | } 92 | -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/compareStructExtended.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "check.h" 10 | 11 | #include "../testHelper.h" 12 | #include "open62541/types_structExtended_generated.h" 13 | #include 14 | #include 15 | 16 | UA_Server *server; 17 | char *nodesetPath = NULL; 18 | 19 | static void setup(void) 20 | { 21 | printf("path to testnodesets %s\n", nodesetPath); 22 | server = UA_Server_new(); 23 | UA_ServerConfig *config = UA_Server_getConfig(server); 24 | UA_ServerConfig_setDefault(config); 25 | } 26 | 27 | static void teardown(void) 28 | { 29 | 30 | UA_Server_run_shutdown(server); 31 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 32 | const UA_DataTypeArray *customTypes = 33 | UA_Server_getConfig(server)->customDataTypes; 34 | #endif 35 | UA_Server_delete(server); 36 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 37 | NodesetLoader_cleanupCustomDataTypes(customTypes); 38 | #endif 39 | } 40 | 41 | START_TEST(compareDI) 42 | { 43 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL)); 44 | 45 | setNamespaceIndexOfGeneratedStruct(server, 46 | "http://yourorganisation.org/struct/", 47 | UA_TYPES_STRUCTEXTENDED, UA_TYPES_STRUCTEXTENDED_COUNT); 48 | 49 | UA_ServerConfig* config = UA_Server_getConfig(server); 50 | ck_assert(config->customDataTypes); 51 | 52 | ck_assert(config->customDataTypes->typesSize == UA_TYPES_STRUCTEXTENDED_COUNT); 53 | 54 | for (const UA_DataType *generatedType = UA_TYPES_STRUCTEXTENDED; 55 | generatedType != UA_TYPES_STRUCTEXTENDED + 56 | UA_TYPES_STRUCTEXTENDED_COUNT; 57 | generatedType++) 58 | { 59 | const UA_DataType* importedType = NodesetLoader_getCustomDataType(server, &generatedType->typeId); 60 | ck_assert(importedType!=NULL); 61 | typesAreMatching( 62 | generatedType, importedType, 63 | &UA_TYPES_STRUCTEXTENDED[0], config->customDataTypes->types); 64 | } 65 | } 66 | END_TEST 67 | 68 | 69 | static Suite *testSuite_Client(void) 70 | { 71 | Suite *s = suite_create("datatype Import"); 72 | TCase *tc_server = tcase_create("server nodeset import"); 73 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 74 | tcase_add_test(tc_server, compareDI); 75 | suite_add_tcase(s, tc_server); 76 | return s; 77 | } 78 | 79 | int main(int argc, char *argv[]) 80 | { 81 | printf("%s", argv[0]); 82 | if (!(argc > 1)) 83 | return 1; 84 | nodesetPath = argv[1]; 85 | Suite *s = testSuite_Client(); 86 | SRunner *sr = srunner_create(s); 87 | srunner_set_fork_status(sr, CK_NOFORK); 88 | srunner_run_all(sr, CK_NORMAL); 89 | int number_failed = srunner_ntests_failed(sr); 90 | srunner_free(sr); 91 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 92 | } -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/compareStructSpecialized.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "check.h" 10 | 11 | #include "../testHelper.h" 12 | #include "open62541/types_specializedStruct_generated.h" 13 | #include "open62541/types_struct_generated.h" 14 | #include 15 | #include 16 | 17 | UA_Server *server; 18 | char *nodeset1 = NULL; 19 | char *nodeset2 = NULL; 20 | 21 | static void setup(void) 22 | { 23 | server = UA_Server_new(); 24 | UA_ServerConfig *config = UA_Server_getConfig(server); 25 | UA_ServerConfig_setDefault(config); 26 | } 27 | 28 | static void teardown(void) 29 | { 30 | 31 | UA_Server_run_shutdown(server); 32 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 33 | const UA_DataTypeArray *customTypes = 34 | UA_Server_getConfig(server)->customDataTypes; 35 | #endif 36 | UA_Server_delete(server); 37 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 38 | NodesetLoader_cleanupCustomDataTypes(customTypes); 39 | #endif 40 | } 41 | 42 | START_TEST(compareSpecializedStruct) 43 | { 44 | printf("%s \n", nodeset1); 45 | printf("%s \n", nodeset2); 46 | ck_assert(NodesetLoader_loadFile(server, nodeset1, NULL)); 47 | ck_assert(NodesetLoader_loadFile(server, nodeset2, NULL)); 48 | 49 | setNamespaceIndexOfGeneratedStruct(server, 50 | "http://yourorganisation.org/struct/", 51 | UA_TYPES_STRUCT, UA_TYPES_STRUCT_COUNT); 52 | 53 | setNamespaceIndexOfGeneratedStruct( 54 | server, "http://yourorganisation.org/specializedStruct/", 55 | UA_TYPES_SPECIALIZEDSTRUCT, UA_TYPES_SPECIALIZEDSTRUCT_COUNT); 56 | 57 | UA_ServerConfig *config = UA_Server_getConfig(server); 58 | ck_assert(config->customDataTypes); 59 | 60 | ck_assert(config->customDataTypes->typesSize == 61 | UA_TYPES_STRUCT_COUNT + UA_TYPES_SPECIALIZEDSTRUCT_COUNT); 62 | 63 | for (const UA_DataType *generatedType = UA_TYPES_SPECIALIZEDSTRUCT; 64 | generatedType != 65 | UA_TYPES_SPECIALIZEDSTRUCT + UA_TYPES_SPECIALIZEDSTRUCT_COUNT; 66 | generatedType++) 67 | { 68 | const UA_DataType *importedType = 69 | NodesetLoader_getCustomDataType(server, &generatedType->typeId); 70 | ck_assert(importedType != NULL); 71 | typesAreMatching(generatedType, importedType, 72 | &UA_TYPES_SPECIALIZEDSTRUCT[0], 73 | config->customDataTypes->types); 74 | } 75 | } 76 | END_TEST 77 | 78 | static Suite *testSuite_Client(void) 79 | { 80 | Suite *s = suite_create("datatype Import"); 81 | TCase *tc_server = tcase_create("server nodeset import"); 82 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 83 | tcase_add_test(tc_server, compareSpecializedStruct); 84 | suite_add_tcase(s, tc_server); 85 | return s; 86 | } 87 | 88 | int main(int argc, char *argv[]) 89 | { 90 | printf("%s", argv[0]); 91 | if (!(argc > 1)) 92 | return 1; 93 | nodeset1 = argv[1]; 94 | nodeset2 = argv[2]; 95 | Suite *s = testSuite_Client(); 96 | SRunner *sr = srunner_create(s); 97 | srunner_set_fork_status(sr, CK_NOFORK); 98 | srunner_run_all(sr, CK_NORMAL); 99 | int number_failed = srunner_ntests_failed(sr); 100 | srunner_free(sr); 101 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 102 | } -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/compareStructTypes.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "check.h" 10 | 11 | #include "../testHelper.h" 12 | #include "open62541/types_struct_generated.h" 13 | #include 14 | #include 15 | 16 | UA_Server *server; 17 | char *nodesetPath = NULL; 18 | 19 | static void setup(void) 20 | { 21 | printf("path to testnodesets %s\n", nodesetPath); 22 | server = UA_Server_new(); 23 | UA_ServerConfig *config = UA_Server_getConfig(server); 24 | UA_ServerConfig_setDefault(config); 25 | } 26 | 27 | static void teardown(void) 28 | { 29 | 30 | UA_Server_run_shutdown(server); 31 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 32 | const UA_DataTypeArray *customTypes = 33 | UA_Server_getConfig(server)->customDataTypes; 34 | #endif 35 | UA_Server_delete(server); 36 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 37 | NodesetLoader_cleanupCustomDataTypes(customTypes); 38 | #endif 39 | } 40 | 41 | START_TEST(compareDI) 42 | { 43 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL)); 44 | 45 | setNamespaceIndexOfGeneratedStruct(server, 46 | "http://yourorganisation.org/struct/", 47 | UA_TYPES_STRUCT, UA_TYPES_STRUCT_COUNT); 48 | 49 | UA_ServerConfig *config = UA_Server_getConfig(server); 50 | ck_assert(config->customDataTypes); 51 | 52 | ck_assert(config->customDataTypes->typesSize == UA_TYPES_STRUCT_COUNT); 53 | 54 | for (const UA_DataType *generatedType = UA_TYPES_STRUCT; 55 | generatedType != UA_TYPES_STRUCT + UA_TYPES_STRUCT_COUNT; 56 | generatedType++) 57 | { 58 | const UA_DataType *importedType = 59 | NodesetLoader_getCustomDataType(server, &generatedType->typeId); 60 | ck_assert(importedType != NULL); 61 | typesAreMatching(generatedType, importedType, &UA_TYPES_STRUCT[0], 62 | config->customDataTypes->types); 63 | } 64 | } 65 | END_TEST 66 | 67 | static Suite *testSuite_Client(void) 68 | { 69 | Suite *s = suite_create("datatype Import"); 70 | TCase *tc_server = tcase_create("server nodeset import"); 71 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 72 | tcase_add_test(tc_server, compareDI); 73 | suite_add_tcase(s, tc_server); 74 | return s; 75 | } 76 | 77 | int main(int argc, char *argv[]) 78 | { 79 | printf("%s", argv[0]); 80 | if (!(argc > 1)) 81 | return 1; 82 | nodesetPath = argv[1]; 83 | Suite *s = testSuite_Client(); 84 | SRunner *sr = srunner_create(s); 85 | srunner_set_fork_status(sr, CK_NOFORK); 86 | srunner_run_all(sr, CK_NORMAL); 87 | int number_failed = srunner_ntests_failed(sr); 88 | srunner_free(sr); 89 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 90 | } -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/compareUnion.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "check.h" 10 | 11 | #include "../testHelper.h" 12 | #include "open62541/types_union_generated.h" 13 | #include 14 | #include 15 | 16 | UA_Server *server; 17 | char *nodesetPath = NULL; 18 | 19 | static void setup(void) 20 | { 21 | printf("path to testnodesets %s\n", nodesetPath); 22 | server = UA_Server_new(); 23 | UA_ServerConfig *config = UA_Server_getConfig(server); 24 | UA_ServerConfig_setDefault(config); 25 | } 26 | 27 | static void teardown(void) 28 | { 29 | UA_Server_run_shutdown(server); 30 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 31 | const UA_DataTypeArray *customTypes = 32 | UA_Server_getConfig(server)->customDataTypes; 33 | #endif 34 | UA_Server_delete(server); 35 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 36 | NodesetLoader_cleanupCustomDataTypes(customTypes); 37 | #endif 38 | } 39 | 40 | START_TEST(compareUnion) 41 | { 42 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL)); 43 | 44 | setNamespaceIndexOfGeneratedStruct( 45 | server, "http://yourorganisation.org/union/", 46 | UA_TYPES_UNION, UA_TYPES_UNION_COUNT); 47 | 48 | UA_ServerConfig *config = UA_Server_getConfig(server); 49 | ck_assert(config->customDataTypes); 50 | 51 | ck_assert(config->customDataTypes->typesSize == UA_TYPES_UNION_COUNT); 52 | 53 | for (const UA_DataType *generatedType = UA_TYPES_UNION; 54 | generatedType != UA_TYPES_UNION + UA_TYPES_UNION_COUNT; 55 | generatedType++) 56 | { 57 | const UA_DataType *importedType = 58 | NodesetLoader_getCustomDataType(server, &generatedType->typeId); 59 | ck_assert(importedType != NULL); 60 | typesAreMatching(generatedType, importedType, &UA_TYPES_UNION[0], 61 | config->customDataTypes->types); 62 | } 63 | } 64 | END_TEST 65 | 66 | static Suite *testSuite_Client(void) 67 | { 68 | Suite *s = suite_create("datatype Import"); 69 | TCase *tc_server = tcase_create("server nodeset import"); 70 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 71 | tcase_add_test(tc_server, compareUnion); 72 | suite_add_tcase(s, tc_server); 73 | return s; 74 | } 75 | 76 | int main(int argc, char *argv[]) 77 | { 78 | printf("%s", argv[0]); 79 | if (!(argc > 1)) 80 | return 1; 81 | nodesetPath = argv[1]; 82 | Suite *s = testSuite_Client(); 83 | SRunner *sr = srunner_create(s); 84 | srunner_set_fork_status(sr, CK_NOFORK); 85 | srunner_run_all(sr, CK_NORMAL); 86 | int number_failed = srunner_ntests_failed(sr); 87 | srunner_free(sr); 88 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 89 | } 90 | -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/enum.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "check.h" 10 | 11 | #include "../testHelper.h" 12 | #include 13 | #include 14 | 15 | UA_Server *server; 16 | char *nodesetPath = NULL; 17 | 18 | static void setup(void) 19 | { 20 | printf("path to testnodesets %s\n", nodesetPath); 21 | server = UA_Server_new(); 22 | UA_ServerConfig *config = UA_Server_getConfig(server); 23 | UA_ServerConfig_setDefault(config); 24 | } 25 | 26 | static void teardown(void) 27 | { 28 | 29 | UA_Server_run_shutdown(server); 30 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 31 | const UA_DataTypeArray *customTypes = 32 | UA_Server_getConfig(server)->customDataTypes; 33 | #endif 34 | UA_Server_delete(server); 35 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 36 | NodesetLoader_cleanupCustomDataTypes(customTypes); 37 | #endif 38 | } 39 | 40 | START_TEST(OperatingModeEnum) 41 | { 42 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL)); 43 | UA_NodeId typeId = UA_NODEID_NUMERIC(2, 3002); 44 | const UA_DataType *type = NodesetLoader_getCustomDataType(server, &typeId); 45 | ck_assert(type); 46 | 47 | ck_assert(type->typeKind == UA_DATATYPEKIND_ENUM); 48 | } 49 | END_TEST 50 | 51 | static Suite *testSuite_Client(void) 52 | { 53 | Suite *s = suite_create("datatype Import"); 54 | TCase *tc_server = tcase_create("server nodeset import"); 55 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 56 | tcase_add_test(tc_server, OperatingModeEnum); 57 | suite_add_tcase(s, tc_server); 58 | return s; 59 | } 60 | 61 | int main(int argc, char *argv[]) 62 | { 63 | printf("%s", argv[0]); 64 | if (!(argc > 1)) 65 | return 1; 66 | nodesetPath = argv[1]; 67 | Suite *s = testSuite_Client(); 68 | SRunner *sr = srunner_create(s); 69 | srunner_set_fork_status(sr, CK_NOFORK); 70 | srunner_run_all(sr, CK_NORMAL); 71 | int number_failed = srunner_ntests_failed(sr); 72 | srunner_free(sr); 73 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 74 | } 75 | -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/optionalStruct.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "check.h" 10 | 11 | #include "../testHelper.h" 12 | #include "open62541/types_optionalstruct_generated.h" 13 | #include 14 | #include 15 | 16 | UA_Server *server; 17 | char *nodesetPath = NULL; 18 | 19 | static void setup(void) 20 | { 21 | printf("path to testnodesets %s\n", nodesetPath); 22 | server = UA_Server_new(); 23 | UA_ServerConfig *config = UA_Server_getConfig(server); 24 | UA_ServerConfig_setDefault(config); 25 | } 26 | 27 | static void teardown(void) 28 | { 29 | 30 | UA_Server_run_shutdown(server); 31 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 32 | const UA_DataTypeArray *customTypes = 33 | UA_Server_getConfig(server)->customDataTypes; 34 | #endif 35 | UA_Server_delete(server); 36 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 37 | NodesetLoader_cleanupCustomDataTypes(customTypes); 38 | #endif 39 | } 40 | 41 | START_TEST(compareDI) 42 | { 43 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL)); 44 | 45 | setNamespaceIndexOfGeneratedStruct( 46 | server, "http://yourorganisation.org/optionalStruct/", 47 | UA_TYPES_OPTIONALSTRUCT, UA_TYPES_OPTIONALSTRUCT_COUNT); 48 | 49 | UA_ServerConfig *config = UA_Server_getConfig(server); 50 | ck_assert(config->customDataTypes); 51 | 52 | ck_assert(config->customDataTypes->typesSize == 53 | UA_TYPES_OPTIONALSTRUCT_COUNT); 54 | 55 | for (const UA_DataType *generatedType = UA_TYPES_OPTIONALSTRUCT; 56 | generatedType != 57 | UA_TYPES_OPTIONALSTRUCT + UA_TYPES_OPTIONALSTRUCT_COUNT; 58 | generatedType++) 59 | { 60 | const UA_DataType *importedType = 61 | NodesetLoader_getCustomDataType(server, &generatedType->typeId); 62 | ck_assert(importedType != NULL); 63 | typesAreMatching(generatedType, importedType, 64 | &UA_TYPES_OPTIONALSTRUCT[0], 65 | config->customDataTypes->types); 66 | } 67 | } 68 | END_TEST 69 | 70 | static Suite *testSuite_Client(void) 71 | { 72 | Suite *s = suite_create("datatype Import"); 73 | TCase *tc_server = tcase_create("server nodeset import"); 74 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 75 | tcase_add_test(tc_server, compareDI); 76 | suite_add_tcase(s, tc_server); 77 | return s; 78 | } 79 | 80 | int main(int argc, char *argv[]) 81 | { 82 | printf("%s", argv[0]); 83 | if (!(argc > 1)) 84 | return 1; 85 | nodesetPath = argv[1]; 86 | Suite *s = testSuite_Client(); 87 | SRunner *sr = srunner_create(s); 88 | srunner_set_fork_status(sr, CK_NOFORK); 89 | srunner_run_all(sr, CK_NORMAL); 90 | int number_failed = srunner_ntests_failed(sr); 91 | srunner_free(sr); 92 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 93 | } -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/optionalstruct.bsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/optionalstruct.csv: -------------------------------------------------------------------------------- 1 | StructWithOptField,3002,DataType 2 | StructWithOptField_Encoding_DefaultBinary,5001,Object 3 | StructWithOptField_Encoding_DefaultXml,5002,Object 4 | StructWithOptField_Encoding_DefaultJson,5003,Object 5 | Server_Namespaces_http___yourorganisation_org_optionalStruct_,5004,Object 6 | BinarySchema_TypeDictionary_BinarySchema,6001,Variable 7 | BinarySchema_TypeDictionary_BinarySchema_NamespaceUri,6002,Variable 8 | XmlSchema_TypeDictionary_XmlSchema,6003,Variable 9 | XmlSchema_TypeDictionary_XmlSchema_NamespaceUri,6004,Variable 10 | BinarySchema_TypeDictionary_BinarySchema_StructWithOptField,6005,Variable 11 | XmlSchema_TypeDictionary_XmlSchema_StructWithOptField,6006,Variable 12 | Server_Namespaces_http___yourorganisation_org_optionalStruct__IsNamespaceSubset,6007,Variable 13 | Server_Namespaces_http___yourorganisation_org_optionalStruct__NamespacePublicationDate,6008,Variable 14 | Server_Namespaces_http___yourorganisation_org_optionalStruct__NamespaceUri,6009,Variable 15 | Server_Namespaces_http___yourorganisation_org_optionalStruct__NamespaceVersion,6010,Variable 16 | Server_Namespaces_http___yourorganisation_org_optionalStruct__StaticNodeIdTypes,6011,Variable 17 | Server_Namespaces_http___yourorganisation_org_optionalStruct__StaticNumericNodeIdRange,6012,Variable 18 | Server_Namespaces_http___yourorganisation_org_optionalStruct__StaticStringNodeIdPattern,6013,Variable 19 | -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/optionset.bsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/optionset.csv: -------------------------------------------------------------------------------- 1 | DriveState,3002,DataType 2 | DriveState_Encoding_DefaultBinary,5001,Object 3 | DriveState_Encoding_DefaultXml,5002,Object 4 | DriveState_Encoding_DefaultJson,5003,Object 5 | Server_Namespaces_http___yourorganisation_org_optionSet_,5004,Object 6 | BinarySchema_TypeDictionary_BinarySchema,6001,Variable 7 | BinarySchema_TypeDictionary_BinarySchema_NamespaceUri,6002,Variable 8 | XmlSchema_TypeDictionary_XmlSchema,6003,Variable 9 | XmlSchema_TypeDictionary_XmlSchema_NamespaceUri,6004,Variable 10 | DriveState_OptionSetValues,6005,Variable 11 | BinarySchema_TypeDictionary_BinarySchema_DriveState,6006,Variable 12 | Server_Namespaces_http___yourorganisation_org_optionSet__IsNamespaceSubset,6007,Variable 13 | Server_Namespaces_http___yourorganisation_org_optionSet__NamespacePublicationDate,6008,Variable 14 | Server_Namespaces_http___yourorganisation_org_optionSet__NamespaceUri,6009,Variable 15 | Server_Namespaces_http___yourorganisation_org_optionSet__NamespaceVersion,6010,Variable 16 | Server_Namespaces_http___yourorganisation_org_optionSet__StaticNodeIdTypes,6011,Variable 17 | Server_Namespaces_http___yourorganisation_org_optionSet__StaticNumericNodeIdRange,6012,Variable 18 | Server_Namespaces_http___yourorganisation_org_optionSet__StaticStringNodeIdPattern,6013,Variable 19 | XmlSchema_TypeDictionary_XmlSchema_DriveState,6016,Variable 20 | -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/padding.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include "check.h" 6 | 7 | #include "../testHelper.h" 8 | #include "../../src/padding.h" 9 | 10 | 11 | static void setup(void) 12 | { 13 | 14 | } 15 | 16 | static void teardown(void) 17 | { 18 | 19 | } 20 | 21 | START_TEST(noOffset) 22 | { 23 | ck_assert(getPadding(4, 0)==0); 24 | ck_assert(getPadding(8, 0)==0); 25 | ck_assert(getPadding(1, 0)==0); 26 | ck_assert(getPadding(2, 0) == 0); 27 | } 28 | END_TEST 29 | 30 | START_TEST(OneByteOffset) 31 | { 32 | ck_assert(getPadding(4, 1) == 3); 33 | ck_assert(getPadding(8, 1) == 7); 34 | ck_assert(getPadding(1, 1) == 0); 35 | ck_assert(getPadding(2, 1) == 1); 36 | } 37 | END_TEST 38 | 39 | START_TEST(TwoByteOffset) 40 | { 41 | ck_assert(getPadding(4, 2) == 2); 42 | ck_assert(getPadding(8, 2) == 6); 43 | ck_assert(getPadding(1, 2) == 0); 44 | ck_assert(getPadding(2, 2) == 0); 45 | } 46 | END_TEST 47 | 48 | START_TEST(FourByteOffset) 49 | { 50 | ck_assert(getPadding(4, 4) == 0); 51 | ck_assert(getPadding(8, 4) == 4); 52 | ck_assert(getPadding(1, 4) == 0); 53 | ck_assert(getPadding(2, 4) == 0); 54 | } 55 | END_TEST 56 | 57 | static Suite *testSuite_Client(void) 58 | { 59 | Suite *s = suite_create("padding Test"); 60 | TCase *tc_server = tcase_create("padding Test"); 61 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 62 | tcase_add_test(tc_server, noOffset); 63 | tcase_add_test(tc_server, OneByteOffset); 64 | tcase_add_test(tc_server, TwoByteOffset); 65 | tcase_add_test(tc_server, FourByteOffset); 66 | suite_add_tcase(s, tc_server); 67 | return s; 68 | } 69 | 70 | int main(int argc, char *argv[]) 71 | { 72 | Suite *s = testSuite_Client(); 73 | SRunner *sr = srunner_create(s); 74 | srunner_set_fork_status(sr, CK_NOFORK); 75 | srunner_run_all(sr, CK_NORMAL); 76 | int number_failed = srunner_ntests_failed(sr); 77 | srunner_free(sr); 78 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 79 | } 80 | -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/specializedstruct.bsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/specializedstruct.csv: -------------------------------------------------------------------------------- 1 | PointWithOffset,3002,DataType 2 | PointWithOffset_Encoding_DefaultBinary,5001,Object 3 | PointWithOffset_Encoding_DefaultXml,5002,Object 4 | PointWithOffset_Encoding_DefaultJson,5003,Object 5 | BinarySchema_TypeDictionary_BinarySchema,6001,Variable 6 | BinarySchema_TypeDictionary_BinarySchema_NamespaceUri,6002,Variable 7 | XmlSchema_TypeDictionary_XmlSchema,6003,Variable 8 | XmlSchema_TypeDictionary_XmlSchema_NamespaceUri,6004,Variable 9 | BinarySchema_TypeDictionary_BinarySchema_PointWithOffset,6005,Variable 10 | XmlSchema_TypeDictionary_XmlSchema_PointWithOffset,6006,Variable 11 | -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/struct.bsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/struct.csv: -------------------------------------------------------------------------------- 1 | Point,3002,DataType 2 | VectorOfPoints,3003,DataType 3 | Point_Encoding_DefaultBinary,5001,Object 4 | Point_Encoding_DefaultXml,5002,Object 5 | Point_Encoding_DefaultJson,5003,Object 6 | VectorOfPoints_Encoding_DefaultBinary,5004,Object 7 | VectorOfPoints_Encoding_DefaultXml,5005,Object 8 | VectorOfPoints_Encoding_DefaultJson,5006,Object 9 | BinarySchema_TypeDictionary_BinarySchema,6001,Variable 10 | BinarySchema_TypeDictionary_BinarySchema_NamespaceUri,6002,Variable 11 | XmlSchema_TypeDictionary_XmlSchema,6003,Variable 12 | XmlSchema_TypeDictionary_XmlSchema_NamespaceUri,6004,Variable 13 | BinarySchema_TypeDictionary_BinarySchema_Point,6005,Variable 14 | XmlSchema_TypeDictionary_XmlSchema_Point,6006,Variable 15 | BinarySchema_TypeDictionary_BinarySchema_VectorOfPoints,6007,Variable 16 | XmlSchema_TypeDictionary_XmlSchema_VectorOfPoints,6008,Variable 17 | -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/structExtended.bsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/structExtended.csv: -------------------------------------------------------------------------------- 1 | Point,3002,DataType 2 | VectorOfPoints,3003,DataType 3 | SpecialVectorOfPoints,3004,DataType 4 | Point_Encoding_DefaultBinary,5001,Object 5 | Point_Encoding_DefaultXml,5002,Object 6 | Point_Encoding_DefaultJson,5003,Object 7 | VectorOfPoints_Encoding_DefaultBinary,5004,Object 8 | VectorOfPoints_Encoding_DefaultXml,5005,Object 9 | VectorOfPoints_Encoding_DefaultJson,5006,Object 10 | SpecialVectorOfPoints_Encoding_DefaultBinary,5007,Object 11 | SpecialVectorOfPoints_Encoding_DefaultXml,5008,Object 12 | SpecialVectorOfPoints_Encoding_DefaultJson,5009,Object 13 | BinarySchema_TypeDictionary_BinarySchema,6001,Variable 14 | BinarySchema_TypeDictionary_BinarySchema_NamespaceUri,6002,Variable 15 | XmlSchema_TypeDictionary_XmlSchema,6003,Variable 16 | XmlSchema_TypeDictionary_XmlSchema_NamespaceUri,6004,Variable 17 | BinarySchema_TypeDictionary_BinarySchema_Point,6005,Variable 18 | XmlSchema_TypeDictionary_XmlSchema_Point,6006,Variable 19 | BinarySchema_TypeDictionary_BinarySchema_VectorOfPoints,6007,Variable 20 | XmlSchema_TypeDictionary_XmlSchema_VectorOfPoints,6008,Variable 21 | BinarySchema_TypeDictionary_BinarySchema_SpecialVectorOfPoints,6009,Variable 22 | XmlSchema_TypeDictionary_XmlSchema_SpecialVectorOfPoints,6010,Variable 23 | -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/subDataType.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "check.h" 10 | 11 | #include "../testHelper.h" 12 | #include 13 | #include 14 | 15 | UA_Server *server; 16 | char *nodesetPath = NULL; 17 | 18 | static void setup(void) 19 | { 20 | printf("path to testnodesets %s\n", nodesetPath); 21 | server = UA_Server_new(); 22 | UA_ServerConfig *config = UA_Server_getConfig(server); 23 | UA_ServerConfig_setDefault(config); 24 | } 25 | 26 | static void teardown(void) 27 | { 28 | UA_Server_run_shutdown(server); 29 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 30 | const UA_DataTypeArray *customTypes = 31 | UA_Server_getConfig(server)->customDataTypes; 32 | #endif 33 | UA_Server_delete(server); 34 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 35 | NodesetLoader_cleanupCustomDataTypes(customTypes); 36 | #endif 37 | } 38 | 39 | START_TEST(SubTypeOfInt32) 40 | { 41 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL)); 42 | UA_NodeId typeId = UA_NODEID_NUMERIC(2, 3002); 43 | const UA_DataType *type = NodesetLoader_getCustomDataType(server, &typeId); 44 | ck_assert(type); 45 | ck_assert(type->typeKind == UA_DATATYPEKIND_INT32); 46 | UA_Variant var; 47 | UA_StatusCode status = UA_Server_readValue(server, UA_NODEID_NUMERIC(2, 6002), &var); 48 | ck_assert(UA_STATUSCODE_GOOD==status); 49 | ck_assert(*(UA_Int32*)var.data==12); 50 | UA_Variant_clear(&var); 51 | } 52 | END_TEST 53 | 54 | static Suite *testSuite_Client(void) 55 | { 56 | Suite *s = suite_create("datatype Import"); 57 | TCase *tc_server = tcase_create("server nodeset import"); 58 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 59 | tcase_add_test(tc_server, SubTypeOfInt32); 60 | suite_add_tcase(s, tc_server); 61 | return s; 62 | } 63 | 64 | int main(int argc, char *argv[]) 65 | { 66 | printf("%s", argv[0]); 67 | if (!(argc > 1)) 68 | return 1; 69 | nodesetPath = argv[1]; 70 | Suite *s = testSuite_Client(); 71 | SRunner *sr = srunner_create(s); 72 | srunner_set_fork_status(sr, CK_NOFORK); 73 | srunner_run_all(sr, CK_NORMAL); 74 | int number_failed = srunner_ntests_failed(sr); 75 | srunner_free(sr); 76 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 77 | } 78 | -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/union.bsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /backends/open62541/tests/dataTypeImport/union.csv: -------------------------------------------------------------------------------- 1 | MyUnion,3003,DataType 2 | UnionWithArrayField,3004,DataType 3 | UnionWithArrayField_Encoding_DefaultBinary,5001,Object 4 | UnionWithArrayField_Encoding_DefaultXml,5002,Object 5 | UnionWithArrayField_Encoding_DefaultJson,5003,Object 6 | Server_Namespaces_http___yourorganisation_org_union_,5004,Object 7 | MyUnion_Encoding_DefaultBinary,5005,Object 8 | MyUnion_Encoding_DefaultXml,5006,Object 9 | MyUnion_Encoding_DefaultJson,5007,Object 10 | TypeDictionary_BinarySchema,6001,Variable 11 | TypeDictionary_BinarySchema_NamespaceUri,6002,Variable 12 | TypeDictionary_XmlSchema,6003,Variable 13 | TypeDictionary_XmlSchema_NamespaceUri,6004,Variable 14 | TypeDictionary_BinarySchema_UnionWithArrayField,6005,Variable 15 | TypeDictionary_XmlSchema_UnionWithArrayField,6006,Variable 16 | Server_Namespaces_http___yourorganisation_org_union__IsNamespaceSubset,6007,Variable 17 | Server_Namespaces_http___yourorganisation_org_union__NamespacePublicationDate,6008,Variable 18 | Server_Namespaces_http___yourorganisation_org_union__NamespaceUri,6009,Variable 19 | Server_Namespaces_http___yourorganisation_org_union__NamespaceVersion,6010,Variable 20 | Server_Namespaces_http___yourorganisation_org_union__StaticNodeIdTypes,6011,Variable 21 | Server_Namespaces_http___yourorganisation_org_union__StaticNumericNodeIdRange,6012,Variable 22 | Server_Namespaces_http___yourorganisation_org_union__StaticStringNodeIdPattern,6013,Variable 23 | TypeDictionary_BinarySchema_MyUnion,6014,Variable 24 | TypeDictionary_XmlSchema_MyUnion,6015,Variable 25 | -------------------------------------------------------------------------------- /backends/open62541/tests/extension.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | http://yourorganisation.org/extension/ 5 | 6 | 7 | i=6 8 | i=35 9 | i=40 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | VarWithExtension 18 | 19 | i=63 20 | i=85 21 | 22 | 23 | 24 |
demo.test
25 |
26 |
27 |
28 |
29 | -------------------------------------------------------------------------------- /backends/open62541/tests/import.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "check.h" 10 | 11 | #include "testHelper.h" 12 | #include 13 | #include 14 | 15 | UA_Server *server; 16 | char* nodesetPath=NULL; 17 | 18 | static void setup(void) { 19 | printf("path to testnodesets %s\n", nodesetPath); 20 | server = UA_Server_new(); 21 | UA_ServerConfig *config = UA_Server_getConfig(server); 22 | UA_ServerConfig_setDefault(config); 23 | } 24 | 25 | static void teardown(void) { 26 | UA_Server_run_shutdown(server); 27 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 28 | const UA_DataTypeArray *customTypes = 29 | UA_Server_getConfig(server)->customDataTypes; 30 | #endif 31 | UA_Server_delete(server); 32 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 33 | NodesetLoader_cleanupCustomDataTypes(customTypes); 34 | #endif 35 | } 36 | 37 | START_TEST(Server_ImportNodeset) { 38 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, 39 | NULL)); 40 | } 41 | END_TEST 42 | 43 | 44 | START_TEST(Server_ImportNoFile) { 45 | ck_assert( 46 | !NodesetLoader_loadFile(server, "notExisting.xml", NULL)); 47 | } 48 | END_TEST 49 | 50 | 51 | START_TEST(Server_EmptyHandler) { 52 | ck_assert(!NodesetLoader_loadFile(NULL, NULL, NULL)); 53 | } 54 | END_TEST 55 | 56 | static Suite *testSuite_Client(void) { 57 | Suite *s = suite_create("server nodeset import"); 58 | TCase *tc_server = tcase_create("server nodeset import"); 59 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 60 | tcase_add_test(tc_server, Server_ImportNodeset); 61 | tcase_add_test(tc_server, Server_ImportNoFile); 62 | tcase_add_test(tc_server, Server_EmptyHandler); 63 | suite_add_tcase(s, tc_server); 64 | return s; 65 | } 66 | 67 | int main(int argc, char*argv[]) { 68 | printf("%s", argv[0]); 69 | if (!(argc > 1)) 70 | return 1; 71 | nodesetPath = argv[1]; 72 | Suite *s = testSuite_Client(); 73 | SRunner *sr = srunner_create(s); 74 | srunner_set_fork_status(sr, CK_NOFORK); 75 | srunner_run_all(sr, CK_NORMAL); 76 | int number_failed = srunner_ntests_failed(sr); 77 | srunner_free(sr); 78 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 79 | } 80 | -------------------------------------------------------------------------------- /backends/open62541/tests/integration/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(PLCOPEN_NODESET_PATH "${open62541_NODESET_BASE_DIR}/PLCopen/Opc.Ua.PLCopen.NodeSet2_V1.02.xml") 2 | 3 | add_subdirectory(client) 4 | add_subdirectory(reference_server) 5 | add_subdirectory(test_server) 6 | 7 | find_program (BASH_PROGRAM bash) 8 | 9 | message(WARNING ${CMAKE_CURRENT_BINARY_DIR}) 10 | 11 | add_test(IntegrationTest_DI ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/start_test.sh 12 | "${CMAKE_CURRENT_BINARY_DIR}/client/integrationClient" 13 | "${CMAKE_CURRENT_BINARY_DIR}/Output/DI/" 14 | "${CMAKE_CURRENT_BINARY_DIR}/reference_server/refServer_DI" 15 | "${CMAKE_CURRENT_BINARY_DIR}/test_server/testServer" 16 | "${open62541_NODESET_BASE_DIR}/DI/Opc.Ua.Di.NodeSet2.xml") 17 | 18 | 19 | add_test(IntegrationTest_DI_PLCOpen ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/start_test.sh 20 | "${CMAKE_CURRENT_BINARY_DIR}/client/integrationClient" 21 | "${CMAKE_CURRENT_BINARY_DIR}/Output/DI_PLCopen/" 22 | "${CMAKE_CURRENT_BINARY_DIR}/reference_server/refServer_DI_PLCopen" 23 | "${CMAKE_CURRENT_BINARY_DIR}/test_server/testServer" 24 | "${open62541_NODESET_BASE_DIR}/DI/Opc.Ua.Di.NodeSet2.xml" 25 | "${PLCOPEN_NODESET_PATH}" 26 | ) 27 | 28 | 29 | add_test(IntegrationTest_DI_Euromap_83_77 ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/start_test.sh 30 | "${CMAKE_CURRENT_BINARY_DIR}/client/integrationClient" 31 | "${CMAKE_CURRENT_BINARY_DIR}/Output/DI_Euromap_83_77" 32 | "${CMAKE_CURRENT_BINARY_DIR}/reference_server/refServer_DI_Euromap_83_77" 33 | "${CMAKE_CURRENT_BINARY_DIR}/test_server/testServer" 34 | "${open62541_NODESET_BASE_DIR}/DI/Opc.Ua.Di.NodeSet2.xml" 35 | "${PROJECT_SOURCE_DIR}/nodesets/euromap/Opc.Ua.PlasticsRubber.GeneralTypes.NodeSet2.xml" 36 | "${PROJECT_SOURCE_DIR}/nodesets/euromap/Opc.Ua.PlasticsRubber.IMM2MES.NodeSet2.xml" 37 | ) 38 | -------------------------------------------------------------------------------- /backends/open62541/tests/integration/client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(integrationClient client.cpp utils.cpp operator_ov.cpp browse_utils.cpp sort_utils.cpp value_utils_mock.cpp) 2 | target_include_directories(integrationClient PRIVATE client) 3 | target_link_libraries(integrationClient PRIVATE open62541::open62541) 4 | target_compile_features(integrationClient PRIVATE cxx_std_17) 5 | -------------------------------------------------------------------------------- /backends/open62541/tests/integration/client/browse_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _BROWSE_UTILS_H 2 | #define _BROWSE_UTILS_H 3 | 4 | #include 5 | #include 6 | 7 | class UA_Client; 8 | 9 | typedef struct 10 | { 11 | UA_NodeId *pReferenceTypeId; 12 | UA_NodeId *pTargetId; 13 | } TReference; 14 | 15 | typedef std::vector TReferenceVec; 16 | 17 | UA_Boolean BrowseReferences(UA_Client *pClient, const UA_NodeId &Id, 18 | TReferenceVec &oReferences); 19 | 20 | void FreeReferencesVec(TReferenceVec &References); 21 | 22 | UA_Boolean IsSubType(UA_Client *pClient, const UA_NodeId &BaseType, 23 | const UA_NodeId &SubType); 24 | 25 | #endif // _BROWSE_UTILS_H -------------------------------------------------------------------------------- /backends/open62541/tests/integration/client/common_defs.h: -------------------------------------------------------------------------------- 1 | #ifndef _COMMON_DEFS_H 2 | #define _COMMON_DEFS_H 3 | 4 | #include 5 | #include 6 | 7 | /*****************************************************************************/ 8 | // constants 9 | static const UA_NodeId HasPropertyId = 10 | UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY); 11 | static const UA_NodeId HasSubtypeId = UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE); 12 | static const UA_NodeId HierarchicalReferenceId = 13 | UA_NODEID_NUMERIC(0, UA_NS0ID_HIERARCHICALREFERENCES); 14 | static const UA_NodeId HasTypeDefinitionId = 15 | UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION); 16 | static const UA_NodeId HasModellingRuleId = 17 | UA_NODEID_NUMERIC(0, UA_NS0ID_HASMODELLINGRULE); 18 | static const UA_NodeId HasEncodingId = 19 | UA_NODEID_NUMERIC(0, UA_NS0ID_HASENCODING); 20 | static const UA_NodeId StructureId = UA_NODEID_NUMERIC(0, UA_NS0ID_STRUCTURE); 21 | static const UA_NodeId EnumerationId = 22 | UA_NODEID_NUMERIC(0, UA_NS0ID_ENUMERATION); 23 | static const UA_NodeId OptionSetId = UA_NODEID_NUMERIC(0, UA_NS0ID_OPTIONSET); 24 | static const UA_NodeId OptionSetValuesId = 25 | UA_NODEID_NUMERIC(0, UA_NS0ID_OPTIONSETVALUES); 26 | static const UA_NodeId UnsignedIntegerId = 27 | UA_NODEID_NUMERIC(0, UA_NS0ID_UINTEGER); 28 | static const UA_NodeId DataTypeDefinitionId = 29 | UA_NODEID_NUMERIC(0, UA_NS0ID_DATATYPEDEFINITION); 30 | 31 | static const UA_QualifiedName PropertyBrowseNameOptionSetValues = 32 | UA_QUALIFIEDNAME(0, (char *)"OptionSetValues"); 33 | 34 | #endif // _COMMON_DEFS_H -------------------------------------------------------------------------------- /backends/open62541/tests/integration/client/operator_ov.h: -------------------------------------------------------------------------------- 1 | #ifndef _OPERATOR_OV_H 2 | #define _OPERATOR_OV_H 3 | 4 | #include "browse_utils.h" 5 | #include 6 | #include 7 | 8 | std::ostream &operator<<(std::ostream &os, const UA_NodeId &Id); 9 | std::ostream &operator<<(std::ostream &os, const UA_ExpandedNodeId &Id); 10 | std::ostream &operator<<(std::ostream &os, const UA_String &Str); 11 | std::ostream &operator<<(std::ostream &os, const UA_Guid &Guid); 12 | std::ostream &operator<<(std::ostream &os, const UA_NodeClass &NodeClass); 13 | std::ostream &operator<<(std::ostream &os, 14 | const UA_QualifiedName &QualifiedName); 15 | std::ostream &operator<<(std::ostream &os, 16 | const UA_LocalizedText &LocalizedText); 17 | std::ostream &operator<<(std::ostream &os, 18 | const UA_DiagnosticInfo &DiagnosticInfo); 19 | std::ostream &operator<<(std::ostream &os, const TReference &Reference); 20 | 21 | #endif // _OPERATOR_OV_H -------------------------------------------------------------------------------- /backends/open62541/tests/integration/client/sort_utils.cpp: -------------------------------------------------------------------------------- 1 | #include "sort_utils.h" 2 | 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | /*****************************************************************************/ 9 | bool SortNodeId(const UA_NodeId *pLhs, const UA_NodeId *pRhs) 10 | { 11 | assert(pLhs != 0); 12 | assert(pRhs != 0); 13 | if ((pLhs == 0) || (pRhs == 0)) 14 | { 15 | cout << "Error SortNodeId(): null pointer" << endl; 16 | return false; 17 | } 18 | 19 | if (UA_NodeId_order(pLhs, pRhs) <= 0) 20 | { 21 | return true; 22 | } 23 | return false; 24 | } 25 | -------------------------------------------------------------------------------- /backends/open62541/tests/integration/client/sort_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _SORT_UTILS_H 2 | #define _SORT_UTILS_H 3 | 4 | #include 5 | #include 6 | 7 | typedef std::vector TNodeIdContainer; 8 | 9 | bool SortNodeId(const UA_NodeId *pLhs, const UA_NodeId *pRhs); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /backends/open62541/tests/integration/client/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTILS_H 2 | #define _UTILS_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | UA_Boolean PrintNode(UA_Client *pClient, const UA_NodeId &Id, 9 | std::ofstream &out); 10 | 11 | #endif // _UTILS_H 12 | -------------------------------------------------------------------------------- /backends/open62541/tests/integration/client/value_utils.cpp: -------------------------------------------------------------------------------- 1 | #include "value_utils.h" 2 | #include "common_defs.h" 3 | #include "operator_ov.h" 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | // // note: Input-OutputArguments: Variant contains TypeId of ExtensionObject 12 | // // which does not provide information about the type ... 13 | // // decoded .. typeId? 14 | 15 | // UA_Boolean PrintVariant(UA_Client *pClient, const UA_NodeId &DataTypeId, 16 | // UA_DataTypeMember *pDataTypeMembers, 17 | // size_t &CurrentMember, size_t NestedStructureDepth, 18 | // size_t ArrayLen, void *pData, size_t &DataOffset, 19 | // const UA_UInt32 Indentation, ostream &out); 20 | 21 | // // TODO: rework cout, out -> error messages 22 | // // TODO: rework return values 23 | // // TODO: refactor param names 24 | 25 | void PrintArrayDimensions(const size_t arrayDimSize, 26 | const UA_UInt32 *const pArrayDimensions, 27 | const UA_UInt32 Indentation, ostream &out) 28 | { 29 | string strIndent = string(Indentation, '\t'); 30 | out << strIndent << "ArrayDimensions = ["; 31 | if (pArrayDimensions != 0) 32 | { 33 | for (size_t i = 0; i < arrayDimSize; i++) 34 | { 35 | out << strIndent << "\t" << pArrayDimensions[i] << ","; 36 | } 37 | } 38 | out << "]" << endl; 39 | } 40 | 41 | // Note: DataTypeId is necessary for ExtensionObject, otherwise we can't get 42 | // the type Id 43 | UA_Boolean PrintValueAttribute(const UA_Variant &Value, std::ostream &out) 44 | { 45 | UA_String sVal = UA_STRING_NULL; 46 | UA_print(&Value, &UA_TYPES[UA_TYPES_VARIANT], &sVal); 47 | out << std::string_view{reinterpret_cast(sVal.data), sVal.length} << "\n"; 48 | UA_String_clear(&sVal); 49 | 50 | return UA_TRUE; 51 | } 52 | -------------------------------------------------------------------------------- /backends/open62541/tests/integration/client/value_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _VALUE_UTILS_H 2 | #define _VALUE_UTILS_H 3 | 4 | #include 5 | #include 6 | 7 | void PrintArrayDimensions(const size_t arrayDimSize, 8 | const UA_UInt32 *const pArrayDimensions, 9 | const UA_UInt32 Indentation, std::ostream &out); 10 | 11 | UA_Boolean PrintValueAttribute(const UA_Variant &NL_Value, std::ostream &out); 12 | 13 | #endif // _VALUE_UTILS_H -------------------------------------------------------------------------------- /backends/open62541/tests/integration/client/value_utils_mock.cpp: -------------------------------------------------------------------------------- 1 | #include "value_utils.h" 2 | #include "common_defs.h" 3 | #include "operator_ov.h" 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | void PrintArrayDimensions(const size_t arrayDimSize, 12 | const UA_UInt32 *const pArrayDimensions, 13 | const UA_UInt32 Indentation, ostream &out) 14 | { 15 | string strIndent = string(Indentation, '\t'); 16 | out << strIndent << "ArrayDimensions = ["; 17 | if (pArrayDimensions != 0) 18 | { 19 | for (size_t i = 0; i < arrayDimSize; i++) 20 | { 21 | out << strIndent << "\t" << pArrayDimensions[i] << ","; 22 | } 23 | } 24 | out << "]" << endl; 25 | } 26 | 27 | // Note: DataTypeId is necessary for ExtensionObject, otherwise we can't get 28 | // the type Id 29 | UA_Boolean PrintValueAttribute(const UA_Variant &Value, std::ostream &out) 30 | { 31 | out << "printing value omitted" << "\n"; 32 | return UA_TRUE; 33 | } 34 | -------------------------------------------------------------------------------- /backends/open62541/tests/integration/test_server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(testServer server.cpp) 2 | target_link_libraries(testServer PRIVATE NodesetLoader open62541::open62541) 3 | -------------------------------------------------------------------------------- /backends/open62541/tests/issue_201.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include "check.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "testHelper.h" 13 | 14 | UA_Server *server; 15 | char *nodesetPath = NULL; 16 | 17 | static void setup(void) 18 | { 19 | printf("path to testnodesets %s\n", nodesetPath); 20 | server = UA_Server_new(); 21 | UA_ServerConfig *config = UA_Server_getConfig(server); 22 | UA_ServerConfig_setDefault(config); 23 | } 24 | 25 | static void teardown(void) 26 | { 27 | UA_Server_run_shutdown(server); 28 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 29 | const UA_DataTypeArray *customTypes = 30 | UA_Server_getConfig(server)->customDataTypes; 31 | #endif 32 | UA_Server_delete(server); 33 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 34 | NodesetLoader_cleanupCustomDataTypes(customTypes); 35 | #endif 36 | } 37 | 38 | START_TEST(Server_Issue_201) 39 | { 40 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL)); 41 | 42 | ck_assert(hasReference( 43 | server, UA_NODEID_NUMERIC(2, 5000), UA_NODEID_NUMERIC(2, 4000), 44 | UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT), UA_BROWSEDIRECTION_INVERSE)); 45 | 46 | ck_assert(hasReference(server, UA_NODEID_NUMERIC(2, 6000), 47 | UA_NODEID_NUMERIC(2, 4000), 48 | UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT), 49 | UA_BROWSEDIRECTION_INVERSE)); 50 | } 51 | END_TEST 52 | 53 | static Suite *testSuite_Client(void) 54 | { 55 | Suite *s = suite_create("server nodeset import"); 56 | TCase *tc_server = tcase_create("server nodeset import"); 57 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 58 | tcase_add_test(tc_server, Server_Issue_201); 59 | suite_add_tcase(s, tc_server); 60 | return s; 61 | } 62 | 63 | int main(int argc, char *argv[]) 64 | { 65 | printf("%s", argv[0]); 66 | if (!(argc > 1)) 67 | return 1; 68 | nodesetPath = argv[1]; 69 | Suite *s = testSuite_Client(); 70 | SRunner *sr = srunner_create(s); 71 | srunner_set_fork_status(sr, CK_NOFORK); 72 | srunner_run_all(sr, CK_NORMAL); 73 | int number_failed = srunner_ntests_failed(sr); 74 | srunner_free(sr); 75 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 76 | } 77 | -------------------------------------------------------------------------------- /backends/open62541/tests/issue_201.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | http://open62541.com/tests/issue_201/ 5 | 6 | 7 | i=11 8 | i=12 9 | i=15 10 | i=35 11 | i=37 12 | i=38 13 | i=39 14 | i=40 15 | i=45 16 | i=46 17 | i=47 18 | ns=1;i=3002 19 | 20 | 21 | Parent 22 | 23 | i=85 24 | ns=1;i=5000 25 | 26 | 27 | 28 | Child 29 | 30 | 31 | 32 | 33 | 34 | Child2 35 | 36 | ns=1;i=4000 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /backends/open62541/tests/issue_241.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include "check.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "testHelper.h" 13 | 14 | UA_Server *server; 15 | char *nodesetPath = NULL; 16 | 17 | static void setup(void) 18 | { 19 | printf("path to testnodesets %s\n", nodesetPath); 20 | server = UA_Server_new(); 21 | UA_ServerConfig *config = UA_Server_getConfig(server); 22 | UA_ServerConfig_setDefault(config); 23 | } 24 | 25 | static void teardown(void) 26 | { 27 | UA_Server_run_shutdown(server); 28 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 29 | const UA_DataTypeArray *customTypes = 30 | UA_Server_getConfig(server)->customDataTypes; 31 | #endif 32 | UA_Server_delete(server); 33 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 34 | NodesetLoader_cleanupCustomDataTypes(customTypes); 35 | #endif 36 | } 37 | 38 | START_TEST(Server_Issue_241) 39 | { 40 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL)); 41 | 42 | UA_Variant var; 43 | UA_Variant_init(&var); 44 | UA_StatusCode retval = UA_Server_readValue( 45 | server, UA_NODEID_STRING(2, "Demo.Static.Arrays.StatusCode"), &var); 46 | ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD); 47 | 48 | ck_assert(var.type = &UA_TYPES[UA_TYPES_STATUSCODE]); 49 | ck_assert(var.arrayLength==10); 50 | 51 | UA_StatusCode *first = (UA_StatusCode*)var.data; 52 | ck_assert(*first == 0u); 53 | UA_StatusCode last = first[9]; 54 | ck_assert(last == 2151022592u); 55 | 56 | UA_Variant_clear(&var); 57 | } 58 | END_TEST 59 | 60 | static Suite *testSuite_Client(void) 61 | { 62 | Suite *s = suite_create("server nodeset import"); 63 | TCase *tc_server = tcase_create("server nodeset import"); 64 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 65 | tcase_add_test(tc_server, Server_Issue_241); 66 | suite_add_tcase(s, tc_server); 67 | return s; 68 | } 69 | 70 | int main(int argc, char *argv[]) 71 | { 72 | printf("%s", argv[0]); 73 | if (!(argc > 1)) 74 | return 1; 75 | nodesetPath = argv[1]; 76 | Suite *s = testSuite_Client(); 77 | SRunner *sr = srunner_create(s); 78 | srunner_set_fork_status(sr, CK_NOFORK); 79 | srunner_run_all(sr, CK_NORMAL); 80 | int number_failed = srunner_ntests_failed(sr); 81 | srunner_free(sr); 82 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 83 | } 84 | -------------------------------------------------------------------------------- /backends/open62541/tests/issue_241.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | http://www.unifiedautomation.com/DemoServer/ 5 | 6 | 7 | i=1 8 | i=2 9 | i=3 10 | i=4 11 | i=5 12 | i=6 13 | i=7 14 | i=8 15 | i=9 16 | i=10 17 | i=11 18 | i=12 19 | i=13 20 | i=14 21 | i=15 22 | i=16 23 | i=17 24 | i=18 25 | i=19 26 | i=20 27 | i=21 28 | i=22 29 | i=24 30 | i=26 31 | i=27 32 | i=28 33 | i=35 34 | i=40 35 | i=290 36 | i=291 37 | i=294 38 | i=852 39 | i=2003 40 | 41 | 42 | StatusCode 43 | 44 | i=63 45 | i=85 46 | 47 | 48 | 49 | 50 | 0 51 | 52 | 53 | 2150694912 54 | 55 | 56 | 2150825984 57 | 58 | 59 | 2151022592 60 | 61 | 62 | 2151284736 63 | 64 | 65 | 2151677952 66 | 67 | 68 | 0 69 | 70 | 71 | 2150694912 72 | 73 | 74 | 2150825984 75 | 76 | 77 | 2151022592 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /backends/open62541/tests/issue_246.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include "check.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | UA_Server *server; 12 | char *nodesetPath = NULL; 13 | 14 | static void setup(void) 15 | { 16 | printf("path to testnodesets %s\n", nodesetPath); 17 | server = UA_Server_new(); 18 | UA_ServerConfig *config = UA_Server_getConfig(server); 19 | UA_ServerConfig_setDefault(config); 20 | } 21 | 22 | static void teardown(void) 23 | { 24 | UA_Server_run_shutdown(server); 25 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 26 | const UA_DataTypeArray *customTypes = 27 | UA_Server_getConfig(server)->customDataTypes; 28 | #endif 29 | UA_Server_delete(server); 30 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 31 | NodesetLoader_cleanupCustomDataTypes(customTypes); 32 | #endif 33 | } 34 | 35 | START_TEST(Server_Issue_246) 36 | { 37 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL)); 38 | 39 | UA_Variant var; 40 | UA_Variant_init(&var); 41 | // Check if the last node in the chain exists. It should be. 42 | UA_StatusCode retval = UA_Server_readValue( 43 | server, UA_NODEID_STRING(2, "Test.Var4"), &var); 44 | ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD); 45 | UA_Variant_clear(&var); 46 | } 47 | END_TEST 48 | 49 | static Suite *testSuite_Client(void) 50 | { 51 | Suite *s = suite_create("server nodeset import"); 52 | TCase *tc_server = tcase_create("server nodeset import"); 53 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 54 | tcase_add_test(tc_server, Server_Issue_246); 55 | suite_add_tcase(s, tc_server); 56 | return s; 57 | } 58 | 59 | int main(int argc, char *argv[]) 60 | { 61 | printf("%s", argv[0]); 62 | if (!(argc > 1)) 63 | return 1; 64 | nodesetPath = argv[1]; 65 | Suite *s = testSuite_Client(); 66 | SRunner *sr = srunner_create(s); 67 | srunner_set_fork_status(sr, CK_NOFORK); 68 | srunner_run_all(sr, CK_NORMAL); 69 | int number_failed = srunner_ntests_failed(sr); 70 | srunner_free(sr); 71 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 72 | } 73 | -------------------------------------------------------------------------------- /backends/open62541/tests/issue_266_testdata.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include "check.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | UA_Server *server; 12 | char *nodesetPath = NULL; 13 | 14 | static void setup(void) 15 | { 16 | printf("path to testnodesets %s\n", nodesetPath); 17 | server = UA_Server_new(); 18 | UA_ServerConfig *config = UA_Server_getConfig(server); 19 | UA_ServerConfig_setDefault(config); 20 | } 21 | 22 | static void teardown(void) 23 | { 24 | UA_Server_run_shutdown(server); 25 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 26 | const UA_DataTypeArray *customTypes = 27 | UA_Server_getConfig(server)->customDataTypes; 28 | #endif 29 | UA_Server_delete(server); 30 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 31 | NodesetLoader_cleanupCustomDataTypes(customTypes); 32 | #endif 33 | } 34 | 35 | START_TEST(Server_Issue_266) 36 | { 37 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL)); 38 | } 39 | END_TEST 40 | 41 | static Suite *testSuite_Client(void) 42 | { 43 | Suite *s = suite_create("server nodeset import"); 44 | TCase *tc_server = tcase_create("server nodeset import"); 45 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 46 | tcase_add_test(tc_server, Server_Issue_266); 47 | suite_add_tcase(s, tc_server); 48 | return s; 49 | } 50 | 51 | int main(int argc, char *argv[]) 52 | { 53 | printf("%s", argv[0]); 54 | if (!(argc > 1)) 55 | return 1; 56 | nodesetPath = argv[1]; 57 | Suite *s = testSuite_Client(); 58 | SRunner *sr = srunner_create(s); 59 | srunner_set_fork_status(sr, CK_NOFORK); 60 | srunner_run_all(sr, CK_NORMAL); 61 | int number_failed = srunner_ntests_failed(sr); 62 | srunner_free(sr); 63 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 64 | } 65 | -------------------------------------------------------------------------------- /backends/open62541/tests/multipleNamespaces.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "check.h" 10 | 11 | #include "testHelper.h" 12 | #include 13 | #include 14 | 15 | UA_Server *server; 16 | char* nodesetPath=NULL; 17 | 18 | static void setup(void) { 19 | printf("path to testnodesets %s\n", nodesetPath); 20 | server = UA_Server_new(); 21 | UA_ServerConfig *config = UA_Server_getConfig(server); 22 | UA_ServerConfig_setDefault(config); 23 | } 24 | 25 | static void teardown(void) { 26 | UA_Server_run_shutdown(server); 27 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 28 | const UA_DataTypeArray *customTypes = 29 | UA_Server_getConfig(server)->customDataTypes; 30 | #endif 31 | UA_Server_delete(server); 32 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 33 | NodesetLoader_cleanupCustomDataTypes(customTypes); 34 | #endif 35 | } 36 | 37 | START_TEST(Server_ImportNodeset) { 38 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, 39 | NULL)); 40 | } 41 | END_TEST 42 | 43 | static Suite *testSuite_Client(void) { 44 | Suite *s = suite_create("server nodeset import"); 45 | TCase *tc_server = tcase_create("server nodeset import"); 46 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 47 | tcase_add_test(tc_server, Server_ImportNodeset); 48 | suite_add_tcase(s, tc_server); 49 | return s; 50 | } 51 | 52 | int main(int argc, char*argv[]) { 53 | printf("%s", argv[0]); 54 | if (!(argc > 1)) 55 | return 1; 56 | nodesetPath = argv[1]; 57 | Suite *s = testSuite_Client(); 58 | SRunner *sr = srunner_create(s); 59 | srunner_set_fork_status(sr, CK_NOFORK); 60 | srunner_run_all(sr, CK_NORMAL); 61 | int number_failed = srunner_ntests_failed(sr); 62 | srunner_free(sr); 63 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 64 | } 65 | -------------------------------------------------------------------------------- /backends/open62541/tests/multipleNamespaces.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | http://yourorganisation.org/instances/ 5 | http://yourorganisation.org/types/ 6 | 7 | 8 | i=35 9 | i=40 10 | i=47 11 | i=37 12 | i=45 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | MyListInstance 21 | 22 | ns=1;i=5001 23 | ns=1;i=5003 24 | ns=2;i=1002 25 | i=85 26 | 27 | 28 | 29 | Instance1 30 | The type for objects that organize other nodes. 31 | 32 | i=61 33 | ns=1;i=5002 34 | 35 | 36 | 37 | Instance2 38 | The base type for all object nodes. 39 | 40 | i=61 41 | ns=1;i=5002 42 | 43 | 44 | 45 | MyList 46 | 47 | ns=2;i=5001 48 | i=58 49 | 50 | 51 | 52 | <Data> 53 | 54 | i=58 55 | i=11508 56 | ns=2;i=1002 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /backends/open62541/tests/newHierachicalRef.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "check.h" 10 | 11 | #include "testHelper.h" 12 | #include 13 | #include 14 | 15 | UA_Server *server; 16 | char *nodesetPath1 = NULL; 17 | char *nodesetPath2 = NULL; 18 | 19 | static void setup(void) 20 | { 21 | server = UA_Server_new(); 22 | UA_ServerConfig *config = UA_Server_getConfig(server); 23 | UA_ServerConfig_setDefault(config); 24 | } 25 | 26 | static void teardown(void) 27 | { 28 | UA_Server_run_shutdown(server); 29 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 30 | const UA_DataTypeArray *customTypes = 31 | UA_Server_getConfig(server)->customDataTypes; 32 | #endif 33 | UA_Server_delete(server); 34 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 35 | NodesetLoader_cleanupCustomDataTypes(customTypes); 36 | #endif 37 | } 38 | 39 | START_TEST(loadNodeset) 40 | { 41 | ck_assert(NodesetLoader_loadFile(server, nodesetPath1, NULL)); 42 | ck_assert(NodesetLoader_loadFile(server, nodesetPath2, NULL)); 43 | } 44 | END_TEST 45 | 46 | START_TEST(newHierachicalRef) 47 | { 48 | ck_assert(UA_NODECLASS_REFERENCETYPE == 49 | getNodeClass(server, UA_NODEID_NUMERIC(2, 4002))); 50 | 51 | ck_assert(UA_NODECLASS_OBJECT == getNodeClass(server, UA_NODEID_NUMERIC(2, 5002))); 52 | 53 | ck_assert(UA_NODECLASS_OBJECT == 54 | getNodeClass(server, UA_NODEID_NUMERIC(2, 5004))); 55 | 56 | ck_assert(hasReference(server, UA_NODEID_NUMERIC(2, 5004), 57 | UA_NODEID_NUMERIC(2, 5002), 58 | UA_NODEID_NUMERIC(2, 4002), UA_BROWSEDIRECTION_INVERSE)); 59 | 60 | ck_assert(hasReference(server, UA_NODEID_NUMERIC(2, 5002), 61 | UA_NODEID_NUMERIC(2, 5004), 62 | UA_NODEID_NUMERIC(2, 4002), UA_BROWSEDIRECTION_FORWARD)); 63 | } 64 | END_TEST 65 | 66 | // check if node is also added, if there's no hierachical reference on it 67 | START_TEST(noHierachicalRef) 68 | { 69 | ck_assert(UA_NODECLASS_OBJECT == 70 | getNodeClass(server, UA_NODEID_NUMERIC(2, 5003))); 71 | } 72 | END_TEST 73 | 74 | START_TEST(otherNamespace) 75 | { 76 | ck_assert(UA_NODECLASS_OBJECT == 77 | getNodeClass(server, UA_NODEID_NUMERIC(3, 5002))); 78 | } 79 | END_TEST 80 | 81 | static Suite *testSuite_Client(void) 82 | { 83 | Suite *s = suite_create("newHierachicalReference"); 84 | TCase *tc_server = tcase_create("newHierachicalReference"); 85 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 86 | tcase_add_test(tc_server, loadNodeset); 87 | tcase_add_test(tc_server, newHierachicalRef); 88 | tcase_add_test(tc_server, noHierachicalRef); 89 | tcase_add_test(tc_server, otherNamespace); 90 | suite_add_tcase(s, tc_server); 91 | return s; 92 | } 93 | 94 | int main(int argc, char *argv[]) 95 | { 96 | printf("%s", argv[0]); 97 | if (!(argc > 1)) 98 | return 1; 99 | nodesetPath1 = argv[1]; 100 | nodesetPath2 = argv[2]; 101 | Suite *s = testSuite_Client(); 102 | SRunner *sr = srunner_create(s); 103 | srunner_set_fork_status(sr, CK_NOFORK); 104 | srunner_run_all(sr, CK_NORMAL); 105 | int number_failed = srunner_ntests_failed(sr); 106 | srunner_free(sr); 107 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 108 | } 109 | -------------------------------------------------------------------------------- /backends/open62541/tests/newHierachicalRef.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | http://yourorganisation.org/HierachicalReferences/ 5 | 6 | 7 | i=40 8 | i=45 9 | ns=1;i=4002 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | SubComponentOfSubcomponent 18 | 19 | ns=1;i=5002 20 | i=61 21 | 22 | 23 | 24 | HasSubComponent 25 | 26 | i=47 27 | 28 | isSubComponentOf 29 | 30 | 31 | SubComponent 32 | 33 | i=85 34 | i=61 35 | 36 | 37 | 38 | NoHierachicalRef 39 | 40 | 41 | i=58 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /backends/open62541/tests/newHierachicalRef2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | http://yourorganisation.org/HierachicalReferences2/ 5 | http://yourorganisation.org/HierachicalReferences/ 6 | 7 | 8 | i=40 9 | i=45 10 | ns=2;i=4002 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | SubComponent_OtherNamespace 19 | 20 | i=85 21 | i=61 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /backends/open62541/tests/orderingStringNodeIds.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include "check.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "testHelper.h" 13 | 14 | UA_Server *server; 15 | char *nodesetPath = NULL; 16 | 17 | static void setup(void) 18 | { 19 | printf("path to testnodesets %s\n", nodesetPath); 20 | server = UA_Server_new(); 21 | UA_ServerConfig *config = UA_Server_getConfig(server); 22 | UA_ServerConfig_setDefault(config); 23 | } 24 | 25 | static void teardown(void) 26 | { 27 | UA_Server_run_shutdown(server); 28 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 29 | const UA_DataTypeArray *customTypes = 30 | UA_Server_getConfig(server)->customDataTypes; 31 | #endif 32 | UA_Server_delete(server); 33 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 34 | NodesetLoader_cleanupCustomDataTypes(customTypes); 35 | #endif 36 | } 37 | 38 | START_TEST(OrderingStringNodeIds) 39 | { 40 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL)); 41 | } 42 | END_TEST 43 | 44 | static Suite *testSuite_Client(void) 45 | { 46 | Suite *s = suite_create("server nodeset import"); 47 | TCase *tc_server = tcase_create("server nodeset import"); 48 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 49 | tcase_add_test(tc_server, OrderingStringNodeIds); 50 | suite_add_tcase(s, tc_server); 51 | return s; 52 | } 53 | 54 | int main(int argc, char *argv[]) 55 | { 56 | printf("%s", argv[0]); 57 | if (!(argc > 1)) 58 | return 1; 59 | nodesetPath = argv[1]; 60 | Suite *s = testSuite_Client(); 61 | SRunner *sr = srunner_create(s); 62 | srunner_set_fork_status(sr, CK_NOFORK); 63 | srunner_run_all(sr, CK_NORMAL); 64 | int number_failed = srunner_ntests_failed(sr); 65 | srunner_free(sr); 66 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 67 | } 68 | -------------------------------------------------------------------------------- /backends/open62541/tests/orderingStringNodeIds.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | urn:WS:LTA:Vars 5 | 6 | 7 | i=1 8 | i=2 9 | i=3 10 | i=4 11 | i=5 12 | i=6 13 | i=7 14 | i=8 15 | i=9 16 | i=10 17 | i=11 18 | i=12 19 | i=13 20 | i=15 21 | i=17 22 | i=19 23 | i=21 24 | i=24 25 | i=29 26 | i=35 27 | i=36 28 | i=37 29 | i=40 30 | i=45 31 | i=46 32 | i=47 33 | i=48 34 | i=9006 35 | i=58 36 | i=61 37 | i=63 38 | i=2041 39 | i=2782 40 | i=2881 41 | i=2915 42 | i=10523 43 | i=10637 44 | i=9002 45 | i=8995 46 | i=68 47 | i=77 48 | i=85 49 | i=256 50 | i=291 51 | i=294 52 | i=296 53 | i=2365 54 | i=7594 55 | 56 | 57 | CMB_VMS 58 | 59 | ObjectsFolder 60 | ns=1;s=CMB_VMS.Test 61 | FolderType 62 | 63 | 64 | 65 | Test 66 | 67 | ns=1;s=CMB_VMS 68 | BaseObjectType 69 | 70 | 71 | -------------------------------------------------------------------------------- /backends/open62541/tests/primitiveValues.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include "check.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "testHelper.h" 13 | 14 | UA_Server *server; 15 | char *nodesetPath = NULL; 16 | 17 | static void setup(void) 18 | { 19 | printf("path to testnodesets %s\n", nodesetPath); 20 | server = UA_Server_new(); 21 | UA_ServerConfig *config = UA_Server_getConfig(server); 22 | UA_ServerConfig_setDefault(config); 23 | } 24 | 25 | static void teardown(void) 26 | { 27 | UA_Server_run_shutdown(server); 28 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 29 | const UA_DataTypeArray *customTypes = 30 | UA_Server_getConfig(server)->customDataTypes; 31 | #endif 32 | UA_Server_delete(server); 33 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 34 | NodesetLoader_cleanupCustomDataTypes(customTypes); 35 | #endif 36 | } 37 | 38 | START_TEST(loadPrimitiveValues) 39 | { 40 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL)); 41 | } 42 | END_TEST 43 | 44 | static Suite *testSuite_Client(void) 45 | { 46 | Suite *s = suite_create("primitiveValues"); 47 | TCase *tc_server = tcase_create("primitiveValues"); 48 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 49 | tcase_add_test(tc_server, loadPrimitiveValues); 50 | suite_add_tcase(s, tc_server); 51 | return s; 52 | } 53 | 54 | int main(int argc, char *argv[]) 55 | { 56 | printf("%s", argv[0]); 57 | if (!(argc > 1)) 58 | return 1; 59 | nodesetPath = argv[1]; 60 | Suite *s = testSuite_Client(); 61 | SRunner *sr = srunner_create(s); 62 | srunner_set_fork_status(sr, CK_NOFORK); 63 | srunner_run_all(sr, CK_NORMAL); 64 | int number_failed = srunner_ntests_failed(sr); 65 | srunner_free(sr); 66 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 67 | } 68 | -------------------------------------------------------------------------------- /backends/open62541/tests/stringNodeId_issue_224.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include "check.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "testHelper.h" 13 | 14 | UA_Server *server; 15 | char *nodesetPath = NULL; 16 | 17 | static void setup(void) 18 | { 19 | printf("path to testnodesets %s\n", nodesetPath); 20 | server = UA_Server_new(); 21 | UA_ServerConfig *config = UA_Server_getConfig(server); 22 | UA_ServerConfig_setDefault(config); 23 | } 24 | 25 | static void teardown(void) 26 | { 27 | UA_Server_run_shutdown(server); 28 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 29 | const UA_DataTypeArray *customTypes = 30 | UA_Server_getConfig(server)->customDataTypes; 31 | #endif 32 | UA_Server_delete(server); 33 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 34 | NodesetLoader_cleanupCustomDataTypes(customTypes); 35 | #endif 36 | } 37 | 38 | START_TEST(Server_Issue_224) 39 | { 40 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL)); 41 | 42 | UA_Variant var; 43 | UA_Variant_init(&var); 44 | ck_assert_uint_eq( 45 | UA_STATUSCODE_GOOD, 46 | UA_Server_readValue(server, UA_NODEID_NUMERIC(2, 6011), &var)); 47 | ck_assert(var.arrayLength==3); 48 | ck_assert(var.type==&UA_TYPES[UA_TYPES_NODEID]); 49 | UA_NodeId* ids = (UA_NodeId*)var.data; 50 | UA_NodeId firstId = UA_NODEID_STRING(0, "someNode"); 51 | UA_NodeId secondId = UA_NODEID_STRING(0, "someNodeButCooler"); 52 | UA_NodeId thirdId = UA_NODEID_STRING(0, "theNodeIsALie"); 53 | ck_assert(UA_NodeId_equal(&firstId, ids)); 54 | ck_assert(UA_NodeId_equal(&secondId, ids+1)); 55 | ck_assert(UA_NodeId_equal(&thirdId, ids+2)); 56 | UA_Variant_clear(&var); 57 | 58 | ck_assert_uint_eq( 59 | UA_STATUSCODE_GOOD, 60 | UA_Server_readValue(server, UA_NODEID_NUMERIC(2, 6012), &var)); 61 | ck_assert(var.type == &UA_TYPES[UA_TYPES_PUBLISHEDVARIABLEDATATYPE]); 62 | UA_PublishedVariableDataType *publishedVar = 63 | (UA_PublishedVariableDataType *) var.data; 64 | UA_NodeId publishedVariableId = UA_NODEID_STRING(0, "abcdef"); 65 | ck_assert(UA_NodeId_equal(&publishedVariableId, &publishedVar->publishedVariable)); 66 | UA_Variant_clear(&var); 67 | } 68 | END_TEST 69 | 70 | static Suite *testSuite_Client(void) 71 | { 72 | Suite *s = suite_create("server nodeset import"); 73 | TCase *tc_server = tcase_create("server nodeset import"); 74 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 75 | tcase_add_test(tc_server, Server_Issue_224); 76 | suite_add_tcase(s, tc_server); 77 | return s; 78 | } 79 | 80 | int main(int argc, char *argv[]) 81 | { 82 | printf("%s", argv[0]); 83 | if (!(argc > 1)) 84 | return 1; 85 | nodesetPath = argv[1]; 86 | Suite *s = testSuite_Client(); 87 | SRunner *sr = srunner_create(s); 88 | srunner_set_fork_status(sr, CK_NOFORK); 89 | srunner_run_all(sr, CK_NORMAL); 90 | int number_failed = srunner_ntests_failed(sr); 91 | srunner_free(sr); 92 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 93 | } 94 | -------------------------------------------------------------------------------- /backends/open62541/tests/structMultipleNamespaces.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "check.h" 10 | 11 | #include "testHelper.h" 12 | #include 13 | #include 14 | 15 | UA_Server *server; 16 | char *nodesetPath1 = NULL; 17 | char *nodesetPath2 = NULL; 18 | 19 | static void setup(void) 20 | { 21 | server = UA_Server_new(); 22 | UA_ServerConfig *config = UA_Server_getConfig(server); 23 | UA_ServerConfig_setDefault(config); 24 | } 25 | 26 | static void teardown(void) 27 | { 28 | UA_Server_run_shutdown(server); 29 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 30 | const UA_DataTypeArray *customTypes = 31 | UA_Server_getConfig(server)->customDataTypes; 32 | #endif 33 | UA_Server_delete(server); 34 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 35 | NodesetLoader_cleanupCustomDataTypes(customTypes); 36 | #endif 37 | } 38 | 39 | struct Point 40 | { 41 | UA_Int32 x; 42 | UA_Int32 y; 43 | UA_Int32 z; 44 | }; 45 | 46 | struct PointWithOffset 47 | { 48 | UA_Int32 x; 49 | UA_Int32 y; 50 | UA_Int32 z; 51 | struct Point offset; 52 | }; 53 | 54 | START_TEST(Server_ReadPointWithOffset) 55 | { 56 | ck_assert(NodesetLoader_loadFile(server, nodesetPath1, NULL)); 57 | ck_assert(NodesetLoader_loadFile(server, nodesetPath2, NULL)); 58 | 59 | UA_Variant var; 60 | UA_Variant_init(&var); 61 | // Point with offset 62 | UA_StatusCode retval = 63 | UA_Server_readValue(server, UA_NODEID_NUMERIC(3, 6015), &var); 64 | ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD); 65 | 66 | struct PointWithOffset *p = (struct PointWithOffset *)var.data; 67 | ck_assert(p->x == 10); 68 | ck_assert(p->y == 20); 69 | ck_assert(p->z == 30); 70 | ck_assert(p->offset.x == -1); 71 | ck_assert(p->offset.y == -2); 72 | ck_assert(p->offset.z == -3); 73 | 74 | UA_Variant_clear(&var); 75 | } 76 | END_TEST 77 | 78 | static Suite *testSuite_Client(void) 79 | { 80 | Suite *s = suite_create("server nodeset import"); 81 | TCase *tc_server = tcase_create("server nodeset import"); 82 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 83 | tcase_add_test(tc_server, Server_ReadPointWithOffset); 84 | suite_add_tcase(s, tc_server); 85 | return s; 86 | } 87 | 88 | int main(int argc, char *argv[]) 89 | { 90 | printf("%s", argv[0]); 91 | if (!(argc > 1)) 92 | return 1; 93 | nodesetPath1 = argv[1]; 94 | nodesetPath2 = argv[2]; 95 | Suite *s = testSuite_Client(); 96 | SRunner *sr = srunner_create(s); 97 | srunner_set_fork_status(sr, CK_NOFORK); 98 | srunner_run_all(sr, CK_NORMAL); 99 | int number_failed = srunner_ntests_failed(sr); 100 | srunner_free(sr); 101 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 102 | } 103 | -------------------------------------------------------------------------------- /backends/open62541/tests/structwitharray.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "check.h" 10 | 11 | #include "testHelper.h" 12 | #include 13 | #include 14 | 15 | UA_Server *server; 16 | char *nodesetPath = NULL; 17 | 18 | static void setup(void) 19 | { 20 | printf("path to testnodesets %s\n", nodesetPath); 21 | server = UA_Server_new(); 22 | UA_ServerConfig *config = UA_Server_getConfig(server); 23 | UA_ServerConfig_setDefault(config); 24 | } 25 | 26 | static void teardown(void) 27 | { 28 | UA_Server_run_shutdown(server); 29 | const UA_DataTypeArray* customTypes = UA_Server_getConfig(server)->customDataTypes; 30 | UA_Server_delete(server); 31 | #ifdef USE_CLEANUP_CUSTOM_DATATYPES 32 | NodesetLoader_cleanupCustomDataTypes(customTypes); 33 | #endif 34 | } 35 | 36 | START_TEST(Server_loadNodeset) 37 | { 38 | ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL)); 39 | ck_assert(getNodeClass(server, UA_NODEID_NUMERIC(2, 3002))==UA_NODECLASS_DATATYPE); 40 | ck_assert(getNodeClass(server, UA_NODEID_NUMERIC(2, 6008)) == 41 | UA_NODECLASS_VARIABLE); 42 | struct Point 43 | { 44 | UA_Int32 x; 45 | UA_Int32 y; 46 | size_t size; 47 | UA_Int32* scaleFactors; 48 | }; 49 | 50 | UA_Variant var; 51 | UA_Variant_init(&var); 52 | 53 | UA_StatusCode status = UA_Server_readValue(server, UA_NODEID_NUMERIC(2,6008), &var); 54 | ck_assert(status == UA_STATUSCODE_GOOD); 55 | struct Point* p = (struct Point*)var.data; 56 | ck_assert(p->x==10); 57 | ck_assert(p->y==20); 58 | ck_assert(p->size==4); 59 | ck_assert(p->scaleFactors[3]==23); 60 | 61 | UA_Variant_clear(&var); 62 | } 63 | END_TEST 64 | 65 | static Suite *testSuite_Client(void) 66 | { 67 | Suite *s = suite_create("server nodeset import"); 68 | TCase *tc_server = tcase_create("server nodeset import"); 69 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 70 | tcase_add_test(tc_server, Server_loadNodeset); 71 | suite_add_tcase(s, tc_server); 72 | return s; 73 | } 74 | 75 | int main(int argc, char *argv[]) 76 | { 77 | printf("%s", argv[0]); 78 | if (!(argc > 1)) 79 | return 1; 80 | nodesetPath = argv[1]; 81 | Suite *s = testSuite_Client(); 82 | SRunner *sr = srunner_create(s); 83 | srunner_set_fork_status(sr, CK_NOFORK); 84 | srunner_run_all(sr, CK_NORMAL); 85 | int number_failed = srunner_ntests_failed(sr); 86 | srunner_free(sr); 87 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 88 | } 89 | -------------------------------------------------------------------------------- /backends/stdout/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(${ENABLE_EXAMPLES}) 2 | add_subdirectory(examples) 3 | endif() -------------------------------------------------------------------------------- /backends/stdout/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(parserDemo main.c dump.c) 2 | target_link_libraries(parserDemo PRIVATE NodesetLoader) 3 | target_link_libraries(parserDemo PRIVATE open62541::open62541) 4 | -------------------------------------------------------------------------------- /backends/stdout/examples/backend.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2019 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef __BACKEND_H__ 9 | #define __BACKEND_H__ 10 | 11 | #include "NodesetLoader/NodesetLoader.h" 12 | #include 13 | #include 14 | 15 | unsigned short addNamespace(void *userContext, const char *namespaceUri); 16 | void dumpNode(void *userContext, const NL_Node *node); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /backends/stdout/examples/csv.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2019 (c) Matthias Konnerth 6 | */ 7 | 8 | #include "backend.h" 9 | 10 | static int namespaceIdx = 0; 11 | int addNamespace(void *userContext, const char *uri) { return namespaceIdx++; } 12 | 13 | void dumpNode(void *userContext, const NL_Node *node) 14 | { 15 | FILE *f = (FILE *)userContext; 16 | fprintf(f, "%d:%s,%s\n", node->id.nsIdx, node->id.id, 17 | node->browseName.name); 18 | } -------------------------------------------------------------------------------- /backends/stdout/examples/dump.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2019 (c) Matthias Konnerth 6 | */ 7 | 8 | #include "backend.h" 9 | 10 | char nodeidDump[256]; 11 | static char * 12 | printId(const UA_NodeId *id) { 13 | UA_String myStr = {0}; 14 | UA_NodeId_print(id, &myStr); 15 | if(myStr.length >= 256) 16 | myStr.length = 255; 17 | memcpy(nodeidDump, myStr.data, myStr.length); 18 | nodeidDump[myStr.length] = 0; 19 | UA_String_clear(&myStr); 20 | return nodeidDump; 21 | } 22 | 23 | unsigned short addNamespace(void *userContext, const char *uri) { return 1; } 24 | 25 | void dumpNode(void *userContext, const NL_Node *node) 26 | { 27 | printf("NodeId: %s BrowseName: %s DisplayName: %s\n", printId(&node->id), 28 | node->browseName.name, node->displayName.text); 29 | 30 | switch (node->nodeClass) 31 | { 32 | case NODECLASS_OBJECT: 33 | printf("\tparentNodeId: %s\n", printId(&((const NL_ObjectNode *)node)->parentNodeId)); 34 | printf("\teventNotifier: %s\n", ((const NL_ObjectNode *)node)->eventNotifier); 35 | break; 36 | case NODECLASS_VARIABLE: 37 | printf("\tparentNodeId: %s\n", 38 | printId(&((const NL_VariableNode *)node)->parentNodeId)); 39 | printf("\tdatatype: %s\n", printId(&((const NL_VariableNode *)node)->datatype)); 40 | printf("\tvalueRank: %s\n", ((const NL_VariableNode *)node)->valueRank); 41 | printf("\tarrayDimensions: %s\n", 42 | ((const NL_VariableNode *)node)->valueRank); 43 | printf("\tminimumSamplingInterval: %s\n", 44 | ((const NL_VariableNode *)node)->minimumSamplingInterval); 45 | break; 46 | case NODECLASS_OBJECTTYPE: 47 | break; 48 | case NODECLASS_DATATYPE: 49 | break; 50 | case NODECLASS_METHOD: 51 | break; 52 | case NODECLASS_REFERENCETYPE: 53 | case NODECLASS_VARIABLETYPE: 54 | break; 55 | } 56 | NL_Reference *hierachicalRef = node->hierachicalRefs; 57 | while (hierachicalRef) 58 | { 59 | printf("\treftype: %s", printId(&hierachicalRef->refType)); 60 | printf(" target: %s\n", printId(&hierachicalRef->target)); 61 | hierachicalRef = hierachicalRef->next; 62 | } 63 | 64 | NL_Reference *nonHierRef = node->nonHierachicalRefs; 65 | while (nonHierRef) 66 | { 67 | printf("\treftype: %s", printId(&nonHierRef->refType)); 68 | printf(" target: %s\n", printId(&nonHierRef->target)); 69 | nonHierRef = nonHierRef->next; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /backends/stdout/examples/main.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2019 (c) Matthias Konnerth 6 | */ 7 | 8 | #include "backend.h" 9 | #include 10 | #include 11 | 12 | int main(int argc, char *argv[]) 13 | { 14 | if (argc < 2) 15 | { 16 | printf("specify nodesetfile as argument. E.g. parserDemo text.xml\n"); 17 | return 1; 18 | } 19 | 20 | int maxValueRank = -1; 21 | NL_FileContext handler; 22 | handler.addNamespace = addNamespace; 23 | handler.userContext = &maxValueRank; 24 | 25 | NodesetLoader *loader = NodesetLoader_new(NULL, NULL); 26 | 27 | for (int cnt = 1; cnt < argc; cnt++) 28 | { 29 | handler.file = argv[cnt]; 30 | if (!NodesetLoader_importFile(loader, &handler)) 31 | { 32 | printf("nodeset could not be loaded, exit\n"); 33 | return 1; 34 | } 35 | } 36 | 37 | NodesetLoader_sort(loader); 38 | 39 | for (int i = 0; i < NL_NODECLASS_COUNT; i++) 40 | { 41 | NodesetLoader_forEachNode(loader, (NL_NodeClass)i, NULL, (NodesetLoader_forEachNode_Func)dumpNode); 42 | } 43 | 44 | NodesetLoader_delete(loader); 45 | 46 | printf("maxValue Rank: %d", maxValueRank); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /cmake/FindCheck.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find the CHECK libraries 2 | # Once done this will define 3 | # 4 | # CHECK_FOUND - system has check 5 | # CHECK_INCLUDE_DIR - the check include directory 6 | # CHECK_LIBRARIES - check library 7 | # 8 | # This configuration file for finding libcheck is originally from 9 | # the opensync project. The originally was downloaded from here: 10 | # opensync.org/browser/branches/3rd-party-cmake-modules/modules/FindCheck.cmake 11 | # 12 | # Copyright (c) 2007 Daniel Gollub 13 | # Copyright (c) 2007 Bjoern Ricks 14 | # 15 | # Redistribution and use is allowed according to the terms of the New 16 | # BSD license. 17 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 18 | 19 | 20 | INCLUDE( FindPkgConfig ) 21 | 22 | # Take care about check.pc settings 23 | PKG_SEARCH_MODULE( CHECK check ) 24 | 25 | # Look for CHECK include dir and libraries 26 | IF( NOT CHECK_FOUND ) 27 | IF ( CHECK_INSTALL_DIR ) 28 | MESSAGE ( STATUS "Using override CHECK_INSTALL_DIR to find check" ) 29 | SET ( CHECK_INCLUDE_DIR "${CHECK_INSTALL_DIR}/include" ) 30 | SET ( CHECK_INCLUDE_DIRS "${CHECK_INCLUDE_DIR}" ) 31 | FIND_LIBRARY( CHECK_LIBRARY NAMES check PATHS "${CHECK_INSTALL_DIR}/lib" ) 32 | FIND_LIBRARY( COMPAT_LIBRARY NAMES compat PATHS "${CHECK_INSTALL_DIR}/lib" ) 33 | SET ( CHECK_LIBRARIES "${CHECK_LIBRARY}" "${COMPAT_LIBRARY}" ) 34 | ELSE ( CHECK_INSTALL_DIR ) 35 | FIND_PATH( CHECK_INCLUDE_DIR check.h ) 36 | FIND_LIBRARY( CHECK_LIBRARIES NAMES check ) 37 | ENDIF ( CHECK_INSTALL_DIR ) 38 | 39 | IF ( CHECK_INCLUDE_DIR AND CHECK_LIBRARIES ) 40 | SET( CHECK_FOUND 1 ) 41 | IF ( NOT Check_FIND_QUIETLY ) 42 | MESSAGE ( STATUS "Found CHECK: ${CHECK_LIBRARIES}" ) 43 | ENDIF ( NOT Check_FIND_QUIETLY ) 44 | ELSE ( CHECK_INCLUDE_DIR AND CHECK_LIBRARIES ) 45 | IF ( Check_FIND_REQUIRED ) 46 | MESSAGE( FATAL_ERROR "Could NOT find CHECK" ) 47 | ELSE ( Check_FIND_REQUIRED ) 48 | IF ( NOT Check_FIND_QUIETLY ) 49 | MESSAGE( STATUS "Could NOT find CHECK" ) 50 | ENDIF ( NOT Check_FIND_QUIETLY ) 51 | ENDIF ( Check_FIND_REQUIRED ) 52 | ENDIF ( CHECK_INCLUDE_DIR AND CHECK_LIBRARIES ) 53 | ENDIF( NOT CHECK_FOUND ) 54 | 55 | # Hide advanced variables from CMake GUIs 56 | MARK_AS_ADVANCED( CHECK_INCLUDE_DIR CHECK_LIBRARIES ) -------------------------------------------------------------------------------- /conanfile.txt: -------------------------------------------------------------------------------- 1 | [generators] 2 | CMakeDeps 3 | CMakeToolchain 4 | 5 | [requires] 6 | libxml2/2.9.9 7 | libcheck/0.15.2 8 | open62541/1.4.6 9 | 10 | [options] 11 | libxml2*:shared=False 12 | libxml2*:iconv=False 13 | libcheck*:with_subunit=False 14 | 15 | 16 | -------------------------------------------------------------------------------- /coverage/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_program(LCOV lcov) 2 | 3 | if (LCOV) 4 | # Final tracefile for code coverage 5 | set(OUTPUT_FILE "coverage.info") 6 | 7 | # Directory where to generate the HTML report 8 | # set(REPORT_DIR "codecov-report") 9 | 10 | 11 | # The baseline run needs to run before tests to learn what zero 12 | # coverage looks like 13 | add_custom_command( 14 | OUTPUT ${OUTPUT_FILE} 15 | COMMENT "Generating code coverage base file" 16 | COMMAND ${LCOV} 17 | --capture 18 | --no-external # Do not include external source files 19 | --base-directory ${CMAKE_SOURCE_DIR} 20 | --directory ${CMAKE_BINARY_DIR} 21 | --output-file ${OUTPUT_FILE} 22 | DEPENDS NodesetLoader) 23 | 24 | add_custom_target(coverage 25 | DEPENDS 26 | ${OUTPUT_FILE}) 27 | endif() -------------------------------------------------------------------------------- /include/NodesetLoader/Extension.h: -------------------------------------------------------------------------------- 1 | #ifndef NODESETLOADER_EXTENSION_H 2 | #define NODESETLOADER_EXTENSION_H 3 | 4 | typedef void *(*NodesetLoader_newExtensionCb)(void); 5 | typedef void (*NodesetLoader_startExtensionCb)(void *extensionData, 6 | const char *name, 7 | int nAttributes, 8 | const char **attributes); 9 | typedef void (*NodesetLoader_endExtensionCb)(void *extensionData, 10 | const char *name, 11 | const char *value); 12 | typedef void (*NodesetLoader_finishExtensionCb)(void *extensionData); 13 | 14 | typedef struct 15 | { 16 | void *userContext; 17 | NodesetLoader_newExtensionCb newExtension; 18 | NodesetLoader_startExtensionCb start; 19 | NodesetLoader_endExtensionCb end; 20 | NodesetLoader_finishExtensionCb finish; 21 | } NodesetLoader_ExtensionInterface; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /include/NodesetLoader/Logger.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef NODESETLOADER_LOGGER_H 9 | #define NODESETLOADER_LOGGER_H 10 | 11 | struct NodesetLoader_Logger; 12 | typedef struct NodesetLoader_Logger NodesetLoader_Logger; 13 | 14 | enum NodesetLoader_LogLevel 15 | { 16 | NODESETLOADER_LOGLEVEL_DEBUG, 17 | NODESETLOADER_LOGLEVEL_WARNING, 18 | NODESETLOADER_LOGLEVEL_ERROR 19 | }; 20 | 21 | typedef void (*NodesetLoader_Logger_log)(void *context, 22 | enum NodesetLoader_LogLevel level, 23 | const char *message, ...); 24 | struct NodesetLoader_Logger 25 | { 26 | void *context; 27 | NodesetLoader_Logger_log log; 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /include/NodesetLoader/ReferenceService.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef NODESETLOADER_REFERENCESERVICE_H 9 | #define NODESETLOADER_REFERENCESERVICE_H 10 | #include 11 | 12 | struct NL_Reference; 13 | struct NL_ReferenceTypeNode; 14 | typedef bool (*RefService_isRefHierachical)(void* context, const struct NL_Reference* ref); 15 | typedef bool (*RefService_isRefNonHierachical)(void* context, const struct NL_Reference *ref); 16 | typedef bool (*RefService_isHasTypeDefRef)(void *context, const struct NL_Reference *ref); 17 | typedef void (*RefService_addNewReferenceType)(void* context, const struct NL_ReferenceTypeNode* node); 18 | struct NL_ReferenceService 19 | { 20 | void* context; 21 | RefService_isRefHierachical isHierachicalRef; 22 | RefService_isRefNonHierachical isNonHierachicalRef; 23 | RefService_isHasTypeDefRef isHasTypeDefRef; 24 | RefService_addNewReferenceType addNewReferenceType; 25 | }; 26 | typedef struct NL_ReferenceService NL_ReferenceService; 27 | #endif 28 | -------------------------------------------------------------------------------- /include/NodesetLoader/arch.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef NODESETLOADER_ARCH_H 9 | #define NODESETLOADER_ARCH_H 10 | 11 | /* this is taken from open62541.com */ 12 | #if defined(_WIN32) 13 | #ifdef __GNUC__ 14 | #define LOADER_EXPORT __attribute__((dllexport)) 15 | #else 16 | #define LOADER_EXPORT __declspec(dllexport) 17 | #endif 18 | #else /* non win32 */ 19 | #if __GNUC__ || __clang__ 20 | #define LOADER_EXPORT __attribute__((visibility("default"))) 21 | #endif 22 | #endif 23 | 24 | #ifndef LOADER_EXPORT 25 | #define LOADER_EXPORT /* fallback to default */ 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /nodesetloader-config.cmake: -------------------------------------------------------------------------------- 1 | get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) 2 | include(${SELF_DIR}/NodesetLoader.cmake) -------------------------------------------------------------------------------- /nodesets/euromap/Opc.Ua.PlasticsRubber.IMM2MES.NodeSet2.bsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | This Enumeration specifies the values to be used in the Classification property in the MessageConditionType and related logbook events of OPC 40083 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 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /nodesets/euromap_instances/euromapinstances.tt2pro: -------------------------------------------------------------------------------- 1 | ########################### 2 | # UaModeler Project File # 3 | # Generated at 08.06.2020 # 4 | ########################### 5 | 6 | PROJECTNAME = EuromapInstances 7 | 8 | TEMPLATESET = ($TEMPLATES)/ansi_c/v1_9/t1/ansi_c.tt2set 9 | 10 | MODELS += ($MODELS)/Opc.Ua.NodeSet2.ua \ 11 | ($MODELS)/Opc.Ua.Di.NodeSet2.ua \ 12 | ../euromap/Opc.Ua.PlasticsRubber.GeneralTypes.NodeSet2.ua \ 13 | ../euromap/Opc.Ua.PlasticsRubber.IMM2MES.NodeSet2.ua \ 14 | euromapinstances.ua 15 | 16 | COLORS = ($MODELS)/Opc.Ua.NodeSet2.ua: #0000ff\ 17 | ($MODELS)/Opc.Ua.Di.NodeSet2.ua: #0000ff\ 18 | ../euromap/Opc.Ua.PlasticsRubber.GeneralTypes.NodeSet2.ua: #0000ff\ 19 | ../euromap/Opc.Ua.PlasticsRubber.IMM2MES.NodeSet2.ua: #0000ff\ 20 | euromapinstances.ua: #0000ff 21 | 22 | PROJECTVARIABLES += ProviderName = EuromapInstances \ 23 | alarmAndEvents = false 24 | 25 | OUTPUTPATH = 26 | 27 | NODEACCESSINFOROLES += Administrator \ 28 | SecurityAdmin \ 29 | ConfigurationAdmin \ 30 | Operator \ 31 | Observer 32 | 33 | -------------------------------------------------------------------------------- /nodesets/struct_union_optionset/structtest.csv: -------------------------------------------------------------------------------- 1 | TSimple,3002,DataType 2 | TSimpleUnion,3003,DataType 3 | TComplexUnion,3004,DataType 4 | MyOptionSet,3005,DataType 5 | My_UInt64_OptionSet,3006,DataType 6 | TNested_1,3007,DataType 7 | TOptional,3008,DataType 8 | TAllOptional,3009,DataType 9 | TSimple_Encoding_DefaultBinary,5001,Object 10 | TSimple_Encoding_DefaultXml,5002,Object 11 | TSimple_Encoding_DefaultJson,5003,Object 12 | TSimpleUnion_Encoding_DefaultBinary,5004,Object 13 | Structs,5005,Object 14 | Unions,5006,Object 15 | TSimpleUnion_Encoding_DefaultXml,5007,Object 16 | TSimpleUnion_Encoding_DefaultJson,5008,Object 17 | TComplexUnion_Encoding_DefaultBinary,5009,Object 18 | TComplexUnion_Encoding_DefaultXml,5010,Object 19 | TComplexUnion_Encoding_DefaultJson,5011,Object 20 | Server_Namespaces_http___yourorganisation_org_StructTest_,5012,Object 21 | OptionSets,5013,Object 22 | TNested_1_Encoding_DefaultBinary,5014,Object 23 | TNested_1_Encoding_DefaultXml,5015,Object 24 | TNested_1_Encoding_DefaultJson,5016,Object 25 | TOptional_Encoding_DefaultBinary,5017,Object 26 | TOptional_Encoding_DefaultXml,5018,Object 27 | TOptional_Encoding_DefaultJson,5019,Object 28 | TAllOptional_Encoding_DefaultBinary,5020,Object 29 | TAllOptional_Encoding_DefaultXml,5021,Object 30 | TAllOptional_Encoding_DefaultJson,5022,Object 31 | My_UInt64_OptionSet_OptionSetValues,6001,Variable 32 | Structs_Simple_Null,6002,Variable 33 | Unions_Simple_D3,6003,Variable 34 | Unions_Simple_D1,6004,Variable 35 | Unions_Simple_D4,6005,Variable 36 | Unions_Simple_D1_Arr_DIM_1_LEN_3,6006,Variable 37 | Structs_Simple,6007,Variable 38 | Structs_SimpleArr_DIM_1_LEN_2,6008,Variable 39 | Structs_SimpleArr_DIM_2,6009,Variable 40 | Unions_Complex_D1,6010,Variable 41 | Unions_Complex_D2,6011,Variable 42 | Unions_Complex_D7_maxStringLength,6012,Variable 43 | Unions_Complex_D4,6013,Variable 44 | Unions_Complex_D4_Arr_DIM_1_LEN_2,6014,Variable 45 | Unions_Simple_D2,6015,Variable 46 | Server_Namespaces_http___yourorganisation_org_StructTest__IsNamespaceSubset,6016,Variable 47 | OptionSets_My_UInt64_OptionSet_Bit_B,6017,Variable 48 | OptionSets_My_UInt64_OptionSet_Bit_C,6018,Variable 49 | OptionSets_DataSetFieldFlag,6019,Variable 50 | Server_Namespaces_http___yourorganisation_org_StructTest__NamespacePublicationDate,6020,Variable 51 | MyOptionSet_OptionSetValues,6021,Variable 52 | Server_Namespaces_http___yourorganisation_org_StructTest__NamespaceUri,6022,Variable 53 | Server_Namespaces_http___yourorganisation_org_StructTest__NamespaceVersion,6023,Variable 54 | Server_Namespaces_http___yourorganisation_org_StructTest__StaticNodeIdTypes,6024,Variable 55 | Server_Namespaces_http___yourorganisation_org_StructTest__StaticNumericNodeIdRange,6025,Variable 56 | Server_Namespaces_http___yourorganisation_org_StructTest__StaticStringNodeIdPattern,6026,Variable 57 | Structs_MyOptionalStruct_1,6028,Variable 58 | Structs_MyOptionalStruct_2,6029,Variable 59 | Structs_MyOptionalStruct_3,6030,Variable 60 | Structs_MyNestedStruct,6031,Variable 61 | -------------------------------------------------------------------------------- /nodesets/struct_union_optionset/structtest.tt2pro: -------------------------------------------------------------------------------- 1 | ########################### 2 | # UaModeler Project File # 3 | # Generated at 08.06.2020 # 4 | ########################### 5 | 6 | PROJECTNAME = StructTest 7 | 8 | TEMPLATESET = ($TEMPLATES)/ansi_c/v1_8/t2/ansi_c.tt2set 9 | 10 | MODELS += ($MODELS)/Opc.Ua.NodeSet2.ua \ 11 | structtest.ua 12 | 13 | COLORS = ($MODELS)/Opc.Ua.NodeSet2.ua: #0000ff\ 14 | structtest.ua: #008000 15 | 16 | PROJECTVARIABLES += ProviderName = StructTest \ 17 | alarmAndEvents = false 18 | 19 | OUTPUTPATH = 20 | 21 | GENERATE += structtest.ua 22 | 23 | NODEACCESSINFOROLES += Administrator \ 24 | SecurityAdmin \ 25 | ConfigurationAdmin \ 26 | Operator \ 27 | Observer 28 | 29 | -------------------------------------------------------------------------------- /runCppcheck.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cppcheck . -i src_generated -i CMakeFiles 3 | -------------------------------------------------------------------------------- /runLcov.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | lcov --capture --directory ./build --output-file coverage.info 3 | lcov --remove coverage.info '/usr/*' --output-file coverage.info 4 | #lcov --remove coverage.info '*/open62541/*' --output-file coverage.info 5 | lcov --remove coverage.info '*tests*' --output-file coverage.info 6 | lcov --remove coverage.info '*conan*' --output-file coverage.info 7 | lcov --list coverage.info 8 | genhtml coverage.info --output-directory coverageHtml 9 | chromium ./coverage/index.html -------------------------------------------------------------------------------- /src/AliasList.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #include "AliasList.h" 9 | #include 10 | #include 11 | 12 | #define MAX_ALIAS 300 13 | 14 | struct AliasList 15 | { 16 | Alias *data; 17 | size_t size; 18 | }; 19 | 20 | AliasList *AliasList_new(void) 21 | { 22 | struct AliasList *list = (AliasList *)calloc(1, sizeof(*list)); 23 | if(!list) 24 | { 25 | return NULL; 26 | } 27 | list->data = (Alias *)calloc(MAX_ALIAS, sizeof(Alias)); 28 | if(!list->data) 29 | { 30 | free(list); 31 | return NULL; 32 | } 33 | return list; 34 | } 35 | 36 | Alias *AliasList_newAlias(AliasList *list, char *name) 37 | { 38 | if(list->size >= MAX_ALIAS) 39 | { 40 | return NULL; 41 | } 42 | list->data[list->size].name = name; 43 | UA_NodeId_init(&list->data[list->size].id); 44 | list->size++; 45 | return &list->data[list->size - 1]; 46 | } 47 | 48 | const UA_NodeId * 49 | AliasList_getNodeId(const AliasList *list, const char *name) { 50 | if(!name) 51 | return NULL; 52 | 53 | for(Alias* alias = list->data; alias != list->data + list->size; alias++) { 54 | if (!strcmp(name, alias->name)) 55 | return &alias->id; 56 | } 57 | return NULL; 58 | } 59 | 60 | void AliasList_delete(AliasList *list) 61 | { 62 | free(list->data); 63 | free(list); 64 | } 65 | -------------------------------------------------------------------------------- /src/AliasList.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef ALIASLIST_H 9 | #define ALIASLIST_H 10 | 11 | #include "NodesetLoader/NodesetLoader.h" 12 | 13 | struct Alias 14 | { 15 | char *name; 16 | UA_NodeId id; 17 | }; 18 | 19 | typedef struct Alias Alias; 20 | 21 | struct AliasList; 22 | typedef struct AliasList AliasList; 23 | AliasList *AliasList_new(void); 24 | Alias *AliasList_newAlias(AliasList *list, char *name); 25 | const UA_NodeId *AliasList_getNodeId(const AliasList *list, const char *alias); 26 | void AliasList_delete(AliasList *list); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/CharAllocator.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #include "CharAllocator.h" 9 | #include 10 | #include 11 | 12 | struct Region; 13 | 14 | struct Region 15 | { 16 | size_t capacity; 17 | size_t size; 18 | struct Region *next; 19 | char *mem; 20 | char *userPtr; 21 | size_t userSize; 22 | }; 23 | 24 | struct CharArenaAllocator 25 | { 26 | size_t initialSize; 27 | struct Region *current; 28 | }; 29 | 30 | static struct Region *Region_new(size_t capacity) 31 | { 32 | struct Region *region = (struct Region *)calloc(1, sizeof(struct Region)); 33 | if(!region) 34 | { 35 | return NULL; 36 | } 37 | region->mem = (char *)calloc(capacity, sizeof(char)); 38 | if(!region->mem) 39 | { 40 | free(region); 41 | return NULL; 42 | } 43 | region->capacity = capacity; 44 | region->userPtr = region->mem; 45 | return region; 46 | } 47 | 48 | CharArenaAllocator *CharArenaAllocator_new(size_t initialSize) 49 | { 50 | CharArenaAllocator *arena = 51 | (CharArenaAllocator *)calloc(1, sizeof(CharArenaAllocator)); 52 | if(!arena) 53 | { 54 | return NULL; 55 | } 56 | arena->initialSize = initialSize; 57 | arena->current = Region_new(arena->initialSize); 58 | return arena; 59 | } 60 | 61 | static size_t getRegionSize(size_t requested, size_t initialArenaSize) 62 | { 63 | size_t regionSize = initialArenaSize; 64 | if (requested > initialArenaSize) 65 | { 66 | regionSize = requested * 2; 67 | } 68 | return regionSize; 69 | } 70 | 71 | char *CharArenaAllocator_malloc(CharArenaAllocator *arena, size_t size) 72 | { 73 | if ((arena->current->size + size) > arena->current->capacity) 74 | { 75 | struct Region *newRegion = Region_new(getRegionSize(size, arena->initialSize)); 76 | if (!newRegion) 77 | { 78 | return NULL; 79 | } 80 | newRegion->next = arena->current; 81 | arena->current = newRegion; 82 | } 83 | arena->current->userPtr = arena->current->mem + arena->current->size; 84 | arena->current->size += size; 85 | arena->current->userSize = size; 86 | return arena->current->userPtr; 87 | } 88 | 89 | char *CharArenaAllocator_realloc(CharArenaAllocator *arena, size_t size) 90 | { 91 | if ((arena->current->size + size) > arena->current->capacity) 92 | { 93 | // we also have to consider the size we have to transfer 94 | struct Region *newRegion = 95 | Region_new(getRegionSize(size + arena->current->userSize*2, arena->initialSize)); 96 | if (!newRegion) 97 | { 98 | return NULL; 99 | } 100 | //we have to copy over the old stuff 101 | memcpy(newRegion->userPtr, arena->current->userPtr, arena->current->userSize); 102 | newRegion->userSize = arena->current->userSize; 103 | newRegion->next = arena->current; 104 | newRegion->size = newRegion->userSize; 105 | arena->current = newRegion; 106 | } 107 | arena->current->userSize += size; 108 | arena->current->size += size; 109 | return arena->current->userPtr; 110 | } 111 | 112 | void CharArenaAllocator_delete(CharArenaAllocator *arena) 113 | { 114 | struct Region *r = arena->current; 115 | while (r) 116 | { 117 | struct Region *tmp = r->next; 118 | free(r->mem); 119 | free(r); 120 | r = tmp; 121 | } 122 | free(arena); 123 | } 124 | -------------------------------------------------------------------------------- /src/CharAllocator.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef CHARALLOCATOR_H 9 | #define CHARALLOCATOR_H 10 | #include 11 | 12 | struct CharArenaAllocator; 13 | typedef struct CharArenaAllocator CharArenaAllocator; 14 | 15 | CharArenaAllocator *CharArenaAllocator_new(size_t initialSize); 16 | char *CharArenaAllocator_malloc(struct CharArenaAllocator *arena, size_t size); 17 | char *CharArenaAllocator_realloc(struct CharArenaAllocator *arena, size_t size); 18 | void CharArenaAllocator_delete(struct CharArenaAllocator *arena); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/InternalLogger.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef INTERNALLOGGER_H 9 | #define INTERNALLOGGER_H 10 | 11 | #include "NodesetLoader/Logger.h" 12 | 13 | NodesetLoader_Logger *InternalLogger_new(void); 14 | void InternalLogger_delete(NodesetLoader_Logger *logger); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/InternalRefService.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef INTERNALREFSERVICE_H 9 | #define INTERNALREFSERVICE_H 10 | #include "NodesetLoader/ReferenceService.h" 11 | 12 | NL_ReferenceService *InternalRefService_new(void); 13 | void InternalRefService_delete(NL_ReferenceService *service); 14 | #endif 15 | -------------------------------------------------------------------------------- /src/NamespaceList.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #include "NamespaceList.h" 9 | #include 10 | 11 | struct NamespaceList 12 | { 13 | size_t size; 14 | Namespace *data; 15 | NL_addNamespaceCallback cb; 16 | }; 17 | 18 | NamespaceList *NamespaceList_new(NL_addNamespaceCallback cb) 19 | { 20 | NamespaceList *list = (NamespaceList *)calloc(1, sizeof(NamespaceList)); 21 | if(!list) 22 | { 23 | return NULL; 24 | } 25 | list->cb = cb; 26 | list->size = 1; 27 | list->data = (Namespace *)calloc(1, sizeof(Namespace)); 28 | if(!list->data) 29 | { 30 | free(list); 31 | return NULL; 32 | } 33 | list->data[0].name = "http://opcfoundation.org/UA/"; 34 | list->data[0].idx = 0; 35 | return list; 36 | } 37 | 38 | void NamespaceList_delete(NamespaceList *list) 39 | { 40 | free(list->data); 41 | free(list); 42 | } 43 | 44 | Namespace *NamespaceList_newNamespace(NamespaceList *list, void *userContext, 45 | const char *uri) 46 | { 47 | // ask backend to create/get overall namespaceIndex 48 | short unsigned globalIdx = list->cb(userContext, uri); 49 | list->size++; 50 | list->data = 51 | (Namespace *)realloc(list->data, sizeof(Namespace) * list->size); 52 | if(!list->data) 53 | { 54 | return NULL; 55 | } 56 | list->data[list->size - 1].name = uri; 57 | list->data[list->size - 1].idx = globalIdx; 58 | return &list->data[list->size - 1]; 59 | } 60 | 61 | const Namespace *NamespaceList_getNamespace(const NamespaceList *list, 62 | int relativeIndex) 63 | { 64 | if((size_t)relativeIndex >=list->size) 65 | { 66 | return NULL; 67 | } 68 | return &list->data[relativeIndex]; 69 | } 70 | -------------------------------------------------------------------------------- /src/NamespaceList.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef NAMESPACELIST_H 9 | #define NAMESPACELIST_H 10 | #include "NodesetLoader/NodesetLoader.h" 11 | 12 | struct NamespaceList; 13 | typedef struct NamespaceList NamespaceList; 14 | 15 | struct Namespace; 16 | typedef struct Namespace Namespace; 17 | 18 | struct Namespace 19 | { 20 | short unsigned idx; 21 | const char *name; 22 | }; 23 | 24 | NamespaceList *NamespaceList_new(NL_addNamespaceCallback cb); 25 | Namespace *NamespaceList_newNamespace(NamespaceList *list, void *userContext, 26 | const char *uri); 27 | void NamespaceList_setUri(NamespaceList *list, Namespace *ns); 28 | void NamespaceList_delete(NamespaceList *list); 29 | const Namespace *NamespaceList_getNamespace(const NamespaceList *list, 30 | int relativeIndex); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/Nodeset.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2019 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef NODESET_H 9 | #define NODESET_H 10 | 11 | #include "CharAllocator.h" 12 | #include "NodesetLoader/NodesetLoader.h" 13 | 14 | #include 15 | #include 16 | 17 | struct Nodeset; 18 | typedef struct Nodeset Nodeset; 19 | struct Alias; 20 | struct TParserCtx; 21 | typedef struct TParserCtx TParserCtx; 22 | 23 | struct NamespaceList; 24 | 25 | struct NodeContainer; 26 | struct AliasList; 27 | struct SortContext; 28 | struct Nodeset 29 | { 30 | CharArenaAllocator *charArena; 31 | struct AliasList *aliasList; 32 | struct NodeContainer *nodes[NL_NODECLASS_COUNT]; 33 | struct NamespaceList *namespaces; 34 | struct SortContext *sortCtx; 35 | NL_BiDirectionalReference *hasEncodingRefs; 36 | NodesetLoader_Logger* logger; 37 | struct NodeContainer *nodesWithUnknownRefs; 38 | struct NodeContainer *refTypesWithUnknownRefs; 39 | NL_ReferenceService* refService; 40 | }; 41 | 42 | Nodeset *Nodeset_new(NL_addNamespaceCallback nsCallback, NodesetLoader_Logger* logger, NL_ReferenceService* refService); 43 | void Nodeset_cleanup(Nodeset *nodeset); 44 | bool Nodeset_sort(Nodeset *nodeset); 45 | NL_Node *Nodeset_newNode(Nodeset *nodeset, NL_NodeClass nodeClass, 46 | int attributeSize, const char **attributes); 47 | void Nodeset_newNodeFinish(Nodeset *nodeset, NL_Node *node); 48 | NL_Reference *Nodeset_newReference(Nodeset *nodeset, NL_Node *node, 49 | int attributeSize, const char **attributes); 50 | void Nodeset_newReferenceFinish(Nodeset *nodeset, NL_Reference *ref, NL_Node *node, 51 | char *targetId); 52 | struct Alias *Nodeset_newAlias(Nodeset *nodeset, int attributeSize, 53 | const char **attribute); 54 | void Nodeset_newAliasFinish(Nodeset *nodeset, struct Alias *alias, 55 | char *idString); 56 | void Nodeset_newNamespaceFinish(Nodeset *nodeset, void *userContext, 57 | char *namespaceUri); 58 | void Nodeset_addDataTypeDefinition(Nodeset *nodeset, NL_Node *node, int attributeSize, 59 | const char **attributes); 60 | void Nodeset_addDataTypeField(Nodeset *nodeset, NL_Node *node, int attributeSize, 61 | const char **attributes); 62 | void Nodeset_setDisplayName(Nodeset *nodeset, NL_Node *node, int attributeSize, 63 | const char **attributes); 64 | void Nodeset_DisplayNameFinish(const Nodeset *nodeset, NL_Node *node, char *text); 65 | void Nodeset_setDescription(Nodeset *nodeset, NL_Node *node, int attributeSize, 66 | const char **attributes); 67 | void Nodeset_DescriptionFinish(const Nodeset *nodeset, NL_Node *node, char *text); 68 | void Nodeset_setInverseName(Nodeset *nodeset, NL_Node *node, int attributeSize, 69 | const char **attributes); 70 | void Nodeset_InverseNameFinish(const Nodeset *nodeset, NL_Node *node, char *text); 71 | const NL_BiDirectionalReference * 72 | Nodeset_getBiDirectionalRefs(const Nodeset *nodeset); 73 | size_t Nodeset_forEachNode(Nodeset *nodeset, NL_NodeClass nodeClass, 74 | void *context, NodesetLoader_forEachNode_Func fn); 75 | #endif 76 | -------------------------------------------------------------------------------- /src/Parser.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #include "Parser.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | struct Parser 15 | { 16 | void *context; 17 | }; 18 | 19 | Parser *Parser_new(void *context) 20 | { 21 | Parser *parser = (Parser *)calloc(1, sizeof(Parser)); 22 | assert(parser); 23 | parser->context = context; 24 | return parser; 25 | } 26 | 27 | int Parser_run(Parser *parser, FILE *file, Parser_callbackStart start, 28 | Parser_callbackEnd end, Parser_callbackChar onChars) 29 | { 30 | char chars[1024]; 31 | int res = (int)fread(chars, 1, 4, file); 32 | if (res <= 0) 33 | { 34 | return 1; 35 | } 36 | 37 | xmlSAXHandler hdl; 38 | memset(&hdl, 0, sizeof(xmlSAXHandler)); 39 | hdl.initialized = XML_SAX2_MAGIC; 40 | // nodesets are encoded with UTF-8 41 | // this code does no transformation on the encoded text or interprets it 42 | // so it should be safe to cast xmlChar* to char* 43 | hdl.startElementNs = (startElementNsSAX2Func)start; 44 | hdl.endElementNs = (endElementNsSAX2Func)end; 45 | hdl.characters = (charactersSAXFunc)onChars; 46 | xmlInitParser(); // Fix memory leak: https://gitlab.gnome.org/GNOME/libxml2/-/issues/9 47 | xmlParserCtxtPtr ctxt = 48 | xmlCreatePushParserCtxt(&hdl, parser->context, chars, res, NULL); 49 | while ((res = (int)fread(chars, 1, sizeof(chars), file)) > 0) 50 | { 51 | if (xmlParseChunk(ctxt, chars, res, 0)) 52 | { 53 | xmlParserError(ctxt, "xmlParseChunk"); 54 | return 1; 55 | } 56 | } 57 | xmlParseChunk(ctxt, chars, 0, 1); 58 | xmlFreeParserCtxt(ctxt); 59 | xmlCleanupParser(); 60 | return 0; 61 | } 62 | void Parser_delete(Parser *parser) { free(parser); } 63 | -------------------------------------------------------------------------------- /src/Parser.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef PARSER_H 9 | #define PARSER_H 10 | #include 11 | 12 | struct Parser; 13 | typedef struct Parser Parser; 14 | 15 | typedef void (*Parser_callbackStart)(void *ctx, const char *localname, 16 | const char *prefix, const char *URI, 17 | int nb_namespaces, const char **namespaces, 18 | int nb_attributes, int nb_defaulted, 19 | const char **attributes); 20 | 21 | typedef void (*Parser_callbackEnd)(void *ctx, const char *localname, 22 | const char *prefix, const char *URI); 23 | 24 | typedef void (*Parser_callbackChar)(void *ctx, const char *ch, int len); 25 | 26 | Parser *Parser_new(void *context); 27 | int Parser_run(Parser *parser, FILE *file, Parser_callbackStart start, 28 | Parser_callbackEnd end, Parser_callbackChar onChars); 29 | void Parser_delete(Parser *parser); 30 | #endif 31 | -------------------------------------------------------------------------------- /src/PrintfLogger.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #include "InternalLogger.h" 9 | #include 10 | #include 11 | #include 12 | 13 | static const char *logLevel[3] = {"Debug", "Warning", "Error"}; 14 | 15 | static void logStdOut(void *context, enum NodesetLoader_LogLevel level, 16 | const char *message, ...) 17 | { 18 | va_list vl; 19 | va_start(vl, message); 20 | va_end(vl); 21 | printf("NODESETLOADER: %s : %s\n", logLevel[level], message); 22 | } 23 | 24 | NodesetLoader_Logger *InternalLogger_new(void) 25 | { 26 | NodesetLoader_Logger *logger = 27 | (NodesetLoader_Logger *)calloc(1, sizeof(NodesetLoader_Logger)); 28 | logger->log = &logStdOut; 29 | return logger; 30 | } 31 | 32 | void InternalLogger_delete(NodesetLoader_Logger *logger) { free(logger); } 33 | -------------------------------------------------------------------------------- /src/Sort.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2019 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef SORT_H 9 | #define SORT_H 10 | 11 | #include 12 | #include "NodesetLoader/NodesetLoader.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | struct NL_Node; 19 | struct Nodeset; 20 | struct SortContext; 21 | struct NodesetLoader_Logger; 22 | typedef struct SortContext SortContext; 23 | SortContext* Sort_init(void); 24 | void Sort_cleanup(SortContext * ctx); 25 | bool Sort_addNode(SortContext* ctx, struct NL_Node *node); 26 | typedef void (*Sort_SortedNodeCallback)(struct Nodeset *nodeset, struct NL_Node *node); 27 | bool Sort_start(SortContext* ctx, struct Nodeset *nodeset, Sort_SortedNodeCallback callback, struct NodesetLoader_Logger* logger); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/Value.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #include "NodesetLoader/NodesetLoader.h" 9 | #include 10 | #include 11 | 12 | enum ParserState 13 | { 14 | PARSERSTATE_INIT, 15 | PARSERSTATE_LISTOF, 16 | PARSERSTATE_EXTENSIONOBJECT, 17 | PARSERSTATE_EXTENSIONOBJECT_TYPEID, 18 | PARSERSTATE_EXTENSIONOBJECT_BODY, 19 | PARSERSTATE_DATA, 20 | PARSERSTATE_FINISHED 21 | }; 22 | typedef enum ParserState ParserState; 23 | 24 | struct NL_ParserCtx 25 | { 26 | ParserState state; 27 | NL_Data *currentData; 28 | }; 29 | typedef struct NL_ParserCtx NL_ParserCtx; 30 | 31 | NL_Value *Value_new(const NL_Node *node); 32 | void Value_start(NL_Value *val, const char *name); 33 | void Value_end(NL_Value *val, const char *name, const char *value); 34 | void Value_delete(NL_Value *val); 35 | -------------------------------------------------------------------------------- /src/nodes/DataTypeNode.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #include "DataTypeNode.h" 9 | #include 10 | 11 | static NL_DataTypeDefinitionField *getNewField(NL_DataTypeDefinition *definition) 12 | { 13 | definition->fieldCnt++; 14 | definition->fields = (NL_DataTypeDefinitionField *)realloc( 15 | definition->fields, 16 | definition->fieldCnt * sizeof(NL_DataTypeDefinitionField)); 17 | if(!definition->fields) 18 | { 19 | return NULL; 20 | } 21 | return &definition->fields[definition->fieldCnt - 1]; 22 | } 23 | 24 | NL_DataTypeDefinition* DataTypeDefinition_new(NL_DataTypeNode* node) 25 | { 26 | node->definition = 27 | (NL_DataTypeDefinition *)calloc(1, sizeof(NL_DataTypeDefinition)); 28 | if (!node->definition) 29 | { 30 | return NULL; 31 | } 32 | return node->definition; 33 | } 34 | 35 | NL_DataTypeDefinitionField *DataTypeNode_addDefinitionField(NL_DataTypeDefinition *def) 36 | { 37 | return getNewField(def); 38 | } 39 | 40 | void DataTypeNode_clear(NL_DataTypeNode *node) 41 | { 42 | if (node->definition) 43 | { 44 | free(node->definition->fields); 45 | } 46 | free(node->definition); 47 | } 48 | -------------------------------------------------------------------------------- /src/nodes/DataTypeNode.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef DATATYPENODE_H 9 | #define DATATYPENODE_H 10 | #include "NodesetLoader/NodesetLoader.h" 11 | 12 | void DataTypeNode_clear(NL_DataTypeNode *node); 13 | NL_DataTypeDefinition *DataTypeDefinition_new(NL_DataTypeNode *node); 14 | NL_DataTypeDefinitionField *DataTypeNode_addDefinitionField(NL_DataTypeDefinition *def); 15 | #endif 16 | -------------------------------------------------------------------------------- /src/nodes/InstanceNode.c: -------------------------------------------------------------------------------- 1 | #include "NodesetLoader/NodesetLoader.h" 2 | 3 | bool NodesetLoader_isInstanceNode(const NL_Node *baseNode) 4 | { 5 | if (baseNode->nodeClass == NODECLASS_VARIABLE || 6 | baseNode->nodeClass == NODECLASS_OBJECT || 7 | baseNode->nodeClass == NODECLASS_METHOD || 8 | baseNode->nodeClass == NODECLASS_VIEW) 9 | { 10 | return true; 11 | } 12 | return false; 13 | } 14 | -------------------------------------------------------------------------------- /src/nodes/Node.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #include "Node.h" 9 | #include "DataTypeNode.h" 10 | #include 11 | #include "Value.h" 12 | 13 | NL_Node *Node_new(NL_NodeClass nodeClass) 14 | { 15 | void *node = NULL; 16 | switch (nodeClass) 17 | { 18 | case NODECLASS_VARIABLE: 19 | node = calloc(1, sizeof(NL_VariableNode)); 20 | break; 21 | case NODECLASS_OBJECT: 22 | node = calloc(1, sizeof(NL_ObjectNode)); 23 | break; 24 | case NODECLASS_OBJECTTYPE: 25 | node = calloc(1, sizeof(NL_ObjectTypeNode)); 26 | break; 27 | case NODECLASS_REFERENCETYPE: 28 | node = calloc(1, sizeof(NL_ReferenceTypeNode)); 29 | break; 30 | case NODECLASS_VARIABLETYPE: 31 | node = calloc(1, sizeof(NL_VariableTypeNode)); 32 | break; 33 | case NODECLASS_DATATYPE: 34 | node = calloc(1, sizeof(NL_DataTypeNode)); 35 | break; 36 | case NODECLASS_METHOD: 37 | node = calloc(1, sizeof(NL_MethodNode)); 38 | break; 39 | case NODECLASS_VIEW: 40 | node = calloc(1, sizeof(NL_ViewNode)); 41 | break; 42 | } 43 | if(!node) 44 | { 45 | return NULL; 46 | } 47 | return (NL_Node*)node; 48 | } 49 | 50 | static void deleteRef(NL_Reference *ref) 51 | { 52 | while (ref) 53 | { 54 | NL_Reference *tmp = ref->next; 55 | UA_NodeId_clear(&ref->target); 56 | UA_NodeId_clear(&ref->refType); 57 | free(ref); 58 | ref = tmp; 59 | } 60 | } 61 | 62 | void Node_delete(NL_Node *node) 63 | { 64 | UA_NodeId_clear(&node->id); 65 | deleteRef(node->hierachicalRefs); 66 | deleteRef(node->nonHierachicalRefs); 67 | if (node->nodeClass == NODECLASS_DATATYPE) 68 | { 69 | DataTypeNode_clear((NL_DataTypeNode *)node); 70 | } 71 | if(node->nodeClass == NODECLASS_VARIABLE) 72 | { 73 | NL_VariableNode* varNode = (NL_VariableNode*)node; 74 | free(varNode->refToTypeDef); 75 | UA_NodeId_clear(&varNode->parentNodeId); 76 | if(varNode->value) 77 | { 78 | Value_delete(varNode->value); 79 | } 80 | } 81 | if(node->nodeClass==NODECLASS_OBJECT) 82 | { 83 | NL_ObjectNode *objNode = (NL_ObjectNode *)node; 84 | UA_NodeId_clear(&objNode->parentNodeId); 85 | free(objNode->refToTypeDef); 86 | } 87 | free(node); 88 | } 89 | -------------------------------------------------------------------------------- /src/nodes/Node.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef NODE_H 9 | #define NODE_H 10 | #include "NodesetLoader/NodesetLoader.h" 11 | 12 | NL_Node *Node_new(NL_NodeClass nodeClass); 13 | void Node_delete(NL_Node *node); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /src/nodes/NodeContainer.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #include "NodeContainer.h" 9 | #include "Node.h" 10 | #include 11 | 12 | NodeContainer *NodeContainer_new(size_t initialSize, bool owner) 13 | { 14 | NodeContainer *container = 15 | (NodeContainer *)calloc(1, sizeof(NodeContainer)); 16 | if(!container) 17 | { 18 | return NULL; 19 | } 20 | container->nodes = 21 | (NL_Node **)calloc(initialSize, sizeof(NL_Node*)); 22 | if(!container->nodes) 23 | { 24 | free(container); 25 | return NULL; 26 | } 27 | container->size = 0; 28 | container->capacity = initialSize; 29 | container->incrementSize = initialSize; 30 | container->owner = owner; 31 | return container; 32 | } 33 | 34 | void NodeContainer_add(NodeContainer *container, NL_Node *node) 35 | { 36 | if (container->size == container->capacity) 37 | { 38 | container->nodes = (NL_Node **)realloc( 39 | container->nodes, 40 | (container->size + container->incrementSize) * sizeof(void *)); 41 | if(!container->nodes) 42 | { 43 | return; 44 | } 45 | container->capacity += container->incrementSize; 46 | } 47 | container->nodes[container->size] = node; 48 | container->size++; 49 | } 50 | 51 | void NodeContainer_delete(NodeContainer *container) 52 | { 53 | if (container->owner) 54 | { 55 | for (size_t i = 0; i < container->size; i++) 56 | { 57 | Node_delete(container->nodes[i]); 58 | } 59 | } 60 | free(container->nodes); 61 | free(container); 62 | } 63 | -------------------------------------------------------------------------------- /src/nodes/NodeContainer.h: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * 5 | * Copyright 2020 (c) Matthias Konnerth 6 | */ 7 | 8 | #ifndef NODECONTAINER_H 9 | #define NODECONTAINER_H 10 | #include "Nodeset.h" 11 | 12 | struct NodeContainer 13 | { 14 | NL_Node **nodes; 15 | size_t size; 16 | size_t capacity; 17 | size_t incrementSize; 18 | bool owner; 19 | }; 20 | typedef struct NodeContainer NodeContainer; 21 | 22 | NodeContainer *NodeContainer_new(size_t initialSize, bool owner); 23 | void NodeContainer_delete(NodeContainer *container); 24 | void NodeContainer_add(NodeContainer *container, NL_Node *node); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(sort sort.c 2 | ${CMAKE_CURRENT_SOURCE_DIR}/../src/Sort.c 3 | ${CMAKE_CURRENT_SOURCE_DIR}/../src/nodes/InstanceNode.c) 4 | target_include_directories(sort PRIVATE ${CHECK_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../src ${CMAKE_CURRENT_SOURCE_DIR}/../include) 5 | target_link_libraries(sort PRIVATE ${CHECK_LIBRARIES} ${PTHREAD_LIB} coverageLib open62541::open62541) 6 | add_test(NAME sort_Test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND sort ${CMAKE_CURRENT_LIST_DIR}) 7 | 8 | add_executable(nodeContainer 9 | NodeContainer.c 10 | ${CMAKE_CURRENT_SOURCE_DIR}/../src/nodes/NodeContainer.c 11 | ${CMAKE_CURRENT_SOURCE_DIR}/../src/nodes/Node.c 12 | ${CMAKE_CURRENT_SOURCE_DIR}/../src/nodes/DataTypeNode.c 13 | ${CMAKE_CURRENT_SOURCE_DIR}/../src/Value.c 14 | ) 15 | target_include_directories(nodeContainer PRIVATE ${CHECK_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../include ${CMAKE_CURRENT_SOURCE_DIR}/../src) 16 | target_link_libraries(nodeContainer PRIVATE ${CHECK_LIBRARIES} ${PTHREAD_LIB} coverageLib open62541::open62541) 17 | add_test(NAME nodeContainer_Test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND nodeContainer ${CMAKE_CURRENT_LIST_DIR}) 18 | 19 | add_executable(value ValueTest.c ${CMAKE_CURRENT_SOURCE_DIR}/../src/Value.c) 20 | target_include_directories(value PRIVATE ${CHECK_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../include) 21 | target_link_libraries(value PRIVATE ${CHECK_LIBRARIES} ${PTHREAD_LIB} coverageLib open62541::open62541) 22 | add_test(NAME value_Test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND value ${CMAKE_CURRENT_LIST_DIR}) 23 | 24 | add_executable(allocator allocator.c ${CMAKE_CURRENT_SOURCE_DIR}/../src/CharAllocator.c) 25 | target_include_directories(allocator PRIVATE ${CHECK_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../src) 26 | target_link_libraries(allocator PRIVATE ${CHECK_LIBRARIES} ${PTHREAD_LIB} coverageLib open62541::open62541) 27 | add_test(NAME allocatorTest WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND allocator ${CMAKE_CURRENT_LIST_DIR}) 28 | 29 | add_executable(parser parser.c) 30 | target_link_libraries(parser PRIVATE NodesetLoader ${CHECK_LIBRARIES} ${PTHREAD_LIB} coverageLib open62541::open62541) 31 | target_include_directories(parser PRIVATE ${CHECK_INCLUDE_DIR}) 32 | add_test(NAME parser_Test 33 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 34 | COMMAND parser ${CMAKE_CURRENT_SOURCE_DIR}/basicNodeClasses.xml) 35 | add_test(NAME parser_invalid_Test 36 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 37 | COMMAND parser ${CMAKE_CURRENT_SOURCE_DIR}/invalidNodeDefinitions.xml) 38 | 39 | #these tests are simple loading nodesets and dumping it to stdout 40 | add_test(NAME import_testNodeset WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND parserDemo ${PROJECT_SOURCE_DIR}/nodesets/testNodeset100nodes.xml) 41 | add_test(NAME import_Nodeset2 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND parserDemo ${PROJECT_SOURCE_DIR}/nodesets/Opc.Ua.NodeSet2.xml) 42 | add_test(NAME import_DI WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 43 | COMMAND parserDemo ${PROJECT_SOURCE_DIR}/nodesets/Opc.Ua.NodeSet2.xml ${PROJECT_SOURCE_DIR}/nodesets/Opc.Ua.Di.NodeSet2.xml) 44 | 45 | #add_test(NAME import_PLCOpen WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND parserDemo ${PROJECT_SOURCE_DIR}/nodesets/Opc.Ua.NodeSet2.xml 46 | # ${PROJECT_SOURCE_DIR}/nodesets/Opc.Ua.Di.NodeSet2.xml 47 | # ${PROJECT_SOURCE_DIR}/nodesets/Opc.Ua.Plc.NodeSet2.xml) 48 | 49 | -------------------------------------------------------------------------------- /tests/NodeContainer.c: -------------------------------------------------------------------------------- 1 | #include "nodes/NodeContainer.h" 2 | #include "NodesetLoader/NodesetLoader.h" 3 | #include "check.h" 4 | #include 5 | 6 | static void initNode(NL_VariableNode* n) 7 | { 8 | memset(n, 0, sizeof(NL_VariableNode)); 9 | } 10 | 11 | START_TEST(newEmptyContainer) { 12 | 13 | NodeContainer* container = NodeContainer_new(100, true); 14 | NodeContainer_delete(container); 15 | } 16 | END_TEST 17 | 18 | START_TEST(ownership) { 19 | 20 | NL_VariableNode varNode; 21 | initNode(&varNode); 22 | 23 | NodeContainer* container = NodeContainer_new(100, false); 24 | for(int i=0; i<100; i++) 25 | { 26 | NodeContainer_add(container, (NL_Node*)&varNode); 27 | } 28 | NodeContainer_delete(container); 29 | } 30 | END_TEST 31 | 32 | int main(void) { 33 | Suite *s = suite_create("Sort tests"); 34 | TCase *tc = tcase_create("test cases"); 35 | tcase_add_test(tc, newEmptyContainer); 36 | tcase_add_test(tc, ownership); 37 | suite_add_tcase(s, tc); 38 | 39 | SRunner *sr = srunner_create(s); 40 | srunner_set_fork_status(sr, CK_NOFORK); 41 | srunner_run_all(sr, CK_NORMAL); 42 | int number_failed = srunner_ntests_failed(sr); 43 | srunner_free(sr); 44 | 45 | return (number_failed == 0) ? 0 : -1; 46 | } 47 | -------------------------------------------------------------------------------- /tests/allocator.c: -------------------------------------------------------------------------------- 1 | #include "CharAllocator.h" 2 | #include "check.h" 3 | 4 | START_TEST(simpleMalloc) 5 | { 6 | CharArenaAllocator *a = (CharArenaAllocator *)CharArenaAllocator_new(100); 7 | char *val = CharArenaAllocator_malloc(a, 100); 8 | memset(val, 0, 100); 9 | CharArenaAllocator_delete(a); 10 | } 11 | END_TEST 12 | 13 | START_TEST(simpleMalloc2) 14 | { 15 | CharArenaAllocator *a = (CharArenaAllocator *)CharArenaAllocator_new(100); 16 | char *val = CharArenaAllocator_malloc(a, 50); 17 | char *val2 = CharArenaAllocator_malloc(a, 50); 18 | char *val3 = CharArenaAllocator_malloc(a, 50); 19 | CharArenaAllocator_delete(a); 20 | } 21 | END_TEST 22 | 23 | START_TEST(simpleRealloc) 24 | { 25 | CharArenaAllocator *a = (CharArenaAllocator *)CharArenaAllocator_new(100); 26 | char *val = CharArenaAllocator_malloc(a, 50); 27 | memcpy(val, "alsökdjfaösldfj", strlen("alsökdjfaösldfj")); 28 | char *val2 = CharArenaAllocator_realloc(a, 50); 29 | ck_assert(val == val2); 30 | ck_assert(!strcmp(val, "alsökdjfaösldfj")); 31 | CharArenaAllocator_delete(a); 32 | } 33 | END_TEST 34 | 35 | START_TEST(simpleRealloc2) 36 | { 37 | CharArenaAllocator *a = (CharArenaAllocator *)CharArenaAllocator_new(100); 38 | char *val = CharArenaAllocator_malloc(a, 50); 39 | val = CharArenaAllocator_malloc(a, 40); 40 | val = CharArenaAllocator_malloc(a, 10); 41 | memcpy(val, "123", 3); 42 | char *val2 = CharArenaAllocator_realloc(a, 3); 43 | CharArenaAllocator_delete(a); 44 | } 45 | END_TEST 46 | 47 | START_TEST(overcommit) 48 | { 49 | CharArenaAllocator *a = (CharArenaAllocator *)CharArenaAllocator_new(100); 50 | char *val = CharArenaAllocator_malloc(a, 200); 51 | memset(val, 0, 200); 52 | CharArenaAllocator_delete(a); 53 | } 54 | END_TEST 55 | 56 | int main(void) 57 | { 58 | Suite *s = suite_create("Sort tests"); 59 | TCase *tc = tcase_create("test cases"); 60 | tcase_add_test(tc, simpleMalloc); 61 | tcase_add_test(tc, simpleMalloc2); 62 | tcase_add_test(tc, simpleRealloc); 63 | tcase_add_test(tc, simpleRealloc2); 64 | tcase_add_test(tc, overcommit); 65 | suite_add_tcase(s, tc); 66 | 67 | SRunner *sr = srunner_create(s); 68 | srunner_set_fork_status(sr, CK_NOFORK); 69 | srunner_run_all(sr, CK_NORMAL); 70 | int number_failed = srunner_ntests_failed(sr); 71 | srunner_free(sr); 72 | 73 | return (number_failed == 0) ? 0 : -1; 74 | } 75 | -------------------------------------------------------------------------------- /tests/invalidNodeDefinitions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | http://open62541.com/tests/BasicNodeClassTests/ 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/parser.c: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | #include "check.h" 6 | #include "NodesetLoader/NodesetLoader.h" 7 | #include 8 | 9 | unsigned short addNamespace(void *userContext, const char *uri) { return 1; } 10 | 11 | void addNode(void *userContext, const NL_Node *node) 12 | { 13 | (*((int*)userContext))++; 14 | } 15 | 16 | char *nodesetPath = NULL; 17 | 18 | static void setup(void) 19 | { 20 | 21 | } 22 | 23 | static void teardown(void) 24 | { 25 | 26 | } 27 | 28 | START_TEST(Server_ImportBasicNodeClassTest) 29 | { 30 | NL_FileContext handler; 31 | handler.addNamespace = addNamespace; 32 | 33 | NodesetLoader *loader = NodesetLoader_new(NULL, NULL); 34 | handler.file = nodesetPath; 35 | ck_assert(NodesetLoader_importFile(loader, &handler)); 36 | ck_assert(NodesetLoader_sort(loader)); 37 | 38 | int nodeCount=0; 39 | 40 | for (int i = 0; i < NL_NODECLASS_COUNT; i++) 41 | { 42 | NodesetLoader_forEachNode(loader, (NL_NodeClass)i, &nodeCount, 43 | (NodesetLoader_forEachNode_Func)addNode); 44 | } 45 | 46 | printf("Loaded %i nodes\n", nodeCount); 47 | 48 | NodesetLoader_delete(loader); 49 | } 50 | END_TEST 51 | 52 | static Suite *testSuite_Client(void) 53 | { 54 | Suite *s = suite_create("server nodeset import"); 55 | TCase *tc_server = tcase_create("server nodeset import"); 56 | tcase_add_unchecked_fixture(tc_server, setup, teardown); 57 | tcase_add_test(tc_server, Server_ImportBasicNodeClassTest); 58 | suite_add_tcase(s, tc_server); 59 | return s; 60 | } 61 | 62 | int main(int argc, char *argv[]) 63 | { 64 | if (!(argc > 1)) 65 | return 1; 66 | nodesetPath = argv[1]; 67 | Suite *s = testSuite_Client(); 68 | SRunner *sr = srunner_create(s); 69 | srunner_set_fork_status(sr, CK_NOFORK); 70 | srunner_run_all(sr, CK_NORMAL); 71 | int number_failed = srunner_ntests_failed(sr); 72 | srunner_free(sr); 73 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 74 | } 75 | --------------------------------------------------------------------------------