Giter VIP home page Giter VIP logo

Comments (3)

kreuzberger avatar kreuzberger commented on July 2, 2024

QtWireProtocolHandler.zip

Idea / Solution is to implement and use a Qt based WireProtocolServer

in the main of the test applikation:

  // initialize qt base wire protocol server
  QtWireProtocolHandler wire_protocol_handler( listenHost, port, parser.isSet( "verbose" ) );
  // start processung
  wire_protocol_handler.process();
  // run qt eventloop in main thread
  return app.exec();

Implementations (attached as zip)

class QtWireProtocolHandler : public QObject
{
  Q_OBJECT
public:
  explicit QtWireProtocolHandler( const std::string& host, int port, bool verbose );
  ~QtWireProtocolHandler() override;
  void process();
protected slots:
  void onClose();

private:
  std::unique_ptr<CukeEngineImpl>       cukeEngine      = nullptr;
  std::unique_ptr<JsonWireMessageCodec> wireCodec       = nullptr;
  std::unique_ptr<WireProtocolHandler>  protocolHandler = nullptr;
  std::unique_ptr<SocketServer> server = nullptr;
  bool                                  verbose         = false;
};

Which uses a custom Implementation of SocketServer

class QtTCPSocketServer : public QObject, public SocketServer
{
  Q_OBJECT
public:
  typedef unsigned short port_type;
  explicit QtTCPSocketServer( const ProtocolHandler* protocolHandler );

  void listen( const port_type port );
 void listen( const asio::ip::tcp::endpoint endpoint );

  asio::ip::tcp::endpoint listenEndpoint() const;

  void acceptOnce() override;

signals:
  void closed();

private:
  void doAcceptOnce( asio::basic_socket_acceptor<asio::ip::tcp>& acceptor );
  void timerEvent( QTimerEvent* ) override;

  asio::ip::tcp::acceptor            acceptor;
  std::unique_ptr<AsyncStreamReader> mAsyncStreamReader = nullptr;
  asio::ip::tcp::iostream            mStream;
};

from cucumber-cpp.

ursfassler avatar ursfassler commented on July 2, 2024

@kreuzberger I strongly recommend to not include the Qt classes nor UI in the acceptance tests. And not timer, you don't want to make your tests slower than needed. Only include and test the business logic of the application. When doing so, you probably don't need the event handling. This removes asynchronous (non-deterministic) behavior, making the tests stable.

I had cases where we had queues (in Qt this would be queued connections) in the code under test. The solution was to dispatch the stuff in the queue until empty after every step. I think it was with QEventLoop::processEvents within AFTER_STEP hook. Or something like here.

from cucumber-cpp.

kreuzberger avatar kreuzberger commented on July 2, 2024

I agree with most of your doubts. Testing with no such constraints make live easier. Main advantage of the gherkin language is for me still to test user scenarios (not the gui) but if the app under the test is a rich desktop qt app and runs in a multi process enviroment i have to face it. Or use Squish. But testing the logic with squish is much more slower and complicated i think. But this is currently my intention, test the app instead of squish/gherkin with a different (and maybe better) approach.

But back to the questions:

  • The existence of a nomain library is for me the hint that this library could be used.
  • The names and used classes have an "internal" namespace, but if used as static library i can access them without any problems. The CUCUMBER_CPP_EXPORT is a hint for me that the classes could be used as an API even if builded as shared libraries?

from cucumber-cpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.