@@ -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
- !
152
+ !>
151
153
!--------------------------------------------------------------------------------------
152
- subroutine mpas_test_remove_head (err )
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
!**************************************************************************************
@@ -239,12 +286,10 @@ end subroutine mpas_test_insert_duplicate_at_begin_and_end
239
286
!--------------------------------------------------------------------------------------
240
287
subroutine mpas_test_remove_from_empty_list(err)
241
288
integer, intent(out) :: err
242
- type(MPAS_stream_list_type), pointer :: list, s1, removed
289
+ type(MPAS_stream_list_type), pointer :: list, removed
243
290
integer :: ierr
244
291
245
292
err = 0
246
- allocate(s1)
247
- s1%name = ' stream1'
248
293
249
294
call MPAS_stream_list_create(list)
250
295
@@ -397,7 +442,7 @@ end subroutine mpas_test_query_partial_match
397
442
subroutine mpas_test_insert_duplicate_at_begin (err )
398
443
integer , intent (out ) :: err
399
444
type(MPAS_stream_list_type), pointer :: list
400
- type(MPAS_stream_list_type), pointer :: s1, s1_dup
445
+ type(MPAS_stream_list_type), pointer :: s1
401
446
integer :: ierr
402
447
403
448
err = 0
@@ -406,21 +451,17 @@ subroutine mpas_test_insert_duplicate_at_begin(err)
406
451
allocate(s1)
407
452
s1%name = ' stream1'
408
453
409
- allocate(s1_dup)
410
- s1_dup%name = ' stream1'
411
-
412
454
call MPAS_stream_list_insert(list, s1, ierr)
413
455
if (ierr /= MPAS_STREAM_LIST_NOERR) then
414
456
err = err + 1
415
457
end if
416
458
417
- call MPAS_stream_list_insert(list, s1_dup , ierr)
459
+ call MPAS_stream_list_insert(list, s1 , ierr)
418
460
if (ierr /= MPAS_STREAM_LIST_DUPLICATE) then
419
461
err = err + 1
420
462
end if
421
463
422
464
call MPAS_stream_list_destroy(list)
423
- deallocate(s1_dup)
424
465
end subroutine mpas_test_insert_duplicate_at_begin
425
466
426
467
!**************************************************************************************
@@ -438,7 +479,7 @@ end subroutine mpas_test_insert_duplicate_at_begin
438
479
subroutine mpas_test_insert_duplicate_at_end (err )
439
480
integer , intent (out ) :: err
440
481
type(MPAS_stream_list_type), pointer :: list
441
- type(MPAS_stream_list_type), pointer :: s1, s2, s2_dup
482
+ type(MPAS_stream_list_type), pointer :: s1, s2
442
483
integer :: ierr
443
484
444
485
err = 0
@@ -450,9 +491,6 @@ subroutine mpas_test_insert_duplicate_at_end(err)
450
491
allocate(s2)
451
492
s2%name = ' stream2'
452
493
453
- allocate(s2_dup)
454
- s2_dup%name = ' stream2'
455
-
456
494
call MPAS_stream_list_insert(list, s1, ierr)
457
495
if (ierr /= MPAS_STREAM_LIST_NOERR) then
458
496
err = err + 1
@@ -463,13 +501,12 @@ subroutine mpas_test_insert_duplicate_at_end(err)
463
501
err = err + 1
464
502
end if
465
503
466
- call MPAS_stream_list_insert(list, s2_dup , ierr)
504
+ call MPAS_stream_list_insert(list, s2 , ierr)
467
505
if (ierr /= MPAS_STREAM_LIST_DUPLICATE) then
468
506
err = err + 1
469
507
end if
470
508
471
509
call MPAS_stream_list_destroy(list)
472
- deallocate(s2_dup)
473
510
end subroutine mpas_test_insert_duplicate_at_end
474
511
475
512
@@ -522,13 +559,13 @@ subroutine mpas_test_stream_list(err)
522
559
call mpas_log_write(' mpas_test_query_exact_match: FAILURE' )
523
560
end if
524
561
525
- ! Test removing the head stream from the list and verify removal .
526
- call mpas_test_remove_head (test_err)
562
+ ! Test removing streams at beginning, middle, and end of a list .
563
+ call mpas_test_remove_existing_streams (test_err)
527
564
if (test_err == 0 ) then
528
- call mpas_log_write(' mpas_test_remove_head : SUCCESS' )
565
+ call mpas_log_write(' mpas_test_remove_existing_streams : SUCCESS' )
529
566
else
530
567
err = err + test_err
531
- call mpas_log_write(' mpas_test_remove_head : FAILURE' )
568
+ call mpas_log_write(' mpas_test_remove_existing_streams : FAILURE' )
532
569
end if
533
570
534
571
! Test inserting a duplicate stream at both the beginning and the end of the list.
0 commit comments