I am trying to run the GUI unit test with DUnit for an application whose main form creates dynamic frames for itself. I was able to create the main form of the application for testing as a form in the test case and access its menu items, etc.
The problem occurs when an application tries to create a frame dynamically. The reading of the frame resource occurs to such an extent that it needs a window handle (in my case, setting the title of the tab sheet). Here it goes from TWinControl.GetHandle to TWinControl.CreateWnd and to TCustomFrame.CreateParams.
This CreateParams code says:
if Parent = nil then Params.WndParent := Application.Handle;
There is a difference. When I run the actual application (not in the test), Application.Handle returns a nonzero number, and the thread continues normally. But in the DUnit test application, Application.Handle returns 0. This causes the code in TWinControl.CreateWnd to throw an exception indicating that there is no parent in the frame:
with Params do begin if (WndParent = 0) and (Style and WS_CHILD <> 0) then if (Owner <> nil) and (csReading in Owner.ComponentState) and (Owner is TWinControl) then WndParent := TWinControl(Owner).Handle else raise EInvalidOperation.CreateFmt(SParentRequired, [Name]);
I would like to try to get around this problem (and generally, all test problems) without changing the "production" code just because of the tests. Can you give any information on whether I can somehow get the “Application” to do something else or somehow get around this?
If you look at the code, perhaps another workaround scenario might be to try to get the owner (which is my "MainForm" for the application to the test, ie whose descriptor I want to get) to be in csReading in the process of creating this frame in the test, but at least at first glance, it’s not so easy for this to happen.
source share