|
| 1 | +!!!!!!!!!!!!!!!!!!!!!!!! GNU General Public License 2.0 !!!!!!!!!!!!!!!!!!!!!!!! |
| 2 | +!! !! |
| 3 | +!! Copyright (C) 2022 Kevin Matthes !! |
| 4 | +!! !! |
| 5 | +!! This program is free software; you can redistribute it and/or modify !! |
| 6 | +!! it under the terms of the GNU General Public License as published by !! |
| 7 | +!! the Free Software Foundation; either version 2 of the License, or !! |
| 8 | +!! (at your option) any later version. !! |
| 9 | +!! !! |
| 10 | +!! This program is distributed in the hope that it will be useful, !! |
| 11 | +!! but WITHOUT ANY WARRANTY; without even the implied warranty of !! |
| 12 | +!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the !! |
| 13 | +!! GNU General Public License for more details. !! |
| 14 | +!! !! |
| 15 | +!! You should have received a copy of the GNU General Public License along !! |
| 16 | +!! with this program; if not, write to the Free Software Foundation, Inc., !! |
| 17 | +!! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. !! |
| 18 | +!! !! |
| 19 | +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 20 | + |
| 21 | +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 22 | +!! |
| 23 | +!> \file test_character.f08 |
| 24 | +!! |
| 25 | +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 26 | + |
| 27 | +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 28 | +!! |
| 29 | +!> \author Kevin Matthes |
| 30 | +!> \copyright GPL-2.0 |
| 31 | +!> \date 2022 |
| 32 | +!> \note See `LICENSE' for full license. |
| 33 | +!> See `README.md' for project details. |
| 34 | +!> |
| 35 | +!> \brief A set of simple tests for the `character` type (default). |
| 36 | +!> \return Whether this test succeeds. |
| 37 | +!> |
| 38 | +!> This unit test will check whether |
| 39 | +!> |
| 40 | +!> * an unallocated allocatable object can be deallocated. |
| 41 | +!> * an unallocated allocatable object can be allocated and receive a constant. |
| 42 | +!> * an allocated allocatable object can receive another constant by conditional |
| 43 | +!> reallocation. |
| 44 | +!> * an allocated allocatable object can be deallocated. |
| 45 | +!! |
| 46 | +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 47 | + |
| 48 | +program test_character |
| 49 | + use, non_intrinsic :: libf18cndmem, only: cndall |
| 50 | + use, non_intrinsic :: libf18cndmem, only: cnddel |
| 51 | +implicit none |
| 52 | + character (:), allocatable :: object |
| 53 | + character (*), parameter :: constant & |
| 54 | + = 'constant' |
| 55 | + character (*), parameter :: error_allocated & |
| 56 | + = 'Allocatable object should not be allocated!' |
| 57 | + character (*), parameter :: error_not_allocated & |
| 58 | + = 'Allocatable object should be allocated!' |
| 59 | + character (*), parameter :: error_wrong_value & |
| 60 | + = 'Allocatable object does not have the expect& |
| 61 | + &ed value!' |
| 62 | + character (*), parameter :: hello & |
| 63 | + = 'Hello' |
| 64 | + character (*), parameter :: world & |
| 65 | + = ', World!' |
| 66 | + intrinsic :: allocated |
| 67 | + |
| 68 | + if (allocated (object)) then |
| 69 | + error stop error_allocated |
| 70 | + else |
| 71 | + call cnddel (object) |
| 72 | + end if |
| 73 | + |
| 74 | + if (allocated (object)) then |
| 75 | + error stop error_allocated |
| 76 | + else |
| 77 | + call cndall (object, constant) |
| 78 | + end if |
| 79 | + |
| 80 | + if (.not. allocated (object)) then |
| 81 | + error stop error_not_allocated |
| 82 | + else if (object /= constant) then |
| 83 | + error stop error_wrong_value |
| 84 | + end if |
| 85 | + |
| 86 | + call cndall (object, hello) |
| 87 | + |
| 88 | + if (.not. allocated (object)) then |
| 89 | + error stop error_not_allocated |
| 90 | + else if (object // world /= hello // world) then |
| 91 | + error stop error_wrong_value |
| 92 | + end if |
| 93 | + |
| 94 | + if (.not. allocated (object)) then |
| 95 | + error stop error_not_allocated |
| 96 | + else |
| 97 | + call cnddel (object) |
| 98 | + end if |
| 99 | + |
| 100 | + if (allocated (object)) then |
| 101 | + error stop error_allocated |
| 102 | + end if |
| 103 | +end program test_character |
| 104 | + |
| 105 | +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
0 commit comments