testing_networklayers.c 1.4 KB

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