check_nodeset_compiler_testnodeset.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #include <open62541/server.h>
  5. #include <open62541/server_config_default.h>
  6. #include <open62541/types.h>
  7. #include "check.h"
  8. #include "testing_clock.h"
  9. #include "tests/namespace_tests_testnodeset_generated.h"
  10. #include "unistd.h"
  11. UA_Server *server = NULL;
  12. UA_DataTypeArray customTypesArray = { NULL, UA_TYPES_TESTS_TESTNODESET_COUNT, UA_TYPES_TESTS_TESTNODESET};
  13. static void setup(void) {
  14. server = UA_Server_new();
  15. UA_ServerConfig *config = UA_Server_getConfig(server);
  16. UA_ServerConfig_setDefault(config);
  17. config->customDataTypes = &customTypesArray;
  18. UA_Server_run_startup(server);
  19. }
  20. static void teardown(void) {
  21. UA_Server_run_shutdown(server);
  22. UA_Server_delete(server);
  23. }
  24. START_TEST(Server_addTestNodeset) {
  25. UA_StatusCode retval = namespace_tests_testnodeset_generated(server);
  26. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  27. }
  28. END_TEST
  29. START_TEST(checkScalarValues) {
  30. UA_Variant out;
  31. UA_Variant_init(&out);
  32. // Point_scalar_Init
  33. UA_Server_readValue(server, UA_NODEID_NUMERIC(2, 10002), &out);
  34. ck_assert(UA_Variant_isScalar(&out));
  35. UA_Point *p = (UA_Point *)out.data;
  36. ck_assert(p->x == (UA_Double)1.0);
  37. ck_assert(p->y == (UA_Double)2.0);
  38. UA_Variant_clear(&out);
  39. // Point_scalar_noInit
  40. UA_Server_readValue(server, UA_NODEID_NUMERIC(2, 10005), &out);
  41. ck_assert(out.data == NULL);
  42. UA_Variant_clear(&out);
  43. }
  44. END_TEST
  45. START_TEST(check1dimValues) {
  46. UA_Variant out;
  47. UA_Variant_init(&out);
  48. // Point_1dim_noInit
  49. UA_Server_readValue(server, UA_NODEID_NUMERIC(2, 10007), &out);
  50. ck_assert(!UA_Variant_isScalar(&out));
  51. ck_assert(out.arrayDimensionsSize == 0);
  52. UA_Variant_clear(&out);
  53. // Point_1dim_init
  54. UA_Server_readValue(server, UA_NODEID_NUMERIC(2, 10004), &out);
  55. UA_Point *p = (UA_Point *)out.data;
  56. ck_assert(!UA_Variant_isScalar(&out));
  57. ck_assert(out.arrayLength == 4);
  58. ck_assert(out.arrayDimensionsSize == 0); // For 1 dimension arrays, initializing arrayDimensionsSize may confuse some OPC clients.
  59. ck_assert(p[0].x == (UA_Double)1.0);
  60. ck_assert(p[3].y == (UA_Double)8.0);
  61. UA_Variant_clear(&out);
  62. }
  63. END_TEST
  64. START_TEST(readValueRank) {
  65. UA_Int32 rank;
  66. UA_Variant dims;
  67. // scalar
  68. UA_Server_readValueRank(server, UA_NODEID_NUMERIC(2, 10002), &rank);
  69. ck_assert_int_eq(rank, -1);
  70. UA_Server_readValueRank(server, UA_NODEID_NUMERIC(2, 10002), &rank);
  71. ck_assert_int_eq(rank, -1);
  72. UA_Variant_init(&dims);
  73. UA_Server_readArrayDimensions(server, UA_NODEID_NUMERIC(2, 10002), &dims);
  74. ck_assert_int_eq(dims.arrayLength, 0);
  75. UA_Variant_clear(&dims);
  76. // 1-dim
  77. UA_Server_readValueRank(server, UA_NODEID_NUMERIC(2, 10007), &rank);
  78. ck_assert_int_eq(rank, 1);
  79. UA_Server_readArrayDimensions(server, UA_NODEID_NUMERIC(2, 10007), &dims);
  80. ck_assert_int_eq(dims.arrayLength, 1);
  81. ck_assert_int_eq(*((UA_UInt32 *)dims.data), 0);
  82. UA_Variant_clear(&dims);
  83. UA_Server_readValueRank(server, UA_NODEID_NUMERIC(2, 10004), &rank);
  84. ck_assert_int_eq(rank, 1);
  85. UA_Server_readArrayDimensions(server, UA_NODEID_NUMERIC(2, 10004), &dims);
  86. ck_assert_int_eq(dims.arrayLength, 1);
  87. ck_assert_int_eq(*((UA_UInt32 *)dims.data), 4);
  88. UA_Variant_clear(&dims);
  89. // 2-dim
  90. UA_Server_readValueRank(server, UA_NODEID_NUMERIC(2, 10006), &rank);
  91. ck_assert_int_eq(rank, 2);
  92. UA_Server_readArrayDimensions(server, UA_NODEID_NUMERIC(2, 10006), &dims);
  93. ck_assert_int_eq(dims.arrayLength, 2);
  94. UA_UInt32 *dimensions = (UA_UInt32 *)dims.data;
  95. ck_assert_int_eq(dimensions[0], 2);
  96. ck_assert_int_eq(dimensions[1], 2);
  97. UA_Variant_clear(&dims);
  98. }
  99. END_TEST
  100. static Suite *testSuite_Client(void) {
  101. Suite *s = suite_create("Server Nodeset Compiler");
  102. TCase *tc_server = tcase_create("Server Testnodeset");
  103. tcase_add_unchecked_fixture(tc_server, setup, teardown);
  104. tcase_add_test(tc_server, Server_addTestNodeset);
  105. tcase_add_test(tc_server, checkScalarValues);
  106. tcase_add_test(tc_server, check1dimValues);
  107. tcase_add_test(tc_server, readValueRank);
  108. suite_add_tcase(s, tc_server);
  109. return s;
  110. }
  111. int main(void) {
  112. Suite *s = testSuite_Client();
  113. SRunner *sr = srunner_create(s);
  114. srunner_set_fork_status(sr, CK_NOFORK);
  115. srunner_run_all(sr, CK_NORMAL);
  116. int number_failed = srunner_ntests_failed(sr);
  117. srunner_free(sr);
  118. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  119. }