text stringlengths 0 234 |
|---|
Function Body: use type HAL.Filesystem.Status_Code; |
package Hash renames GNAT.MD5; |
Test_File_Size : constant := 2000; |
function Write_File (Filename : String) return String; |
function Check_File (Filename : String; Md5 : String) return Boolean; |
function Delete_Tree (Filename : String) return Boolean; |
function Check_Read_Test_Dir return Boolean; |
---------------- |
-- Write_File -- |
---------------- |
function Write_File (Filename : String) return String is |
FD : File_Descriptor; |
Status : Status_Code; |
Context : aliased GNAT.MD5.Context := GNAT.MD5.Initial_Context; |
Buffer : Ada.Streams.Stream_Element_Array (1 .. Test_File_Size); |
Last : Ada.Streams.Stream_Element_Offset; |
Size : File_Size; |
use type Ada.Streams.Stream_Element_Offset; |
begin |
Status := Open (FD, Filename, Write_Only); |
if Status /= OK then |
Put_Line ("Cannot open file: '" & Filename & "'"); |
Put_Line ("Status: " & Status'Img); |
return ""; |
end if; |
Size := Buffer'Length; |
Buffer := (others => 42); |
Last := Ada.Streams.Stream_Element_Offset (Size); |
Hash.Update (Context, Buffer (1 .. Last)); |
if Write (FD, Buffer'Address, Size) /= Size then |
Put_Line ("Cannot write file: '" & Filename & "'"); |
Put_Line ("Status: " & Status'Img); |
return ""; |
end if; |
Close (FD); |
return Hash.Digest (Context); |
end Write_File; |
---------------- |
-- Check_File -- |
---------------- |
function Check_File (Filename : String; |
Md5 : String) |
return Boolean |
is |
FD : File_Descriptor; |
Status : Status_Code; |
begin |
Status := Open (FD, Filename, Read_Only); |
if Status /= OK then |
Put_Line ("Cannot open file: '" & Filename & "'"); |
Put_Line ("Status: " & Status'Img); |
return False; |
end if; |
if Size (FD) /= Test_File_Size then |
Put_Line ("Error: wrong file size: " & Size (FD)'Img & |
" (expected " & Test_File_Size'Img & ")"); |
return False; |
end if; |
declare |
Hash_Str : constant String := Compare_Files.Compute_Hash (FD); |
begin |
if Hash_Str /= Md5 then |
Put_Line ("Error: Hash is different than filename"); |
return False; |
else |
return True; |
end if; |
Function Definition: procedure TC_Virtual_Wire is |
Function Body: pragma Assertion_Policy (Assert => Check); |
No_Pull_Wire : Virtual_Wire (Default_Pull => Floating, |
Max_Points => 2); |
Pull_Up_Wire : Virtual_Wire (Default_Pull => Pull_Up, |
Max_Points => 2); |
Pull_Down_Wire : Virtual_Wire (Default_Pull => Pull_Down, |
Max_Points => 2); |
Unref : Boolean with Unreferenced; |
begin |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.