4

I use DUnit. It has an VCL GUITestRunner and a console TextTestRunner.

In an unit used by both Firemonkey and VCL Forms applications I would like to achieve the following:

  1. If Firemonkey app, if target is OS X, and executing on OS X -> TextTestRunner
  2. If Firemonkey app, if target is 32-bit Windows, executing on Windows -> AllocConsole + TextTestRunner
  3. If VCL app -> GUITestRunner

{$IFDEF MACOS}
TextTestRunner.RunRegisteredTests;      // Case 1
{$ELSE}
   {$IFDEF MSWINDOWS}
   AllocConsole;
   {$ENDIF}
   {$IFDEF FIREMONKEY_APP}              // Case 2 <--------------- HERE
   TextTestRunner.RunRegisteredTests;  
   {$ELSE}                              // Case 3
   GUITestRunner.RunRegisteredTests;
   {$IFEND}
{$ENDIF}

Which is the best way to make Case 2 work?

Gad D Lord
  • 6,620
  • 12
  • 60
  • 106
  • It is possible to have an app that has uses both FireMonkey and VCL units. – David Heffernan Sep 21 '12 at 09:16
  • Is case 1 ever true? I mean MACOS and MSWINDOWS defined at the same time? Also, what do you mean by "target is OS X, but executing on Windows"? – Ondrej Kelle Sep 21 '12 at 09:22
  • @TOndrej: Question refactored as suggested since running Mac OSX apps on Wnidows in not possible – Gad D Lord Sep 21 '12 at 09:37
  • @David: "It is possible to have an app that has uses both FireMonkey and VCL units". I don't want to include them since they make the app bigger and most of them have Win API calls. In order to conditionally include them in uses clause I need exactly the same check IFDEF FIREMONKEY_APP – Gad D Lord Sep 21 '12 at 09:40
  • You might not include VCL units in an FMX app. But some people do. So there can't exist a conditional that does what you want. Remember, conditionals are known at the point at which the code is compiled. – David Heffernan Sep 21 '12 at 09:47
  • I like Remy's answer to this same question at http://stackoverflow.com/a/12789316/74137 – John Kaster Feb 05 '16 at 01:12

2 Answers2

0

There are no built in conditionals that tell you whether the project's FrameworkType, as specified in the .dproj file, is VCL or FMX. To the very best of my knowledge you cannot switch on that setting in code. Remember also that it is perfectly possible, although certainly not mainstream, to have an application that uses both VCL and FMX. It's really not an either or condition.

So I recommend that you declare your own conditional define that controls whether you use the GUI runner or the text runner.

In fact, you presumably already have some sort of a mechanism to do this. You code names the unit GUITestRunner. So that means it must be in a uses in the same file as the code in the question. How did you conditionally include GUITestRunner in the uses clause?

Note: The same question has been asked on the Embarcadero forums: https://newsgroups.embarcadero.com/message.jspa?messageID=400077

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • I ended up adding FIREMONKEY conditional define under 'Conditional Defines' in my projects settings (in order to make it work globally in the applciation for all units). I might have created an FireMonkey.inc with the {$DEFINE FOREMONKEY} as well. – Gad D Lord Sep 21 '12 at 09:52
  • "How did you conditionally include GUITestRunner in the uses clause?" Quite right - I had the same issue in the uses clause as well. – Gad D Lord Sep 21 '12 at 09:54
-1

use {$IF Defined(MSWINDOWS)}

instead of {$IFDEF MSWINDOWS}

because {$IFDEF MSWINDOWS} is not working correctly in Firemonkey VCL applications.

Wanna Coffee
  • 2,742
  • 7
  • 40
  • 66
suathd
  • 19
  • 1