check_nodeset_compiler_testnodeset.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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(p[0].x == (UA_Double)1.0);
  59. ck_assert(p[3].y == (UA_Double)8.0);
  60. UA_Variant_clear(&out);
  61. }
  62. END_TEST
  63. START_TEST(readValueRank) {
  64. UA_Int32 rank;
  65. UA_Variant dims;
  66. // scalar
  67. UA_Server_readValueRank(server, UA_NODEID_NUMERIC(2, 10002), &rank);
  68. ck_assert_int_eq(rank, -1);
  69. UA_Server_readValueRank(server, UA_NODEID_NUMERIC(2, 10002), &rank);
  70. ck_assert_int_eq(rank, -1);
  71. UA_Variant_init(&dims);
  72. UA_Server_readArrayDimensions(server, UA_NODEID_NUMERIC(2, 10002), &dims);
  73. ck_assert_int_eq(dims.arrayLength, 0);
  74. UA_Variant_clear(&dims);
  75. // 1-dim
  76. UA_Server_readValueRank(server, UA_NODEID_NUMERIC(2, 10007), &rank);
  77. ck_assert_int_eq(rank, 1);
  78. UA_Server_readArrayDimensions(server, UA_NODEID_NUMERIC(2, 10007), &dims);
  79. ck_assert_int_eq(dims.arrayLength, 1);
  80. ck_assert_int_eq(*((UA_UInt32 *)dims.data), 0);
  81. UA_Variant_clear(&dims);
  82. UA_Server_readValueRank(server, UA_NODEID_NUMERIC(2, 10004), &rank);
  83. ck_assert_int_eq(rank, 1);
  84. UA_Server_readArrayDimensions(server, UA_NODEID_NUMERIC(2, 10004), &dims);
  85. ck_assert_int_eq(dims.arrayLength, 1);
  86. ck_assert_int_eq(*((UA_UInt32 *)dims.data), 4);
  87. UA_Variant_clear(&dims);
  88. // 2-dim
  89. UA_Server_readValueRank(server, UA_NODEID_NUMERIC(2, 10006), &rank);
  90. ck_assert_int_eq(rank, 2);
  91. UA_Server_readArrayDimensions(server, UA_NODEID_NUMERIC(2, 10006), &dims);
  92. ck_assert_int_eq(dims.arrayLength, 2);
  93. UA_UInt32 *dimensions = (UA_UInt32 *)dims.data;
  94. ck_assert_int_eq(dimensions[0], 2);
  95. ck_assert_int_eq(dimensions[1], 2);
  96. UA_Variant_clear(&dims);
  97. }
  98. END_TEST
  99. static Suite *testSuite_Client(void) {
  100. Suite *s = suite_create("Server Nodeset Compiler");
  101. TCase *tc_server = tcase_create("Server Testnodeset");
  102. tcase_add_unchecked_fixture(tc_server, setup, teardown);
  103. tcase_add_test(tc_server, Server_addTestNodeset);
  104. tcase_add_test(tc_server, checkScalarValues);
  105. tcase_add_test(tc_server, check1dimValues);
  106. tcase_add_test(tc_server, readValueRank);
  107. suite_add_tcase(s, tc_server);
  108. return s;
  109. }
  110. int main(void) {
  111. Suite *s = testSuite_Client();
  112. SRunner *sr = srunner_create(s);
  113. srunner_set_fork_status(sr, CK_NOFORK);
  114. srunner_run_all(sr, CK_NORMAL);
  115. int number_failed = srunner_ntests_failed(sr);
  116. srunner_free(sr);
  117. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  118. }