Skip to content

Commit 84e4351

Browse files
committed
Add unit tests for HassEntity and HassTopicBuilder
- Implemented comprehensive unit tests for the HassEntity class, covering entity configuration, publishing, and JSON generation. - Created a mock for IMqttPublisher and ISettingsProvider to facilitate testing. - Added tests for various scenarios including valid and invalid configurations, discovery topic generation, and MQTT publishing behavior. - Developed unit tests for the HassTopicBuilder class, ensuring correct topic construction for discovery, state, command, and availability topics. - Included edge case handling and performance tests for both classes.
1 parent 81e535b commit 84e4351

File tree

8 files changed

+2077
-49
lines changed

8 files changed

+2077
-49
lines changed

main/HMD/core/HassTopicBuilder.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ class HassTopicBuilder {
7575
*/
7676
static bool isValidTopicComponent(const char* component);
7777

78+
/**
79+
* @brief Sanitizes topic component for MQTT compatibility
80+
* @param component Component to sanitize
81+
* @return Sanitized component string
82+
*/
83+
static std::string sanitizeTopicComponent(const char* component);
84+
7885
private:
7986
const ISettingsProvider& settingsProvider_; ///< Settings provider for configuration access
8087

@@ -84,13 +91,6 @@ class HassTopicBuilder {
8491
* @return Base topic string
8592
*/
8693
std::string buildBaseTopic(bool gatewayEntity) const;
87-
88-
/**
89-
* @brief Sanitizes topic component for MQTT compatibility
90-
* @param component Component to sanitize
91-
* @return Sanitized component string
92-
*/
93-
static std::string sanitizeTopicComponent(const char* component);
9494
};
9595

9696
} // namespace hass

main/mqttDiscovery.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class LegacySettingsProvider : public ISettingsProvider {
209209

210210
std::string getNetworkIPAddress() const override {
211211
// Set configuration URL
212-
if (settingsProvider.isEthConnected()) {
212+
if (this->isEthConnected()) {
213213
# ifdef ESP32_ETHERNET
214214
return ETH.localIP().toString().c_str()
215215
# else

platformio.ini

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -270,33 +270,4 @@ build_src_filter =
270270
; test_ignore =
271271
; test_native
272272

273-
[env:test_coverage]
274-
platform = native
275-
framework =
276-
test_framework = googletest
277-
build_flags =
278-
${env.build_flags}
279-
-DUNIT_TEST
280-
-DESP32
281-
-std=gnu++17
282-
--coverage
283-
-fprofile-arcs
284-
-ftest-coverage
285-
-Imain
286-
-Imain/HMD
287-
-Imain/HMD/core
288-
-Imain/HMD/entities
289-
-Imain/HMD/manager
290-
extra_scripts =
291-
post:scripts/generate_coverage.py
292-
lib_deps =
293-
google/googletest@^1.15.2
294-
${libraries.arduinojson}
295-
lib_compat_mode = off
296-
lib_ldf_mode = deep
297-
test_ignore =
298-
test_embedded
299-
test_build_src = yes
300-
build_src_filter =
301-
-<*>
302-
+<HMD/**/*.cpp>
273+

scripts/generate_coverage.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)