testing_networklayers.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 <stdlib.h>
  5. #include <assert.h>
  6. #include "testing_networklayers.h"
  7. #include "ua_config_default.h"
  8. UA_ByteString *vBuffer;
  9. static UA_StatusCode
  10. dummyGetSendBuffer(UA_Connection *connection, size_t length, UA_ByteString *buf) {
  11. buf->data = (length == 0) ? NULL : (UA_Byte*)UA_malloc(length);
  12. buf->length = length;
  13. return UA_STATUSCODE_GOOD;
  14. }
  15. static void
  16. dummyReleaseSendBuffer(UA_Connection *connection, UA_ByteString *buf) {
  17. UA_ByteString_deleteMembers(buf);
  18. }
  19. static UA_StatusCode
  20. dummySend(UA_Connection *connection, UA_ByteString *buf) {
  21. assert(connection != NULL);
  22. assert(buf != NULL);
  23. UA_ByteString_deleteMembers(vBuffer);
  24. UA_ByteString_copy(buf, vBuffer);
  25. UA_ByteString_deleteMembers(buf);
  26. return UA_STATUSCODE_GOOD;
  27. }
  28. static void
  29. dummyReleaseRecvBuffer(UA_Connection *connection, UA_ByteString *buf) {
  30. }
  31. static void
  32. dummyClose(UA_Connection *connection) {
  33. UA_ByteString_deleteMembers(vBuffer);
  34. }
  35. UA_Connection createDummyConnection(UA_ByteString *verificationBuffer) {
  36. assert(verificationBuffer != NULL);
  37. vBuffer = verificationBuffer;
  38. UA_Connection c;
  39. c.state = UA_CONNECTION_ESTABLISHED;
  40. c.localConf = UA_ConnectionConfig_default;
  41. c.remoteConf = UA_ConnectionConfig_default;
  42. c.channel = NULL;
  43. c.sockfd = 0;
  44. c.handle = NULL;
  45. c.incompleteMessage = UA_BYTESTRING_NULL;
  46. c.getSendBuffer = dummyGetSendBuffer;
  47. c.releaseSendBuffer = dummyReleaseSendBuffer;
  48. c.send = dummySend;
  49. c.recv = NULL;
  50. c.releaseRecvBuffer = dummyReleaseRecvBuffer;
  51. c.close = dummyClose;
  52. return c;
  53. }