#pragma once #include #include #include #include #include #include #include #include namespace aissia::tests { using json = nlohmann::json; /** * @brief Mock implementation of grove::IIO for testing * * Captures published messages and allows injecting incoming messages. */ class MockIO : public grove::IIO { public: // ======================================================================== // IIO Interface Implementation // ======================================================================== void publish(const std::string& topic, std::unique_ptr data) override; void subscribe(const std::string& topicPattern, const grove::SubscriptionConfig& config = {}) override { // Mock: just record subscription m_subscriptions.push_back(topicPattern); } void subscribeLowFreq(const std::string& topicPattern, const grove::SubscriptionConfig& config = {}) override { // Mock: same as subscribe m_subscriptions.push_back(topicPattern); } int hasMessages() const override { return static_cast(m_incomingMessages.size()); } grove::Message pullMessage() override; grove::IOHealth getHealth() const override { return grove::IOHealth{ .queueSize = static_cast(m_incomingMessages.size()), .maxQueueSize = 1000, .dropping = false, .averageProcessingRate = 100.0f, .droppedMessageCount = 0 }; } grove::IOType getType() const override { return grove::IOType::INTRA; } // ======================================================================== // Test Helpers - Message Injection // ======================================================================== /** * @brief Inject a message to be received by the module under test */ void injectMessage(const std::string& topic, const json& data); /** * @brief Inject multiple messages at once */ void injectMessages(const std::vector>& messages); // ======================================================================== // Test Helpers - Verification // ======================================================================== /** * @brief Check if a message was published to a specific topic */ bool wasPublished(const std::string& topic) const; /** * @brief Get the last message published to a topic */ json getLastPublished(const std::string& topic) const; /** * @brief Get all messages published to a topic */ std::vector getAllPublished(const std::string& topic) const; /** * @brief Count messages published to a topic */ size_t countPublished(const std::string& topic) const; /** * @brief Get all published messages (topic -> data pairs) */ const std::vector>& getPublishedMessages() const { return m_publishedMessages; } /** * @brief Clear all captured and pending messages */ void clear(); /** * @brief Clear only published messages (keep incoming queue) */ void clearPublished(); // ======================================================================== // Test State // ======================================================================== /// All messages published by the module under test std::vector> m_publishedMessages; /// Messages waiting to be received by the module std::queue m_incomingMessages; /// Subscribed topic patterns (for verification) std::vector m_subscriptions; }; } // namespace aissia::tests