TABLE OF CONTENTS


ABINIT/21_hashfuncs/tests/test_md5_sum_from_file [ Programs ]

[ Top ] [ Programs ]

NAME

  test_md5_sum_from_file

FUNCTION

  Unit test for the test_md5_sum_from_file routine of m_hash_md5.

COPYRIGHT

  Copyright (C) 2016-2024 ABINIT Group (Yann Pouillon)
  This file is distributed under the terms of the
  GNU General Public License, see ~abinit/COPYING
  or http://www.gnu.org/copyleft/gpl.txt .
  For the initials of contributors, see
  ~abinit/doc/developers/contributors.txt .

NOTES

  This program is run by "make check".

INPUTS

  (main routine)

OUTPUT

  (main routine)

SOURCE

 27 #if defined HAVE_CONFIG_H
 28 #include "config.h"
 29 #endif
 30 
 31 program test_md5_sum_from_file
 32 
 33 use defs_basis, only: ch10,fnlen,std_out
 34 use m_hash_md5
 35 implicit none
 36 
 37 character(len=*), parameter  :: abinit_input_string = "ABINIT"
 38 character(len=32), parameter :: abinit_md5_single_line_ref = &
 39 &                                 "1c57f60933157a3b6e13def40286f0c5"
 40 character(len=32), parameter :: abinit_md5_multi_line_ref = &
 41 &                                 "953ac666dcdbf651ee3393d374216499"
 42 
 43 character(len=fnlen), parameter :: tmp_file = "test_md5_sum_from_file.tmp"
 44 
 45 character(len=32) :: chk_value_single, chk_value_multi
 46 logical :: test_ok
 47 
 48 #if defined DEBUG_MODE
 49 write(std_out,'(a,a)') "Unitary test: md5_sum_from_file", ch10
 50 #endif
 51 
 52 ! File of one line + newline character
 53 #if defined DEBUG_MODE
 54 write(std_out,'(1x,a,1x,a)') "Creating single-line ", trim(tmp_file)
 55 write(std_out,'(1x,a," = ",a)') "Reference MD5 sum", abinit_md5_single_line_ref
 56 #endif
 57 
 58 open(unit=1, file=trim(tmp_file), form="formatted", status="replace")
 59 write(1,'(a)') abinit_input_string
 60 close(1)
 61 
 62 chk_value_single = md5_sum_from_file(tmp_file)
 63 
 64 #if defined DEBUG_MODE
 65 write(std_out,'(1x,a," = ",a)') "Computed  MD5 sum", chk_value_single
 66 #endif
 67 
 68 ! File of three lines + newline characters
 69 #if defined DEBUG_MODE
 70 write(std_out,*)
 71 write(std_out,'(1x,a,1x,a)') "Creating multi-line ", trim(tmp_file)
 72 write(std_out,'(1x,a," = ",a)') "Reference MD5 sum", abinit_md5_multi_line_ref
 73 #endif
 74 
 75 open(unit=1, file=trim(tmp_file), form="formatted", status="replace")
 76 write(1,'(a)') abinit_input_string
 77 write(1,'(a)') abinit_input_string
 78 write(1,'(a)') abinit_input_string
 79 close(1)
 80 
 81 chk_value_multi = md5_sum_from_file(tmp_file)
 82 
 83 #if defined DEBUG_MODE
 84 write(std_out,'(1x,a," = ",a)') "Computed  MD5 sum", chk_value_multi
 85 #endif
 86 
 87 ! Report test result
 88 test_ok = ( md5_check(abinit_md5_single_line_ref, chk_value_single) .and. &
 89 & md5_check(abinit_md5_multi_line_ref, chk_value_multi) )
 90 #if defined DEBUG_MODE
 91 write(std_out,*)
 92 if ( test_ok ) then
 93   write(std_out,'(a,a)') "TEST OK", ch10
 94 else
 95   write(std_out,'(a,a)') "TEST FAILED", ch10
 96 end if
 97 #else
 98 if ( .not. test_ok ) then
 99   write(std_out,'(a,a)') "TEST FAILED", ch10
100 end if
101 #endif
102 
103 end program test_md5_sum_from_file