From d883f87fb5a9bbaa40d95dbcf29cfaaf678c182a Mon Sep 17 00:00:00 2001 From: Daniele Teti Date: Mon, 14 Dec 2020 14:40:07 +0100 Subject: [PATCH] Added unit test for time/date types in RQL query --- .../general/Several/ActiveRecordTestsU.pas | 33 ++++++++++++++++--- .../general/Several/DMVCFrameworkTests.dproj | 2 +- unittests/general/Several/PGUtilsU.pas | 24 ++++++++++++++ 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/unittests/general/Several/ActiveRecordTestsU.pas b/unittests/general/Several/ActiveRecordTestsU.pas index 1d57bfaa..a3256950 100644 --- a/unittests/general/Several/ActiveRecordTestsU.pas +++ b/unittests/general/Several/ActiveRecordTestsU.pas @@ -62,6 +62,8 @@ type [Test] procedure TestRQL; [Test] + procedure TestRQLWithDateTime; + [Test] procedure TestRQLLimit; [Test] procedure TestIssue424; @@ -123,6 +125,7 @@ const var GDBFileName: string = ''; + SQLiteFileName: string = 'sqlitetest.db'; GDBTemplateFileName: string = ''; GPGIsInitialized: boolean = false; @@ -142,8 +145,8 @@ var begin LParams := TStringList.Create; try - GDBFileName := TPath.Combine(TPath.GetDirectoryName(ParamStr(0)), 'sqlitetest.db'); - LParams.Add('Database=' + GDBFileName); + SQLiteFileName := TPath.Combine(TPath.GetDirectoryName(ParamStr(0)), SQLiteFileName); + LParams.Add('Database=' + SQLiteFileName); LParams.Add('OpenMode=CreateUTF8'); if AIsPooled then begin @@ -550,6 +553,26 @@ begin Assert.AreEqual(Int64(0), TMVCActiveRecord.Count(RQL1)); end; +procedure TTestActiveRecordBase.TestRQLWithDateTime; +var + lCustomers: TObjectList; +const + RQL1 = 'and(and(gt(CreationDate, "2010-10-01"),le(CreationDate, "2022-12-31")),' + + 'and(gt(CreationTime, "00:00:00"),le(CreationTime, "08:00:00")))'; +begin + TMVCActiveRecord.DeleteAll(TCustomer); + Assert.AreEqual(Int64(0), TMVCActiveRecord.Count(TCustomer)); + LoadData; + lCustomers := TMVCActiveRecord.SelectRQL(RQL1, MAXINT); + try + Assert.AreEqual(140, lCustomers.Count); + finally + lCustomers.Free; + end; + TMVCActiveRecord.DeleteRQL(TCustomer, RQL1); + Assert.AreEqual(Int64(0), TMVCActiveRecord.Count(RQL1)); +end; + procedure TTestActiveRecordBase.TestSelectWithExceptions; var lCustomer: TCustomer; @@ -676,6 +699,8 @@ begin Format('%s %s %s', [lCustomer.City, Stuff[Random(high(Stuff) + 1)], CompanySuffix[Random(high(CompanySuffix) + 1)]]); lCustomer.Note := Stuff[I mod Length(Stuff)]; + lCustomer.CreationTime := EncodeTime(I mod 23, I, 60 - 1, 0); + lCustomer.CreationDate := EncodeDate(2020 - I, (I mod 12) + 1, (I mod 27) + 1); lCustomer.Insert; finally lCustomer.Free; @@ -704,9 +729,9 @@ begin if FDManager.ConnectionDefs.FindConnectionDef(fConDefName) = nil then begin CreatePrivateConnDef(True); - if TFile.Exists(GDBFileName) then + if TFile.Exists(SQLiteFileName) then begin - TFile.Delete(GDBFileName); + TFile.Delete(SQLiteFileName); end; fConnection.Open; diff --git a/unittests/general/Several/DMVCFrameworkTests.dproj b/unittests/general/Several/DMVCFrameworkTests.dproj index b88ce2db..71b79d13 100644 --- a/unittests/general/Several/DMVCFrameworkTests.dproj +++ b/unittests/general/Several/DMVCFrameworkTests.dproj @@ -4,7 +4,7 @@ 19.1 VCL True - CONSOLE + GUI Win32 1 Console diff --git a/unittests/general/Several/PGUtilsU.pas b/unittests/general/Several/PGUtilsU.pas index db2d56cc..3e44a72a 100644 --- a/unittests/general/Several/PGUtilsU.pas +++ b/unittests/general/Several/PGUtilsU.pas @@ -1,3 +1,27 @@ +// *************************************************************************** +// +// Delphi MVC Framework +// +// Copyright (c) 2010-2020 Daniele Teti and the DMVCFramework Team +// +// https://github.com/danieleteti/delphimvcframework +// +// *************************************************************************** +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// *************************************************************************** } + unit PGUtilsU; interface