aboutsummaryrefslogblamecommitdiffstats
path: root/lib/cosFileTransfer/test/fileTransfer_SUITE.erl
blob: eb7a0a67230937a2a5c2638cf899e4c5e6c60343 (plain) (tree)
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
965
966
967
968
969































                                                                         
                                                    






































                                                                                 
                                
                                           
                  

                           







                                    
                            









                                                                   

                                         














                                     
 



                                                  
                                 
 








                                                                   
                                  



                                     
                         




























                                                                                
                        



































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                                                      
%%-----------------------------------------------------------------------
%%
%% %CopyrightBegin%
%% 
%% Copyright Ericsson AB 2000-2010. All Rights Reserved.
%% 
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved online at http://www.erlang.org/.
%% 
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%% 
%% %CopyrightEnd%
%%
%%
%%----------------------------------------------------------------------
%% File    : fileTransfer_SUITE.erl
%% Purpose : 
%%----------------------------------------------------------------------

-module(fileTransfer_SUITE).



%%--------------- INCLUDES -----------------------------------
-include_lib("cosFileTransfer/src/cosFileTransferApp.hrl").

-include_lib("test_server/include/test_server.hrl").

%%--------------- DEFINES ------------------------------------
-define(default_timeout, ?t:minutes(20)).
-define(match(ExpectedRes, Expr),
        fun() ->
               AcTuAlReS = (catch (Expr)),
               case AcTuAlReS of
                   ExpectedRes ->
                       io:format("------ CORRECT RESULT ------~n~p~n",
                                 [AcTuAlReS]),
                       AcTuAlReS;
                   _ ->
                       io:format("###### ERROR ERROR ######~n~p~n",
                                 [AcTuAlReS]),
                       exit(AcTuAlReS)
               end
       end()).
 
-define(matchnopr(ExpectedRes, Expr),
        fun() ->
               AcTuAlReS = (catch (Expr)),
               case AcTuAlReS of
                   ExpectedRes ->
                       io:format("------ CORRECT RESULT (~p) ------~n", [?LINE]),
                       AcTuAlReS;
                   _ ->
                       io:format("###### ERROR ERROR ######~n~p~n",
                                 [AcTuAlReS]),
                       exit(AcTuAlReS)
               end
       end()).
 



 
%%-----------------------------------------------------------------
%% External exports
%%-----------------------------------------------------------------
-export([all/0,suite/0,groups/0,
	 init_per_group/2,end_per_group/2, 
	 cases/0, 
	 init_per_suite/1, 
	 end_per_suite/1, 
	 fileIterator_api/1,
	 fts_ftp_file_api/1, 
	 fts_ftp_file_ssl_api/1, 
	 fts_ftp_dir_api/1, 
	 fts_native_file_api/1, 
	 fts_native_file_ssl_api/1, 
	 fts_native_dir_api/1, 
	 init_per_testcase/2, 
	 end_per_testcase/2,
	 install_data/2,
	 uninstall_data/1,
	 slave_sup/0,
	 app_test/1]).

%%-----------------------------------------------------------------
%% Func: all/1
%% Args: 
%% Returns: 
%%-----------------------------------------------------------------
suite() ->
    [{suite_callbacks,[ts_install_scb]}].

all() -> 
    cases().

groups() -> 
    [].

    

init_per_group(_GroupName, Config) ->
	Config.

end_per_group(_GroupName, Config) ->
	Config.

 
cases() -> 
    [fts_ftp_dir_api, fts_ftp_file_api,
     fts_ftp_file_ssl_api, fts_native_dir_api,
     fts_native_file_api, fts_native_file_ssl_api,
     fileIterator_api, app_test].

%%-----------------------------------------------------------------
%% Init and cleanup functions.
%%-----------------------------------------------------------------

init_per_testcase(_Case, Config) ->
    ?line Dog=test_server:timetrap(?default_timeout),
    [{watchdog, Dog}|Config].


end_per_testcase(_Case, Config) ->
    Dog = ?config(watchdog, Config),
    test_server:timetrap_cancel(Dog),
    ok.

init_per_suite(Config) ->
    orber:jump_start(),
    cosProperty:install(),
    cosProperty:start(),
    Dir = filename:join([code:lib_dir(ssl), "examples", "certs", "etc"]),
    %% Client
    cosFileTransferApp:configure(ssl_client_certfile,
				 filename:join([Dir, "client", "cert.pem"])),
    cosFileTransferApp:configure(ssl_client_cacertfile,
				 filename:join([Dir, "client", "cacerts.pem"])),
    cosFileTransferApp:configure(ssl_client_verify, 1),
    cosFileTransferApp:configure(ssl_client_depth, 0),
    %% Server
    cosFileTransferApp:configure(ssl_server_certfile,
				 filename:join([Dir, "server", "cert.pem"])),
    cosFileTransferApp:configure(ssl_server_cacertfile,
				 filename:join([Dir, "server", "cacerts.pem"])),
    cosFileTransferApp:configure(ssl_server_verify, 1),
    cosFileTransferApp:configure(ssl_server_depth, 0),
    crypto:start(),
    ssl:start(),
    cosFileTransferApp:install(),
    cosFileTransferApp:start(),
    if
        is_list(Config) ->
	    Config;
        true ->
            exit("Config not a list")
    end.

end_per_suite(Config) ->
    ssl:stop(),
    crypto:stop(),
    cosFileTransferApp:stop(),
    cosProperty:stop(),
    cosProperty:uninstall(),
    cosFileTransferApp:uninstall(),
    orber:jump_stop(),
    Config.

%%-----------------------------------------------------------------
%%  Local definitions
%%-----------------------------------------------------------------
-define(FTP_USER, "anonymous").
-define(FTP_PASS, "fileTransfer_SUITE@localhost").
-define(TEST_DIR,["/", "incoming"]).


-define(FTP_PORT, 21).
-define(FTP_ACC,  "anonymous").
 
-define(BAD_HOST, "badhostname").
-define(BAD_USER, "baduser").
-define(BAD_DIR,  "baddirectory").

-define(TEST_FILE_DATA,   "If this file exists after a completed test an error occurred.").   
-define(TEST_FILE_DATA2,  "1234567890123").


%%-----------------------------------------------------------------
%%  aoo-file test
%%-----------------------------------------------------------------
app_test(doc) -> [];
app_test(suite) -> [];
app_test(_Config) ->
    ?line ok=?t:app_test(cosFileTransfer),
    ok.

%%-----------------------------------------------------------------
%%  FileIterator API tests 
%%-----------------------------------------------------------------
fileIterator_api(doc) -> ["CosFileTransfer FileIterator API tests.", ""];
fileIterator_api(suite) -> [];
fileIterator_api(Config) ->
    case ftp_host(Config) of
	{skipped, SkippedReason} ->
	    {skipped, SkippedReason};
	Host ->
	    
	    ?line {ok, Node} = create_node("fileIterator_api", 4008, normal),
	    ?line ?match(ok, remote_apply(Node, ?MODULE, install_data, 
					  [tcp, {{'NATIVE', 
						  'cosFileTransferNATIVE_file'}, Host, 
						 "fileIterator_api"}])),
	    
            %% Create a Virtual File System.
%%    ?line VFS = ?match({_,_,_,_,_,_},
%%		 cosFileTransferApp:create_VFS({'NATIVE', 
%%						'cosFileTransferNATIVE_file'}, 
%%					       [], Host, ?FTP_PORT)),
	    ?line VFS = ?matchnopr({'IOP_IOR',"IDL:omg.org/CosFileTransfer/VirtualFileSystem:1.0",_}, 
				   corba:string_to_object("corbaname::1.2@localhost:4008/NameService#fileIterator_api")),

            %% Start two File Transfer Sessions (Source and Target).
	    ?line {FS, Dir} = ?matchnopr({{_,_,_},{_,_,_}},
			'CosFileTransfer_VirtualFileSystem':login(VFS, 
								  ?FTP_USER, 
								  ?FTP_PASS, 
								  ?FTP_ACC)),

            %% Do some basic test on one of the Directories attributes.
	    ?line ?match([_H|_], 'CosFileTransfer_Directory':'_get_name'(Dir)),
	    ?line ?match([_H|_], 'CosFileTransfer_Directory':'_get_complete_file_name'(Dir)),
	    ?line ?match({'IOP_IOR',[],[]}, 'CosFileTransfer_Directory':'_get_parent'(Dir)),
	    ?line ?matchnopr(FS, 'CosFileTransfer_Directory':'_get_associated_session'(Dir)),
	    {ok,[],FileIter} = ?match({ok,[],_}, 'CosFileTransfer_Directory':list(Dir, 0)),
            %% Usually the working directory for the test is not empty so no need for
            %% creating files of our own?!
	    #any{value=Children} = ?match({any, _, _},
					  'CosPropertyService_PropertySet':
					  get_property_value(Dir, "num_children")),

	    if
		Children > 5 ->
		    ?line ?matchnopr({true, _}, 'CosFileTransfer_FileIterator':next_one(FileIter)),
		    ?line ?matchnopr({true, _}, 'CosFileTransfer_FileIterator':next_n(FileIter, 3)),
		    ?line ?matchnopr({true, _}, 'CosFileTransfer_FileIterator':next_n(FileIter, 
										      Children)),
		    ?line ?matchnopr({false, _}, 'CosFileTransfer_FileIterator':next_one(FileIter)),
		    ?line ?match({false, []}, 'CosFileTransfer_FileIterator':next_n(FileIter, 1)),
		    ok;
		true ->
	    ok
	    end,
	    ?line ?match(ok, 'CosFileTransfer_FileIterator':destroy(FileIter)),
	    ?line ?match(false, corba_object:non_existent(FS)),
	    ?line ?match(ok, 'CosFileTransfer_FileTransferSession':logout(FS)),
            %% To make sure Orber can remove it from mnesia.
	    timer:sleep(1000),
	    ?line ?match(true, corba_object:non_existent(FS)),
	    ?line ?match(ok, remote_apply(Node, ?MODULE, uninstall_data, ["fileIterator_api"])),
	    stop_orber_remote(Node, normal),
	    ok
    end.
    

%%-----------------------------------------------------------------
%%  FileTransferSession API tests 
%%-----------------------------------------------------------------
fts_ftp_file_api(doc) -> ["CosFileTransfer FTP FileTransferSession API tests.", ""];
fts_ftp_file_api(suite) -> [];
fts_ftp_file_api(Config) ->
    ?line {ok, Node} = create_node("ftp_file_api", 4004, normal),
    file_helper(Config, 'FTP', ?TEST_DIR, Node, 4004, "ftp_file_api", tcp).

fts_ftp_file_ssl_api(doc) -> ["CosFileTransfer FTP FileTransferSession API tests.", ""];
fts_ftp_file_ssl_api(suite) -> [];
fts_ftp_file_ssl_api(Config) ->
    case os:type() of
        vxworks ->
	    {skipped, "No SSL-support for VxWorks."};
        _ ->
	    ?line {ok, Node} = create_node("ftp_file_api_ssl", {4005, 1}, ssl),
	    file_helper(Config, 'FTP', ?TEST_DIR, Node, 4005, "ftp_file_api_ssl", ssl)
    end.

fts_native_file_api(doc) -> ["CosFileTransfer NATIVE FileTransferSession API tests.", ""];
fts_native_file_api(suite) -> [];
fts_native_file_api(Config) ->
    ?line {ok, Node} = create_node("native_file_api", 4006, normal),
    {ok, Pwd} = file:get_cwd(),
    file_helper(Config,{'NATIVE', 'cosFileTransferNATIVE_file'},filename:split(Pwd),
		Node, 4006, "native_file_api", tcp).
				 
fts_native_file_ssl_api(doc) -> ["CosFileTransfer NATIVE FileTransferSession API tests.", ""];
fts_native_file_ssl_api(suite) -> [];
fts_native_file_ssl_api(Config) ->
    case os:type() of
        vxworks ->
	    {skipped, "No SSL-support for VxWorks."};
        _ ->
	    ?line {ok, Node} = create_node("native_file_ssl_api", {4007, 1}, ssl),
	    {ok, Pwd} = file:get_cwd(),
	    file_helper(Config,{'NATIVE', 'cosFileTransferNATIVE_file'},filename:split(Pwd),
			Node, 4007, "native_file_ssl_api", ssl)
    end.   
				 


file_helper(Config, WhichType, TEST_DIR, Node, Port, Name, Type) ->
    case ftp_host(Config) of
	{skipped, SkippedReason} ->
	    {skipped, SkippedReason};
	Host ->
	    TEST_SOURCE  = TEST_DIR ++ [create_name(remove_me_source)],
	    TEST_SOURCE2 = TEST_DIR ++ [create_name(remove_me_source)],
	    TEST_TARGET  = TEST_DIR ++ [create_name(remove_me_target)],
	    
	    io:format("<<<<<< CosFileTransfer Testing Configuration >>>>>>~n",[]),
	    io:format("Source: ~p~nTarget: ~p~n", [TEST_SOURCE, TEST_TARGET]),
	    
	    ?line ?match(ok, remote_apply(Node, ?MODULE, install_data, 
					  [Type, {WhichType, Host, Name}])),

	    ?line VFST = ?match({'IOP_IOR',"IDL:omg.org/CosFileTransfer/VirtualFileSystem:1.0",_}, 
				corba:string_to_object("corbaname::1.2@localhost:"++integer_to_list(Port)++"/NameService#"++Name)),


            %% Create a Virtual File System.
	    ?line VFS = ?match({_,_,_,_,_,_},
			       cosFileTransferApp:create_VFS(WhichType, [], Host, ?FTP_PORT, 
							     [{protocol, Type}])),
            %% Start two File Transfer Sessions (Source and Target).
	    ?line {FST, _DirT} = ?match({{_,_,_},{_,_,_}},
					'CosFileTransfer_VirtualFileSystem':login(VFST, 
										  ?FTP_USER, 
										  ?FTP_PASS, 
										  ?FTP_ACC)),
	    ?line {FSS, DirS} = ?match({{_,_,_,_,_,_},{_,_,_,_,_,_}},
				       'CosFileTransfer_VirtualFileSystem':login(VFS, 
										 ?FTP_USER, 
										 ?FTP_PASS, 
										 ?FTP_ACC)),

            %% Do some basic test on one of the Directories attributes.
	    ?line ?match([_H|_], 'CosFileTransfer_Directory':'_get_name'(DirS)),
	    ?line ?match([_H|_], 'CosFileTransfer_Directory':'_get_complete_file_name'(DirS)),
	    ?line ?match({'IOP_IOR',[],[]}, 'CosFileTransfer_Directory':'_get_parent'(DirS)),
	    ?line ?match(FSS, 'CosFileTransfer_Directory':'_get_associated_session'(DirS)),

            %% Get a FileList before we create any new Files
	    ?line #'CosFileTransfer_FileWrapper'{the_file = Dir} = 
		?match({'CosFileTransfer_FileWrapper', _, ndirectory},
		       'CosFileTransfer_FileTransferSession':get_file(FSS, TEST_DIR)),
	    ?line {ok,FileList, Iter1} = ?match({ok,_,_}, 'CosFileTransfer_Directory':list(Dir, 10)),
	    ?line loop_files(FileList),

	    case Iter1 of
		{'IOP_IOR',[],[]} ->
		    ok;
		_->
		    ?line ?match(ok, 'CosFileTransfer_FileIterator':destroy(Iter1))
	    end,
	    
	    #any{value=Count1} = ?match({any, _, _}, 'CosPropertyService_PropertySet':
					get_property_value(Dir, "num_children")),
	    
            %% Now we want to transfer a file from source to target. First, we'll create
            %% a a file to work with.
	    ?line create_file_on_source_node(WhichType, Config, Host, 
					     filename:join(TEST_SOURCE), TEST_DIR, 
					     ?TEST_FILE_DATA),
	    ?line create_file_on_source_node(WhichType, Config, Host, 
					     filename:join(TEST_SOURCE2), TEST_DIR, 
					     ?TEST_FILE_DATA2),

	    ?line #'CosFileTransfer_FileWrapper'{the_file = FileS} = 
		?matchnopr({'CosFileTransfer_FileWrapper', _, nfile},
			   'CosFileTransfer_FileTransferSession':get_file(FSS, TEST_SOURCE)),
	    ?line #'CosFileTransfer_FileWrapper'{the_file = FileS2} = 
		?matchnopr({'CosFileTransfer_FileWrapper', _, nfile},
			   'CosFileTransfer_FileTransferSession':get_file(FSS, TEST_SOURCE2)),
	    
	    #any{value=Count2} = ?match({any, _, _}, 'CosPropertyService_PropertySet':
					get_property_value(Dir, "num_children")),
	    timer:sleep(2000),
	    ?match(true, (Count1+2 == Count2)),

            %% Create a target File
	    ?line FileT = ?matchnopr({_,_,_}, 
				     'CosFileTransfer_FileTransferSession':create_file(FST, TEST_TARGET)),
            %% Try to delete the non-existing file.
	    ?line ?match({'EXCEPTION', _}, 
			 'CosFileTransfer_FileTransferSession':delete(FST, FileT)),

	    ?line ?match(ok, 'CosFileTransfer_FileTransferSession':transfer(FSS, FileS, FileT)),
    
            %% Remove this test when ftp supports append.
	    case WhichType of
		{'NATIVE', 'cosFileTransferNATIVE_file'} ->
		    ?line ?match(ok, 'CosFileTransfer_FileTransferSession':append(FSS, FileS, FileT)),
		    ?line ?match(ok, 'CosFileTransfer_FileTransferSession':insert(FSS, FileS2, FileT, 7));
		_->
		    ok
	    end,
	    
            %% Delete source and target files
	    ?line ?match(ok, 'CosFileTransfer_FileTransferSession':delete(FSS, FileS)),
	    ?line ?match(ok, 'CosFileTransfer_FileTransferSession':delete(FSS, FileS2)),
	    ?line ?match(ok, 'CosFileTransfer_FileTransferSession':delete(FST, FileT)),

            %% Should be back where we started.
	    timer:sleep(2000),
	    #any{value=Count3} = ?match({any, _, _}, 'CosPropertyService_PropertySet':
					get_property_value(Dir, "num_children")),
	    ?match(true, (Count1 == Count3)),


	    ?line ?match(false, corba_object:non_existent(FSS)),
	    ?line ?match(false, corba_object:non_existent(FST)),
	    ?line ?match(ok, 'CosFileTransfer_FileTransferSession':logout(FSS)),
	    ?line ?match(ok, 'CosFileTransfer_FileTransferSession':logout(FST)),
            %% To make sure Orber can remove it from mnesia.
	    timer:sleep(2000),
	    ?line ?match(true, corba_object:non_existent(FSS)),
	    ?line ?match(true, corba_object:non_existent(FST)),
	    ?line ?match(ok, remote_apply(Node, ?MODULE, uninstall_data, [Name])),
	    stop_orber_remote(Node, normal),
	    ok
    end.

%%-----------------------------------------------------------------
%%  FileTransferSession API tests 
%%-----------------------------------------------------------------
fts_ftp_dir_api(doc) -> ["CosFileTransfer FTP FileTransferSession API tests.", ""];
fts_ftp_dir_api(suite) -> [];
fts_ftp_dir_api(Config) ->
    ?line {ok, Node} = create_node("ftp_dir_api", 4009, normal),
    dir_helper(Config, 'FTP', ?TEST_DIR, Node, 4009, "ftp_dir_api").


fts_native_dir_api(doc) -> ["CosFileTransfer NATIVE FileTransferSession API tests.", ""];
fts_native_dir_api(suite) -> [];
fts_native_dir_api(Config) ->
    ?line {ok, Node} = create_node("native_dir_api", 4010, normal),
    {ok, Pwd} = file:get_cwd(),
    dir_helper(Config, {'NATIVE', 'cosFileTransferNATIVE_file'}, 
	       filename:split(Pwd), Node, 4010, "native_dir_api").

dir_helper(Config, WhichType, TEST_DIR, Node, Port, Name) ->
    case ftp_host(Config) of
	{skipped, SkippedReason} ->
	    {skipped, SkippedReason};
	Host ->
	    TEST_DIR_LEVEL1 = TEST_DIR ++ [create_name(remove_me_dir1)],
	    TEST_DIR_LEVEL2 = TEST_DIR_LEVEL1 ++ [create_name(remove_me_dir2)],
	    
	    io:format("<<<<<< CosFileTransfer Testing Configuration >>>>>>~n",[]),
	    io:format("Top Dir: ~p~nLevel2 Dir: ~p~n", [TEST_DIR_LEVEL1, TEST_DIR_LEVEL2]),
	    
	    ?line ?match(ok, remote_apply(Node, ?MODULE, install_data, 
					  [tcp, {WhichType, Host, Name}])),
	    
	    ?line VFS = ?matchnopr({'IOP_IOR',"IDL:omg.org/CosFileTransfer/VirtualFileSystem:1.0",_}, 
				   corba:string_to_object("corbaname::1.2@localhost:"++integer_to_list(Port)++"/NameService#"++Name)),
	    
            %% Start two File Transfer Sessions (Source and Target).
	    ?line {FS, DirS} = ?matchnopr({{'IOP_IOR',_,_}, _},
					  'CosFileTransfer_VirtualFileSystem':login(VFS, 
										    ?FTP_USER, 
										    ?FTP_PASS, 
										    ?FTP_ACC)),

            %% Do some basic test on one of the Directories attributes.
	    ?line ?match([_H|_], 'CosFileTransfer_Directory':'_get_name'(DirS)),
	    ?line ?match([_H|_], 'CosFileTransfer_Directory':'_get_complete_file_name'(DirS)),
	    ?line ?match({'IOP_IOR',[],[]}, 'CosFileTransfer_Directory':'_get_parent'(DirS)),
	    ?line ?matchnopr(FS, 'CosFileTransfer_Directory':'_get_associated_session'(DirS)),

            %% Create a Root Directory. Currently we only need to create one but
            %% later on, when supporting other protocols than FTP it's not enough.
	    ?line Dir1 =  'CosFileTransfer_FileTransferSession':create_directory(FS, 
										 TEST_DIR_LEVEL1),
	    io:format("<<<<<< CosFileTransfer Testing Properties >>>>>>~n",[]),
	    ?line ?match({ok, [tk_long, tk_boolean]}, 
			 'CosFileTransfer_Directory':get_allowed_property_types(Dir1)),
	    ?line ?match({ok, [_,_]}, 
			 'CosFileTransfer_Directory':get_allowed_properties(Dir1)),
	    ?line ?match({'EXCEPTION', _}, 
			 'CosFileTransfer_Directory':define_property_with_mode(Dir1, 
									       "num_children",
									       #any{typecode=tk_long, value=0},
									       fixed_readonly)),
	    ?line ?match({'EXCEPTION', _}, 
			 'CosFileTransfer_Directory':define_property_with_mode(Dir1, 
									       "wrong",
									       #any{typecode=tk_long, value=0},
									       fixed_readonly)),
	    ?line ?match({'EXCEPTION', _}, 
			 'CosFileTransfer_Directory':define_property_with_mode(Dir1, 
									       "num_children",
									       #any{typecode=tk_short, value=0},
									       fixed_readonly)),
	    ?line ?match({'EXCEPTION', _}, 
			 'CosFileTransfer_Directory':define_property_with_mode(Dir1, 
									       "num_children",
									       #any{typecode=tk_long, value=0},
									       fixed_normal)),
	    ?line ?match({'EXCEPTION', _}, 
			 'CosFileTransfer_Directory':define_properties_with_modes(Dir1, 
										  [#'CosPropertyService_PropertyDef'
										   {property_name  = "num_children", 
										    property_value = #any{typecode=tk_long, value=0}, 
										    property_mode  = fixed_readonly}])),
	    ?line ?match(fixed_readonly, 
			 'CosFileTransfer_Directory':get_property_mode(Dir1, "num_children")),
	    ?line ?match({true,
			  [#'CosPropertyService_PropertyMode'{property_name = "num_children", 
							      property_mode = fixed_readonly}]}, 
			 'CosFileTransfer_Directory':get_property_modes(Dir1, ["num_children"])),
	    ?line ?match({'EXCEPTION', _}, 
			 'CosFileTransfer_Directory':set_property_mode(Dir1, "num_children", fixed_readonly)),
	    
	    ?line ?match({'EXCEPTION', _}, 
			 'CosFileTransfer_Directory':
			 set_property_modes(Dir1, 
					    [#'CosPropertyService_PropertyMode'
					     {property_name = "num_children", 
					      property_mode = fixed_readonly}])),
	    ?line ?match({'EXCEPTION', _}, 
			 'CosFileTransfer_Directory':
			 set_property_modes(Dir1, 
					    [#'CosPropertyService_PropertyMode'
					     {property_name = "wrong", 
					      property_mode = fixed_readonly}])),
	    ?line ?match({'EXCEPTION', _}, 
			 'CosFileTransfer_Directory':
			 set_property_modes(Dir1, 
					    [#'CosPropertyService_PropertyMode'
					     {property_name = "num_children", 
					      property_mode = fixed_normal}])),
	    ?line ?match({'EXCEPTION', _},
			 'CosFileTransfer_Directory':define_property(Dir1, 
								     "num_children",
								     #any{typecode=tk_long, value=0})),
	    ?line ?match({'EXCEPTION', _},
			 'CosFileTransfer_Directory':define_property(Dir1, 
								     "wrong",
								     #any{typecode=tk_long, value=0})),
	    ?line ?match({'EXCEPTION', _},
			 'CosFileTransfer_Directory':define_property(Dir1, 
								     "num_children",
								     #any{typecode=tk_short, value=0})),
	    
	    ?line ?match({'EXCEPTION', _},
			 'CosFileTransfer_Directory':define_property(Dir1, 
								     "num_children",
								     #any{typecode=tk_long, value=0})),

	    ?line ?match({'EXCEPTION', _},
			 'CosFileTransfer_Directory':
			 define_properties(Dir1, 
					   [#'CosPropertyService_Property'
					    {property_name = "num_children", 
					     property_value = #any{typecode=tk_long, 
								   value=0}}])),
	    ?line ?match({'EXCEPTION', _},
			 'CosFileTransfer_Directory':
			 define_properties(Dir1, 
					   [#'CosPropertyService_Property'
					    {property_name = "wrong", 
					     property_value = #any{typecode=tk_long, 
								   value=0}}])),
	    ?line ?match({'EXCEPTION', _},
			 'CosFileTransfer_Directory':
			 define_properties(Dir1, 
					   [#'CosPropertyService_Property'
					    {property_name = "num_children", 
					     property_value = #any{typecode=tk_short, 
								   value=0}}])),
	    ?line ?match(2, 'CosFileTransfer_Directory':get_number_of_properties(Dir1)),

	    ?line ?match({ok, ["num_children", "is_directory"], {'IOP_IOR',[],[]}}, 
			 'CosFileTransfer_Directory':get_all_property_names(Dir1, 2)),
	    ?line ?match({ok, ["is_directory"], _}, 
			 'CosFileTransfer_Directory':get_all_property_names(Dir1, 1)),
	    
	    ?line ?match(#any{}, 
			 'CosFileTransfer_Directory':get_property_value(Dir1, "num_children")),
	    ?line ?match(#any{}, 
			 'CosFileTransfer_Directory':get_property_value(Dir1, "is_directory")),
	    ?line ?match({'EXCEPTION', _}, 
			 'CosFileTransfer_Directory':get_property_value(Dir1, "wrong")),
	    
	    ?line ?match({true, 
			  [#'CosPropertyService_Property'{property_name = "num_children"}]}, 
			 'CosFileTransfer_Directory':get_properties(Dir1, ["num_children"])),
	    ?line ?match({false, 
			  [#'CosPropertyService_Property'{property_name = "wrong"}]},
			 'CosFileTransfer_Directory':get_properties(Dir1, ["wrong"])),
	    
	    ?line ?match({ok, [_],_}, 
			 'CosFileTransfer_Directory':get_all_properties(Dir1, 1)),
	    ?line ?match({ok, [_,_], {'IOP_IOR',[],[]}}, 
			 'CosFileTransfer_Directory':get_all_properties(Dir1, 2)),
	    
	    ?line ?match({'EXCEPTION', _}, 
			 'CosFileTransfer_Directory':delete_property(Dir1, "num_children")),
	    ?line ?match({'EXCEPTION', _}, 
			 'CosFileTransfer_Directory':delete_property(Dir1, "wrong")),
	    
	    
	    ?line ?match({'EXCEPTION', _}, 
			 'CosFileTransfer_Directory':delete_properties(Dir1, ["num_children"])),
	    ?line ?match({'EXCEPTION', _}, 
			 'CosFileTransfer_Directory':delete_properties(Dir1, ["wrong"])),
	    ?line ?match(false, 'CosFileTransfer_Directory':delete_all_properties(Dir1)),
	    ?line ?match(true, 
			 'CosFileTransfer_Directory':is_property_defined(Dir1, "num_children")),
	    ?line ?match(false, 
			 'CosFileTransfer_Directory':is_property_defined(Dir1, "wrong")),

            %% The Top Dir should be empty and ...
	    ?line ?match({ok,[],_}, 'CosFileTransfer_Directory':list(Dir1, 1000)),
	    ?line ?match( #any{value=0},
			  'CosPropertyService_PropertySet':get_property_value(Dir1, "num_children")),
            %% Create a sub-directory.
	    ?line Dir2 = 'CosFileTransfer_FileTransferSession':create_directory(FS, 
										TEST_DIR_LEVEL2),
	    ?line ?match( #any{value=1},
			  'CosPropertyService_PropertySet':get_property_value(Dir1, "num_children")),
	    
	    ?line ?match({ok, [_,_], {'IOP_IOR',[],[]}}, 
			 'CosFileTransfer_Directory':get_all_properties(Dir1, 2)),
	    ?line {_,_,Iterator1} = ?match({ok, [_], _}, 
					   'CosFileTransfer_Directory':get_all_properties(Dir1, 1)),
	    ?line ?match({false, [_]}, 
			 'CosPropertyService_PropertiesIterator':next_n(Iterator1,4)),
	    
	    ?line {_,_,Iterator0} = ?match({ok, [], _}, 
					   'CosFileTransfer_Directory':get_all_properties(Dir1, 0)),
	    
	    ?line ?match({false, [_, {'CosPropertyService_Property',
				      "num_children",{any,tk_long,1}}]},
			 'CosPropertyService_PropertiesIterator':next_n(Iterator0,4)),
	    
	    ?line ?match({true, 
			  [#'CosPropertyService_Property'{property_name = "num_children"}]}, 
			 'CosFileTransfer_Directory':get_properties(Dir1, ["num_children"])),
	    
            %% The Top Directory is not emtpy any more and ...
	    ?line {ok,[#'CosFileTransfer_FileWrapper'{the_file = DirRef}],_} = 
		?matchnopr({ok,[{'CosFileTransfer_FileWrapper', _, ndirectory}],_}, 
			   'CosFileTransfer_Directory':list(Dir1, 1000)),
            %% ... its name eq. to 'TEST_DIR_LEVEL2'
	    ?line ?match(TEST_DIR_LEVEL2, 
			 'CosFileTransfer_Directory':'_get_complete_file_name'(DirRef)),
	    
	    ?line #'CosFileTransfer_FileWrapper'{the_file = Dir3} = 
		?matchnopr({'CosFileTransfer_FileWrapper', _, ndirectory},
			   'CosFileTransfer_FileTransferSession':get_file(FS, TEST_DIR_LEVEL1)),
	    
            %% Must get the same result for the 'get_file' operation.
	    ?line {ok,[#'CosFileTransfer_FileWrapper'{the_file = DirRef2}],_} = 
		?matchnopr({ok,[{'CosFileTransfer_FileWrapper', _, ndirectory}],_}, 
			   'CosFileTransfer_Directory':list(Dir3,1000)),
	    ?line ?match(TEST_DIR_LEVEL2, 
			 'CosFileTransfer_Directory':'_get_complete_file_name'(DirRef2)),
	    
            %% Since the top directory isn't empty deleting it must fail.
	    ?line ?match({'EXCEPTION', _}, 
			 'CosFileTransfer_FileTransferSession':delete(FS, Dir1)),
	    
            %% Delete the sub-directory and ...
	    ?line ?match(ok, 'CosFileTransfer_FileTransferSession':delete(FS, Dir2)),
            %% ... see if the top directory realyy is empty.
	    ?line ?match({ok,[],_}, 'CosFileTransfer_Directory':list(Dir1, 1000)),

	    ?line ?match(ok, 'CosFileTransfer_FileTransferSession':delete(FS, Dir1)),
            %% Test if the top directory been removed as intended.
	    ?line ?match({'EXCEPTION', {'CosFileTransfer_FileNotFoundException', _, _}},
			 'CosFileTransfer_FileTransferSession':get_file(FS, TEST_DIR_LEVEL1)),

	    ?line ?match(false, corba_object:non_existent(FS)),
	    ?line ?match(ok, 'CosFileTransfer_FileTransferSession':logout(FS)),
            %% To make sure Orber can remove it from mnesia.
	    timer:sleep(1000),
	    ?line ?match(true, corba_object:non_existent(FS)),
	    ?line ?match(ok, remote_apply(Node, ?MODULE, uninstall_data, [Name])),
	    stop_orber_remote(Node, normal),
	    ok
    end.


%%-----------------------------------------------------------------
%%  Internal functions
%%-----------------------------------------------------------------
ftp_host(Config) ->
    case ?config(ftp_remote_host, Config) of
	undefined ->
	    {skipped, "The configuration parameter 'ftp_remote_host' not defined."};
	Host ->
	    Host
    end.

loop_files([]) ->
    io:format("@@@ DONE @@@~n", []);
loop_files([#'CosFileTransfer_FileWrapper'{the_file = H}|T]) ->
    FullName = 'CosFileTransfer_File':'_get_complete_file_name'(H),
    Name = 'CosFileTransfer_File':'_get_name'(H),
    io:format("FULL NAME: ~p   SHORT NAME: ~p~n", [FullName, Name]),
    loop_files(T).


create_file_on_source_node('FTP', _Config, Host, FileName, Path, Data) ->
    io:format("<<<<<< CosFileTransfer Testing File >>>>>>~n",[]),
    io:format("Host: ~p~nPath: ~p~nFile: ~p~n", [Host, Path, FileName]),
    {ok, Pid} = ?match({ok, _}, inets:start(ftpc, [{host, Host}], stand_alone)),
    ?match(ok, ftp:user(Pid, ?FTP_USER, ?FTP_PASS)),
    ?match(ok, ftp:cd(Pid, Path)),
    ?match(ok, ftp:send_bin(Pid, list_to_binary(Data), FileName)),
    ?match(ok, inets:stop(ftpc, Pid));
create_file_on_source_node({'NATIVE', _}, _Config, Host, FileName, Path, Data) ->
    io:format("<<<<<< CosFileTransfer Testing File >>>>>>~n",[]),
    io:format("Host: ~p~nPath: ~p~nFile: ~p~n", [Host, Path, FileName]),
    ?match(ok, file:write_file(FileName, list_to_binary(Data))).
    
create_name(Type) ->
    {MSec, Sec, USec} = erlang:now(),
    lists:concat([Type,'_',MSec, '_', Sec, '_', USec]).




%%------------------------------------------------------------
%% function : create_node/4
%% Arguments: Name - the name of the new node (atom())
%%            Port - which iiop_port (integer())
%%            Domain - which domain.
%%            Type - if /4 used the types defines the extra arguments
%%                   to be used.
%% Returns  : {ok, Node} | {error, _}
%% Effect   : Starts a new slave-node with given (optinally)
%%            extra arguments. If fails it retries 'Retries' times.
%%------------------------------------------------------------
create_node(Name, Port, normal) ->
    Args = basic_args(Name),
    create_node(Name, Port, 10, normal, Args, []);
create_node(Name, {Port, _Depth}, ssl) ->
    Dir = filename:join([code:lib_dir(ssl), "examples", "certs", "etc"]),
    Args = basic_args(Name),
    {ok, Node} = create_node(list_to_atom(Name), Port, 10, ssl, Args, []),
    %% Client
    rpc:call(Node, application, set_env, [cosFileTransfer, ssl_client_certfile,
					  filename:join([Dir, "client", "cert.pem"])]),
    rpc:call(Node, application, set_env, [cosFileTransfer, ssl_client_cacertfile,
					  filename:join([Dir, "client", "cacerts.pem"])]),
    rpc:call(Node, application, set_env, [cosFileTransfer, ssl_client_keyfile,
					  filename:join([Dir, "client", "key.pem"])]),
    rpc:call(Node, application, set_env, [cosFileTransfer, ssl_client_verify, 1]),
    rpc:call(Node, application, set_env, [cosFileTransfer, ssl_client_depth, 0]),
    
    %% Server
    rpc:call(Node, application, set_env, [cosFileTransfer, ssl_server_certfile,
					  filename:join([Dir, "server", "cert.pem"])]),
    rpc:call(Node, application, set_env, [cosFileTransfer, ssl_server_cacertfile,
					  filename:join([Dir, "server", "cacerts.pem"])]),
    rpc:call(Node, application, set_env, [cosFileTransfer, ssl_server_keyfile,
					  filename:join([Dir, "server", "key.pem"])]),
    rpc:call(Node, application, set_env, [cosFileTransfer, ssl_server_verify, 1]),
    rpc:call(Node, application, set_env, [cosFileTransfer, ssl_server_depth, 0]),
    {ok, Node}.

%create_node(Name, {Port, Depth}, ssl) ->
%    TestLibs = filename:join(filename:dirname(code:which(?MODULE)), "ssl_data"),
%    Args = basic_args(Name),
%    SArgs = basic_ssl_args(TestLibs, Args),
%    LArgs = level_based_ssl(Depth, TestLibs, SArgs),
%    create_node(list_to_atom(Name), Port, 10, ssl, LArgs, [{sslpath, TestLibs}]).

create_node(Name, Port, Retries, Type, Args, Options) ->
    [_, Host] = ?match([_,_],string:tokens(atom_to_list(node()), [$@])),
    case starter(Host, Name, Args) of
	{ok, NewNode} ->
            ?line ?match(pong, net_adm:ping(NewNode)),
            {ok, Cwd} = file:get_cwd(),
            Path = code:get_path(),
            ?line ?match(ok, rpc:call(NewNode, file, set_cwd, [Cwd])),
            true = rpc:call(NewNode, code, set_path, [Path]),
	    ?match(ok, start_orber_remote(NewNode, Type, Options, Port)),
            spawn_link(NewNode, ?MODULE, slave_sup, []),
            rpc:multicall([node() | nodes()], global, sync, []),
            {ok, NewNode};
        {error, Reason} when Retries == 0->
            {error, Reason};
        {error, Reason} ->          
            io:format("Could not start slavenode ~p ~p retrying~n", 
                      [{Host, Name, Args}, Reason]),
            timer:sleep(500),
            create_node(Name, Port, Retries - 1, Type, Args, Options)
    end.

starter(Host, Name, Args) ->
    case os:type() of
        vxworks ->
            test_server:start_node(Name, slave, [{args,Args}]);
        _ ->
            slave:start(Host, Name, Args)
    end.

slave_sup() ->
    process_flag(trap_exit, true),
    receive
        {'EXIT', _, _} -> 
            case os:type() of
                vxworks ->
                    erlang:halt();
                _  ->
                    ignore
            end
    end.


%%------------------------------------------------------------
%% function : destroy_node
%% Arguments: Node - which node to destroy.
%%            Type - normal | ssl
%% Returns  : 
%% Effect   : 
%%------------------------------------------------------------
-ifdef(false).
destroy_node(Node, Type) ->
    stopper(Node, Type).

stopper(Node, Type) ->
    catch stop_orber_remote(Node, Type),
    case os:type() of
        vxworks ->
            test_server:stop_node(Node);
        _ ->
            slave:stop(Node)
    end.
-endif.
  
%%------------------------------------------------------------
%% function : remote_apply
%% Arguments: N - Node, M - Module,
%%            F - Function, A - Arguments (list)
%% Returns  : 
%% Effect   : 
%%------------------------------------------------------------
remote_apply(N, M,F,A) ->
    case rpc:call(N, M, F, A) of
	{badrpc, Reason} ->
	    exit(Reason);
	Other ->
	    Other
    end.

%%------------------------------------------------------------
%% function : stop_orber_remote
%% Arguments: Node - which node to stop orber on.
%%            Type - normal | ssl | light | .......
%% Returns  : ok
%% Effect   : Stops orber on given node and, if specified,
%%            other applications or programs.
%%------------------------------------------------------------
stop_orber_remote(Node, ssl) ->
    rpc:call(Node, ssl, stop, []),
    rpc:call(Node, crypto, stop, []),
    orb_rpc_blast(Node, ssl);
stop_orber_remote(Node, Type) ->
    orb_rpc_blast(Node, Type).

orb_rpc_blast(Node, _) ->
    rpc:call(Node, cosFileTransferApp, stop, []),
    rpc:call(Node, cosProperty, stop, []),
    rpc:call(Node, cosFileTransferApp, uninstall, []),
    rpc:call(Node, cosProperty, uninstall, []),
    rpc:call(Node, orber, jump_stop, []).

%%------------------------------------------------------------
%% function : start_orber_remote
%% Arguments: Node - which node to start orber on.
%%            Type - normal | ssl | light | .......
%% Returns  : ok
%% Effect   : Starts orber on given node and, if specified,
%%            other applications or programs.
%%------------------------------------------------------------
start_orber_remote(Node, ssl, _Options, Port) ->
    rpc:call(Node, ssl, start, []),
    rpc:call(Node, crypto, start, []),
    rpc:call(Node, ssl, seed, ["testing"]),
    orb_rpc_setup(Node, ssl, Port);
start_orber_remote(Node, Type, _, Port) ->
    orb_rpc_setup(Node, Type, Port).

orb_rpc_setup(Node, _, Port) ->
    rpc:call(Node, orber, jump_start, [Port]),
    rpc:call(Node, cosProperty, install, []),
    rpc:call(Node, cosProperty, start, []),
    rpc:call(Node, cosFileTransferApp, install, []).

%%--------------- MISC FUNCTIONS -----------------------------
basic_args(_Name) ->
    TestLibs = filename:dirname(code:which(?MODULE)),
    " -orber orber_debug_level 10" ++
	" -pa " ++
        TestLibs ++ 
	" -pa " ++
        filename:join(TestLibs, "all_SUITE_data") ++ 
        " -pa " ++ 
        filename:dirname(code:which(cosFileTransferApp)).

-ifdef(false).
basic_ssl_args(TestLibs, Args) ->
%    Args ++
%	" -cosFileTransfer ssl_client_certfile \\\"" ++
%	filename:join(TestLibs, "ssl_client_cert.pem") ++
%	"\\\" -cosFileTransfer ssl_server_certfile \\\""++
%	filename:join(TestLibs, "ssl_server_cert.pem")++"\\\"".

    io:format("<<<<<< SSL LIBS ~p >>>>>>~n",[TestLibs]),
    NewArgs = Args ++
	" -cosFileTransfer ssl_client_certfile \\\"" ++
	filename:join(TestLibs, "ssl_client_cert.pem") ++
	"\\\" -cosFileTransfer ssl_server_certfile \\\""++
	filename:join(TestLibs, "ssl_server_cert.pem")++"\\\"",
    io:format("<<<<<< SSL LIBS ARGS ~p >>>>>>~n",[NewArgs]),
    NewArgs.

level_based_ssl(1, _TestLibs, Args) ->
    Args;
level_based_ssl(2, _TestLibs, Args) ->
    Args.% ++
%	" -cosFileTransfer ssl_server_depth 2 " ++
%	" -cosFileTransfer ssl_client_depth 2 " ++
%	" -cosFileTransfer ssl_server_verify " ++
%	" -cosFileTransfer ssl_client_verify " ++
%	" -cosFileTransfer ssl_server_cacertfile " ++
%	" -cosFileTransfer ssl_client_cacertfile " ++

-endif.

install_data(Protocol, {WhichType, Host, Name}) ->
    io:format("<<<<<< Starting ~p/~p VFS at ~p/~p>>>>>>~n",
	      [Protocol, WhichType, Host, Name]),
    %% Create a Virtual File System.
    ?line VFS = ?match({_,_,_,_,_,_},
		       cosFileTransferApp:create_VFS(WhichType, [], Host, ?FTP_PORT, 
						     [{protocol, Protocol}])),
    NS = corba:resolve_initial_references("NameService"),
    NC1 = lname_component:set_id(lname_component:create(), Name),
    N = lname:insert_component(lname:create(), 1, NC1),
    'CosNaming_NamingContext':rebind(NS, N, VFS).

uninstall_data(Name) ->
    ?line VFS = ?match({_,_,_,_,_,_}, 
		       corba:string_to_object("corbaname:rir:/NameService#"++Name)),
    ?line ?match(ok, corba:dispose(VFS)),
    ok.
    


%%------------------- EOF MODULE-----------------------------------