# SPDX-FileCopyrightText: 2026 Matvey Shcherbinin # SPDX-License-Identifier: BSD-2-Clause # The classes under test are compiled into each test rather than into a # shared library. The project builds a single executable, so there is no # library to link against yet. # # Every suite that links SecretStore.cpp puts it in its in-memory mode in # main(). Test mode alone does not close KWallet, so until that call these # tests wrote their throwaway identity keys into the real wallet. It also # makes a run here and a run on headless CI take the same path, where before # they differed for want of a running wallet daemon. What must never happen # either way is a secret quietly written in plain text anywhere. # tools/wallet-cleanup.sh clears out what an older build left behind. # # The application dropped OpenSSL when CryptoManager moved to libsodium, but # CryptoManagerTest's ForgedPeer still builds its attacker keys with raw EVP, so # the dependency lives on here alone until that helper is ported too. find_package(OpenSSL REQUIRED) ecm_add_test( CryptoManagerTest.cpp ../core/security/CryptoManager.cpp ../core/security/SecretStore.cpp ${KOUTNET_CRYPTO_LOGGING_SRCS} TEST_NAME crypto-manager NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core PkgConfig::Sodium OpenSSL::Crypto KF6::I18n ) # CryptoManager.cpp includes its logging category header, which is generated # into the parent directory's build tree and not into this one. target_include_directories(crypto-manager PRIVATE ${KOUTNET_GENERATED_INCLUDE_DIR}) # No sockets bound, no peers contacted and no wallet: the packet path is driven # by handing handleDatagram() the bytes a datagram would have carried, so this # runs on a machine with no network at all. CryptoManager comes along because a # session key is what the signature policy is made of. The full logging set is # linked rather than just the crypto category because NetworkManager.cpp now # speaks too. if(WIN32) set(NETWORK_MANAGER_EXTRA_LIBS iphlpapi) else() set(NETWORK_MANAGER_EXTRA_LIBS) endif() ecm_add_test( NetworkManagerTest.cpp ../network/NetworkManager.cpp ../network/StunClient.cpp ../network/Protocol.cpp ../network/TlsChannel.cpp ../network/FrameRouter.cpp ../network/FrameRouter.h ../network/VoiceTransport.cpp ../network/VoiceTransport.h ../network/AvatarExchange.cpp ../network/AvatarExchange.h ../network/BannerExchange.cpp ../network/BannerExchange.h ../network/FileTransferSender.cpp ../network/FileTransferSender.h ../network/SessionTransport.cpp ../network/SessionTransport.h ../network/PresenceService.cpp ../network/PresenceService.h ../network/GroupKeyStore.cpp ../network/GroupKeyStore.h ../network/GroupKeyStore.cpp ../network/GroupKeyStore.h ../core/security/IdentityCertificate.cpp ../core/chat/ChatAddress.cpp ../core/media/OutgoingFile.cpp ../core/security/CryptoManager.cpp ../core/security/SecretStore.cpp ${KOUTNET_LOGGING_SRCS} ${KOUTNET_CRYPTO_LOGGING_SRCS} TEST_NAME network-manager NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core Qt6::Gui Qt6::Network PkgConfig::Sodium OpenSSL::Crypto KF6::I18n ${NETWORK_MANAGER_EXTRA_LIBS} ) # NetworkManager.cpp reads the project version from koutnet-version.h, which # ecm_setup_version emits at the top of the build tree. target_include_directories(network-manager PRIVATE ${PROJECT_BINARY_DIR}) target_include_directories(network-manager PRIVATE ${KOUTNET_GENERATED_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/..) # SecretStore.cpp is compiled into the crypto and network suites, and strays # into KWallet when the app build has it; the suites never open a wallet (their # main() forces in-memory mode), but the binary still has to resolve the symbol. if(KF6Wallet_FOUND) target_compile_definitions(crypto-manager PRIVATE KOUTNET_HAVE_KWALLET) target_compile_definitions(network-manager PRIVATE KOUTNET_HAVE_KWALLET) target_link_libraries(crypto-manager KF6::Wallet) target_link_libraries(network-manager KF6::Wallet) endif() # The TLS transport gets no unit test strips: it is the two halves of a real # handshake on loopback, so the test runs on any machine with a network stack, # and needs OpenSSL only through IdentityCertificate (QSslSocket links it in). # The pin store goes under AppDataLocation, and main() puts that in test mode # so a run here never touches a real user's pins. ecm_add_test( TlsChannelTest.cpp ../network/TlsChannel.cpp ../core/security/IdentityCertificate.cpp TEST_NAME tls-channel NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core Qt6::Network OpenSSL::Crypto ) target_include_directories(tls-channel PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..) # This one writes real files, so its main() points HOME at a scratch directory # before anything else runs: the download location is the one path # QStandardPaths test mode does not move out of the user's home. ecm_add_test( FileTransferHandlerTest.cpp ../network/FileTransferHandler.cpp TEST_NAME file-transfer-handler NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core KF6::I18n ) # What is put on the wire when something is attached. No network, no window and # no libQuotient: the whole decision is "is this file smaller and still a # picture, and is it named for the format it is in", which is arithmetic over a # QImage and a temporary directory. Qt6::Gui is for the QImage encoder. ecm_add_test( OutgoingFileTest.cpp ../core/media/OutgoingFile.cpp TEST_NAME outgoing-file NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core Qt6::Gui ) target_include_directories(outgoing-file PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..) # The reversing proxy is arithmetic over model signals with no window anywhere # near it, so it is the one part of the timeline that can be tested at all - and # an off-by-one in it is a conversation whose messages are all signed by the # wrong person, which nothing reports. Qt6::Qml is here for the QML_ELEMENT # marker in the header and QAbstractItemModelTester comes from Qt6::Test. ecm_add_test( ReversedChatModelTest.cpp ../core/chat/ReversedChatModel.cpp TEST_NAME reversed-chat-model NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core Qt6::Qml ) # TDLib publishes an outgoing message under a negative placeholder id and then # under the real one, in either order. ChatModel is the only place that sees # both, and a mistake there is a message drawn twice. History/crypto sources are # here only because ChatModel links against them; no wallet or server is used. ecm_add_test( TelegramDuplicateTest.cpp ../core/chat/ChatModel.cpp ../core/chat/MessageEntry.cpp ../core/chat/HistoryManager.cpp ../core/chat/UnreadManager.cpp ../core/chat/ReactionStore.cpp ../core/security/CryptoManager.cpp ../core/security/SecretStore.cpp ${KOUTNET_LOGGING_SRCS} ${KOUTNET_CRYPTO_LOGGING_SRCS} TEST_NAME telegram-duplicate NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core Qt6::Qml PkgConfig::Sodium KF6::I18n ) target_include_directories(telegram-duplicate PRIVATE ${KOUTNET_GENERATED_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/..) if(KF6Wallet_FOUND) target_compile_definitions(telegram-duplicate PRIVATE KOUTNET_HAVE_KWALLET) target_link_libraries(telegram-duplicate KF6::Wallet) endif() # The registry is pure routing over the chat-id prefix table - no sockets, no # libQuotient, no wallet - so the fakes are ten-line classes and the test runs # on a machine with no network at all. ecm_add_test( ChatBackendRegistryTest.cpp ../core/chat/ChatAddress.cpp ../core/backend/ChatBackendRegistry.cpp TEST_NAME chat-backend-registry NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core ) target_include_directories(chat-backend-registry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..) # The Matrix path with no homeserver, no network and - deliberately - no # libQuotient linked in: MatrixTranslate.cpp is kept free of Quotient types # exactly so the decisions worth checking can be checked here. What is left is # the addressing scheme and the file naming it has to survive, which is where a # mistake quietly files a conversation under the wrong name or merges two of # them into one log. MatrixManager and MatrixRoomBridge are absent because # everything they do is a round trip to a server. # # Qt6::Qml is for the QML_ELEMENT marker in HistoryManager's header. ecm_add_test( MatrixWiringTest.cpp ../core/chat/ChatAddress.cpp ../core/chat/HistoryManager.cpp ../matrix/MatrixTranslate.cpp ../core/security/CryptoManager.cpp ../core/security/SecretStore.cpp ${KOUTNET_LOGGING_SRCS} ${KOUTNET_CRYPTO_LOGGING_SRCS} TEST_NAME matrix-wiring NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core Qt6::Qml PkgConfig::Sodium KF6::I18n ) # HistoryManager.cpp includes its logging category header, which is generated # into the parent directory's build tree and not into this one; CryptoManager.cpp # and SecretStore.cpp pull the crypto category and stray into KWallet when the # app build has it, exactly as the crypto-manager and network-manager suites do. target_include_directories(matrix-wiring PRIVATE ${KOUTNET_GENERATED_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/..) if(KF6Wallet_FOUND) target_compile_definitions(matrix-wiring PRIVATE KOUTNET_HAVE_KWALLET) target_link_libraries(matrix-wiring KF6::Wallet) endif() # Pure helpers for the Matrix sign-in: the SSO redirect URL builder and the # recovery-key shape check. No Quotient, no wallet, no network - the same # server-independent testing line as MatrixWiringTest, and the part of the new # token/SSO login that a homeserver round trip cannot cover. ecm_add_test( MatrixLoginTest.cpp ../matrix/MatrixLoginUtils.cpp TEST_NAME matrix-login NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core ) # The conversation list's folders: which folder a chat is in, and what that # decides about the sections drawn over the list. No sockets and no libQuotient; # the members of a list are written by hand and the folders are asked about them. # HistoryManager and its crypto come along because ChatListModel holds one, and # the test never opens a wallet. ecm_add_test( ChatFoldersTest.cpp ../core/chat/ChatFolders.cpp ../core/chat/ChatListModel.cpp ../core/chat/UnreadManager.cpp ../core/chat/HistoryManager.cpp ../core/chat/ChatAddress.cpp ../core/security/CryptoManager.cpp ../core/security/SecretStore.cpp ${KOUTNET_LOGGING_SRCS} ${KOUTNET_CRYPTO_LOGGING_SRCS} TEST_NAME chat-folders NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core Qt6::Qml PkgConfig::Sodium KF6::I18n ) target_include_directories(chat-folders PRIVATE ${KOUTNET_GENERATED_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/..) if(KF6Wallet_FOUND) target_compile_definitions(chat-folders PRIVATE KOUTNET_HAVE_KWALLET) target_link_libraries(chat-folders KF6::Wallet) endif() # Every transport's chat-id prefix, round-tripped and not confused with another. # The Telegram and Rocket.Chat prefixes are already in the routing table and were # until now untested; a wrong prefix files a conversation under the wrong backend. ecm_add_test( ChatAddressTest.cpp ../core/chat/ChatAddress.cpp TEST_NAME chat-address NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core ) # The language list the settings page offers, which is a directory listing rather # than an array in QML - so this is about what the listing accepts and what it # calls a language. No window and no network: a catalog here is an empty file of # the right name in the right place, which is all the search ever looked at. # Qt6::Qml is for the QML_ELEMENT marker in the header. ecm_add_test( TranslationCatalogTest.cpp ../core/i18n/TranslationCatalog.cpp TEST_NAME translation-catalog NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core Qt6::Qml KF6::I18n ) target_include_directories(translation-catalog PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..) # The chat list's resize handle, under real pointer events. The column's width # is a DragHandler's translation, and neither a stuck grab nor a handle parked # over the list's own scrollbar can be seen without pressing, moving and # releasing a mouse - both were reported as the width jumping to a limit and # refusing to move again. QQC2::ScrollView stands in for ChatListPage's, and # Kirigami is left out because none of this needs it. ecm_add_test( ChatListHandleDragTest.cpp TEST_NAME chat-list-handle-drag NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core Qt6::Gui Qt6::Quick Qt6::Qml Qt6::QuickControls2 ) # The same story as the two suites below: the drags here are pointer events # against a window that is already on the screen, and on the CI's X server the # pace of those events is whatever the window manager and the frame pacing make # of it - on Qt 6.13 one of four cancelling drags was swallowed whole and the # column finished twenty pixels from where it started. The offscreen platform # delivers every event the suite asks for, in the order it asks. set_tests_properties(koutnet-chat-list-handle-drag PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen") # What a tap on a face in a column of avatars does. In that width the row is the # picture, so the first tap opens the conversation and only a second one on the # same face opens the menu - the one thing the strip has no other way to reach. # It is a state machine over chat ids, so it is tested as one: which of the two a # given run of taps lands on, what is left armed, and when the arrangement is # dropped again. No pointer, no Kirigami and no ContactDelegate, since the face # itself is not what is under test. ecm_add_test( ChatListAvatarTapTest.cpp TEST_NAME chat-list-avatar-tap NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core Qt6::Gui Qt6::Quick Qt6::Qml Qt6::QuickControls2 ) # What the picker's search box finds. The panel named an emoji by its shortcode # while searching only the shortcode, so it could not be found by the name it was # shown under; the table behind the search is where both names are and the fix is # to read both. The table is built from the generated emojis.h and the skin tone # list beside it, and it keeps its recently used list in the state config, which # is why the config libraries come along. ecm_add_test( EmojiModelTest.cpp ../core/emoji/EmojiModel.cpp ../core/emoji/EmojiTones.cpp TEST_NAME emoji-model NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core Qt6::Gui Qt6::Qml KF6::ConfigCore KF6::I18n ) # Where a category of the emoji panel is left, and which categories the tabs are. # The panel keeps the scroll top of each category the way Telegram's tabs do, and # shows the history in a strip rather than as a tab, so the tabs start one along. # A reduction of EmojiPicker.qml's state, with no EmojiModel and no Kirigami: what # is under test is where the grid ends up, not what is in it. ecm_add_test( EmojiPanelScrollTest.cpp TEST_NAME emoji-panel-scroll NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core Qt6::Gui Qt6::Quick Qt6::Qml Qt6::QuickControls2 ) # Where the emoji panel is put and how big it is. Telegram's is a fixed 345 wide, # takes three quarters of the room the compose button leaves it, and hangs off # the trailing edge of the compose row; KOutNet's was sized off the window and # aligned by the button's left edge, which is what put it in the corner of the # chat. A reduction of EmojiPopup.qml's geometry, with the real QQC2.Popup's # overlay and menu left out but Kirigami imported for the units, so the figures # are compared in the scale the panel actually measures itself in. ecm_add_test( EmojiPopupPositionTest.cpp TEST_NAME emoji-popup-position NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core Qt6::Gui Qt6::Quick Qt6::Qml Qt6::QuickControls2 ) # The suite resizes a window that is already on the screen, and on the CI's X # server such a resize does not come back as a geometry change - the panel is # measured in a window that kept the size it opened at, which is every width # and height this suite asserts against. A resize asked before the window is # shown does arrive (the scroll suite resizes that way and passes), so the # suite runs on the offscreen platform instead, where the window's geometry is # the platform's own and there is no window manager to take the resize. set_tests_properties(koutnet-emoji-popup-position PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen") # What the emoji panel's column of its own costs the conversation: the column is # the height of the page rather than of its content item, the composer and the # timeline both give up its width, and a window in one column drops the panel # down over the conversation instead. A reduction of ChatPage.qml's arrangement, # with the timeline, the composer and the panel stood in for. ecm_add_test( EmojiSidePanelTest.cpp TEST_NAME emoji-side-panel NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core Qt6::Gui Qt6::Quick Qt6::Qml Qt6::QuickControls2 ) # The themes the settings page offers, which are read off a folder rather than # listed in QML: which files in it are themes, what a theme is named, what a tile # is handed to draw, and what tone a picture washes a scrim with. No window: what # is inside a file is not this search's business, and a file of a name in a place # is all it looks at - except for the tone, which is the one thing about a file # that is asked of it. ecm_add_test( ThemeLibraryTest.cpp ../core/theme/ThemeLibrary.cpp TEST_NAME theme-library NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core Qt6::Gui Qt6::Qml ) target_include_directories(theme-library PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..) # The shape of the themes tab: how many tiles fit to a row and whether they fill # it, that the tile in use is the one carrying the wallpaper that is set, and that # a tile clicked says which picture was picked. The tile is the file itself - the # test is told where the QML lives and puts it in a module of its own - and the # gallery is its grid with the form cards left out, because what is measured here # is the grid. ecm_add_test( ThemeGalleryTest.cpp TEST_NAME theme-gallery NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core Qt6::Gui Qt6::Quick Qt6::Qml Qt6::QuickControls2 ) target_compile_definitions(theme-gallery PRIVATE KOUTNET_QML_DIR="${CMAKE_CURRENT_SOURCE_DIR}/../qml/settings") # As with the emoji popup suite above: the window here is resized after it is # shown, and on the CI's X server that resize does not come back as a geometry # change - the grid keeps counting tiles for the width it opened at, and the # decoded size never has anything to differ from. The offscreen platform has # no window manager to take the resize away. set_tests_properties(koutnet-theme-gallery PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen") # The three appearance selectors that are not colours - the font, the icon theme # and the controls style - and the one piece of arithmetic among them: a blank # setting has to resolve back to the desktop's font rather than to a nameless # one. The settings class is generated into this target's own build directory # rather than borrowed from the application's, so a run here never touches the # settings file the application keeps. Qt6::QuickControls2 is for QQuickStyle, # which the style selector reads the running name out of. ecm_add_test( AppearanceSelectorsTest.cpp ../core/theme/FontSelector.cpp ../core/theme/IconThemeSelector.cpp ../core/theme/StyleSelector.cpp TEST_NAME appearance-selectors NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core Qt6::Gui Qt6::QuickControls2 KF6::ConfigGui ) kconfig_add_kcfg_files(appearance-selectors GENERATE_MOC ../core/constructor/koutnetsettings.kcfgc) target_include_directories(appearance-selectors PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR}) ecm_add_test( TextHandlerTest.cpp ../core/chat/TextHandler.cpp TEST_NAME text-handler NAME_PREFIX koutnet- LINK_LIBRARIES Qt6::Test Qt6::Core Qt6::Qml ) target_include_directories(text-handler PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..)