From 49b4d63f43b210621baf71f9db6a7dc0e6e2a276 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois-Simon=20Fauteux-Chapleau?=
 <francois-simon.fauteux-chapleau@savoirfairelinux.com>
Date: Tue, 25 Mar 2025 15:32:43 -0400
Subject: [PATCH] build: fix incorrect use of LIBJAMI_TESTABLE macro

The LIBJAMI_TESTABLE macro was always defined, so using it in ifdef
directives had no effect.

Change-Id: I0f7ac906c70a90230cf224f9dc001712e1d5ca86
---
 CMakeLists.txt                              |  4 ++--
 src/jami/def.h                              |  6 +++---
 src/jamidht/conversation.cpp                | 10 +++++-----
 src/jamidht/conversation.h                  |  2 +-
 src/jamidht/conversation_module.cpp         | 16 ++++++++--------
 src/jamidht/conversation_module.h           |  2 +-
 src/jamidht/conversationrepository.cpp      |  4 ++--
 src/jamidht/conversationrepository.h        |  8 ++++----
 src/jamidht/gitserver.h                     |  2 +-
 src/jamidht/jamiaccount.cpp                 |  2 +-
 src/jamidht/jamiaccount.h                   |  4 ++--
 src/jamidht/swarm/swarm_channel_handler.cpp |  4 ++--
 src/jamidht/swarm/swarm_channel_handler.h   |  2 +-
 src/manager.h                               |  4 ++--
 src/plugin/jamipluginmanager.cpp            |  3 +++
 src/plugin/jamipluginmanager.h              |  2 +-
 16 files changed, 39 insertions(+), 36 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index deb2d26d2..8e4ff658f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -598,7 +598,7 @@ else()
         PJ_AUTOCONF=1
     )
     if (BUILD_TESTING)
-        target_compile_definitions(${PROJECT_NAME} PRIVATE DEBUG)
+        target_compile_definitions(${PROJECT_NAME} PRIVATE LIBJAMI_TEST)
     endif()
     if (ANDROID)
         target_link_libraries(${PROJECT_NAME} PRIVATE OpenSLES log)
@@ -822,7 +822,7 @@ else()
             HAVE_RINGNS=1
             ASIO_STANDALONE
             MSGPACK_NO_BOOST
-            DEBUG
+            LIBJAMI_TEST
         )
         if (JAMI_PLUGIN)
             target_compile_definitions(ut_library PUBLIC ENABLE_PLUGIN)
diff --git a/src/jami/def.h b/src/jami/def.h
index 0e56b10ef..fa0229f0a 100644
--- a/src/jami/def.h
+++ b/src/jami/def.h
@@ -43,8 +43,8 @@
 #define LIBJAMI_LOCAL
 #endif // jami_EXPORTS
 
-#ifdef DEBUG
-#define LIBJAMI_TESTABLE LIBJAMI_EXPORT
+#ifdef LIBJAMI_TEST
+#define LIBJAMI_TEST_EXPORT LIBJAMI_EXPORT
 #else
-#define LIBJAMI_TESTABLE
+#define LIBJAMI_TEST_EXPORT
 #endif
diff --git a/src/jamidht/conversation.cpp b/src/jamidht/conversation.cpp
index eb6e224fc..495ca4fbd 100644
--- a/src/jamidht/conversation.cpp
+++ b/src/jamidht/conversation.cpp
@@ -628,7 +628,7 @@ public:
     std::mutex membersMtx_ {};
     std::set<std::string> checkedMembers_; // Store members we tried
     std::function<void()> bootstrapCb_;
-#ifdef LIBJAMI_TESTABLE
+#ifdef LIBJAMI_TEST
     std::function<void(std::string, BootstrapStatus)> bootstrapCbTest_;
 #endif
 
@@ -2298,7 +2298,7 @@ Conversation::onMessageStatusChanged(const std::function<void(const std::map<std
     pimpl_->messageStatusCb_ = cb;
 }
 
-#ifdef LIBJAMI_TESTABLE
+#ifdef LIBJAMI_TEST
 void
 Conversation::onBootstrapStatus(const std::function<void(std::string, BootstrapStatus)>& cb)
 {
@@ -2333,7 +2333,7 @@ Conversation::checkBootstrapMember(const asio::error_code& ec,
         JAMI_WARNING("{}[SwarmManager {}] Bootstrap: Fallback failed. Wait for remote connections.",
                     sthis->pimpl_->toString(),
                     fmt::ptr(sthis->pimpl_->swarmManager_.get()));
-#ifdef LIBJAMI_TESTABLE
+#ifdef LIBJAMI_TEST
         if (sthis->pimpl_->bootstrapCbTest_)
             sthis->pimpl_->bootstrapCbTest_(sthis->id(), BootstrapStatus::FAILED);
 #endif
@@ -2363,7 +2363,7 @@ Conversation::checkBootstrapMember(const asio::error_code& ec,
                 return;
             auto checkNext = true;
             if (ok && devices->size() != 0) {
-#ifdef LIBJAMI_TESTABLE
+#ifdef LIBJAMI_TEST
                 if (sthis->pimpl_->bootstrapCbTest_)
                     sthis->pimpl_->bootstrapCbTest_(sthis->id(), BootstrapStatus::FALLBACK);
 #endif
@@ -2447,7 +2447,7 @@ Conversation::bootstrap(std::function<void()> onBootstraped,
                 }
                 if (sthis->pimpl_->bootstrapCb_)
                     sthis->pimpl_->bootstrapCb_();
-#ifdef LIBJAMI_TESTABLE
+#ifdef LIBJAMI_TEST
                 if (sthis->pimpl_->bootstrapCbTest_)
                     sthis->pimpl_->bootstrapCbTest_(sthis->id(), BootstrapStatus::SUCCESS);
 #endif
diff --git a/src/jamidht/conversation.h b/src/jamidht/conversation.h
index 0e6109402..f4458e7da 100644
--- a/src/jamidht/conversation.h
+++ b/src/jamidht/conversation.h
@@ -163,7 +163,7 @@ public:
      */
     void monitor();
 
-#ifdef LIBJAMI_TESTABLE
+#ifdef LIBJAMI_TEST
     enum class BootstrapStatus { FAILED, FALLBACK, SUCCESS };
     /**
      * Used by the tests to get whenever the DRT is connected/disconnected
diff --git a/src/jamidht/conversation_module.cpp b/src/jamidht/conversation_module.cpp
index 77cc1c025..71b2e5d68 100644
--- a/src/jamidht/conversation_module.cpp
+++ b/src/jamidht/conversation_module.cpp
@@ -406,7 +406,7 @@ public:
     std::map<std::string, uint64_t> refreshMessage;
     std::atomic_int syncCnt {0};
 
-#ifdef LIBJAMI_TESTABLE
+#ifdef LIBJAMI_TEST
     std::function<void(std::string, Conversation::BootstrapStatus)> bootstrapCbTest_;
 #endif
 
@@ -814,9 +814,9 @@ ConversationModule::Impl::handlePendingConversation(const std::string& conversat
             sendMessageNotification(*conversation, false, commitId);
         erasePending(); // Will unlock
 
-#ifdef LIBJAMI_TESTABLE
+#ifdef LIBJAMI_TEST
         conversation->onBootstrapStatus(bootstrapCbTest_);
-#endif // LIBJAMI_TESTABLE
+#endif
         conversation->bootstrap(std::bind(&ConversationModule::Impl::bootstrapCb,
                                           this,
                                           conversation->id()),
@@ -1405,9 +1405,9 @@ ConversationModule::Impl::bootstrap(const std::string& convId)
     }
     auto bootstrap = [&](auto& conv) {
         if (conv) {
-#ifdef LIBJAMI_TESTABLE
+#ifdef LIBJAMI_TEST
             conv->onBootstrapStatus(bootstrapCbTest_);
-#endif // LIBJAMI_TESTABLE
+#endif
             conv->bootstrap(std::bind(&ConversationModule::Impl::bootstrapCb, this, conv->id()), kd);
         }
     };
@@ -1537,7 +1537,7 @@ ConversationModule::setAccountManager(std::shared_ptr<AccountManager> accountMan
     pimpl_->accountManager_ = accountManager;
 }
 
-#ifdef LIBJAMI_TESTABLE
+#ifdef LIBJAMI_TEST
 void
 ConversationModule::onBootstrapStatus(
     const std::function<void(std::string, Conversation::BootstrapStatus)>& cb)
@@ -2088,9 +2088,9 @@ ConversationModule::startConversation(ConversationMode mode, const dht::InfoHash
                 });
             });
         conversation->onNeedSocket(pimpl_->onNeedSwarmSocket_);
-#ifdef LIBJAMI_TESTABLE
+#ifdef LIBJAMI_TEST
         conversation->onBootstrapStatus(pimpl_->bootstrapCbTest_);
-#endif // LIBJAMI_TESTABLE
+#endif
         conversation->bootstrap(std::bind(&ConversationModule::Impl::bootstrapCb,
                                           pimpl_.get(),
                                           conversationId),
diff --git a/src/jamidht/conversation_module.h b/src/jamidht/conversation_module.h
index 479331005..b3024b70f 100644
--- a/src/jamidht/conversation_module.h
+++ b/src/jamidht/conversation_module.h
@@ -87,7 +87,7 @@ public:
 
     void loadSingleConversation(const std::string& convId);
 
-#ifdef LIBJAMI_TESTABLE
+#ifdef LIBJAMI_TEST
     void onBootstrapStatus(const std::function<void(std::string, Conversation::BootstrapStatus)>& cb);
 #endif
 
diff --git a/src/jamidht/conversationrepository.cpp b/src/jamidht/conversationrepository.cpp
index 7b5715a66..0bdafb080 100644
--- a/src/jamidht/conversationrepository.cpp
+++ b/src/jamidht/conversationrepository.cpp
@@ -40,7 +40,7 @@ constexpr size_t MAX_FETCH_SIZE {256 * 1024 * 1024}; // 256Mb
 
 namespace jami {
 
-#ifdef LIBJAMI_TESTABLE
+#ifdef LIBJAMI_TEST
 bool ConversationRepository::DISABLE_RESET = false;
 #endif
 
@@ -3129,7 +3129,7 @@ ConversationRepository::Impl::addUserDevice()
 void
 ConversationRepository::Impl::resetHard()
 {
-#ifdef LIBJAMI_TESTABLE
+#ifdef LIBJAMI_TEST
     if (DISABLE_RESET)
         return;
 #endif
diff --git a/src/jamidht/conversationrepository.h b/src/jamidht/conversationrepository.h
index d9d5ef1df..97e00add3 100644
--- a/src/jamidht/conversationrepository.h
+++ b/src/jamidht/conversationrepository.h
@@ -138,10 +138,10 @@ using OnMembersChanged = std::function<void(const std::set<std::string>&)>;
 /**
  * This class gives access to the git repository that represents the conversation
  */
-class LIBJAMI_TESTABLE ConversationRepository
+class LIBJAMI_TEST_EXPORT ConversationRepository
 {
 public:
-    #ifdef LIBJAMI_TESTABLE
+    #ifdef LIBJAMI_TEST
     static bool DISABLE_RESET; // Some tests inject bad files so resetHard() will break the test
     #endif
     /**
@@ -151,7 +151,7 @@ public:
      * @param otherMember   The other uri
      * @return  the conversation repository object
      */
-    static LIBJAMI_TESTABLE std::unique_ptr<ConversationRepository> createConversation(
+    static LIBJAMI_TEST_EXPORT std::unique_ptr<ConversationRepository> createConversation(
         const std::shared_ptr<JamiAccount>& account,
         ConversationMode mode = ConversationMode::INVITES_ONLY,
         const std::string& otherMember = "");
@@ -164,7 +164,7 @@ public:
      * @param conversationId    Conversation to clone
      * @param checkCommitCb     Used if commits should be treated
      */
-    static LIBJAMI_TESTABLE std::unique_ptr<ConversationRepository> cloneConversation(
+    static LIBJAMI_TEST_EXPORT std::unique_ptr<ConversationRepository> cloneConversation(
         const std::shared_ptr<JamiAccount>& account,
         const std::string& deviceId,
         const std::string& conversationId,
diff --git a/src/jamidht/gitserver.h b/src/jamidht/gitserver.h
index e119428ee..bdba3f0fe 100644
--- a/src/jamidht/gitserver.h
+++ b/src/jamidht/gitserver.h
@@ -34,7 +34,7 @@ using onFetchedCb = std::function<void(const std::string&)>;
 /**
  * This class offers to a ChannelSocket the possibility to interact with a Git repository
  */
-class LIBJAMI_TESTABLE GitServer
+class LIBJAMI_TEST_EXPORT GitServer
 {
 public:
     /**
diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp
index 67426a11b..6d8ed25cc 100644
--- a/src/jamidht/jamiaccount.cpp
+++ b/src/jamidht/jamiaccount.cpp
@@ -2583,7 +2583,7 @@ JamiAccount::sha3SumVerify() const
     return !noSha3sumVerification_;
 }
 
-#ifdef LIBJAMI_TESTABLE
+#ifdef LIBJAMI_TEST
 void
 JamiAccount::noSha3sumVerification(bool newValue)
 {
diff --git a/src/jamidht/jamiaccount.h b/src/jamidht/jamiaccount.h
index 183d6993d..dec8ec3e8 100644
--- a/src/jamidht/jamiaccount.h
+++ b/src/jamidht/jamiaccount.h
@@ -446,7 +446,7 @@ public:
                        const std::string& fileType,
                        int32_t flag) override;
 
-#ifdef LIBJAMI_TESTABLE
+#ifdef LIBJAMI_TEST
     dhtnet::ConnectionManager& connectionManager() { return *connectionManager_; }
 
     /**
@@ -598,7 +598,7 @@ public:
      */
     bool isMobile() const { return config().proxyEnabled and not config().deviceKey.empty(); }
 
-#ifdef LIBJAMI_TESTABLE
+#ifdef LIBJAMI_TEST
     std::map<Uri::Scheme, std::unique_ptr<ChannelHandlerInterface>>& channelHandlers()
     {
         return channelHandlers_;
diff --git a/src/jamidht/swarm/swarm_channel_handler.cpp b/src/jamidht/swarm/swarm_channel_handler.cpp
index 334be67da..e06661164 100644
--- a/src/jamidht/swarm/swarm_channel_handler.cpp
+++ b/src/jamidht/swarm/swarm_channel_handler.cpp
@@ -35,7 +35,7 @@ SwarmChannelHandler::connect(const DeviceId& deviceId,
                              const std::string& connectionType,
                              bool forceNewConnection)
 {
-#ifdef LIBJAMI_TESTABLE
+#ifdef LIBJAMI_TEST
     if (disableSwarmManager)
         return;
 #endif
@@ -46,7 +46,7 @@ bool
 SwarmChannelHandler::onRequest(const std::shared_ptr<dht::crypto::Certificate>& cert,
                                const std::string& name)
 {
-#ifdef LIBJAMI_TESTABLE
+#ifdef LIBJAMI_TEST
     if (disableSwarmManager)
         return false;
 #endif
diff --git a/src/jamidht/swarm/swarm_channel_handler.h b/src/jamidht/swarm/swarm_channel_handler.h
index 65940ef36..b03e4a881 100644
--- a/src/jamidht/swarm/swarm_channel_handler.h
+++ b/src/jamidht/swarm/swarm_channel_handler.h
@@ -37,7 +37,7 @@ public:
     SwarmChannelHandler(const std::shared_ptr<JamiAccount>& acc, dhtnet::ConnectionManager& cm);
     ~SwarmChannelHandler();
 
-#ifdef LIBJAMI_TESTABLE
+#ifdef LIBJAMI_TEST
     std::atomic_bool disableSwarmManager {false};
 #endif
 
diff --git a/src/manager.h b/src/manager.h
index 2edb0cf4e..b68016f48 100644
--- a/src/manager.h
+++ b/src/manager.h
@@ -63,14 +63,14 @@ class JamiPluginManager;
 
 /** Manager (controller) of daemon */
 // TODO LIBJAMI_PUBLIC only if tests
-class LIBJAMI_TESTABLE Manager
+class LIBJAMI_TEST_EXPORT Manager
 {
 private:
     std::mt19937_64 rand_;
 
 public:
     // TODO LIBJAMI_PUBLIC only if tests
-    static LIBJAMI_TESTABLE Manager& instance();
+    static LIBJAMI_TEST_EXPORT Manager& instance();
 
     void setAutoAnswer(bool enable);
 
diff --git a/src/plugin/jamipluginmanager.cpp b/src/plugin/jamipluginmanager.cpp
index a0042f612..65a2b1f40 100644
--- a/src/plugin/jamipluginmanager.cpp
+++ b/src/plugin/jamipluginmanager.cpp
@@ -545,9 +545,12 @@ JamiPluginManager::registerServices()
     pm_.registerService("getPluginAccPreferences", getPluginAccPreferences);
 }
 
+#ifdef LIBJAMI_TEST
 void
 JamiPluginManager::addPluginAuthority(const dht::crypto::Certificate& cert)
 {
     trust_.add(cert);
 }
+#endif
+
 } // namespace jami
diff --git a/src/plugin/jamipluginmanager.h b/src/plugin/jamipluginmanager.h
index 32f0f88f2..c74ec8abb 100644
--- a/src/plugin/jamipluginmanager.h
+++ b/src/plugin/jamipluginmanager.h
@@ -208,7 +208,7 @@ public:
 
     PreferenceServicesManager& getPreferenceServicesManager() { return preferencesm_; }
 
-#ifdef LIBJAMI_TESTABLE
+#ifdef LIBJAMI_TEST
     void addPluginAuthority(const dht::crypto::Certificate& cert);
 #endif
 
-- 
GitLab