UnitTestShaderCompilerServer.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #ifndef UNITTESTSHADERCOMPILERSERVER_H
  9. #define UNITTESTSHADERCOMPILERSERVER_H
  10. #if !defined(Q_MOC_RUN)
  11. #include <QString>
  12. #include <QByteArray>
  13. #include <QObject>
  14. #endif
  15. class QTcpServer;
  16. class QTcpSocket;
  17. /** This Class will be used by the UnitTest class for testing
  18. * the Shader Compiler Manager Class.Basically we change the value
  19. * of the server status variable and see whether we are getting the
  20. * expected response from the shader compiler.
  21. */
  22. class UnitTestShaderCompilerServer
  23. : public QObject
  24. {
  25. Q_OBJECT
  26. public:
  27. explicit UnitTestShaderCompilerServer(QObject* parent = 0);
  28. virtual ~UnitTestShaderCompilerServer();
  29. enum ServerStatus
  30. {
  31. GoodServer,
  32. BadServer_SendsIncompletePayload,
  33. BadServer_ReadsPayloadAndDisconnect,
  34. BadServer_DisconnectAfterConnect,
  35. };
  36. void constructPayload(QByteArray& payload);
  37. void Init(QString serverAddress, int serverPort);
  38. void closeSocket();
  39. void startServer();
  40. void setServerStatus(const ServerStatus& serverStatus);
  41. signals:
  42. void errorMessage(QString error);
  43. public slots:
  44. void newConnection();
  45. void incomingMessage();
  46. private:
  47. QTcpSocket* m_socket;
  48. QTcpServer* m_server;
  49. ServerStatus m_serverStatus;
  50. QString m_serverAddress;
  51. int m_serverPort;
  52. QString m_incomingPayload;
  53. QString m_outgoingPayload;
  54. bool m_isPayloadSizeKnown;
  55. qint64 m_payloadSize;
  56. qint64 m_bytesRemainingInPayloadSize;
  57. qint64 m_totalBytesReadInPayloadSize;
  58. QByteArray m_payload;
  59. qint64 m_bytesRemainingInPayload;
  60. qint64 m_totalBytesReadInPayload;
  61. };
  62. #endif //UNITTESTSHADERCOMPILERSERVER_H