{$MODE OBJFPC} { -*- delphi -*- } {$INCLUDE settings.inc} program test_techtree; uses techtree, sysutils, exceptions, storable, actors; procedure Fail(S: UTF8String); begin Writeln('test_techtree: FAIL -- ', S); Halt(1); end; type TTestTree = class(TTechnologyTreeManager) procedure Test2(); end; TExceptionClass = class of Exception; procedure TTestTree.Test2(); begin // ... end; procedure CheckForException(FileName: RawByteString; ExceptionClass: TExceptionClass; Message: UTF8String; LineNumber: Cardinal); var TechnologyTree: TTestTree; begin Message := FileName + ':' + IntToStr(LineNumber) + ':' + Message; try TechnologyTree := TTestTree.Create(FileName); TechnologyTree.Free(); Fail('No exception caught in parser test "' + FileName + '"'); except on E: Exception do if ((not (E is ExceptionClass)) or (E.Message <> Message)) then begin ReportCurrentException(); Fail('Wrong exception in parser test "' + FileName + '": ' + E.Message); end; else begin ReportCurrentException(); Fail('Exception caught in parser test "' + FileName + '" was not an Exception object'); end; end; end; var TechnologyTree: TTestTree; begin RegisterStorableClass(TTestTree); CheckForException('tests/test_techtree1.tt', ESyntaxError, 'Input file did not contain any data blocks', 0); try TechnologyTree := TTestTree.Create('tests/test_techtree2.tt'); TechnologyTree.Test2(); TechnologyTree.Free(); except on E: Exception do Fail('Exception caught in test 2: ' + E.Message); else Fail('Exception caught in test 2 was not an Exception object'); end; CheckForException('tests/test_techtree3.tt', ESyntaxError, 'Unknown property "From" in Breakthrough block', 17); CheckForException('tests/test_techtree4.tt', ESyntaxError, 'Duplicate property "Obscurity" in Breakthrough block', 3); end.