[453] | 1 | { **************************************************************
|
---|
| 2 | Package: XWB - Kernel RPCBroker
|
---|
| 3 | Date Created: Sept 18, 1997 (Version 1.1)
|
---|
| 4 | Site Name: Oakland, OI Field Office, Dept of Veteran Affairs
|
---|
| 5 | Developers: Joel Ivey
|
---|
| 6 | Description: Unit testing MFunStr code - requires dUnit for
|
---|
| 7 | unit testing.
|
---|
| 8 | Current Release: Version 1.1 Patch 40 (January 7, 2005))
|
---|
| 9 | *************************************************************** }
|
---|
| 10 |
|
---|
| 11 | unit uUniTTestMFunStr;
|
---|
| 12 |
|
---|
| 13 | interface
|
---|
| 14 |
|
---|
| 15 | uses
|
---|
| 16 | TestFramework, Sgnoncnf, Classes, Graphics, SysUtils, Forms;
|
---|
| 17 |
|
---|
| 18 | type
|
---|
| 19 | TTestType = class(TTestCase)
|
---|
| 20 | private
|
---|
| 21 | // any private fields needed for processing
|
---|
| 22 | protected
|
---|
| 23 | // procedure SetUp; override;
|
---|
| 24 | // procedure TearDown; override;
|
---|
| 25 | published
|
---|
| 26 | // procedure TestName1;
|
---|
| 27 | // procedure TestName2;
|
---|
| 28 | end;
|
---|
| 29 |
|
---|
| 30 | TTestMFunStr1 = class(TTestCase)
|
---|
| 31 | private
|
---|
| 32 | protected
|
---|
| 33 | procedure Setup; override;
|
---|
| 34 | public
|
---|
| 35 | published
|
---|
| 36 | procedure TestPiece1;
|
---|
| 37 | procedure TestPiece2;
|
---|
| 38 | procedure TestPiece3;
|
---|
| 39 | procedure TestPiece4;
|
---|
| 40 | procedure TestPiece5;
|
---|
| 41 | procedure TestPiece6;
|
---|
| 42 | procedure TestPiece7;
|
---|
| 43 | procedure TestPiece8;
|
---|
| 44 | procedure TestPiece9;
|
---|
| 45 | end;
|
---|
| 46 |
|
---|
| 47 | TTestMFunStr2 = class(TTestCase)
|
---|
| 48 | protected
|
---|
| 49 | procedure Setup; override;
|
---|
| 50 | published
|
---|
| 51 | procedure TestTran1;
|
---|
| 52 | procedure TestTran2;
|
---|
| 53 | procedure TestTran3;
|
---|
| 54 | procedure TestTran4;
|
---|
| 55 | end;
|
---|
| 56 |
|
---|
| 57 | implementation
|
---|
| 58 |
|
---|
| 59 | uses
|
---|
| 60 | MFunStr_1;
|
---|
| 61 |
|
---|
| 62 | var
|
---|
| 63 | Str: String;
|
---|
| 64 | Val: String;
|
---|
| 65 |
|
---|
| 66 | procedure TTestMFunStr1.TestPiece1;
|
---|
| 67 | begin
|
---|
| 68 | Val := Piece(Str,'^');
|
---|
| 69 | Check(Val = 'Piece1','Failed Piece not specified');
|
---|
| 70 | end;
|
---|
| 71 |
|
---|
| 72 | procedure TTestMFunStr1.Setup;
|
---|
| 73 | begin
|
---|
| 74 | Str := 'Piece1^Piece2^Piece3';
|
---|
| 75 | end;
|
---|
| 76 |
|
---|
| 77 | procedure TTestMFunStr1.TestPiece2;
|
---|
| 78 | begin
|
---|
| 79 | Val := Piece(Str,'^',2);
|
---|
| 80 | Check(Val = 'Piece2', 'Failed Piece specified as 2');
|
---|
| 81 | end;
|
---|
| 82 |
|
---|
| 83 | procedure TTestMFunStr1.TestPiece3;
|
---|
| 84 | begin
|
---|
| 85 | Val := Piece(Str,'^',3);
|
---|
| 86 | Check(Val = 'Piece3', 'Failed Piece specifed as 3');
|
---|
| 87 | end;
|
---|
| 88 |
|
---|
| 89 | procedure TTestMFunStr1.TestPiece4;
|
---|
| 90 | begin
|
---|
| 91 | Val := Piece(Str,'^',4);
|
---|
| 92 | Check(Val = '','Failed piece specifed as 4');
|
---|
| 93 | end;
|
---|
| 94 |
|
---|
| 95 | procedure TTestMFunStr1.TestPiece5;
|
---|
| 96 | begin
|
---|
| 97 | Val := Piece(Str,'^',1,2);
|
---|
| 98 | Check(Val = 'Piece1^Piece2','Failed Piece 1,2');
|
---|
| 99 | end;
|
---|
| 100 |
|
---|
| 101 | procedure TTestMFunStr1.TestPiece6;
|
---|
| 102 | begin
|
---|
| 103 | Val := Piece(Str,'^',2,3);
|
---|
| 104 | Check(Val = 'Piece2^Piece3','Failed Piece 2,3');
|
---|
| 105 | end;
|
---|
| 106 |
|
---|
| 107 | procedure TTestMFunStr1.TestPiece7;
|
---|
| 108 | begin
|
---|
| 109 | Val := Piece(Str,'^',2,4);
|
---|
| 110 | Check(Val = 'Piece2^Piece3', 'Failed on Piece 2,4');
|
---|
| 111 | end;
|
---|
| 112 |
|
---|
| 113 | procedure TTestMFunStr1.TestPiece8;
|
---|
| 114 | begin
|
---|
| 115 | Val := Piece(Str,'^',3,5);
|
---|
| 116 | Check(Val = 'Piece3','Failed on Piece 3,5');
|
---|
| 117 | end;
|
---|
| 118 |
|
---|
| 119 | procedure TTestMFunStr1.TestPiece9;
|
---|
| 120 | begin
|
---|
| 121 | Val := Piece(Str,'^',4,6);
|
---|
| 122 | Check(Val = '','Failed on Piece 4,6');
|
---|
| 123 | end;
|
---|
| 124 |
|
---|
| 125 | procedure TTestMFunStr2.Setup;
|
---|
| 126 | begin
|
---|
| 127 | Str := 'ABCDEFGHABCDE';
|
---|
| 128 | end;
|
---|
| 129 |
|
---|
| 130 | procedure TTestMFunStr2.TestTran1;
|
---|
| 131 | begin
|
---|
| 132 | Val := Translate(Str,'ABCDEFGH','abcdefgh');
|
---|
| 133 | Check(Val = 'abcdefghabcde','Failed upper to lower case');
|
---|
| 134 | end;
|
---|
| 135 |
|
---|
| 136 | procedure TTestMFunStr2.TestTran2;
|
---|
| 137 | begin
|
---|
| 138 | Val := Translate(Str,'ABCD','abcde');
|
---|
| 139 | Check(Val = 'abcdEFGHabcdE', 'Failed Partial');
|
---|
| 140 | end;
|
---|
| 141 |
|
---|
| 142 | procedure TTestMFunStr2.TestTran3;
|
---|
| 143 | begin
|
---|
| 144 | Val := Translate(Str,'ABCDEABC','abcdefgh');
|
---|
| 145 | Check(Val = 'abcdeFGHabcde', 'Failed repeat chars');
|
---|
| 146 | end;
|
---|
| 147 |
|
---|
| 148 | procedure TTestMFunStr2.TestTran4;
|
---|
| 149 | begin
|
---|
| 150 | Val := Translate(Str,'ABCDEFGH','abcdeabc');
|
---|
| 151 | Check(Val = 'abcdeabcabcde', 'Failed in assignment');
|
---|
| 152 | end;
|
---|
| 153 |
|
---|
| 154 | { // used with second method of registering tests
|
---|
| 155 | function UnitTests: ITestSuite;
|
---|
| 156 | var
|
---|
| 157 | ATestSuite: TTestSuite;
|
---|
| 158 | begin
|
---|
| 159 | ATestSuite := TTestSuite.create('Some trivial tests');
|
---|
| 160 | // add each test suite to be tested
|
---|
| 161 | ATestSuite.addSuite(TTestType.Suite);
|
---|
| 162 | // ATestSuite.addSuite(TTestStringlist.Suite);
|
---|
| 163 | Result := ATestSuite;
|
---|
| 164 | end;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 |
|
---|
| 168 | {
|
---|
| 169 | procedure TTestType.TestName1;
|
---|
| 170 | begin
|
---|
| 171 | // Check( Boolean true for success, String comment for failed test)
|
---|
| 172 | Check(1+1=2,'Comment on Failure')
|
---|
| 173 | end;
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | initialization
|
---|
| 177 | // one entry per testclass
|
---|
| 178 | TestFramework.RegisterTest('Test Piece',TTestMFunStr1.Suite);
|
---|
| 179 | TestFramework.RegisterTest('Test Translate',TTestMFunStr2.Suite);
|
---|
| 180 | // or
|
---|
| 181 | // TestFramework.RegisterTest('SimpleTest',UnitTests);
|
---|
| 182 | end.
|
---|