如何在Windows中模拟注册表进行程序测试
How to emulate registry in Windows for program testing?
我的应用程序大量读取和更改windows注册表。由于应用程序的性质,有可能破坏系统。
为了避免系统破坏,我想创建一个注册表的临时副本,并使用copy()。所有的注册文件?或任何其他合适的导出格式)在我的应用程序。我更愿意保持所有的窗口函数相同,所以,为了测试,我想挂钩我自己的应用程序的注册表函数与DLL,将所有注册表访问重定向到一个文件。
我确实找了一些库,但是没有这样的东西可以做这个,或者我不知道我在找什么。在这种情况下我能做些什么?
简而言之:我想模拟windows注册表
我想创建一个钩子DLL,它将被注入到我自己的应用程序
钩子dll将钩子所有的windows注册表函数并重定向到dll目录下的一个文件。
是否有windows注册表功能的开源实现?我只有标题,但我需要完全相同的行为作为windows提供彻底测试应用程序。
在这种情况下我能做些什么?
在注册表API之上实现一个抽象层,并通过抽象层访问API。然后,在需要注册表访问的代码中注入一个实现。
class SettingsStore {
public:
SettingsStore(const std::string&); // receive path or "unique key" for your settings
virtual ~SettingsStore() = 0;
virtual std::string GetValue(const std::string& key) = 0;
virtual void SetValue(const std::string& key, const std::string& value) = 0;
// ...
};
class RegistryStore: public SettingsStore {
public:
SettingsStore(const std::string&); // receive path or "unique key" for your settings
virtual ~SettingsStore();
// implement in terms of Windows Registry API
virtual std::string GetValue(const std::string& key) override;
virtual void SetValue(const std::string& key, const std::string& value) override;
// ...
private:
// registry handle here
};
在此之后,根据注入的SettingsStore引用实现代码。
你的测试代码可以依赖于TestStore(扩展SettingsStore)或其他。
简而言之:我想模拟windows注册表
我想创建一个钩子DLL,它将被注入到我自己的应用程序
这听起来很复杂(与x-y问题相似)。对您来说,实现上面的解决方案是否令人望而却步?
相关文章:
- 试图对缓存进行跨步测试,但程序并没有结束
- Qt QML桌面应用程序自动化测试
- 员工测试驱动程序数据结构
- 如何从测试脚本中运行WAF编译C++程序?
- 测试操作系统时执行程序集"sti"时虚拟框崩溃
- C++低吞吐量 winsock TCP 测试应用程序
- 当我尝试进行TPC-E测试时,实用程序抱怨"undefined reference"
- 如何将参数传递给Google基准测试程序
- Cmake无法在qt-creater/collect2上编译简单的测试程序:错误:ld
- 当要测试的函数需要用户输入时,如何制作驱动程序函数?
- 为什么当测试用例数为 1 时,我的程序不输入而是打印新行?
- 如何使用Boost单元测试框架测试Qt应用程序
- CMake 和 Visual Studio 2015 - C 编译器 cl.exe 无法编译简单的测试程序
- C++编译器 g++.exe 无法编译简单的测试程序 - 确定 CXX 编译器是否工作失败
- 如何编译和运行 vmmlib 测试程序?
- Mongodb Cxx 驱动程序测试在发布版本中崩溃 [ 在调试中工作正常]
- 如何用一个简单的C++程序测试CPU
- 变位程序测试
- Qt程序测试错误
- 如何在Windows中模拟注册表进行程序测试