7

I have the following .dpr

program TPWDDBManager;
{

  Delphi DUnit Test Project
  -------------------------
  This project contains the DUnit test framework and the GUI/Console test runners.
  Add "CONSOLE_TESTRUNNER" to the conditional defines entry in the project options
  to use the console test runner.  Otherwise the GUI test runner will be used by
  default.

}

{$IFDEF CONSOLE_TESTRUNNER}
{$APPTYPE CONSOLE}
{$ENDIF}

uses
  DUnitTestRunner,
  TestuTPWDDBManager in 'TestuTPWDDBManager.pas';

{$R *.RES}

begin
  DUnitTestRunner.RunRegisteredTests;
end.

and the following unit:

unit TestuTPWDDBManager;
{

  Delphi DUnit Test Case
  ----------------------
  This unit contains a skeleton test case class generated by the Test Case Wizard.
  Modify the generated code to correctly setup and call the methods from the unit
  being tested.

}

interface

uses TestFramework;

type
  // Test methods for class TPWDDBManager

  TestTPWDDBManager = class(TTestCase)
  strict private
  public
    procedure SetUp; override;
    procedure TearDown; override;
  published
    procedure TestUpdateVersion;
    procedure TestGetPWD;
    procedure TestChangePWD;
    procedure TestReset;
    procedure TestIsReset;

  end;

  Idlg = interface(IInvokable)
    ['{E369D075-E3CA-4BB3-896C-0D623DE5798F}']

  end;

implementation

uses SysUtils,Delphi.Mocks;

procedure TestTPWDDBManager.SetUp;
var
  FMessageDLG : TMock<IDlg>;
begin
end;

procedure TestTPWDDBManager.TearDown;
begin
end;

procedure TestTPWDDBManager.TestGetPWD;
begin
  // TODO: Validate method results
end;

procedure TestTPWDDBManager.TestIsReset;
begin
end;

procedure TestTPWDDBManager.TestChangePWD;
begin
end;

procedure TestTPWDDBManager.TestReset;
begin
end;

procedure TestTPWDDBManager.TestUpdateVersion;
begin

end;

initialization
  // Register any test cases with the test runner
  RegisterTest(TestTPWDDBManager.Suite);
end.

When I compile I get several warnings like:

[DCC Warning] W1029 Duplicate constructor 'TExpectation.CreateAfter' with identical parameters will be inacessible from C++ [DCC Warning] W1029 Duplicate constructor 'TExpectation.CreateAfterWhen' with identical parameters will be inacessible from C++ [DCC Warning] W1029 Duplicate constructor 'TExpectation.CreateAtLeastOnce' with identical parameters will be inacessible from C++

but if I remove the line FMessageDLG : TMock<IDlg>; then the warning disappears

any idea of how to solve this ?

Jens Mühlenhoff
  • 14,565
  • 6
  • 56
  • 113
pio pio
  • 732
  • 1
  • 7
  • 29
  • 4
    Delphi Mocks and C++ Compatibility Compiler flag in delphi projects are mutually incompatible. Just turn off the C++ Compatibility options in the Compiler settings. Remember that Delphi is used for many purposes. This warning serves a purpose in some use scenarios, but not in most delphi user's daily routines. You can disable the warning. `{$WARN UPLICATE_CTOR_DTOR OFF}` <-- add to your unit – Warren P Nov 10 '13 at 14:02
  • 1
    @WarrenP this should be an answer – jpfollenius Nov 11 '13 at 08:30
  • 1
    @WarrenP: I guess `UPLICATE` is actually `DUPLICATE`, right? One question: putting this on my unit didn't solve, I had to put it on the project's unit and then the warning disappeared, why is that? – Felipe Morais Aug 26 '18 at 05:15
  • Project scope is first. Unit scope won't affect other units, thus the difference. – Warren P Aug 27 '18 at 14:45
  • Can't seem to migrate or edit old comments. Posted as an answer anyways just in case more people see it. – Warren P Aug 27 '18 at 14:47

2 Answers2

7

Delphi Mocks and C++ Compatibility Compiler flag in delphi projects are mutually incompatible. Just turn off the C++ Compatibility options in the Compiler settings. Remember that Delphi is used for many purposes. This warning serves a purpose in some use scenarios, but not in most delphi user's daily routines. You can disable the warning.

{$WARN DUPLICATE_CTOR_DTOR OFF} 

Add to your PROJECT (.dpr) scope or unit scope, as needed to fix.

Warren P
  • 65,725
  • 40
  • 181
  • 316
  • Hi. That directive is automatically removed by the IDE from DPK files. Any fix for this? https://stackoverflow.com/questions/71725441/warn-duplicate-ctor-dtor-off-gets-deleted-from-dpk-file – Gabriel May 25 '22 at 10:09
4

The warning means exactly what it says. If you're not interested in C++ compatibility, then simply disable the warning. Anything else would require changing the definition of TExpectation to give it constructors that differ by parameter list instead of just by name.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467