|
| 1 | +// DirectXOperation_UnitTest.cpp |
| 2 | +#include "pch.h" |
| 3 | +#include "CppUnitTest.h" |
| 4 | +#include "../DX11Operation/DirectXOperation.h" |
| 5 | +#include <Windows.h> // Include Windows API header for LoadLibrary, FreeLibrary |
| 6 | +#include <memory> |
| 7 | +#include <iostream> |
| 8 | +#include <filesystem> |
| 9 | +#include "../OpNode/IOperate.h" // Include IOperate from OpNode project |
| 10 | + |
| 11 | +using namespace Microsoft::VisualStudio::CppUnitTestFramework; |
| 12 | + |
| 13 | +namespace DirectXOperationTests { |
| 14 | + |
| 15 | + // Simple window procedure for a dummy window. |
| 16 | + LRESULT CALLBACK DummyWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { |
| 17 | + return DefWindowProc(hWnd, message, wParam, lParam); |
| 18 | + } |
| 19 | + |
| 20 | + // Helper function to create a hidden window. |
| 21 | + HWND CreateDummyWindow() { |
| 22 | + const wchar_t CLASS_NAME[] = L"DummyWindowClass"; |
| 23 | + |
| 24 | + WNDCLASS wc = {}; |
| 25 | + wc.lpfnWndProc = DummyWndProc; |
| 26 | + wc.hInstance = GetModuleHandle(nullptr); |
| 27 | + wc.lpszClassName = CLASS_NAME; |
| 28 | + RegisterClass(&wc); |
| 29 | + |
| 30 | + HWND hWnd = CreateWindowEx( |
| 31 | + 0, // Optional window styles. |
| 32 | + CLASS_NAME, // Window class |
| 33 | + L"Dummy Window", // Window text |
| 34 | + WS_OVERLAPPEDWINDOW, // Window style |
| 35 | + CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, |
| 36 | + nullptr, // Parent window |
| 37 | + nullptr, // Menu |
| 38 | + GetModuleHandle(nullptr), // Instance handle |
| 39 | + nullptr // Additional application data |
| 40 | + ); |
| 41 | + |
| 42 | + // Hide the window (for unit testing, no need to show it). |
| 43 | + ShowWindow(hWnd, SW_HIDE); |
| 44 | + return hWnd; |
| 45 | + } |
| 46 | + |
| 47 | + TEST_CLASS(DirectXOperationUnitTests) |
| 48 | + { |
| 49 | + public: |
| 50 | + TEST_METHOD(TestDirectXInitialization) { |
| 51 | + HWND hWnd = CreateDummyWindow(); |
| 52 | + DirectXOperation dxOp; |
| 53 | + bool result = dxOp.Initialize(hWnd, 800, 600); |
| 54 | + Assert::IsTrue(result, L"DirectXOperation should initialize successfully."); |
| 55 | + |
| 56 | + // Optionally call Render to see if the device works. |
| 57 | + dxOp.Render(); |
| 58 | + dxOp.Cleanup(); |
| 59 | + DestroyWindow(hWnd); // Clean up dummy window. |
| 60 | + } |
| 61 | + }; |
| 62 | +} |
0 commit comments