tests: add MockDDS and use it in GTest smoke-tests to simulate publish/subscribe flows
This commit is contained in:
1 parent
b44bb09891
commit
7372bdc766
5 files changed
+61
-4
No files matched your search
@@ -0,0 +1,27 @@
|
||||
#include "MockDDS.h"
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
namespace MockDDS {
|
||||
|
||||
static std::map<std::string, std::string> g_last_message;
|
||||
static std::mutex g_mtx;
|
||||
|
||||
void publish(const std::string &topic, const std::string &msg) {
|
||||
std::lock_guard<std::mutex> lk(g_mtx);
|
||||
g_last_message[topic] = msg;
|
||||
}
|
||||
|
||||
std::string take_last(const std::string &topic) {
|
||||
std::lock_guard<std::mutex> lk(g_mtx);
|
||||
auto it = g_last_message.find(topic);
|
||||
if (it == g_last_message.end()) return std::string();
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void clear_all() {
|
||||
std::lock_guard<std::mutex> lk(g_mtx);
|
||||
g_last_message.clear();
|
||||
}
|
||||
|
||||
} // namespace MockDDS
|
||||
Reference in new issue
Block a user