Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Qtmock - Interesting thing, but I can’t figure it out. Has anybody tried it?
Forum Updated to NodeBB v4.3 + New Features

Qtmock - Interesting thing, but I can’t figure it out. Has anybody tried it?

Scheduled Pinned Locked Moved 3rd Party Software
8 Posts 2 Posters 5.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    artem.marchenko
    wrote on last edited by
    #1

    I am into test-driven development and for was looking for a Qt compatible mocking framework (something to simulate e.g. file reads without having to write full blown QFile simulation myself).

    I found an interesting branch called qtmock here - https://qt.gitorious.org/~niandong/qt/niandongs-qttools/commits/qtmock

    It compiles and demo does work, but I can't figure it out further :)
    This mock framework is heavily based on macros so trying to understand what's generated automatically and what's written by hand isn't easy. My helloworldish trials failed as well.

    Has anybody looked at it?
    I would appreciate if somebody experienced could have a look or maybe even create a helloworldish example with it.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chikuba
      wrote on last edited by
      #2

      hi

      im in a worser situation that you. how where you able to build it? i opened the qttools.pro file and tried to build it but it failed since it coudlnt find qfunctions_h.h in a "private" folder. what project did you build and what test did you do? im trying to mock the QNAM for a larger project

      1 Reply Last reply
      0
      • A Offline
        A Offline
        artem.marchenko
        wrote on last edited by
        #3

        Yep, I am building it fine with the usual qmake-make. Framework itself is not well documented, but works more or less.

        However, I don't touch qttools.pro you mention at all. I cloned only qtmock part of it (inside qtestlib). I am not 100% sure if I modified anything to make it compile in a stand-alone way, but even if I did it definitely was something simple.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chikuba
          wrote on last edited by
          #4

          so you imported that part of it and just rebuild your qt? im really new to building things on windows and my qt is built to fit with visual studio so i cant really rebuild it without it taking about 3 hours. could you please specify what you mean?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            artem.marchenko
            wrote on last edited by
            #5

            I made qtmock just one of subprojects of my big project (an engine library, app, a couple of external libraries that are built as a part of the project, a number of automatic tests).

            So the library is built as if it was one of the libraries I've written myself.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              chikuba
              wrote on last edited by
              #6

              ah that makes sense. yeah i tried to build the qtmock.pro file and that worked fine. i really hope this is the answer to my qtprayes. absolutly hate that the QNAM doesnt have any virtual functions so that i can produce a fake version of it. ...

              1 Reply Last reply
              0
              • C Offline
                C Offline
                chikuba
                wrote on last edited by
                #7

                been looking at the demos and it seem pretty clear to me. in the NetworkTest you just take a QNAM and then define its behaviour. the wierd thing that I dont understand is how those settings gets transfered since there's no injection taking place what i can see. Just like you set how the QNAM should act and then in any object that you create where u have a QNAM it will act the way we wanted to.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  artem.marchenko
                  wrote on last edited by
                  #8

                  What they do in the examples is that they mock the whole QNAM library, i.e. create a stand-alone separate library that looks totally like QNAM, implements the same interfaces, but instead of the real QNAM implementation all the methods just pass the ball to the mocking framework as in the following:
                  @
                  QNetworkCookie &QNetworkCookie::operator=(const QNetworkCookie &other)
                  {
                  QVector<QGenericArgument> args;
                  args.append(Q_ARG(const QNetworkCookie &, other));

                  QTMOCK_METHOD_DOACTIONS("QNetworkCookie", "operator=", QRET_REF(QNetworkCookie), &args, NULL);
                  

                  }
                  @

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved