Browse Source

* Patch from Dean Zobec:
- added AssertSame, AssertNotSame, AssertNull, AssertNotNull for pointers
- fixed a TTestCase test: thanks to Peter Vreman RTTI method names are not
uppercase anymore in 1.9.7

michael 20 years ago
parent
commit
102de9b240
2 changed files with 50 additions and 1 deletions
  1. 1 1
      fcl/fpcunit/exampletests/fpcunittests.pp
  2. 49 0
      fcl/fpcunit/fpcunit.pp

+ 1 - 1
fcl/fpcunit/exampletests/fpcunittests.pp

@@ -145,7 +145,7 @@ end;
 
 
 procedure TTestCaseTest.TestAsString;
 procedure TTestCaseTest.TestAsString;
 begin
 begin
-  AssertEquals( 'TTestCaseTest: wrong AsString output', 'TESTASSTRING(TTestCaseTest)', AsString);
+  AssertEquals( 'TTestCaseTest: wrong AsString output', 'TestAsString(TTestCaseTest)', AsString);
 end;
 end;
 
 
 procedure TTestSuiteTest.SetUp;
 procedure TTestSuiteTest.SetUp;

+ 49 - 0
fcl/fpcunit/fpcunit.pp

@@ -78,12 +78,20 @@ type
     class procedure AssertEquals(Expected, Actual: TClass); overload;
     class procedure AssertEquals(Expected, Actual: TClass); overload;
     class procedure AssertSame(const AMessage: string; Expected, Actual: TObject); overload;
     class procedure AssertSame(const AMessage: string; Expected, Actual: TObject); overload;
     class procedure AssertSame(Expected, Actual: TObject); overload;
     class procedure AssertSame(Expected, Actual: TObject); overload;
+    class procedure AssertSame(const AMessage: string; Expected, Actual: Pointer); overload;
+    class procedure AssertSame(Expected, Actual: Pointer); overload;
     class procedure AssertNotSame(const AMessage: string; Expected, Actual: TObject); overload;
     class procedure AssertNotSame(const AMessage: string; Expected, Actual: TObject); overload;
     class procedure AssertNotSame(Expected, Actual: TObject); overload;
     class procedure AssertNotSame(Expected, Actual: TObject); overload;
+    class procedure AssertNotSame(const AMessage: string; Expected, Actual: Pointer); overload;
+    class procedure AssertNotSame(Expected, Actual: Pointer); overload;
     class procedure AssertNotNull(const AMessage: string; AObject: TObject); overload;
     class procedure AssertNotNull(const AMessage: string; AObject: TObject); overload;
     class procedure AssertNotNull(AObject: TObject); overload;
     class procedure AssertNotNull(AObject: TObject); overload;
+    class procedure AssertNotNull(const AMessage: string; APointer: Pointer); overload;
+    class procedure AssertNotNull(APointer: Pointer); overload;
     class procedure AssertNull(const AMessage: string; AObject: TObject); overload;
     class procedure AssertNull(const AMessage: string; AObject: TObject); overload;
     class procedure AssertNull(AObject: TObject); overload;
     class procedure AssertNull(AObject: TObject); overload;
+    class procedure AssertNull(const AMessage: string; APointer: Pointer); overload;
+    class procedure AssertNull(APointer: Pointer); overload;
     class procedure AssertNotNull(const AMessage, AString: string); overload;
     class procedure AssertNotNull(const AMessage, AString: string); overload;
     class procedure AssertNotNull(const AString: string); overload;
     class procedure AssertNotNull(const AString: string); overload;
     class procedure AssertException(const AMessage: string; AExceptionClass: ExceptClass; AMethod: TRunMethod); overload;
     class procedure AssertException(const AMessage: string; AExceptionClass: ExceptClass; AMethod: TRunMethod); overload;
@@ -448,6 +456,17 @@ begin
   AssertSame('', Expected, Actual);
   AssertSame('', Expected, Actual);
 end;
 end;
 
 
+class procedure TAssert.AssertSame(const AMessage: string; Expected, Actual: Pointer);
+begin
+  AssertTrue(AMessage + ComparisonMsg(IntToStr(PtrInt(Expected)), IntToStr(PtrInt(Actual))), 
+    Expected = Actual);
+end;
+
+class procedure TAssert.AssertSame(Expected, Actual: Pointer);
+begin
+  AssertSame('', Expected, Actual);
+end;
+
 class procedure TAssert.AssertNotSame(const AMessage: string; Expected, Actual: TObject);
 class procedure TAssert.AssertNotSame(const AMessage: string; Expected, Actual: TObject);
 begin
 begin
   AssertFalse(SExpectedNotSame, Expected = Actual);
   AssertFalse(SExpectedNotSame, Expected = Actual);
@@ -458,6 +477,16 @@ begin
   AssertNotSame('', Expected, Actual);
   AssertNotSame('', Expected, Actual);
 end;
 end;
 
 
+class procedure TAssert.AssertNotSame(const AMessage: string; Expected, Actual: Pointer);
+begin
+  AssertFalse(SExpectedNotSame, Expected = Actual);
+end;
+
+class procedure TAssert.AssertNotSame(Expected, Actual: Pointer);
+begin
+  AssertNotSame('', Expected, Actual);
+end;
+
 class procedure TAssert.AssertNotNull(const AMessage: string; AObject: TObject);
 class procedure TAssert.AssertNotNull(const AMessage: string; AObject: TObject);
 begin
 begin
   AssertTrue(AMessage, (AObject <> nil));
   AssertTrue(AMessage, (AObject <> nil));
@@ -468,6 +497,16 @@ begin
   AssertNotNull('', AObject);
   AssertNotNull('', AObject);
 end;
 end;
 
 
+class procedure TAssert.AssertNotNull(const AMessage: string; APointer: Pointer);
+begin
+  AssertTrue(AMessage, (APointer <> nil));
+end;
+
+class procedure TAssert.AssertNotNull(APointer: Pointer);
+begin
+  AssertNotNull('', APointer);
+end;
+
 class procedure TAssert.AssertNull(const AMessage: string; AObject: TObject);
 class procedure TAssert.AssertNull(const AMessage: string; AObject: TObject);
 begin
 begin
   AssertTrue(AMessage, (AObject = nil));
   AssertTrue(AMessage, (AObject = nil));
@@ -478,6 +517,16 @@ begin
   AssertNull('', AObject);
   AssertNull('', AObject);
 end;
 end;
 
 
+class procedure TAssert.AssertNull(const AMessage: string; APointer: Pointer);
+begin
+  AssertTrue(AMessage, (APointer = nil));
+end;
+
+class procedure TAssert.AssertNull(APointer: Pointer);
+begin
+  AssertNull('', APointer);
+end;
+
 class procedure TAssert.AssertException(const AMessage: string; AExceptionClass: ExceptClass;
 class procedure TAssert.AssertException(const AMessage: string; AExceptionClass: ExceptClass;
   AMethod: TRunMethod);
   AMethod: TRunMethod);
 var
 var