check_nodeset_compiler_testnodeset.c 4.5 KB

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