The ParaMonte Documentation Website
Current view: top level - kernel/tests - Test_FileContents_mod.f90 (source / functions) Hit Total Coverage
Test: ParaMonte 1.5.1 :: Coarray Parallel Kernel - Code Coverage Report Lines: 70 70 100.0 %
Date: 2021-01-08 12:59:07 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       2             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       3             : !!!!
       4             : !!!!   MIT License
       5             : !!!!
       6             : !!!!   ParaMonte: plain powerful parallel Monte Carlo library.
       7             : !!!!
       8             : !!!!   Copyright (C) 2012-present, The Computational Data Science Lab
       9             : !!!!
      10             : !!!!   This file is part of the ParaMonte library.
      11             : !!!!
      12             : !!!!   Permission is hereby granted, free of charge, to any person obtaining a
      13             : !!!!   copy of this software and associated documentation files (the "Software"),
      14             : !!!!   to deal in the Software without restriction, including without limitation
      15             : !!!!   the rights to use, copy, modify, merge, publish, distribute, sublicense,
      16             : !!!!   and/or sell copies of the Software, and to permit persons to whom the
      17             : !!!!   Software is furnished to do so, subject to the following conditions:
      18             : !!!!
      19             : !!!!   The above copyright notice and this permission notice shall be
      20             : !!!!   included in all copies or substantial portions of the Software.
      21             : !!!!
      22             : !!!!   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
      23             : !!!!   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
      24             : !!!!   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
      25             : !!!!   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
      26             : !!!!   DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
      27             : !!!!   OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
      28             : !!!!   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
      29             : !!!!
      30             : !!!!   ACKNOWLEDGMENT
      31             : !!!!
      32             : !!!!   ParaMonte is an honor-ware and its currency is acknowledgment and citations.
      33             : !!!!   As per the ParaMonte library license agreement terms, if you use any parts of
      34             : !!!!   this library for any purposes, kindly acknowledge the use of ParaMonte in your
      35             : !!!!   work (education/research/industry/development/...) by citing the ParaMonte
      36             : !!!!   library as described on this page:
      37             : !!!!
      38             : !!!!       https://github.com/cdslaborg/paramonte/blob/main/ACKNOWLEDGMENT.md
      39             : !!!!
      40             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      41             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      42             : 
      43             : !>  \brief This module contains tests of the module [FileContents_mod](@ref filecontents_mod).
      44             : !>  \author Amir Shahmoradi
      45             : 
      46             : module Test_FileContents_mod
      47             : 
      48             :     use FileContents_mod
      49             :     use Test_mod, only: Test_type
      50             :     implicit none
      51             : 
      52             :     private
      53             :     public :: test_FileContents
      54             : 
      55             :     type(Test_type) :: Test
      56             : 
      57             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      58             : 
      59             : contains
      60             : 
      61             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      62             : 
      63           3 :     subroutine test_FileContents()
      64             : 
      65           3 :         Test = Test_type(moduleName=MODULE_NAME)
      66           3 :         call Test%run(test_constructFileContents_1, "test_constructFileContents_1")
      67           3 :         call Test%run(test_constructFileContents_2, "test_constructFileContents_2")
      68           3 :         call Test%finalize()
      69             : 
      70           3 :     end subroutine test_FileContents
      71             : 
      72             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      73             : 
      74           3 :     function test_constructFileContents_1() result(assertion)
      75           3 :         use System_mod, only: RandomFileName_type, removeFile, OS_type
      76             :         use String_mod, only: num2str
      77             :         implicit none
      78             :         logical                     :: assertion
      79           3 :         type(RandomFileName_type)   :: RandomFileName
      80           3 :         type(FileContents_type)     :: FileContents
      81           3 :         type(OS_type)               :: OS
      82             :         integer                     :: fileUnit, i, iostat
      83             : 
      84           3 :         RandomFileName = RandomFileName_type(key = Test%outDir//"/Test_FileContents_mod@test_constructFileContents")
      85           3 :         assertion = .not. RandomFileName%Err%occurred
      86           3 :         if (.not. assertion) then
      87             :             ! LCOV_EXCL_START
      88             :             if (Test%isDebugMode) then
      89             :                 write(Test%outputUnit,"(*(g0))") "RandomFileName%Err%occurred = ", RandomFileName%Err%occurred
      90             :                 write(Test%outputUnit,"(*(g0))") "RandomFileName%Err%stat = ", RandomFileName%Err%stat
      91             :                 write(Test%outputUnit,"(*(g0))") "RandomFileName%Err%msg = ", RandomFileName%Err%msg
      92             :             end if
      93             :             return
      94             :             ! LCOV_EXCL_STOP
      95             :         end if
      96             : 
      97             :         open( file = RandomFileName%path & ! LCOV_EXCL_LINE
      98             :             , newunit = fileUnit & ! LCOV_EXCL_LINE
      99             :             , iostat = iostat & ! LCOV_EXCL_LINE
     100             :             , status = "new" & ! LCOV_EXCL_LINE
     101           3 :             )
     102           3 :         assertion = iostat == 0
     103           3 :         if (.not. assertion) then
     104             :             ! LCOV_EXCL_START
     105             :             if (Test%isDebugMode) then
     106             :                 write(Test%outputUnit,"(*(g0))") "iostat = ", iostat, " <= 0"
     107             :             end if
     108             :             return
     109             :             ! LCOV_EXCL_STOP
     110             :         end if
     111             : 
     112           3 :         write(fileUnit,"(A)") "Testing FileContents_type..."
     113           3 :         write(fileUnit,"(A)") " "
     114           3 :         write(fileUnit,"(A)") ""
     115           3 :         write(fileUnit,"(A)")
     116             : 
     117           3 :         FileContents = FileContents_type(RandomFileName%path)
     118           3 :         assertion = .not. FileContents%Err%occurred
     119           3 :         if (.not. assertion) then
     120             :             ! LCOV_EXCL_START
     121             :             if (Test%isDebugMode) then
     122             :                 write(Test%outputUnit,"(*(g0))") "FileContents%Err%occurred = ", FileContents%Err%occurred
     123             :                 write(Test%outputUnit,"(*(g0))") "FileContents%Err%stat = ", FileContents%Err%stat
     124             :                 write(Test%outputUnit,"(*(g0))") "FileContents%Err%msg = ", FileContents%Err%msg
     125             :             end if
     126             :             return
     127             :             ! LCOV_EXCL_STOP
     128             :         end if
     129             : 
     130           3 :         call OS%query()
     131           3 :         assertion = .not. OS%Err%occurred
     132           3 :         if (.not. assertion) then
     133             :             ! LCOV_EXCL_START
     134             :             if (Test%isDebugMode) then
     135             :                 write(Test%outputUnit,"(*(g0))")
     136             :                 write(Test%outputUnit,"(*(g0))") "OS query failed."
     137             :                 write(Test%outputUnit,"(*(g0))") "OS%Err%occurred = ", OS%Err%occurred
     138             :                 write(Test%outputUnit,"(*(g0))")
     139             :             end if
     140             :             return
     141             :             ! LCOV_EXCL_STOP
     142             :         end if
     143             : 
     144           3 :         call removeFile(RandomFileName%path,OS%Err)
     145           3 :         assertion = .not. OS%Err%occurred
     146           3 :         if (.not. assertion) then
     147             :             ! LCOV_EXCL_START
     148             :             if (Test%isDebugMode) then
     149             :                 write(Test%outputUnit,"(*(g0))")
     150             :                 write(Test%outputUnit,"(*(g0))") "File removal failed.", OS%Err%occurred
     151             :                 write(Test%outputUnit,"(*(g0))") "OS%Err%occurred = ", OS%Err%occurred
     152             :                 write(Test%outputUnit,"(*(g0))")
     153             :             end if
     154             :             return
     155             :             ! LCOV_EXCL_STOP
     156             :         end if
     157             : 
     158           3 :         assertion = assertion .and. FileContents%numRecord==4
     159           3 :         if (.not. assertion) then
     160             :             ! LCOV_EXCL_START
     161             :             if (Test%isDebugMode) then
     162             :                 write(Test%outputUnit,"(*(g0))") "FileContents%numRecord = ", FileContents%numRecord, " /= ", 4
     163             :             end if
     164             :             return
     165             :             ! LCOV_EXCL_STOP
     166             :         end if
     167             : 
     168           3 :         assertion = assertion .and. FileContents%Line(1)%record=="Testing FileContents_type..."
     169           3 :         assertion = assertion .and. FileContents%Line(2)%record==""
     170           3 :         assertion = assertion .and. FileContents%Line(3)%record==""
     171           3 :         assertion = assertion .and. FileContents%Line(4)%record==""
     172             : 
     173           3 :         if (Test%isDebugMode .and. .not. assertion) then
     174             :         ! LCOV_EXCL_START
     175             :             write(Test%outputUnit,"(*(g0))")
     176             :             write(Test%outputUnit,"(*(g0))")   "numRecord  : ", num2str(FileContents%numRecord)
     177             :             do i = 1,FileContents%numRecord
     178             :                 write(Test%outputUnit,"(*(g0))") "FileContents%Line(" // num2str(i) // ")%record : '", FileContents%Line(i)%record
     179             :             end do
     180             :             write(Test%outputUnit,"(*(g0))")
     181             :         end if
     182             :         ! LCOV_EXCL_STOP
     183             : 
     184          15 :     end function test_constructFileContents_1
     185             : 
     186             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     187             : 
     188           3 :     function test_constructFileContents_2() result(assertion)
     189             : 
     190           3 :         use System_mod, only: RandomFileName_type, removeFile, OS_type
     191             :         use String_mod, only: num2str
     192             :         implicit none
     193             :         logical                     :: assertion
     194           3 :         type(RandomFileName_type)   :: RandomFileName
     195           3 :         type(FileContents_type)     :: FileContents
     196           3 :         type(OS_type)               :: OS
     197             :         integer                     :: fileUnit, i, iostat
     198             :         logical                     :: exist
     199             : 
     200           3 :         RandomFileName = RandomFileName_type(key = Test%outDir//"/Test_FileContents_mod@test_constructFileContents")
     201           3 :         assertion = .not. RandomFileName%Err%occurred
     202           3 :         if (.not. assertion) then
     203             :             ! LCOV_EXCL_START
     204             :             if (Test%isDebugMode) then
     205             :                 write(Test%outputUnit,"(*(g0))") "RandomFileName%Err%occurred = ", RandomFileName%Err%occurred
     206             :                 write(Test%outputUnit,"(*(g0))") "RandomFileName%Err%stat = ", RandomFileName%Err%stat
     207             :                 write(Test%outputUnit,"(*(g0))") "RandomFileName%Err%msg = ", RandomFileName%Err%msg
     208             :             end if
     209             :             return
     210             :             ! LCOV_EXCL_STOP
     211             :         end if
     212             : 
     213             :         open( file = RandomFileName%path & ! LCOV_EXCL_LINE
     214             :             , newunit = fileUnit & ! LCOV_EXCL_LINE
     215             :             , iostat = iostat & ! LCOV_EXCL_LINE
     216             :             , status = "new" & ! LCOV_EXCL_LINE
     217           3 :             )
     218           3 :         assertion = iostat == 0
     219           3 :         if (.not. assertion) then
     220             :             ! LCOV_EXCL_START
     221             :             if (Test%isDebugMode) then
     222             :                 write(Test%outputUnit,"(*(g0))") "iostat = ", iostat, " <= 0"
     223             :             end if
     224             :             return
     225             :             ! LCOV_EXCL_STOP
     226             :         end if
     227             : 
     228           3 :         write(fileUnit,"(A)") "Testing FileContents_type..."
     229           3 :         write(fileUnit,"(A)") " "
     230           3 :         write(fileUnit,"(A)") ""
     231           3 :         write(fileUnit,"(A)")
     232             : 
     233           3 :         FileContents = FileContents_type(RandomFileName%path, delEnabled = .true.)
     234           3 :         assertion = .not. FileContents%Err%occurred
     235           3 :         if (.not. assertion) then
     236             :             ! LCOV_EXCL_START
     237             :             if (Test%isDebugMode) then
     238             :                 write(Test%outputUnit,"(*(g0))") "FileContents%Err%occurred = ", FileContents%Err%occurred
     239             :                 write(Test%outputUnit,"(*(g0))") "FileContents%Err%stat = ", FileContents%Err%stat
     240             :                 write(Test%outputUnit,"(*(g0))") "FileContents%Err%msg = ", FileContents%Err%msg
     241             :             end if
     242             :             return
     243             :             ! LCOV_EXCL_STOP
     244             :         end if
     245             : 
     246           3 :         call OS%query()
     247           3 :         assertion = .not. OS%Err%occurred
     248           3 :         if (.not. assertion) then
     249             :             ! LCOV_EXCL_START
     250             :             if (Test%isDebugMode) then
     251             :                 write(Test%outputUnit,"(*(g0))")
     252             :                 write(Test%outputUnit,"(*(g0))") "OS query failed."
     253             :                 write(Test%outputUnit,"(*(g0))") "OS%Err%occurred = ", OS%Err%occurred
     254             :                 write(Test%outputUnit,"(*(g0))")
     255             :             end if
     256             :             return
     257             :             ! LCOV_EXCL_STOP
     258             :         end if
     259             : 
     260           3 :         inquire(file = RandomFileName%path, exist = exist)
     261           3 :         assertion = .not. exist
     262           3 :         if (.not. assertion) then
     263             :             ! LCOV_EXCL_START
     264             :             if (Test%isDebugMode) then
     265             :                 write(Test%outputUnit,"(*(g0))") "delEnabled = ", .true.
     266             :                 write(Test%outputUnit,"(*(g0))") "exist = ", exist
     267             :             end if
     268             :             return
     269             :             ! LCOV_EXCL_STOP
     270             :         end if
     271             : 
     272           3 :         assertion = assertion .and. FileContents%numRecord==4
     273           3 :         if (.not. assertion) then
     274             :             ! LCOV_EXCL_START
     275             :             if (Test%isDebugMode) then
     276             :                 write(Test%outputUnit,"(*(g0))") "FileContents%numRecord = ", FileContents%numRecord, " /= ", 4
     277             :             end if
     278             :             return
     279             :             ! LCOV_EXCL_STOP
     280             :         end if
     281             : 
     282           3 :         assertion = assertion .and. FileContents%Line(1)%record=="Testing FileContents_type..."
     283           3 :         assertion = assertion .and. FileContents%Line(2)%record==""
     284           3 :         assertion = assertion .and. FileContents%Line(3)%record==""
     285           3 :         assertion = assertion .and. FileContents%Line(4)%record==""
     286             : 
     287           3 :         if (Test%isDebugMode .and. .not. assertion) then
     288             :         ! LCOV_EXCL_START
     289             :             write(Test%outputUnit,"(*(g0))")
     290             :             write(Test%outputUnit,"(*(g0))")   "numRecord  : ", num2str(FileContents%numRecord)
     291             :             do i = 1,FileContents%numRecord
     292             :                 write(Test%outputUnit,"(*(g0))") "FileContents%Line(" // num2str(i) // ")%record : '", FileContents%Line(i)%record
     293             :             end do
     294             :             write(Test%outputUnit,"(*(g0))")
     295             :         end if
     296             :         ! LCOV_EXCL_STOP
     297             : 
     298          15 :     end function test_constructFileContents_2
     299             : 
     300             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     301             : 
     302             : end module Test_FileContents_mod ! LCOV_EXCL_LINE

ParaMonte: Plain Powerful Parallel Monte Carlo Library 
The Computational Data Science Lab
© Copyright 2012 - 2021