check_nodeset_compiler_testnodeset.c 4.5 KB

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