@@ -138,45 +138,95 @@ subroutine mpas_test_query_exact_match(err)
138
138
end subroutine mpas_test_query_exact_match
139
139
140
140
!**************************************************************************************
141
- ! Subroutine mpas_test_remove_head
141
+ ! Subroutine mpas_test_remove_existing_streams
142
142
!
143
- !> \brief Test removing the head stream from the list and verify removal .
143
+ !> \brief Test removing streams from the beginning, middle, and end of a list .
144
144
!>
145
- !> \details This subroutine tests the removal of the head stream from an MPAS
146
- !> stream list. It ensures that the correct stream is removed and that
147
- !> the list' s state is properly updated after removal.
145
+ !> \details This subroutine verifies that removing streams from different positions
146
+ !> in an MPAS stream list works as expected. It inserts three streams into
147
+ !> the list, then removes one from the middle, one from the end, and one
148
+ !> from the beginning, checking that the correct stream is removed in each
149
+ !> case and that the operation returns a success code.
148
150
!>
149
151
!> \param err The error code that indicates the result of the test.
150
- !
151
- !--------------------------------------------------------------------------------------
152
- subroutine mpas_test_remove_head (err )
152
+ !>
153
+ !**************************************************************************************
154
+ subroutine mpas_test_remove_existing_streams (err)
153
155
integer, intent(out) :: err
154
- type(MPAS_stream_list_type), pointer :: list, stream, removed
156
+ type(MPAS_stream_list_type), pointer :: list, s1, s2, s3, &
157
+ removed1, removed2, removed3
158
+ integer :: ierr
155
159
156
160
err = 0
157
161
158
- call MPAS_stream_list_create(list)
159
- allocate(stream)
160
- stream%name = ' stream1'
161
- call MPAS_stream_list_insert(list, stream)
162
+ allocate(s1)
163
+ s1%name = ' stream1'
164
+ allocate(s2)
165
+ s2%name = ' stream2'
166
+ allocate(s3)
167
+ s3%name = ' stream3'
162
168
163
- call MPAS_stream_list_remove(list, ' stream1' , removed)
169
+ call MPAS_stream_list_create(list, ierr=ierr)
170
+ if (ierr /= MPAS_STREAM_LIST_NOERR) then
171
+ err = err + 1
172
+ end if
164
173
165
- if (.not. associated(removed)) then
174
+ call MPAS_stream_list_insert(list, s1, ierr=ierr)
175
+ if (ierr /= MPAS_STREAM_LIST_NOERR) then
166
176
err = err + 1
167
177
end if
168
178
169
- if (trim (removed%name) /= ' stream1' ) then
179
+ call MPAS_stream_list_insert(list, s2, ierr=ierr)
180
+ if (ierr /= MPAS_STREAM_LIST_NOERR) then
170
181
err = err + 1
171
182
end if
172
183
173
- if (list%nItems /= 0 ) then
184
+ call MPAS_stream_list_insert(list, s3, ierr=ierr)
185
+ if (ierr /= MPAS_STREAM_LIST_NOERR) then
186
+ err = err + 1
187
+ end if
188
+
189
+ ! Remove from the middle
190
+ call MPAS_stream_list_remove(list, ' stream2' , removed2, ierr=ierr)
191
+ if (ierr /= MPAS_STREAM_LIST_NOERR) then
192
+ err = err + 1
193
+ end if
194
+ if (.not. associated(removed2)) then
195
+ err = err + 1
196
+ end if
197
+ if (trim(removed2%name) /= ' stream2' ) then
198
+ err = err + 1
199
+ end if
200
+
201
+ ! Remove from the end
202
+ call MPAS_stream_list_remove(list, ' stream3' , removed3, ierr=ierr)
203
+ if (ierr /= MPAS_STREAM_LIST_NOERR) then
204
+ err = err + 1
205
+ end if
206
+ if (.not. associated(removed3)) then
207
+ err = err + 1
208
+ end if
209
+ if (trim(removed3%name) /= ' stream3' ) then
210
+ err = err + 1
211
+ end if
212
+
213
+ ! Remove from the beginning
214
+ call MPAS_stream_list_remove(list, ' stream1' , removed1, ierr=ierr)
215
+ if (ierr /= MPAS_STREAM_LIST_NOERR) then
216
+ err = err + 1
217
+ end if
218
+ if (.not. associated(removed1)) then
219
+ err = err + 1
220
+ end if
221
+ if (trim(removed1%name) /= ' stream1' ) then
174
222
err = err + 1
175
223
end if
176
224
177
225
call MPAS_stream_list_destroy(list)
178
- deallocate(removed)
179
- end subroutine mpas_test_remove_head
226
+ deallocate(removed1)
227
+ deallocate(removed2)
228
+ deallocate(removed3)
229
+ end subroutine mpas_test_remove_existing_streams
180
230
181
231
!**************************************************************************************
182
232
! Subroutine mpas_test_insert_duplicate_at_begin_and_end
@@ -193,7 +243,7 @@ end subroutine mpas_test_remove_head
193
243
subroutine mpas_test_insert_duplicate_at_begin_and_end(err)
194
244
integer, intent(out) :: err
195
245
type(MPAS_stream_list_type), pointer :: list
196
- type(MPAS_stream_list_type), pointer :: s1, s2, s1_dup
246
+ type(MPAS_stream_list_type), pointer :: s1, s2
197
247
integer :: ierr
198
248
199
249
err = 0
@@ -203,8 +253,6 @@ subroutine mpas_test_insert_duplicate_at_begin_and_end(err)
203
253
s1%name = ' stream1'
204
254
allocate(s2)
205
255
s2%name = ' stream2'
206
- allocate(s1_dup)
207
- s1_dup%name = ' stream1'
208
256
209
257
call MPAS_stream_list_insert(list, s1, ierr)
210
258
if (ierr /= MPAS_STREAM_LIST_NOERR) then
@@ -216,13 +264,12 @@ subroutine mpas_test_insert_duplicate_at_begin_and_end(err)
216
264
err = err + 1
217
265
end if
218
266
219
- call MPAS_stream_list_insert(list, s1_dup , ierr)
267
+ call MPAS_stream_list_insert(list, s1 , ierr)
220
268
if (ierr /= MPAS_STREAM_LIST_DUPLICATE) then
221
269
err = err + 1
222
270
end if
223
271
224
272
call MPAS_stream_list_destroy(list)
225
- deallocate(s1_dup)
226
273
end subroutine mpas_test_insert_duplicate_at_begin_and_end
227
274
228
275
!**************************************************************************************
@@ -397,7 +444,7 @@ end subroutine mpas_test_query_partial_match
397
444
subroutine mpas_test_insert_duplicate_at_begin (err )
398
445
integer , intent (out ) :: err
399
446
type(MPAS_stream_list_type), pointer :: list
400
- type(MPAS_stream_list_type), pointer :: s1, s1_dup
447
+ type(MPAS_stream_list_type), pointer :: s1
401
448
integer :: ierr
402
449
403
450
err = 0
@@ -406,21 +453,17 @@ subroutine mpas_test_insert_duplicate_at_begin(err)
406
453
allocate(s1)
407
454
s1%name = ' stream1'
408
455
409
- allocate(s1_dup)
410
- s1_dup%name = ' stream1'
411
-
412
456
call MPAS_stream_list_insert(list, s1, ierr)
413
457
if (ierr /= MPAS_STREAM_LIST_NOERR) then
414
458
err = err + 1
415
459
end if
416
460
417
- call MPAS_stream_list_insert(list, s1_dup , ierr)
461
+ call MPAS_stream_list_insert(list, s1 , ierr)
418
462
if (ierr /= MPAS_STREAM_LIST_DUPLICATE) then
419
463
err = err + 1
420
464
end if
421
465
422
466
call MPAS_stream_list_destroy(list)
423
- deallocate(s1_dup)
424
467
end subroutine mpas_test_insert_duplicate_at_begin
425
468
426
469
!**************************************************************************************
@@ -438,7 +481,7 @@ end subroutine mpas_test_insert_duplicate_at_begin
438
481
subroutine mpas_test_insert_duplicate_at_end (err )
439
482
integer , intent (out ) :: err
440
483
type(MPAS_stream_list_type), pointer :: list
441
- type(MPAS_stream_list_type), pointer :: s1, s2, s2_dup
484
+ type(MPAS_stream_list_type), pointer :: s1, s2
442
485
integer :: ierr
443
486
444
487
err = 0
@@ -450,9 +493,6 @@ subroutine mpas_test_insert_duplicate_at_end(err)
450
493
allocate(s2)
451
494
s2%name = ' stream2'
452
495
453
- allocate(s2_dup)
454
- s2_dup%name = ' stream2'
455
-
456
496
call MPAS_stream_list_insert(list, s1, ierr)
457
497
if (ierr /= MPAS_STREAM_LIST_NOERR) then
458
498
err = err + 1
@@ -463,13 +503,12 @@ subroutine mpas_test_insert_duplicate_at_end(err)
463
503
err = err + 1
464
504
end if
465
505
466
- call MPAS_stream_list_insert(list, s2_dup , ierr)
506
+ call MPAS_stream_list_insert(list, s2 , ierr)
467
507
if (ierr /= MPAS_STREAM_LIST_DUPLICATE) then
468
508
err = err + 1
469
509
end if
470
510
471
511
call MPAS_stream_list_destroy(list)
472
- deallocate(s2_dup)
473
512
end subroutine mpas_test_insert_duplicate_at_end
474
513
475
514
@@ -522,13 +561,13 @@ subroutine mpas_test_stream_list(err)
522
561
call mpas_log_write(' mpas_test_query_exact_match: FAILURE' )
523
562
end if
524
563
525
- ! Test removing the head stream from the list and verify removal .
526
- call mpas_test_remove_head (test_err)
564
+ ! Test removing streams at beginning, middle, and end of a list .
565
+ call mpas_test_remove_existing_streams (test_err)
527
566
if (test_err == 0 ) then
528
- call mpas_log_write(' mpas_test_remove_head : SUCCESS' )
567
+ call mpas_log_write(' mpas_test_remove_existing_streams : SUCCESS' )
529
568
else
530
569
err = err + test_err
531
- call mpas_log_write(' mpas_test_remove_head : FAILURE' )
570
+ call mpas_log_write(' mpas_test_remove_existing_streams : FAILURE' )
532
571
end if
533
572
534
573
! Test inserting a duplicate stream at both the beginning and the end of the list.
0 commit comments