2005-07-01 13:43:59 +02:00
|
|
|
unit BitsTest;
|
2004-09-20 14:01:08 +02:00
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
|
|
|
TestFramework;
|
|
|
|
|
|
|
|
type
|
|
|
|
TBitsTest = class(TTestCase)
|
|
|
|
published
|
|
|
|
procedure testGet();
|
|
|
|
procedure testSet();
|
|
|
|
procedure testCombine();
|
|
|
|
|
|
|
|
procedure testBitsToString();
|
|
|
|
procedure testStringToBits();
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
uses
|
|
|
|
X2UtBits;
|
|
|
|
|
|
|
|
const
|
2005-07-01 13:43:59 +02:00
|
|
|
Bits = [bit1, bit2, bit4, bit7];
|
2004-09-20 14:01:08 +02:00
|
|
|
BitsValue = 150;
|
|
|
|
BitsString = '10010110';
|
|
|
|
|
|
|
|
|
|
|
|
{ TBitsTest }
|
|
|
|
procedure TBitsTest.testGet;
|
|
|
|
var
|
|
|
|
bValue: Byte;
|
|
|
|
eBits: T8Bits absolute bValue;
|
|
|
|
|
|
|
|
begin
|
|
|
|
bValue := BitsValue;
|
2005-07-01 13:43:59 +02:00
|
|
|
Check(eBits = Bits, 'Bits do not match the value!');
|
2004-09-20 14:01:08 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TBitsTest.testSet;
|
|
|
|
var
|
|
|
|
bValue: Byte;
|
|
|
|
eBits: T8Bits absolute bValue;
|
|
|
|
|
|
|
|
begin
|
2005-07-01 13:43:59 +02:00
|
|
|
eBits := Bits;
|
2004-09-20 14:01:08 +02:00
|
|
|
Check(bValue = BitsValue, 'Value does not match the bits!');
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TBitsTest.testCombine;
|
|
|
|
var
|
|
|
|
eBits1: T8Bits;
|
|
|
|
eBits2: T8Bits;
|
|
|
|
bValue: Byte absolute eBits1;
|
|
|
|
|
|
|
|
begin
|
|
|
|
eBits1 := [bit1, bit7];
|
|
|
|
eBits2 := [bit2, bit4];
|
|
|
|
eBits1 := eBits1 + eBits2;
|
|
|
|
|
|
|
|
Check(bValue = BitsValue, 'Value does not match the bits!');
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TBitsTest.testBitsToString;
|
|
|
|
var
|
|
|
|
eBits: T8Bits;
|
|
|
|
sValue: String;
|
|
|
|
|
|
|
|
begin
|
2005-07-01 13:43:59 +02:00
|
|
|
eBits := Bits;
|
2004-09-20 14:01:08 +02:00
|
|
|
sValue := BitsToString(eBits, bs8);
|
|
|
|
|
|
|
|
Check(sValue = BitsString, 'Bits do not match the string!');
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TBitsTest.testStringToBits;
|
|
|
|
var
|
|
|
|
eBits: T8Bits;
|
|
|
|
sValue: String;
|
|
|
|
|
|
|
|
begin
|
|
|
|
sValue := BitsString;
|
|
|
|
eBits := StringToBits(sValue);
|
|
|
|
|
2005-07-01 13:43:59 +02:00
|
|
|
Check(eBits = Bits, 'String does not match the bits!');
|
2004-09-20 14:01:08 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
initialization
|
2004-12-28 15:43:27 +01:00
|
|
|
RegisterTest('Bits', TBitsTest.Suite);
|
2004-09-20 14:01:08 +02:00
|
|
|
|
|
|
|
end.
|