You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2017/09/09 08:11:41 UTC

thrift git commit: Testcase for THRIFT-4323 range check errors or NPE in edge cases Client: Delphi Patch: Jens Geyer

Repository: thrift
Updated Branches:
  refs/heads/master cc2d558e2 -> cf892d46f


Testcase for THRIFT-4323 range check errors or NPE in edge cases
Client: Delphi
Patch: Jens Geyer


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/cf892d46
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/cf892d46
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/cf892d46

Branch: refs/heads/master
Commit: cf892d46f6c1b295d99705709364c42ae2dc0158
Parents: cc2d558
Author: Jens Geyer <je...@apache.org>
Authored: Sat Sep 9 10:08:22 2017 +0200
Committer: Jens Geyer <je...@apache.org>
Committed: Sat Sep 9 10:11:10 2017 +0200

----------------------------------------------------------------------
 lib/delphi/test/TestClient.pas | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/cf892d46/lib/delphi/test/TestClient.pas
----------------------------------------------------------------------
diff --git a/lib/delphi/test/TestClient.pas b/lib/delphi/test/TestClient.pas
index 74130f4..37d8546 100644
--- a/lib/delphi/test/TestClient.pas
+++ b/lib/delphi/test/TestClient.pas
@@ -528,6 +528,9 @@ begin
   s := client.testString('Test');
   Expect( s = 'Test', 'testString(''Test'') = "'+s+'"');
 
+  s := client.testString('');  // empty string
+  Expect( s = '', 'testString('''') = "'+s+'"');
+
   s := client.testString(HUGE_TEST_STRING);
   Expect( length(s) = length(HUGE_TEST_STRING),
           'testString( length(HUGE_TEST_STRING) = '+IntToStr(Length(HUGE_TEST_STRING))+') '
@@ -543,6 +546,7 @@ begin
   i64 := client.testI64(-34359738368);
   Expect( i64 = -34359738368, 'testI64(-34359738368) = ' + IntToStr( i64));
 
+  // random binary
   binOut := PrepareBinaryData( TRUE);
   Console.WriteLine('testBinary('+BytesToHex(binOut)+')');
   try
@@ -555,6 +559,19 @@ begin
     on e:Exception do Expect( FALSE, 'testBinary(): Unexpected exception "'+e.ClassName+'": '+e.Message);
   end;
 
+  // empty binary
+  SetLength( binOut, 0);
+  Console.WriteLine('testBinary('+BytesToHex(binOut)+')');
+  try
+    binIn := client.testBinary(binOut);
+    Expect( Length(binOut) = Length(binIn), 'testBinary(): length '+IntToStr(Length(binOut))+' = '+IntToStr(Length(binIn)));
+    i32 := Min( Length(binOut), Length(binIn));
+    Expect( CompareMem( binOut, binIn, i32), 'testBinary('+BytesToHex(binOut)+') = '+BytesToHex(binIn));
+  except
+    on e:TApplicationException do Console.WriteLine('testBinary(): '+e.Message);
+    on e:Exception do Expect( FALSE, 'testBinary(): Unexpected exception "'+e.ClassName+'": '+e.Message);
+  end;
+
   Console.WriteLine('testDouble(5.325098235)');
   dub := client.testDouble(5.325098235);
   Expect( abs(dub-5.325098235) < 1e-14, 'testDouble(5.325098235) = ' + FloatToStr( dub));
@@ -1041,7 +1058,7 @@ procedure TClientThread.JSONProtocolReadWriteTest;
 var prot   : IProtocol;
     stm    : TStringStream;
     list   : TThriftList;
-    binary, binRead : TBytes;
+    binary, binRead, emptyBinary : TBytes;
     i,iErr : Integer;
 const
   TEST_SHORT   = ShortInt( $FE);
@@ -1064,6 +1081,7 @@ begin
 
     // prepare binary data
     binary := PrepareBinaryData( FALSE);
+    SetLength( emptyBinary, 0); // empty binary data block
 
     // output setup
     prot := TJSONProtocolImpl.Create(
@@ -1082,6 +1100,8 @@ begin
     prot.WriteDouble( TEST_DOUBLE);
     prot.WriteString( TEST_STRING);
     prot.WriteBinary( binary);
+    prot.WriteString( '');  // empty string
+    prot.WriteBinary( emptyBinary); // empty binary data block
     prot.WriteListEnd;
 
     // input setup
@@ -1104,6 +1124,8 @@ begin
     Expect( abs(prot.ReadDouble-TEST_DOUBLE) < abs(DELTA_DOUBLE), 'WriteDouble/ReadDouble');
     Expect( prot.ReadString = TEST_STRING, 'WriteString/ReadString');
     binRead := prot.ReadBinary;
+    Expect( Length(prot.ReadString) = 0, 'WriteString/ReadString (empty string)');
+    Expect( Length(prot.ReadBinary) = 0, 'empty WriteBinary/ReadBinary (empty data block)');
     prot.ReadListEnd;
 
     // test binary data