- Timestamp:
- Feb 2, 2022, 4:33:25 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormTest.lfm
r90 r91 22 22 item 23 23 Caption = 'Name' 24 Width = 20024 Width = 300 25 25 end 26 26 item 27 27 Caption = 'Result' 28 Width = 86928 Width = 769 29 29 end> 30 30 OwnerData = True 31 PopupMenu = PopupMenuTest 31 32 ReadOnly = True 32 33 RowSelect = True … … 34 35 ViewStyle = vsReport 35 36 OnData = ListViewTestCasesData 37 OnDblClick = AShowExecute 38 OnSelectItem = ListViewTestCasesSelectItem 36 39 end 37 40 object ButtonRun: TButton … … 45 48 TabOrder = 1 46 49 end 50 object ActionList1: TActionList 51 Left = 537 52 Top = 115 53 object AShow: TAction 54 Caption = 'Show' 55 OnExecute = AShowExecute 56 end 57 object ARun: TAction 58 Caption = 'Run' 59 OnExecute = ARunExecute 60 end 61 end 62 object PopupMenuTest: TPopupMenu 63 Left = 539 64 Top = 244 65 object MenuItem1: TMenuItem 66 Action = AShow 67 end 68 object MenuItem2: TMenuItem 69 Action = ARun 70 end 71 end 47 72 end -
trunk/Forms/UFormTest.lrj
r90 r91 3 3 {"hash":346165,"name":"tformtest.listviewtestcases.columns[0].caption","sourcebytes":[78,97,109,101],"value":"Name"}, 4 4 {"hash":93105204,"name":"tformtest.listviewtestcases.columns[1].caption","sourcebytes":[82,101,115,117,108,116],"value":"Result"}, 5 {"hash":22974,"name":"tformtest.buttonrun.caption","sourcebytes":[82,117,110],"value":"Run"} 5 {"hash":22974,"name":"tformtest.buttonrun.caption","sourcebytes":[82,117,110],"value":"Run"}, 6 {"hash":368487,"name":"tformtest.ashow.caption","sourcebytes":[83,104,111,119],"value":"Show"}, 7 {"hash":22974,"name":"tformtest.arun.caption","sourcebytes":[82,117,110],"value":"Run"} 6 8 ]} -
trunk/Forms/UFormTest.pas
r90 r91 7 7 uses 8 8 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls, 9 UTest;9 ActnList, Menus, UTest; 10 10 11 11 type … … 14 14 15 15 TFormTest = class(TForm) 16 ARun: TAction; 17 AShow: TAction; 18 ActionList1: TActionList; 16 19 ButtonRun: TButton; 17 20 ListViewTestCases: TListView; 21 MenuItem1: TMenuItem; 22 MenuItem2: TMenuItem; 23 PopupMenuTest: TPopupMenu; 24 procedure ARunExecute(Sender: TObject); 25 procedure AShowExecute(Sender: TObject); 18 26 procedure ButtonRunClick(Sender: TObject); 19 27 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); … … 22 30 procedure FormShow(Sender: TObject); 23 31 procedure ListViewTestCasesData(Sender: TObject; Item: TListItem); 32 procedure ListViewTestCasesSelectItem(Sender: TObject; Item: TListItem; 33 Selected: Boolean); 24 34 private 25 35 procedure ReloadList; 36 procedure UpdateInterface; 26 37 public 27 38 TestCases: TTestCases; … … 37 48 38 49 uses 39 UCore ;50 UCore, UFormTestCase; 40 51 41 52 { TFormTest } … … 46 57 with TestCases[Item.Index] do begin 47 58 Item.Caption := Name; 59 Item.Data := TestCases[Item.Index]; 60 Item.SubItems.Add(ResultText[Result]); 48 61 end; 62 end; 63 64 procedure TFormTest.ListViewTestCasesSelectItem(Sender: TObject; 65 Item: TListItem; Selected: Boolean); 66 begin 67 UpdateInterface; 49 68 end; 50 69 … … 53 72 ListViewTestCases.Items.Count := TestCases.Count; 54 73 ListViewTestCases.Refresh; 74 end; 75 76 procedure TFormTest.UpdateInterface; 77 begin 78 ARun.Enabled := Assigned(ListViewTestCases.Selected); 79 AShow.Enabled := Assigned(ListViewTestCases.Selected); 55 80 end; 56 81 … … 66 91 for I := 0 to TestCases.Count - 1 do 67 92 TestCases[I].Run; 93 ReloadList; 94 end; 95 96 procedure TFormTest.AShowExecute(Sender: TObject); 97 begin 98 if Assigned(ListViewTestCases.Selected) then 99 with TFormTestCase.Create(nil) do 100 try 101 MemoLog.Text := TTestCase(ListViewTestCases.Selected.Data).Log; 102 ShowModal; 103 finally 104 Free; 105 end; 106 end; 107 108 procedure TFormTest.ARunExecute(Sender: TObject); 109 begin 110 if Assigned(ListViewTestCases.Selected) then begin 111 TTestCase(ListViewTestCases.Selected.Data).Run; 112 ReloadList; 113 end; 68 114 end; 69 115 … … 72 118 TestCases := TTestCases.Create; 73 119 with TestCases do begin 74 AddNew('Load and save'); 75 AddNew('Multi-line'); 76 AddNew('Encoding base64'); 77 AddNew('Encoding quoted-printable'); 78 AddNew('Image format'); 120 with TTestCaseLoadSave(AddNew('Load and save', TTestCaseLoadSave)) do begin 121 Input := 'BEGIN:VCARD' + LineEnding + 122 'VERSION:2.1' + LineEnding + 123 'N:Surname;Name' + LineEnding + 124 'FN:Name Surname' + LineEnding + 125 'END:VCARD' + LineEnding; 126 Output := Input; 127 end; 128 with TTestCaseLoadSave(AddNew('Multi-line', TTestCaseLoadSave)) do begin 129 Input := 'BEGIN:VCARD' + LineEnding + 130 'VERSION:2.1' + LineEnding + 131 'NOTE:This is some long test which is really multi-lined\neach line\nis on' + LineEnding + 132 ' different\nline so it is on multiple\nlines.' + LineEnding + 133 'END:VCARD' + LineEnding; 134 Output := Input; 135 end; 136 AddNew('Encoding base64', TTestCaseLoadSave); 137 AddNew('Encoding quoted-printable', TTestCaseLoadSave); 138 AddNew('Image format', TTestCaseLoadSave); 139 with TTestCaseLoadSave(AddNew('Empty', TTestCaseLoadSave)) do begin 140 Input := ''; 141 Output := ''; 142 end; 143 with TTestCaseLoadSave(AddNew('Begin only', TTestCaseLoadSave)) do begin 144 Input := 'BEGIN:VCARD'; 145 Output := ''; 146 end; 147 with TTestCaseLoadSave(AddNew('Missing end', TTestCaseLoadSave)) do begin 148 Input := 'BEGIN:VCARD' + LineEnding + 149 'VERSION:2.1' + LineEnding + 150 'N:Surname;Name' + LineEnding + 151 'FN:Name Surname' + LineEnding; 152 Output := ''; 153 end; 79 154 end; 80 155 end; … … 89 164 Core.PersistentForm1.Load(Self); 90 165 ReloadList; 166 UpdateInterface; 91 167 end; 92 168 -
trunk/Languages/vCardStudio.cs.po
r90 r91 83 83 msgctxt "tcore.atest.caption" 84 84 msgid "Test" 85 msgstr " "85 msgstr "Testování" 86 86 87 87 #: tformcontact.aphotoclear.caption … … 792 792 msgstr "DPI:" 793 793 794 #: tformtest.arun.caption 795 msgctxt "tformtest.arun.caption" 796 msgid "Run" 797 msgstr "Spustit" 798 799 #: tformtest.ashow.caption 800 msgctxt "tformtest.ashow.caption" 801 msgid "Show" 802 msgstr "Ukázat" 803 794 804 #: tformtest.buttonrun.caption 805 msgctxt "tformtest.buttonrun.caption" 795 806 msgid "Run" 796 msgstr " "807 msgstr "Spustit" 797 808 798 809 #: tformtest.caption 799 810 msgctxt "tformtest.caption" 800 811 msgid "Test" 801 msgstr " "812 msgstr "Testování" 802 813 803 814 #: tformtest.listviewtestcases.columns[0].caption … … 809 820 #: tformtest.listviewtestcases.columns[1].caption 810 821 msgid "Result" 811 msgstr "" 822 msgstr "Výsledek" 823 824 #: tformtestcase.caption 825 msgid "Test case" 826 msgstr "Testový případ" 812 827 813 828 #: ucontact.saim … … 1281 1296 msgid "Invalid line length for encoded text" 1282 1297 msgstr "Neplatná délka řádky kódovaného textu" 1283 -
trunk/Languages/vCardStudio.pot
r90 r91 764 764 msgstr "" 765 765 766 #: tformtest.arun.caption 767 msgctxt "tformtest.arun.caption" 768 msgid "Run" 769 msgstr "" 770 771 #: tformtest.ashow.caption 772 msgctxt "tformtest.ashow.caption" 773 msgid "Show" 774 msgstr "" 775 766 776 #: tformtest.buttonrun.caption 777 msgctxt "tformtest.buttonrun.caption" 767 778 msgid "Run" 768 779 msgstr "" … … 782 793 msgstr "" 783 794 795 #: tformtestcase.caption 796 msgid "Test case" 797 msgstr "" 798 784 799 #: ucontact.saim 785 800 msgid "AIM" -
trunk/UContact.pas
r90 r91 141 141 class destructor Destroy2; 142 142 procedure SaveToStrings(Output: TStrings); 143 function LoadFromStrings(Lines: TStrings; StartLine: Integer = 0): Integer;143 function LoadFromStrings(Lines: TStrings; var StartLine: Integer): Boolean; 144 144 procedure SaveToFile(FileName: string); 145 145 procedure LoadFromFile(FileName: string); … … 1134 1134 end; 1135 1135 end; 1136 if LinePrefix <> '' then Add('');1137 1136 end; 1138 1137 end; … … 1141 1140 end; 1142 1141 1143 function TContact.LoadFromStrings(Lines: TStrings; StartLine: Integer = 0): Integer;1142 function TContact.LoadFromStrings(Lines: TStrings; var StartLine: Integer): Boolean; 1144 1143 type 1145 1144 TParseState = (psNone, psInside, psFinished); … … 1154 1153 Names: string; 1155 1154 begin 1155 Result := False; 1156 1156 ParseState := psNone; 1157 1157 I := StartLine; … … 1166 1166 end else begin 1167 1167 ContactsFile.Error(SExpectedVCardBegin, I + 1); 1168 I := -1;1169 1168 Break; 1170 1169 end; … … 1174 1173 ParseState := psFinished; 1175 1174 Inc(I); 1175 Result := True; 1176 1176 Break; 1177 1177 end else … … 1182 1182 while True do begin 1183 1183 Inc(I); 1184 if I >= Lines.Count then Break; 1184 1185 Line2 := Lines[I]; 1185 if (Length(Line s[I]) > 0) and (Line2[1] = ' ') then begin1186 Value := Value + Trim(Line s[I]);1186 if (Length(Line2) > 0) and (Line2[1] = ' ') then begin 1187 Value := Value + Trim(Line2); 1187 1188 end else 1188 if (Length(Line s[I]) > 0) and (Length(Value) > 0) and (Value[Length(Value)] = '=') and1189 (Line s[I][1] = '=') then begin1190 Value := Value + Copy(Trim(Line s[I]), 2, MaxInt);1189 if (Length(Line2) > 0) and (Length(Value) > 0) and (Value[Length(Value)] = '=') and 1190 (Line2[1] = '=') then begin 1191 Value := Value + Copy(Trim(Line2), 2, MaxInt); 1191 1192 end else begin 1192 1193 Dec(I); … … 1208 1209 end else begin 1209 1210 ContactsFile.Error(SExpectedProperty, I + 1); 1210 I := -1;1211 1211 Break; 1212 1212 end; … … 1214 1214 Inc(I); 1215 1215 end; 1216 Result:= I;1216 if Result then StartLine := I; 1217 1217 end; 1218 1218 … … 1233 1233 var 1234 1234 Lines: TStringList; 1235 StartLine: Integer; 1235 1236 begin 1236 1237 Lines := TStringList.Create; … … 1245 1246 end; 1246 1247 {$ENDIF} 1247 LoadFromStrings(Lines); 1248 StartLine := 0; 1249 LoadFromStrings(Lines, StartLine); 1248 1250 finally 1249 1251 Lines.Free; … … 1285 1287 Contact: TContact; 1286 1288 I: Integer; 1287 NewI: Integer;1288 1289 begin 1289 1290 Contacts.Clear; … … 1293 1294 Contact := TContact.Create; 1294 1295 Contact.ContactsFile := Self; 1295 NewI := Contact.LoadFromStrings(Lines, I); 1296 if NewI <= Lines.Count then begin 1297 if NewI <> -1 then begin 1298 Contacts.Add(Contact); 1299 I := NewI; 1300 end else begin 1301 FreeAndNil(Contact); 1302 Inc(I); 1303 end; 1296 if Contact.LoadFromStrings(Lines, I) then begin 1297 Contacts.Add(Contact); 1304 1298 end else begin 1305 1299 FreeAndNil(Contact); 1306 Break;1300 Inc(I); 1307 1301 end; 1308 1302 end; -
trunk/UTest.pas
r90 r91 14 14 15 15 TTestCase = class 16 public 16 17 Name: string; 17 18 Result: TTestResult; 18 procedure Run; 19 Log: string; 20 procedure Run; virtual; 19 21 end; 22 23 TTestCaseClass = class of TTestCase; 20 24 21 25 { TTestCases } 22 26 23 27 TTestCases = class(TFPGObjectList<TTestCase>) 24 function AddNew(Name: string ): TTestCase;28 function AddNew(Name: string; TestClass: TTestCaseClass): TTestCase; 25 29 end; 26 30 31 { TTestCaseLoadSave } 32 33 TTestCaseLoadSave = class(TTestCase) 34 Input: string; 35 Output: string; 36 procedure Run; override; 37 procedure Evaluate(Passed: Boolean); 38 end; 39 40 const 41 ResultText: array[TTestResult] of string = ('None', 'Passed', 'Failed'); 42 43 27 44 implementation 45 46 uses 47 UContact; 48 49 { TTestCaseLoadSave } 50 51 procedure TTestCaseLoadSave.Run; 52 var 53 Lines: TStringList; 54 begin 55 Lines := TStringList.Create; 56 try 57 with TContactsFile.Create do 58 try 59 Lines.Text := Input; 60 LoadFromStrings(Lines); 61 Lines.Text := ''; 62 SaveToStrings(Lines); 63 Evaluate(Lines.Text = Output); 64 if Result <> trPassed then begin 65 Log := 'Expected:' + LineEnding + 66 '"' + Output + '"' + LineEnding + LineEnding + 67 'Output:' + LineEnding + 68 '"' + Lines.Text + '"'; 69 end; 70 finally 71 Free; 72 end; 73 finally 74 Lines.Free; 75 end; 76 end; 77 78 procedure TTestCaseLoadSave.Evaluate(Passed: Boolean); 79 begin 80 if Passed then Result := trPassed 81 else Result := trFailed; 82 end; 28 83 29 84 { TTestCase } … … 36 91 { TTestCases } 37 92 38 function TTestCases.AddNew(Name: string ): TTestCase;93 function TTestCases.AddNew(Name: string; TestClass: TTestCaseClass): TTestCase; 39 94 begin 40 Result := T TestCase.Create;95 Result := TestClass.Create; 41 96 Result.Name := Name; 42 97 Add(Result); -
trunk/vCardStudio.lpi
r90 r91 104 104 </Item2> 105 105 </RequiredPackages> 106 <Units Count="1 7">106 <Units Count="18"> 107 107 <Unit0> 108 108 <Filename Value="vCardStudio.lpr"/> … … 208 208 <IsPartOfProject Value="True"/> 209 209 </Unit16> 210 <Unit17> 211 <Filename Value="Forms\UFormTestCase.pas"/> 212 <IsPartOfProject Value="True"/> 213 <ComponentName Value="FormTestCase"/> 214 <ResourceBaseClass Value="Form"/> 215 </Unit17> 210 216 </Units> 211 217 </ProjectOptions> -
trunk/vCardStudio.lpr
r90 r91 8 8 {$ENDIF} 9 9 Interfaces, // this includes the LCL widgetset 10 Forms, UFormMain, UCore, Common, UDataFile, SysUtils, UFormTest, UTest; 10 Forms, UFormMain, UCore, Common, UDataFile, SysUtils, UFormTest, UTest, 11 UFormTestCase; 11 12 12 13 {$R *.res}
Note:
See TracChangeset
for help on using the changeset viewer.