Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Supplying test data for LocalStorage in unit tests
QtWS25 Last Chance

Supplying test data for LocalStorage in unit tests

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 962 Views
  • 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.
  • S Offline
    S Offline
    schmittlauch
    wrote on last edited by
    #1

    I want to write an unit test for a pure QtQuick + javascript application which uses LocalStorage 2.0 as its backend. The feature I'm testing is mostly a database migration, so I'd like to supply a test database file with the old schema to the unit test.
    Sadly, LocalStorage.openDatabaseSync doesn't allow specifying a database file directly, just a database name.
    What is the best solution to supply test data for a QtQuick test (QtTest 1.0)? Or do I need to mock away LocalStorage? If yes, how?

    regards,
    a QtQuick novice

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @schmittlauch

      Sadly, LocalStorage.openDatabaseSync doesn't allow specifying a database file directly, just a database name.

      There is a sort of hack. The SQLite database is stored in OfflineStorage path with its name md5 encrypted. You can copy your database to this path with its name md5 hashed. Then as per this example open this database by passing its original non-hashed name.

      157

      S 1 Reply Last reply
      0
      • p3c0P p3c0

        @schmittlauch

        Sadly, LocalStorage.openDatabaseSync doesn't allow specifying a database file directly, just a database name.

        There is a sort of hack. The SQLite database is stored in OfflineStorage path with its name md5 encrypted. You can copy your database to this path with its name md5 hashed. Then as per this example open this database by passing its original non-hashed name.

        S Offline
        S Offline
        schmittlauch
        wrote on last edited by
        #3

        Sorry, it's been a while, but now I'm working on my project again :]

        @p3c0

        There is a sort of hack. The SQLite database is stored in OfflineStorage path with its name md5 encrypted. You can copy your database to this path with its name md5 hashed. Then as per this example open this database by passing its original non-hashed name.

        Uuhh, that sound's messy. But well, if this is the way to go... It'd be useful to at least read out the OfflineStorage dir at runtime and copy the files there instead of trying to do that statically beforehand. This is possible with QQmlEngine::offlineStoragePath, even changing that path is possible thanks to QQmlEngine::setOfflineStoragePath.

        But here the problems start: Exposing the path to QtQuick or changing it before running the test involves some C++ magic. Currently my test runner file looks exactly like this:

        #include <QtQuickTest/quicktest.h>
        // TasklistCalcTestSet is just a convenient name for reports - not linked to any of the main project entities
        QUICK_TEST_MAIN(TasklistTestSet)
        

        I'm afraid there's not much room here for adding additional set-up code, is it? And the code of this macro also doesn't look like I want to customize it and replace the one shipped with Qt with my own setup-code, does it?

        Any ideas what I can do there?

        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