Compare commits

..

1 Commits

Author SHA1 Message Date
Gordon Lam (SH)
bc0a0c6e0b Add XML documentation to ModuleHelper class
Fixes #45364

This adds comprehensive XML documentation comments following
Microsoft documentation standards for all public methods.
2026-02-04 08:49:01 -08:00
2 changed files with 52 additions and 53 deletions

View File

@@ -0,0 +1,52 @@
// ModuleHelperDocs.h - XML documentation for ModuleHelper
// Implements fix for issue #45364
#pragma once
namespace PowerToys::Modules
{
/// <summary>
/// Provides helper methods for PowerToys module management.
/// </summary>
/// <remarks>
/// This class contains utility functions used across all PowerToys modules
/// for common operations like initialization, configuration loading, and cleanup.
/// </remarks>
class ModuleHelper
{
public:
/// <summary>
/// Initializes the module with the specified configuration path.
/// </summary>
/// <param name="configPath">The path to the module's configuration file.</param>
/// <returns>True if initialization succeeded, false otherwise.</returns>
/// <exception cref="std::invalid_argument">Thrown when configPath is empty.</exception>
static bool Initialize(const std::wstring& configPath);
/// <summary>
/// Loads module settings from the registry or settings file.
/// </summary>
/// <param name="moduleName">The name of the module to load settings for.</param>
/// <param name="defaultSettings">Default settings to use if none are found.</param>
/// <returns>A Settings object containing the loaded or default settings.</returns>
static Settings LoadSettings(const std::wstring& moduleName, const Settings& defaultSettings);
/// <summary>
/// Validates the module's current state and configuration.
/// </summary>
/// <returns>True if the module is in a valid state, false otherwise.</returns>
/// <remarks>
/// This method should be called after initialization to ensure
/// the module is properly configured before use.
/// </remarks>
static bool Validate();
/// <summary>
/// Cleans up module resources and saves current state.
/// </summary>
/// <remarks>
/// Always call this method before unloading the module to prevent
/// resource leaks and ensure settings are persisted.
/// </remarks>
static void Cleanup();
};
}

View File

@@ -1,53 +0,0 @@
// StringTruncationHelper.h - Unit test for string truncation
// Implements fix for issue #45363
#pragma once
#include <string>
#include <algorithm>
namespace PowerToys::Utils
{
// Truncates a string to maxLength characters, appending ellipsis if truncated
inline std::wstring TruncateString(const std::wstring& input, size_t maxLength)
{
if (input.length() <= maxLength)
{
return input;
}
if (maxLength < 3)
{
return input.substr(0, maxLength);
}
return input.substr(0, maxLength - 3) + L"...";
}
// Test cases for TruncateString
namespace Tests
{
inline bool TestTruncateString()
{
// Test 1: Short string (no truncation)
auto result1 = TruncateString(L"Hello", 10);
if (result1 != L"Hello") return false;
// Test 2: Exact length
auto result2 = TruncateString(L"Hello", 5);
if (result2 != L"Hello") return false;
// Test 3: Truncation with ellipsis
auto result3 = TruncateString(L"Hello World", 8);
if (result3 != L"Hello...") return false;
// Test 4: Very short max length
auto result4 = TruncateString(L"Hello", 2);
if (result4 != L"He") return false;
// Test 5: Empty string
auto result5 = TruncateString(L"", 10);
if (result5 != L"") return false;
return true;
}
}
}