awa_unit_2.4.0_59135a52/ada-keystore/ada-fuse/examples/rotfs/unittest/src/test_setup.adb

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
--
--
--


-- used packages


with Ada.Text_IO;
with AUnit.Assertions;
with Ada.Directories;
with Ada.IO_Exceptions;

with Command_Line_Calls;


-- package implementation


package body Test_Setup is
   
   
   ----------------------------------------------------------------------------
   --                                                                        --
   -- the scaffolding for the testcases                                      --
   --                                                                        --
   ----------------------------------------------------------------------------
   
   
   -- place for used variables and constants used for testing
   -- e.g.
   -- I1, I2, I3 : Int;
   -- Expected1, Expexted2, Expexted3 : Int;
   
   
   Framework_Test     : Integer;
   Framework_Value    : Integer;
   Framework_Expected : Integer;
   
   
   -- implementation of necessary functions
   
   
   procedure Set_Up_Case(T: in out TC) is
      pragma Unreferenced(T);
      Current_Dir       : constant String := Ada.Directories.Current_Directory;
      Folder_Created    : Boolean := False;
      FS_Mounted        : Boolean := False;
      Mount_Exception   : Exception;
   begin
      Ada.Text_IO.New_Line;
      Ada.Text_IO.Put_Line("Run Set_Up_Case ...");
      Ada.Text_IO.New_Line;
   
      -- Here are the basic setup for testcases.
      -- Especially the expected values of the tests are writen here.
      -- e.g.
      -- Expected1 := 5;
      -- Expected2 := 9;
      -- Expected3 := 1;
   
      Framework_Test       := 2;
      Framework_Expected   := 4;

      -- create folders
      while not Folder_Created loop
         Ada.Directories.Create_Path(Current_Dir & "/from");
         Folder_Created := Ada.Directories.Exists(Current_Dir & "/from");
      end loop;

      Folder_Created := False;

      while not Folder_Created loop
         Ada.Directories.Create_Path(Current_Dir & "/to");
         Folder_Created := Ada.Directories.Exists(Current_Dir & "/to");
      end loop;

      -- mount the filesystem
      FS_Mounted := Command_Line_Calls.Mount_FS;
      if FS_Mounted then
         Ada.Text_IO.Put_Line("-- ok");
      else
         Ada.Text_IO.Put_Line("Filesystem could not be mounted.");
         raise Mount_Exception;
      end if;
   end Set_Up_Case;
   
   
   procedure Set_Up(T: in out TC) is
      pragma Unreferenced(T);
   begin
      -- Procedure not used
      -- May useful for later use.
      null;
   end Set_Up;
   
   
   procedure Tear_Down(T: in out TC) is
      pragma Unreferenced(T);
   begin
      -- Procedure not used
      -- May useful for later use.
      null;
   end Tear_Down;
   
   
   procedure Tear_Down_Case(T: in out TC) is
      pragma Unreferenced(T);
      Current_Dir : constant String := Ada.Directories.Current_Directory;
      Success     : Boolean := False;
      Mount_Exception   : Exception;
   begin
      Ada.Text_IO.New_Line;
      Ada.Text_IO.Put_Line("Run Tear_Down_Case ...");

      -- unmount filesystem
      Success := Command_Line_Calls.Unmount_FS(3, "1");

      -- delete folders
      if Success then
         Ada.Text_IO.Put_Line("-- ok");
         Ada.Directories.Delete_Tree(Current_Dir & "/from");
         Ada.Directories.Delete_Tree(Current_Dir & "/to");
      else
         Ada.Text_IO.Put_Line("The filesystem could not be unmounted.");
         Ada.Text_IO.Put_Line("Folders are not deleted.");
         raise Mount_Exception;
      end if;
   end Tear_Down_Case;
   
   
   ----------------------------------------------------------------------------
   --                                                                        --
   -- the testcases which should be tested                                   --
   --                                                                        --
   ----------------------------------------------------------------------------
   
   
   ---------------------------------------
   -- T1: simple framework test
   ---------------------------------------
   
   
   procedure Simple_Framework_Test(CWTC: in out AUnit.Test_Cases.Test_Case'Class) is
      -- not in example, but compiler warning
      pragma Unreferenced(CWTC);
   begin
      Framework_Value := Framework_Test + Framework_Test; -- should be 4
      AUnit.Assertions.Assert(Condition => (Framework_Value = Framework_Expected),
                              Message => "Incorrect value for a simple addition.");
   end Simple_Framework_Test;
   
   
   ---------------------------------------
   -- T2: create a folder
   ---------------------------------------
   
   
   procedure Create_A_Folder(CWTC: in out AUnit.Test_Cases.Test_Case'Class) is
      -- not in example, but compiler warning
      pragma Unreferenced(CWTC);
      Current_Dir    : constant String := Ada.Directories.Current_Directory;
      New_Dir_Path   : constant String := "/to/";
      Test_Dir       : constant String := "test_dir/";
      New_Dir_Name   : constant String := "ordner";
      Search_Pattern : constant String := "";
      Search         : Ada.Directories.Search_Type;
      Dir_Entry      : Ada.Directories.Directory_Entry_Type;
      Filter         : constant Ada.Directories.Filter_Type := (
         Ada.Directories.Ordinary_File => False,
         Ada.Directories.Special_File  => False,
         Ada.Directories.Directory     => True
      );
      Dir_Found      : Boolean := False;
   begin
      -- part 1: create dir
      Ada.Directories.Create_Path(Current_Dir & New_Dir_Path & Test_Dir &
                                  New_Dir_Name);

      -- part 2: check
      Ada.Directories.Start_Search(Search, Current_Dir & New_Dir_Path &
                                   Test_Dir, Search_Pattern, Filter);

      while Ada.Directories.More_Entries(Search) loop
         Ada.Directories.Get_Next_Entry(Search, Dir_Entry);
         if Ada.Directories.Simple_Name(Dir_Entry) = New_Dir_Name then
            Dir_Found := True;
            Ada.Directories.End_Search (Search);
         end if;
      end loop;

      Ada.Directories.End_Search (Search);
      
      AUnit.Assertions.Assert(Condition => Dir_Found,
                              Message => "The created directory could not be found.");
   end Create_A_Folder;
   
   
   ---------------------------------------
   -- T3: create a folder 2
   ---------------------------------------
   
   
   --#
   --# Should be removed, if there is a solution for te problem.
   pragma Warnings(Off);
   --#
   --#
   procedure Create_A_Folder2(CWTC: in out AUnit.Test_Cases.Test_Case'Class) is
      -- not in example, but compiler warning
      pragma Unreferenced(CWTC);
      Current_Dir    : constant String := Ada.Directories.Current_Directory;
      New_Dir_Path   : constant String := "/to/";
      Test_Dir       : constant String := "test_dir/";
      New_Dir_Name   : constant String := "ordner";
      Dir_Found      : Boolean := False;
   begin
      -- part 1: create dir
      Ada.Directories.Create_Path(Current_Dir & New_Dir_Path & Test_Dir &
                                  New_Dir_Name);

      -- part 2: catch exception
      -- exception should be raised?
      -- Nothing happens. So this test will allways fail.
      -- Because no exception is raised, some variables aren't used.
      -- So some warnings are printed.
      --
      -- Added pragma Warnings, to avoid warnings, see top.

      AUnit.Assertions.Assert(Condition => Dir_Found,
                              Message => "The directory creation raised no exception");
   end Create_A_Folder2;
   --#
   --# Should be removed, if there is a solution for te problem.
   pragma Warnings(On);
   --#
   --#


   ---------------------------------------
   -- T4: remove a folder
   ---------------------------------------
   
   
   procedure Remove_A_Folder(CWTC: in out AUnit.Test_Cases.Test_Case'Class) is
      -- not in example, but compiler warning
      pragma Unreferenced(CWTC);
      Current_Dir    : constant String := Ada.Directories.Current_Directory;
      Dir_Path       : constant String := "/to/";
      Test_Dir       : constant String := "test_dir/";
      Dir_Name       : constant String := "ordner";
      Search_Pattern : constant String := "";
      Search         : Ada.Directories.Search_Type;
      Dir_Entry      : Ada.Directories.Directory_Entry_Type;
      Filter         : constant Ada.Directories.Filter_Type := (
         Ada.Directories.Ordinary_File => False,
         Ada.Directories.Special_File  => False,
         Ada.Directories.Directory     => True
      );
      Dir_Found      : Boolean := False;
   begin
      -- part 1: create dir
      Ada.Directories.Delete_Directory(Current_Dir & Dir_Path & Test_Dir &
                                       Dir_Name);

      -- part 2: check
      Ada.Directories.Start_Search( Search, Current_Dir & Dir_Path & Test_Dir,
                                    Search_Pattern, Filter);

      while Ada.Directories.More_Entries(Search) loop
         Ada.Directories.Get_Next_Entry(Search, Dir_Entry);
         if Ada.Directories.Simple_Name(Dir_Entry) = Dir_Name then
            Dir_Found := True;
            Ada.Directories.End_Search (Search);
         end if;
      end loop;

      Ada.Directories.End_Search (Search);
      
      AUnit.Assertions.Assert(Condition => not Dir_Found,
                              Message => "The directory was not removed.");
   end Remove_A_Folder;


   ---------------------------------------
   -- T5: remove a folder 2
   ---------------------------------------
   
   
   procedure Remove_A_Folder2(CWTC: in out AUnit.Test_Cases.Test_Case'Class) is
      -- not in example, but compiler warning
      pragma Unreferenced(CWTC);
      Current_Dir       : constant String := Ada.Directories.Current_Directory;
      Dir_Path          : constant String := "/to/";
      Test_Dir          : constant String := "test_dir/";
      Dir_Name          : constant String := "ordner";
      Exception_Raised  : Boolean := False;
   begin
      -- part 1: create dir
      Ada.Directories.Delete_Directory(Current_Dir & Dir_Path & Test_Dir & Dir_Name);

      -- part 2: catch exception
      exception
         when Ada.IO_Exceptions.Name_Error =>
            Exception_Raised := True;
      
     AUnit.Assertions.Assert(Condition => Exception_Raised,
                              Message => "The directory was not removed.");
   end Remove_A_Folder2;


   ---------------------------------------
   -- T6: rename a folder
   ---------------------------------------
   
   
   procedure Rename_A_Folder(CWTC: in out AUnit.Test_Cases.Test_Case'Class) is
      -- not in example, but compiler warning
      pragma Unreferenced(CWTC);
      Current_Dir    : constant String := Ada.Directories.Current_Directory;
      Dir_Path       : constant String := "/to/";
      Test_Dir       : constant String := "test_dir/";
      Dir_Name       : constant String := "ordner9";
      New_Dir_Name   : constant String := "ordner10";
      Dir_Found      : Boolean := False;
   begin
      -- part 1: create dir
      Ada.Directories.Create_Path(Current_Dir & Dir_Path & Test_Dir & Dir_Name);

      -- part 2: check if it was created
      Dir_Found := Ada.Directories.Exists(Current_Dir & Dir_Path & Test_Dir &
                                          Dir_Name);
      AUnit.Assertions.Assert(Condition => Dir_Found,
                              Message => "The created directory could not be found.");

      -- part3: rename
      Ada.Directories.Rename(Current_Dir & Dir_Path & Test_Dir & Dir_Name,
                             Current_Dir & Dir_Path & Test_Dir & New_Dir_Name);

      -- part4: check if it was renamed
      Dir_Found := Ada.Directories.Exists(Current_Dir & Dir_Path & Test_Dir &
                                          New_Dir_Name);
      AUnit.Assertions.Assert(Condition => Dir_Found,
                              Message => "The renamed directory could not be found.");
   end Rename_A_Folder;
  

   ---------------------------------------
   -- T7: rename a folder 2
   ---------------------------------------
   
   
   procedure Rename_A_Folder2(CWTC: in out AUnit.Test_Cases.Test_Case'Class) is
      -- not in example, but compiler warning
      pragma Unreferenced(CWTC);
      Current_Dir       : constant String := Ada.Directories.Current_Directory;
      Dir_Path          : constant String := "/to/";
      Test_Dir          : constant String := "test_dir/";
      Dir_Name          : constant String := "ordner9";
      New_Dir_Name      : constant String := "ordner10";
      Exception_Raised  : Boolean := False;
   begin
      -- part 1: rename
      Ada.Directories.Rename(Current_Dir & Dir_Path & Test_Dir & Dir_Name,
                             Current_Dir & Dir_Path & Test_Dir & New_Dir_Name);

      -- part 2: catch exception
      exception
         when Ada.IO_Exceptions.Name_Error =>
            Exception_Raised := True;

      AUnit.Assertions.Assert(Condition => Exception_Raised,
                              Message => "The renamed directory could not be found.");
   end Rename_A_Folder2;
  

   ---------------------------------------
   -- T8: create a file
   ---------------------------------------
   
   
   procedure Create_A_File(CWTC: in out AUnit.Test_Cases.Test_Case'Class) is
      -- not in example, but compiler warning
      pragma Unreferenced(CWTC);
      File           : Ada.Text_IO.File_Type;
      File_Mode      : constant Ada.Text_IO.File_Mode := Ada.Text_IO.Out_File;
      File_Name      : constant String := "datei";
      Current_Dir    : constant String := Ada.Directories.Current_Directory;
      Dir_Path       : constant String := "/to/";
      Test_Dir       : constant String := "test_dir/";
      File_Created   : Boolean := False;
   begin
      -- part 1: create file, stream content
      Ada.Text_IO.Create(File, File_Mode, Current_Dir & Dir_Path & Test_Dir &
                         File_Name, "");
      Ada.Text_IO.Close(File);

      -- part 2: check if file exists
      File_Created := Ada.Directories.Exists(Current_Dir & Dir_Path & Test_Dir &
                                             File_Name);

      AUnit.Assertions.Assert(Condition => File_Created,
                              Message => "The file was not created.");
   end Create_A_File;


   ---------------------------------------
   -- T9: write a file
   ---------------------------------------
   
   
   procedure Write_A_File(CWTC: in out AUnit.Test_Cases.Test_Case'Class) is
      -- not in example, but compiler warning
      pragma Unreferenced(CWTC);
      File           : Ada.Text_IO.File_Type;
      File_Mode      : constant Ada.Text_IO.File_Mode := Ada.Text_IO.Out_File;
      File_Name      : constant String := "datei2";
      Current_Dir    : constant String := Ada.Directories.Current_Directory;
      Dir_Path       : constant String := "/to/";
      Test_Dir       : constant String := "test_dir/";
      Content        : constant String := "Hallo Welt!";
      Size_Before    : Ada.Directories.File_Size;
      Size_After     : Ada.Directories.File_Size;
   begin
      -- part 1: create file, write content
      Ada.Text_IO.Create(File, File_Mode, Current_Dir & Dir_Path & Test_Dir &
                         File_Name, "");
      Size_Before := Ada.Directories.Size(Current_Dir & Dir_Path & Test_Dir &
                                          File_Name);
      Ada.Text_IO.Put(File, Content);
      Ada.Text_IO.Close(File);
      Size_After := Ada.Directories.Size(Current_Dir & Dir_Path & Test_Dir &
                                         File_Name);

      -- part 2: check if file exists
      AUnit.Assertions.Assert(Condition => (Ada.Directories.">"(Size_After, Size_Before)),
                              Message => "The file was not writen.");
   end Write_A_File;


   ---------------------------------------
   -- T10: read a file
   ---------------------------------------
   
   
   procedure Read_A_File(CWTC: in out AUnit.Test_Cases.Test_Case'Class) is
      -- not in example, but compiler warning
      pragma Unreferenced(CWTC);
      File           : Ada.Text_IO.File_Type;
      File_Mode_Out  : constant Ada.Text_IO.File_Mode := Ada.Text_IO.Out_File;
      File_Mode_In   : constant Ada.Text_IO.File_Mode := Ada.Text_IO.In_File;
      File_Name      : constant String := "datei3";
      Current_Dir    : constant String := Ada.Directories.Current_Directory;
      Dir_Path       : constant String := "/to/";
      Test_Dir       : constant String := "test_dir/";
      Content        : constant String := "Hallo Welt! Und noch was ...";
      Input          : String(Content'Range);
   begin
      -- part 1: create file, write content
      Ada.Text_IO.Create(File, File_Mode_Out, Current_Dir & Dir_Path & Test_Dir
                         & File_Name, "");
      Ada.Text_IO.Put(File, Content);
      Ada.Text_IO.Close(File);

      -- part 2: read file and check content
      Ada.Text_IO.Open(File, File_Mode_In, Current_Dir & Dir_Path & Test_Dir &
                       File_Name, "");
      Ada.Text_IO.Get(File, Input);
      Ada.Text_IO.Close(File);

      AUnit.Assertions.Assert(Condition => (Content = Input),
                              Message => "The file could not be read.");
   end Read_A_File;


   ---------------------------------------
   -- T11: delete a file
   ---------------------------------------
   
   
   procedure Delete_A_File(CWTC: in out AUnit.Test_Cases.Test_Case'Class) is
      -- not in example, but compiler warning
      pragma Unreferenced(CWTC);
      File           : Ada.Text_IO.File_Type;
      File_Mode_Out  : constant Ada.Text_IO.File_Mode := Ada.Text_IO.Out_File;
      File_Name      : constant String := "datei4";
      Current_Dir    : constant String := Ada.Directories.Current_Directory;
      Dir_Path       : constant String := "/to/";
      Test_Dir       : constant String := "test_dir/";
      File_Exists    : Boolean := False;
   begin
      -- part 1: create file
      Ada.Text_IO.Create(File, File_Mode_Out, Current_Dir & Dir_Path & Test_Dir
                         & File_Name, "");
      Ada.Text_IO.Close(File);

      -- part 2: check if file was created
      File_Exists := Ada.Directories.Exists(Current_Dir & Dir_Path & Test_Dir &
                                            File_Name);
      AUnit.Assertions.Assert(Condition => File_Exists,
                              Message => "The file was not created.");

      -- part 3: delete file
      Ada.Directories.Delete_File(Current_Dir & Dir_Path & Test_Dir & File_Name);

      -- part 4: check if file was deleted
      File_Exists := Ada.Directories.Exists(Current_Dir & Dir_Path & Test_Dir &
                                            File_Name);
      AUnit.Assertions.Assert(Condition => not File_Exists,
                              Message => "The file was not deleted.");
   end Delete_A_File;


   ---------------------------------------
   -- T12: read a file 2
   ---------------------------------------
   
   
   procedure Read_A_File2(CWTC: in out AUnit.Test_Cases.Test_Case'Class) is
      -- not in example, but compiler warning
      pragma Unreferenced(CWTC);
      File              : Ada.Text_IO.File_Type;
      File_Mode_In      : constant Ada.Text_IO.File_Mode := Ada.Text_IO.In_File;
      File_Name         : constant String := "datei5";
      Current_Dir       : constant String := Ada.Directories.Current_Directory;
      Dir_Path          : constant String := "/to/";
      Test_Dir          : constant String := "test_dir/";
      Exception_Raised  : Boolean := False;
   begin
      -- part 1: try to open file that not exists
      Ada.Text_IO.Open(File, File_Mode_In, Current_Dir & Dir_Path & Test_Dir &
                       File_Name, "");

      -- part 2: catch exception
      exception
         when ADA.IO_Exceptions.NAME_ERROR =>
            Exception_Raised := True;
            
      AUnit.Assertions.Assert(Condition => Exception_Raised,
                              Message => "A not existing file was opened.");
   end Read_A_File2;


   ---------------------------------------
   -- T13: delete a file 2
   ---------------------------------------
   
   
   procedure Delete_A_File2(CWTC: in out AUnit.Test_Cases.Test_Case'Class) is
      -- not in example, but compiler warning
      pragma Unreferenced(CWTC);
      File_Name         : constant String := "datei5";
      Current_Dir       : constant String := Ada.Directories.Current_Directory;
      Dir_Path          : constant String := "/to/";
      Test_Dir          : constant String := "test_dir/";
      Exception_Raised  : Boolean := False;
   begin
      -- part 1: delete file that not exists
      Ada.Directories.Delete_File(Current_Dir & Dir_Path & Test_Dir & File_Name);

      -- part 2: catch exception
      exception
         when ADA.IO_Exceptions.NAME_ERROR =>
            Exception_Raised := True;
            
      AUnit.Assertions.Assert(Condition => Exception_Raised,
                              Message => "The file was not deleted.");
   end Delete_A_File2;


   ---------------------------------------
   -- T14: move a file
   ---------------------------------------
   
   
   procedure Move_A_File(CWTC: in out AUnit.Test_Cases.Test_Case'Class) is
      -- not in example, but compiler warning
      pragma Unreferenced(CWTC);
      File           : Ada.Text_IO.File_Type;
      File_Mode_Out  : constant Ada.Text_IO.File_Mode := Ada.Text_IO.Out_File;
      File_Mode_In   : constant Ada.Text_IO.File_Mode := Ada.Text_IO.In_File;
      File_Name      : constant String := "datei6";
      Current_Dir    : constant String := Ada.Directories.Current_Directory;
      Dir_Path       : constant String := "/to/";
      Test_Dir       : constant String := "test_dir/";
      Source         : constant String := "ordner2/";
      Target         : constant String := "ordner3/";
      Content        : constant String := "Eine Datei zum Verschieben.";
      Input          : String(Content'Range);
      File_Exists    : Boolean := False;
      Dir_Exists     : Boolean := False;
   begin
      -- part 1: create folders and check creation, create file
      Ada.Directories.Create_Path(Current_Dir & Dir_Path & Test_Dir & Source);
      Ada.Directories.Create_Path(Current_Dir & Dir_Path & Test_Dir & Target);

      Dir_Exists := Ada.Directories.Exists(Current_Dir & Dir_Path & Test_Dir &
                                           Source);
      AUnit.Assertions.Assert(Condition => Dir_Exists,
                              Message => "The source directory was not created.");
      Dir_Exists := Ada.Directories.Exists(Current_Dir & Dir_Path & Test_Dir &
                                           Target);
      AUnit.Assertions.Assert(Condition => Dir_Exists,
                              Message => "The target directory was not created.");

      -- part 2: create file, write content
      Ada.Text_IO.Create(File, File_Mode_Out, Current_Dir & Dir_Path & Test_Dir
                         & Source & File_Name, "");
      Ada.Text_IO.Put(File, Content);
      Ada.Text_IO.Close(File);

      -- part 2: copy file, delete source
      Ada.Directories.Copy_File(Current_Dir & Dir_Path & Test_Dir & Source &
                                File_Name,
                                Current_Dir & Dir_Path & Test_Dir & Target &
                                File_Name, "");
      Ada.Directories.Delete_File(Current_Dir & Dir_Path & Test_Dir & Source &
                                  File_Name);
      
      -- part 3: check if source was deleted and if content is correct
      File_Exists := Ada.Directories.Exists(Current_Dir & Dir_Path & Test_Dir &
                                            Source & File_Name);
      AUnit.Assertions.Assert(Condition => not File_Exists,
                              Message => "The source file was not deleted.");
      Ada.Text_IO.Open(File, File_Mode_In, Current_Dir & Dir_Path & Test_Dir &
                       Target & File_Name, "");
      Ada.Text_IO.Get(File, Input);
      Ada.Text_IO.Close(File);

      AUnit.Assertions.Assert(Condition => (Content = Input),
                              Message => "The content of moved file is not equal.");
   end Move_A_File;


   ---------------------------------------
   -- T15: rename a file
   ---------------------------------------
   
   
   procedure Rename_A_File(CWTC: in out AUnit.Test_Cases.Test_Case'Class) is
      -- not in example, but compiler warning
      pragma Unreferenced(CWTC);
      File           : Ada.Text_IO.File_Type;
      File_Mode_Out  : constant Ada.Text_IO.File_Mode := Ada.Text_IO.Out_File;
      File_Mode_In   : constant Ada.Text_IO.File_Mode := Ada.Text_IO.In_File;
      File_Name_Old  : constant String := "datei7";
      File_Name_New  : constant String := "datei8";
      Current_Dir    : constant String := Ada.Directories.Current_Directory;
      Dir_Path       : constant String := "/to/";
      Test_Dir       : constant String := "test_dir/";
      Content        : constant String := "Eine Datei zum Umbenennen.";
      Input          : String(Content'Range);
   begin
      -- part 1: create file, write content
      Ada.Text_IO.Create(File, File_Mode_Out, Current_Dir & Dir_Path & Test_Dir
                         & File_Name_Old, "");
      Ada.Text_IO.Put(File, Content);
      Ada.Text_IO.Close(File);

      -- part 2: rename file
      Ada.Directories.Rename(Current_Dir & Dir_Path & Test_Dir & File_Name_Old,
                             Current_Dir & Dir_Path & Test_Dir & File_Name_New);
      
      -- part 3: read file and check content
      Ada.Text_IO.Open(File, File_Mode_In, Current_Dir & Dir_Path & Test_Dir &
                       File_Name_New, "");
      Ada.Text_IO.Get(File, Input);
      Ada.Text_IO.Close(File);

      AUnit.Assertions.Assert(Condition => (Content = Input),
                              Message => "The content of renamed file is not equal.");
   end Rename_A_File;


   ---------------------------------------
   -- T16: delete a not empty directory
   ---------------------------------------


   procedure Delete_A_Not_Empty_Directory
      (CWTC: in out AUnit.Test_Cases.Test_Case'Class)
   is
      -- not in example, but compiler warning
      pragma Unreferenced(CWTC);
      File              : Ada.Text_IO.File_Type;
      File_Mode_Out     : constant Ada.Text_IO.File_Mode := Ada.Text_IO.Out_File;
      File_Name         : constant String := "datei11";
      Current_Dir       : constant String := Ada.Directories.Current_Directory;
      Dir_Path          : constant String := "/to/";
      Test_Dir          : constant String := "test_dir/";
      Not_Empty_Dir     : constant String := "not_empty/";
      Content           : constant String := "Eine Datei für rmdir.";
      Exception_Raised  : Boolean := False;
   begin
      -- part 1: create folder
      Ada.Directories.Create_Path(Current_Dir & Dir_Path & Test_Dir &
                                  Not_Empty_Dir);
      
      -- part 2: create file, write content
      Ada.Text_IO.Create(File, File_Mode_Out, Current_Dir & Dir_Path & Test_Dir
                         & Not_Empty_Dir & File_Name, "");
      Ada.Text_IO.Put(File, Content);
      Ada.Text_IO.Close(File);

      -- part 3: try to delete directory
      Ada.Directories.Delete_Directory(Current_Dir & Dir_Path & Test_Dir &
                                       Not_Empty_Dir);

      -- part 4: catch exception
      exception
         when ADA.IO_EXCEPTIONS.USE_ERROR =>
            Exception_Raised := True;

      AUnit.Assertions.Assert(Condition => Exception_Raised,
                              Message => "Seemingly a non empty folder was"
                              & " deleted with Delete_Directory().");
   end Delete_A_Not_Empty_Directory;


   ---------------------------------------
   -- T17: copy folder with content
   ---------------------------------------
   -- test not implemented
   -- This test should be equal to cp -r folder1 folder2.
   -- It's not necessary to implement such a test, because it's only a
   -- loop of already tested parts open(), read(), write(), mkdir().


   ---------------------------------------
   -- T18: Read_Without_Permission
   ---------------------------------------
   -- To test read permission of a file, the file should be "locked" via:
   -- chmod 200 file
   -- There is no procedure changing permissions, in the needed way so this
   -- test depents on the chmod function from own package Command_Line_Calls.


   procedure Read_Without_Permission
      (CWTC: in out AUnit.Test_Cases.Test_Case'Class)
   is
      -- not in example, but compiler warning
      pragma Unreferenced(CWTC);
      File              : Ada.Text_IO.File_Type;
      File_Mode_Out     : constant Ada.Text_IO.File_Mode := Ada.Text_IO.Out_File;
      File_Mode_In      : constant Ada.Text_IO.File_Mode := Ada.Text_IO.In_File;
      File_Name         : constant String := "datei12";
      Current_Dir       : constant String := Ada.Directories.Current_Directory;
      Dir_Path          : constant String := "/to/";
      Test_Dir          : constant String := "test_dir/";
      Changed_Mode      : Boolean := False;
      Content           : constant String := "Eine Datei für rmdir.";
      Exception_Raised  : Boolean := False;
   begin
      -- part 1: create file, write content
      Ada.Text_IO.Create(File, File_Mode_Out, Current_Dir & Dir_Path & Test_Dir
                         & File_Name, "");
      Ada.Text_IO.Put(File, Content);
      Ada.Text_IO.Close(File);

      -- part 2: chmod 200 datei
      Changed_Mode := Command_Line_Calls.Chmod(Current_Dir & Dir_Path & Test_Dir
                                               & File_Name, "200");
      AUnit.Assertions.Assert(Condition => Changed_Mode,
                              Message => "Seemingly the permissions could not"
                              & " be changed.");

      -- part 3: try to read
      Ada.Text_IO.Open(File, File_Mode_In, Current_Dir & Dir_Path & Test_Dir &
                       File_Name,"");
      Ada.Text_IO.Close(File);

      -- part 4: catch exception
      exception
         when ADA.IO_EXCEPTIONS.USE_ERROR =>
            Exception_Raised := True;

      AUnit.Assertions.Assert(Condition => Exception_Raised,
                              Message => "Seemingly a non empty folder was"
                              & " deleted with Delete_Directory().");
   end Read_Without_Permission;


   ---------------------------------------
   -- T19: Write_Without_Permission
   ---------------------------------------
   -- Same as above, only with write permissions.


   procedure Write_Without_Permission
      (CWTC: in out AUnit.Test_Cases.Test_Case'Class)
   is
      -- not in example, but compiler warning
      pragma Unreferenced(CWTC);
      File              : Ada.Text_IO.File_Type;
      File_Mode_Out     : constant Ada.Text_IO.File_Mode := Ada.Text_IO.Out_File;
      File_Mode_In      : constant Ada.Text_IO.File_Mode := Ada.Text_IO.In_File;
      File_Name         : constant String := "datei12";
      Current_Dir       : constant String := Ada.Directories.Current_Directory;
      Dir_Path          : constant String := "/to/";
      Test_Dir          : constant String := "test_dir/";
      Changed_Mode      : Boolean := False;
      Content           : constant String := "Eine Datei für rmdir.";
      Exception_Raised  : Boolean := False;
   begin
      -- part 1: create file, write content
      Ada.Text_IO.Create(File, File_Mode_Out, Current_Dir & Dir_Path & Test_Dir
                         & File_Name, "");
      Ada.Text_IO.Put(File, Content);
      Ada.Text_IO.Close(File);

      -- part 2: chmod 200 datei
      Changed_Mode := Command_Line_Calls.Chmod(Current_Dir & Dir_Path & Test_Dir
                                               & File_Name, "400");
      AUnit.Assertions.Assert(Condition => Changed_Mode,
                              Message => "Seemingly the permissions could not"
                              & " be changed.");

      -- part 3: try to write again
      Ada.Text_IO.Open(File, File_Mode_In, Current_Dir & Dir_Path & Test_Dir &
                       File_Name,"");
      Ada.Text_IO.Put(File, Content);
      Ada.Text_IO.Close(File);

      -- part 4: catch exception
      exception
         when ADA.IO_EXCEPTIONS.USE_ERROR =>
            Exception_Raised := True;

      AUnit.Assertions.Assert(Condition => Exception_Raised,
                              Message => "Seemingly a non empty folder was"
                              & " deleted with Delete_Directory().");
   end Write_Without_Permission;


   ---------------------------------------
   -- T20: delete folder with content
   ---------------------------------------
   
   
   procedure Delete_Folder_Content(CWTC: in out AUnit.Test_Cases.Test_Case'Class) is
      -- not in example, but compiler warning
      pragma Unreferenced(CWTC);
      Current_Dir       : constant String := Ada.Directories.Current_Directory;
      Dir_Path          : constant String := "/to/";
      Test_Dir          : constant String := "test_dir";
      Dir_Found         : Boolean := False;
      Exception_Raised  : Boolean := False;
   begin
      -- part 1: delete folder
      Ada.Directories.Delete_Tree(Current_Dir & Dir_Path & Test_Dir);

      -- part 2: check
      exception
         when Ada.IO_Exceptions.Use_Error =>
            Exception_Raised := True;

      AUnit.Assertions.Assert(Condition => not Exception_Raised,
                              Message => "No permission for deleting.");
            
      Dir_Found := Ada.Directories.Exists(Current_Dir & Dir_Path & Test_Dir);
      AUnit.Assertions.Assert(Condition => not Dir_Found,
                              Message => "The directory was not (completly) deleted.");
   end Delete_Folder_Content;


   ----------------------------------------------------------------------------
   --                                                                        --
   -- registration and name of the testcases                                 --
   --                                                                        --
   ----------------------------------------------------------------------------
   
   
   procedure Register_Tests(T: in out TC) is
      -- AUnit.Test_Cases.Registration
      package AU_TC_R renames AUnit.Test_Cases.Registration;
   begin
   
      AU_TC_R.Register_Routine(  Test => T,
                                 Routine => Simple_Framework_Test'Access,
                                 Name => "Simple_Framework_Test");
   
      AU_TC_R.Register_Routine(  Test => T,
                                 Routine => Create_A_Folder'Access,
                                 Name => "Create_A_Folder");
   
      AU_TC_R.Register_Routine(  Test => T,
                                 Routine => Create_A_Folder2'Access,
                                 Name => "Create_A_Folder2");

      AU_TC_R.Register_Routine(  Test => T,
                                 Routine => Remove_A_Folder'Access,
                                 Name => "Delete_A_Folder");
   
      AU_TC_R.Register_Routine(  Test => T,
                                 Routine => Remove_A_Folder2'Access,
                                 Name => "Delete_A_Folder2");
   
      AU_TC_R.Register_Routine(  Test => T,
                                 Routine => Rename_A_Folder'Access,
                                 Name => "Rename_A_Folder");
   
      AU_TC_R.Register_Routine(  Test => T,
                                 Routine => Rename_A_Folder2'Access,
                                 Name => "Rename_A_Folder2");
   
      AU_TC_R.Register_Routine(  Test => T,
                                 Routine => Create_A_File'Access,
                                 Name => "Create_A_File");
   
      AU_TC_R.Register_Routine(  Test => T,
                                 Routine => Write_A_File'Access,
                                 Name => "Write_A_File");
   
      AU_TC_R.Register_Routine(  Test => T,
                                 Routine => Read_A_File'Access,
                                 Name => "Read_A_File");
   
      AU_TC_R.Register_Routine(  Test => T,
                                 Routine => Delete_A_File'Access,
                                 Name => "Delete_A_File");
   
      AU_TC_R.Register_Routine(  Test => T,
                                 Routine => Read_A_File2'Access,
                                 Name => "Read_A_File2");
   
      AU_TC_R.Register_Routine(  Test => T,
                                 Routine => Delete_A_File2'Access,
                                 Name => "Read_A_File2");
   
      AU_TC_R.Register_Routine(  Test => T,
                                 Routine => Move_A_File'Access,
                                 Name => "Move_A_File");
   
      AU_TC_R.Register_Routine(  Test => T,
                                 Routine => Rename_A_File'Access,
                                 Name => "Rename_A_File");

      AU_TC_R.Register_Routine(  Test => T,
                                 Routine => Delete_A_Not_Empty_Directory'Access,
                                 Name => "Delete_A_Not_Empty_Directory");

      AU_TC_R.Register_Routine(  Test => T,
                                 Routine => Read_Without_Permission'Access,
                                 Name => "Read_Without_Permission");

      AU_TC_R.Register_Routine(  Test => T,
                                 Routine => Write_Without_Permission'Access,
                                 Name => "Write_Without_Permission");

      AU_TC_R.Register_Routine(  Test => T,
                                 Routine => Delete_Folder_Content'Access,
                                 Name => "Delete_Folder_Content");
   
   end Register_Tests;
   
   
   function Name(T: TC) return AUnit.Message_String is
      pragma Unreferenced(T);
   begin
      return AUnit.Format("Test-case: Standard");
   end Name;
   
   
end Test_Setup;