我有一个其初始化方法需要处理的类
bool MyClass::init(void* pWnd, void* pDC)
{
/*
HDC m_hDC{ nullptr };
HWND m_hWnd{ nullptr };*/
if (!m_hDC) // if it was not initialized
{
m_hWnd = reinterpret_cast<HWND>(pWnd);
m_hDC = GetDC(m_hWnd);
}
assert(m_hWnd == reinterpret_cast<HWND>(pWnd));
assert(m_hDC != reinterpret_cast<HDC>(pDC));
if (!m_hDC) // if the initialization failed
{
return false; // invalid parameters
}
.....
}
我正在为此课程编写Google测试。有什么方法可以在Google测试中模拟窗口句柄或创建虚拟窗口句柄?
这可能不是正确的方法,但可能会帮助某人。幸运的是,我正在测试的库为GLFW。因此,我使用该窗口创建了窗口。
这里是代码,
glfwInit();
// Set all the required options for GLFW
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
// Create a GLFWwindow object that we can use for GLFW's functions
GLFWwindow* window = glfwCreateWindow(100, 100, "TestWindow", nullptr, nullptr);
HWND val = glfwGetWin32Window(window);
obj.init(val, nullptr);