Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

mRepeator 와 TestCase 추가

  • Loading branch information...
commit c1c46c305d4a5c8af1681b7ebe178c0c5fcde83e 1 parent 98f9589
@gomsun2 authored
View
106 source/utils/mDBXCommandHelper.pas
@@ -0,0 +1,106 @@
+unit mDBXCommandHelper;
+
+interface
+
+uses
+ Data.SqlExpr, Data.DB, Data.DBXCommon, Data.SqlTimSt,
+ System.Classes, System.SysUtils;
+
+type
+ // see http://docwiki.embarcadero.com/RADStudio/XE3/en/DbExpress_Data_Type_Mapping_for_Supported_Databases
+ TDBXCommandHelper = class helper for TDBXCommand
+ private
+ public
+ procedure Init;
+ procedure AddParam(AType: TDBXType; AValue: String); overload;
+ procedure AddParam(AType: TDBXType; AValue: TDateTime); overload;
+ procedure AddParam(AType: TDBXType; AValue: Integer); overload;
+ procedure AddParam(AType: TDBXType; AValue: Double); overload;
+ procedure AddParam(AType: TDBXType; AValue: TStream); overload;
+ end;
+
+implementation
+
+{ TDBXCommandHelper }
+const
+ DBTYPE_CONVERT_ASSERT = 'DataType converter is not ready. plz add handling Code';
+
+procedure TDBXCommandHelper.AddParam(AType: TDBXType; AValue: String);
+var
+ Param: TDBXParameter;
+begin
+ Assert(AType in [TDBXDataTypes.WideStringType, TDBXDataTypes.AnsiStringType], DBTYPE_CONVERT_ASSERT);
+
+ Param := CreateParameter;
+ Param.DataType := AType;
+ case AType of
+ TDBXDataTypes.WideStringType: Param.Value.SetWideString(AValue);
+ TDBXDataTypes.AnsiStringType: Param.Value.SetAnsiString(AnsiString(AValue));
+ end;
+ Parameters.AddParameter(Param);
+end;
+
+procedure TDBXCommandHelper.AddParam(AType: TDBXType; AValue: TDateTime);
+var
+ Param: TDBXParameter;
+begin
+ Assert(AType in [TDBXDataTypes.TimeStampType], DBTYPE_CONVERT_ASSERT);
+
+ Param := CreateParameter;
+ Param.DataType := AType;
+
+ Param.Value.SetTimeStamp(DateTimeToSQLTimeStamp(AValue));
+
+ Parameters.AddParameter(Param);
+end;
+
+procedure TDBXCommandHelper.AddParam(AType: TDBXType; AValue: Integer);
+var
+ Param: TDBXParameter;
+begin
+ with TDBXDataTypes do
+ Assert(AType in [Int32Type, Int16Type], DBTYPE_CONVERT_ASSERT);
+
+ Param := CreateParameter;
+ Param.DataType := AType;
+ case AType of
+ TDBXDataTypes.Int32Type: Param.Value.SetInt32(AValue);
+ TDBXDataTypes.Int16Type: Param.Value.SetInt16(AValue);
+ end;
+ Parameters.AddParameter(Param);
+end;
+
+procedure TDBXCommandHelper.AddParam(AType: TDBXType; AValue: Double);
+var
+ Param: TDBXParameter;
+begin
+ Assert(AType in [TDBXDataTypes.DoubleType], DBTYPE_CONVERT_ASSERT);
+ Param := CreateParameter;
+ Param.DataType := AType;
+
+ Param.Value.SetDouble(AValue);
+
+ Parameters.AddParameter(Param);
+end;
+
+procedure TDBXCommandHelper.AddParam(AType: TDBXType; AValue: TStream);
+var
+ Param: TDBXParameter;
+begin
+ Assert(AType in [TDBXDataTypes.BlobType], DBTYPE_CONVERT_ASSERT);
+ Param := CreateParameter;
+ Param.DataType := AType;
+ Param.SubType := TDBXSubDataTypes.BinarySubType;
+ Param.Value.SetStream(AValue, False);
+ Param.Value.ValueType.ValueTypeFlags := Param.Value.ValueType.ValueTypeFlags or TDBXValueTypeFlags.ExtendedType;
+ Parameters.AddParameter(Param);
+end;
+
+procedure TDBXCommandHelper.Init;
+begin
+ Parameters.ClearParameters;
+ Close;
+ Text := EmptyStr;
+end;
+
+end.
View
54 source/utils/mIniFileHelper.pas
@@ -0,0 +1,54 @@
+unit mIniFileHelper;
+
+interface
+
+uses
+ System.Classes, System.SysUtils, System.IniFiles;
+
+type
+ TIniFileHelper = class helper for TIniFile
+ private
+ const DEFAULT_FIEL_EXT = '.ini';
+ private
+ class function GetFileName: String; static;
+ public
+ class function FileExist: Boolean;
+ class procedure CreateFile;
+
+ class property FileName: String read GetFileName;
+ end;
+
+implementation
+
+uses
+ System.IOUtils;
+
+var
+ FFileName: String = '';
+
+{ TIniFileHelper }
+
+class procedure TIniFileHelper.CreateFile;
+begin
+ TFile.Create(FileName).Free;
+end;
+
+class function TIniFileHelper.FileExist: Boolean;
+begin
+ Result := TFile.Exists(FileName);
+end;
+
+class function TIniFileHelper.GetFileName: String;
+begin
+ if FFileName.IsEmpty then
+ FFileName := TPath.ChangeExtension(ParamStr(0), DEFAULT_FIEL_EXT);
+
+ Result := FFileName;
+end;
+
+initialization
+ FFileName := EmptyStr;
+
+finalization
+
+end.
View
45 source/utils/mParams.pas
@@ -0,0 +1,45 @@
+unit mParams;
+
+interface
+
+type
+ TParams = class
+ private class var
+ class function GetItems(Index: Integer): String; static;
+ class function GetCount: Integer; static;
+ public
+ class function ExePath: String;
+ class function ExeName: String;
+
+ class property Items[Index: Integer]: String read GetItems;
+ class property Count: Integer read GetCount;
+ end;
+
+implementation
+
+uses
+ System.Classes, System.SysUtils, System.IOUtils;
+
+{ TParamInfo }
+
+class function TParams.ExeName: String;
+begin
+ Result := ExtractFileName(ParamStr(0));
+end;
+
+class function TParams.ExePath: String;
+begin
+ Result := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)));
+end;
+
+class function TParams.GetCount: Integer;
+begin
+ Result := ParamCount;
+end;
+
+class function TParams.GetItems(Index: Integer): String;
+begin
+ Result := ParamStr(Index);
+end;
+
+end.
View
116 source/utils/mRepeator.pas
@@ -0,0 +1,116 @@
+unit mRepeator;
+
+interface
+
+uses
+ System.Classes, System.SysUtils,
+ System.Generics.Collections;
+
+type
+ TSimpleRepeator<T> = class
+ private
+ FPosition: Integer;
+ FItemIsClass: Boolean;
+ FItemClass: TClass;
+ FList: TList<T>;
+ procedure OnNotify(Sender: TObject; const Item: T; Action: TCollectionNotification);
+ private
+ FOwnsObjects: Boolean;
+ function GetCount: Integer;
+ procedure SetPosition(const Value: Integer);
+ function GetCurrent: T;
+ public
+ constructor Create(AOwnsObjects: Boolean = True);
+ destructor Destroy; override;
+
+ procedure Init(AItems: array of T);
+ function Next: T;
+ function Eof: Boolean;
+
+ property Count: Integer read GetCount;
+ property Current: T read GetCurrent;
+ property Position: Integer read FPosition write SetPosition;
+
+ property OwnsObjects: Boolean read FOwnsObjects write FOwnsObjects;
+ end;
+
+implementation
+
+uses
+ mConsts,
+ System.RTTI, System.TypInfo;
+
+{ TSimpleRepeator<T> }
+
+constructor TSimpleRepeator<T>.Create(AOwnsObjects: Boolean);
+begin
+ FOwnsObjects := AOwnsObjects;
+
+ FList := TList<T>.Create;
+ FList.OnNotify := OnNotify;
+end;
+
+destructor TSimpleRepeator<T>.Destroy;
+begin
+ FreeAndNil(FList);
+
+ inherited;
+end;
+
+function TSimpleRepeator<T>.Eof: Boolean;
+begin
+ Result := FPosition = Count - 1;
+end;
+
+function TSimpleRepeator<T>.GetCount: Integer;
+begin
+ Result := FList.Count;
+end;
+
+function TSimpleRepeator<T>.GetCurrent: T;
+begin
+ Result := FList[FPosition];
+end;
+
+procedure TSimpleRepeator<T>.Init(AItems: array of T);
+var
+ LInfo: PTypeInfo;
+ LItem: T;
+begin
+ if FOwnsObjects then
+ begin
+ LInfo := TypeInfo(T);
+ FItemIsClass := LInfo.Kind = tkClass;
+ if FItemIsClass then
+ FItemClass := LInfo.TypeData.ClassType;
+ end;
+
+ for LItem in AItems do
+ FList.Add(LItem);
+
+ FPosition := 0;
+end;
+
+function TSimpleRepeator<T>.Next: T;
+begin
+ if FPosition < Count then
+ Inc(FPosition);
+
+ Result := FList[FPosition];
+end;
+
+procedure TSimpleRepeator<T>.OnNotify(Sender: TObject; const Item: T;
+ Action: TCollectionNotification);
+begin
+ if FOwnsObjects and (Action = cnRemoved) then
+ if FItemIsClass then
+ (Item as FItemClass).Free;
+end;
+
+procedure TSimpleRepeator<T>.SetPosition(const Value: Integer);
+begin
+ if Value < Count then
+ FPosition := Value;
+end;
+
+end.
View
152 unittests/TestmRepeatorRecord.pas
@@ -0,0 +1,152 @@
+unit TestmRepeatorRecord;
+{
+
+ 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, System.Classes, System.SysUtils, mRepeator,
+ System.Generics.Collections;
+
+type
+ // Test methods for class TSimpleRepeator
+ TOrder = (oOne = 0, oTwo, oThree);
+
+ TestTSimpleRepeator = class(TTestCase)
+ strict private
+ FRepeator: TSimpleRepeator<TOrder>;
+ public
+ procedure SetUp; override;
+ procedure TearDown; override;
+ published
+ procedure TestInitAndCheckCount;
+ procedure TestInitAndCurrentValue;
+ procedure TestNext;
+ procedure TestNextAndCheckPostion;
+ procedure TestMovePosition;
+ procedure TestCurrentByPosition;
+ procedure TestEof;
+ procedure TestEofBySetPosition;
+ procedure TestEofByCallNext;
+ end;
+
+implementation
+
+procedure TestTSimpleRepeator.SetUp;
+begin
+ FRepeator := TSimpleRepeator<TOrder>.Create;
+end;
+
+procedure TestTSimpleRepeator.TearDown;
+begin
+ FRepeator.Free;
+ FRepeator := nil;
+end;
+
+procedure TestTSimpleRepeator.TestInitAndCheckCount;
+var
+ AItems: TOrder;
+begin
+ FRepeator.Init([oOne, oTwo, oThree]);
+ CheckEquals(3, FRepeator.Count);
+end;
+
+procedure TestTSimpleRepeator.TestMovePosition;
+var
+ ReturnValue: TOrder;
+ i: Integer;
+begin
+ FRepeator.Init([oOne, oTwo, oThree]);
+ for i := 0 to FRepeator.Count - 1 do
+ begin
+ FRepeator.Position := i;
+ ReturnValue := FRepeator.Current;
+ CheckTrue(TOrder(i) = ReturnValue);
+ end;
+end;
+
+procedure TestTSimpleRepeator.TestNext;
+var
+ ReturnValue: TOrder;
+begin
+ FRepeator.Init([oOne, oTwo, oThree]);
+ ReturnValue := FRepeator.Next;
+ CheckTrue(oTwo = ReturnValue);
+end;
+
+procedure TestTSimpleRepeator.TestNextAndCheckPostion;
+var
+ LItem: TOrder;
+ ReturnValue: Integer;
+begin
+ FRepeator.Init([oOne, oTwo, oThree]);
+
+ LItem := FRepeator.Next;
+ ReturnValue := FRepeator.Position;
+ CheckEquals(Integer(LItem), ReturnValue);
+ CheckEquals(1, ReturnValue);
+end;
+
+procedure TestTSimpleRepeator.TestInitAndCurrentValue;
+var
+ Return: TOrder;
+begin
+ FRepeator.Init([oOne, oTwo, oThree]);
+ Return := FRepeator.Current;
+ CheckTrue(oOne = Return);
+end;
+
+procedure TestTSimpleRepeator.TestCurrentByPosition;
+var
+ ReturnValue: TOrder;
+ i: Integer;
+begin
+ FRepeator.Init([oOne, oTwo, oThree]);
+ for i := 0 to FRepeator.Count - 1 do
+ begin
+ FRepeator.Position := i;
+ CheckTrue(TOrder(i) = FRepeator.Current);
+ end;
+end;
+
+procedure TestTSimpleRepeator.TestEof;
+var
+ ReturnValue: Boolean;
+begin
+ FRepeator.Init([oOne, oTwo, oThree]);
+ ReturnValue := FRepeator.Eof;
+ CheckFalse(ReturnValue);
+end;
+
+procedure TestTSimpleRepeator.TestEofByCallNext;
+var
+ ReturnValue: Boolean;
+begin
+ FRepeator.Init([oOne, oTwo, oThree]);
+ FRepeator.Next;
+ FRepeator.Next;
+ ReturnValue := FRepeator.Eof;
+ CheckTrue(ReturnValue);
+end;
+
+procedure TestTSimpleRepeator.TestEofBySetPosition;
+var
+ ReturnValue: Boolean;
+begin
+ FRepeator.Init([oOne, oTwo, oThree]);
+ FRepeator.Position := FRepeator.Count - 1;
+ ReturnValue := FRepeator.Eof;
+ CheckTrue(ReturnValue);
+end;
+
+initialization
+ // Register any test cases with the test runner
+ RegisterTest(TestTSimpleRepeator.Suite);
+end.
View
13 unittests/mgs2libTest.dpr
@@ -16,15 +16,16 @@ program mgs2libTest;
uses
DUnitTestRunner,
- mBitMask in '..\source\utils\mBitMask.pas',
TestmBitMask in 'TestmBitMask.pas',
TestmIntervalCounter in 'TestmIntervalCounter.pas',
- mSysUtilsEx in '..\source\utils\mSysUtilsEx.pas',
- mIntervalCounter in '..\source\utils\mIntervalCounter.pas',
- mGenericClassList in '..\source\utils\mGenericClassList.pas',
TestmGenericClassList in 'TestmGenericClassList.pas',
- mRouter in '..\source\utils\mRouter.pas',
- TestmRouter in 'TestmRouter.pas';
+ TestmRouter in 'TestmRouter.pas',
+ TestmRepeatorRecord in 'TestmRepeatorRecord.pas',
+ mBitMask in '..\source\utils\mBitMask.pas',
+ mGenericClassList in '..\source\utils\mGenericClassList.pas',
+ mIntervalCounter in '..\source\utils\mIntervalCounter.pas',
+ mRepeator in '..\source\utils\mRepeator.pas',
+ mRouter in '..\source\utils\mRouter.pas';
{R *.RES}
View
20 unittests/mgs2libTest.dproj
@@ -84,6 +84,9 @@
<DCC_RemoteDebug>true</DCC_RemoteDebug>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1_Win32)'!=''">
+ <Manifest_File>None</Manifest_File>
+ <DCC_UnitSearchPath>..\source\utils\;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
+ <VerInfo_Locale>1033</VerInfo_Locale>
<DCC_RemoteDebug>false</DCC_RemoteDebug>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2)'!=''">
@@ -99,15 +102,16 @@
<DelphiCompile Include="$(MainSource)">
<MainSource>MainSource</MainSource>
</DelphiCompile>
- <DCCReference Include="..\source\utils\mBitMask.pas"/>
<DCCReference Include="TestmBitMask.pas"/>
<DCCReference Include="TestmIntervalCounter.pas"/>
- <DCCReference Include="..\source\utils\mSysUtilsEx.pas"/>
- <DCCReference Include="..\source\utils\mIntervalCounter.pas"/>
- <DCCReference Include="..\source\utils\mGenericClassList.pas"/>
<DCCReference Include="TestmGenericClassList.pas"/>
- <DCCReference Include="..\source\utils\mRouter.pas"/>
<DCCReference Include="TestmRouter.pas"/>
+ <DCCReference Include="TestmRepeatorRecord.pas"/>
+ <DCCReference Include="..\source\utils\mBitMask.pas"/>
+ <DCCReference Include="..\source\utils\mGenericClassList.pas"/>
+ <DCCReference Include="..\source\utils\mIntervalCounter.pas"/>
+ <DCCReference Include="..\source\utils\mRepeator.pas"/>
+ <DCCReference Include="..\source\utils\mRouter.pas"/>
<BuildConfiguration Include="Release">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
@@ -163,6 +167,12 @@
<Source>
<Source Name="MainSource">mgs2libTest.dpr</Source>
</Source>
+ <Excluded_Packages>
+ <Excluded_Packages Name="C:\realgridplus\WTGrids.XE3.eval.bpl">File C:\realgridplus\WTGrids.XE3.eval.bpl not found</Excluded_Packages>
+ <Excluded_Packages Name="C:\realgridplus\WTGrids.XE3.eval.release.bpl">File C:\realgridplus\WTGrids.XE3.eval.release.bpl not found</Excluded_Packages>
+ <Excluded_Packages Name="$(BDSBIN)\dcloffice2k170.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages>
+ <Excluded_Packages Name="$(BDSBIN)\dclofficexp170.bpl">Microsoft Office XP Sample Automation Server Wrapper Components</Excluded_Packages>
+ </Excluded_Packages>
</Delphi.Personality>
<Deployment/>
<Platforms>
Please sign in to comment.
Something went wrong with that request. Please try again.