1: %%----------------------------------------------------------------------- 2: %% 3: %% %CopyrightBegin% 4: %% 5: %% Copyright Ericsson AB 2000-2013. All Rights Reserved. 6: %% 7: %% The contents of this file are subject to the Erlang Public License, 8: %% Version 1.1, (the "License"); you may not use this file except in 9: %% compliance with the License. You should have received a copy of the 10: %% Erlang Public License along with this software. If not, it can be 11: %% retrieved online at http://www.erlang.org/. 12: %% 13: %% Software distributed under the License is distributed on an "AS IS" 14: %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 15: %% the License for the specific language governing rights and limitations 16: %% under the License. 17: %% 18: %% %CopyrightEnd% 19: %% 20: %% 21: %%---------------------------------------------------------------------- 22: %% File : fileTransfer_SUITE.erl 23: %% Purpose : 24: %%---------------------------------------------------------------------- 25: 26: -module(fileTransfer_SUITE). 27: 28: %%--------------- INCLUDES ----------------------------------- 29: -include_lib("cosFileTransfer/src/cosFileTransferApp.hrl"). 30: 31: -include_lib("test_server/include/test_server.hrl"). 32: 33: %%--------------- DEFINES ------------------------------------ 34: -define(default_timeout, ?t:minutes(20)). 35: -define(match(ExpectedRes, Expr), 36: fun() -> 37: AcTuAlReS = (catch (Expr)), 38: case AcTuAlReS of 39: ExpectedRes -> 40: io:format("------ CORRECT RESULT ------~n~p~n", 41: [AcTuAlReS]), 42: AcTuAlReS; 43: _ -> 44: io:format("###### ERROR ERROR ######~n~p~n", 45: [AcTuAlReS]), 46: exit(AcTuAlReS) 47: end 48: end()). 49: 50: -define(matchnopr(ExpectedRes, Expr), 51: fun() -> 52: AcTuAlReS = (catch (Expr)), 53: case AcTuAlReS of 54: ExpectedRes -> 55: io:format("------ CORRECT RESULT (~p) ------~n", [?LINE]), 56: AcTuAlReS; 57: _ -> 58: io:format("###### ERROR ERROR ######~n~p~n", 59: [AcTuAlReS]), 60: exit(AcTuAlReS) 61: end 62: end()). 63: 64: 65: 66: 67: 68: %%----------------------------------------------------------------- 69: %% External exports 70: %%----------------------------------------------------------------- 71: -export([all/0,suite/0,groups/0, 72: init_per_group/2,end_per_group/2, 73: cases/0, 74: init_per_suite/1, 75: end_per_suite/1, 76: fileIterator_api/1, 77: fts_ftp_file_api/1, 78: fts_ftp_file_ssl_api/1, 79: fts_ftp_dir_api/1, 80: fts_native_file_api/1, 81: fts_native_file_ssl_api/1, 82: fts_native_dir_api/1, 83: init_per_testcase/2, 84: end_per_testcase/2, 85: install_data/2, 86: uninstall_data/1, 87: slave_sup/0, 88: app_test/1]). 89: 90: %%----------------------------------------------------------------- 91: %% Func: all/1 92: %% Args: 93: %% Returns: 94: %%----------------------------------------------------------------- 95: suite() -> 96: [{ct_hooks,[ts_install_cth]}]. 97: 98: all() -> 99: cases(). 100: 101: groups() -> 102: []. 103: 104: 105: 106: init_per_group(_GroupName, Config) -> 107: Config. 108: 109: end_per_group(_GroupName, Config) -> 110: Config. 111: 112: 113: cases() -> 114: [fts_ftp_dir_api, fts_ftp_file_api, 115: fts_ftp_file_ssl_api, fts_native_dir_api, 116: fts_native_file_api, fts_native_file_ssl_api, 117: fileIterator_api, app_test]. 118: 119: %%----------------------------------------------------------------- 120: %% Init and cleanup functions. 121: %%----------------------------------------------------------------- 122: 123: init_per_testcase(_Case, Config) -> 124: ?line Dog=test_server:timetrap(?default_timeout), 125: [{watchdog, Dog}|Config]. 126: 127: 128: end_per_testcase(_Case, Config) -> 129: Dog = ?config(watchdog, Config), 130: test_server:timetrap_cancel(Dog), 131: ok. 132: 133: init_per_suite(Config) -> 134: case crypto_works() of 135: false -> 136: {skip,"Could not start crypto!"}; 137: true -> 138: orber:jump_start(), 139: cosProperty:install(), 140: cosProperty:start(), 141: Dir = filename:join([code:lib_dir(ssl), "examples", "certs", "etc"]), 142: %% Client 143: cosFileTransferApp:configure(ssl_client_certfile, 144: filename:join([Dir, "client", "cert.pem"])), 145: cosFileTransferApp:configure(ssl_client_cacertfile, 146: filename:join([Dir, "client", "cacerts.pem"])), 147: cosFileTransferApp:configure(ssl_client_verify, 1), 148: cosFileTransferApp:configure(ssl_client_depth, 0), 149: %% Server 150: cosFileTransferApp:configure(ssl_server_certfile, 151: filename:join([Dir, "server", "cert.pem"])), 152: cosFileTransferApp:configure(ssl_server_cacertfile, 153: filename:join([Dir, "server", "cacerts.pem"])), 154: cosFileTransferApp:configure(ssl_server_verify, 1), 155: cosFileTransferApp:configure(ssl_server_depth, 0), 156: crypto:start(), 157: ssl:start(), 158: cosFileTransferApp:install(), 159: cosFileTransferApp:start(), 160: if 161: is_list(Config) -> 162: Config; 163: true -> 164: exit("Config not a list") 165: end 166: end. 167: 168: crypto_works() -> 169: try crypto:start() of 170: {error,{already_started,crypto}} -> true; 171: ok -> true 172: catch 173: error:_ -> 174: false 175: end. 176: 177: end_per_suite(Config) -> 178: ssl:stop(), 179: crypto:stop(), 180: cosFileTransferApp:stop(), 181: cosProperty:stop(), 182: cosProperty:uninstall(), 183: cosFileTransferApp:uninstall(), 184: orber:jump_stop(), 185: Config. 186: 187: %%----------------------------------------------------------------- 188: %% Local definitions 189: %%----------------------------------------------------------------- 190: -define(FTP_USER, "anonymous"). 191: -define(FTP_PASS, "fileTransfer_SUITE@localhost"). 192: -define(TEST_DIR,["/", "incoming"]). 193: 194: 195: -define(FTP_PORT, 21). 196: -define(FTP_ACC, "anonymous"). 197: 198: -define(BAD_HOST, "badhostname"). 199: -define(BAD_USER, "baduser"). 200: -define(BAD_DIR, "baddirectory"). 201: 202: -define(TEST_FILE_DATA, "If this file exists after a completed test an error occurred."). 203: -define(TEST_FILE_DATA2, "1234567890123"). 204: 205: 206: %%----------------------------------------------------------------- 207: %% aoo-file test 208: %%----------------------------------------------------------------- 209: app_test(doc) -> []; 210: app_test(suite) -> []; 211: app_test(_Config) -> 212: ?line ok=?t:app_test(cosFileTransfer), 213: ok. 214: 215: %%----------------------------------------------------------------- 216: %% FileIterator API tests 217: %%----------------------------------------------------------------- 218: fileIterator_api(doc) -> ["CosFileTransfer FileIterator API tests.", ""]; 219: fileIterator_api(suite) -> []; 220: fileIterator_api(Config) -> 221: case ftp_host(Config) of 222: {skipped, SkippedReason} -> 223: {skipped, SkippedReason}; 224: Host -> 225: 226: ?line {ok, Node} = create_node("fileIterator_api", 4008, normal), 227: ?line ?match(ok, remote_apply(Node, ?MODULE, install_data, 228: [tcp, {{'NATIVE', 229: 'cosFileTransferNATIVE_file'}, Host, 230: "fileIterator_api"}])), 231: 232: %% Create a Virtual File System. 233: %% ?line VFS = ?match({_,_,_,_,_,_}, 234: %% cosFileTransferApp:create_VFS({'NATIVE', 235: %% 'cosFileTransferNATIVE_file'}, 236: %% [], Host, ?FTP_PORT)), 237: ?line VFS = ?matchnopr({'IOP_IOR',"IDL:omg.org/CosFileTransfer/VirtualFileSystem:1.0",_}, 238: corba:string_to_object("corbaname::1.2@localhost:4008/NameService#fileIterator_api")), 239: 240: %% Start two File Transfer Sessions (Source and Target). 241: ?line {FS, Dir} = ?matchnopr({{_,_,_},{_,_,_}}, 242: 'CosFileTransfer_VirtualFileSystem':login(VFS, 243: ?FTP_USER, 244: ?FTP_PASS, 245: ?FTP_ACC)), 246: 247: %% Do some basic test on one of the Directories attributes. 248: ?line ?match([_H|_], 'CosFileTransfer_Directory':'_get_name'(Dir)), 249: ?line ?match([_H|_], 'CosFileTransfer_Directory':'_get_complete_file_name'(Dir)), 250: ?line ?match({'IOP_IOR',[],[]}, 'CosFileTransfer_Directory':'_get_parent'(Dir)), 251: ?line ?matchnopr(FS, 'CosFileTransfer_Directory':'_get_associated_session'(Dir)), 252: {ok,[],FileIter} = ?match({ok,[],_}, 'CosFileTransfer_Directory':list(Dir, 0)), 253: %% Usually the working directory for the test is not empty so no need for 254: %% creating files of our own?! 255: #any{value=Children} = ?match({any, _, _}, 256: 'CosPropertyService_PropertySet': 257: get_property_value(Dir, "num_children")), 258: 259: if 260: Children > 5 -> 261: ?line ?matchnopr({true, _}, 'CosFileTransfer_FileIterator':next_one(FileIter)), 262: ?line ?matchnopr({true, _}, 'CosFileTransfer_FileIterator':next_n(FileIter, 3)), 263: ?line ?matchnopr({true, _}, 'CosFileTransfer_FileIterator':next_n(FileIter, 264: Children)), 265: ?line ?matchnopr({false, _}, 'CosFileTransfer_FileIterator':next_one(FileIter)), 266: ?line ?match({false, []}, 'CosFileTransfer_FileIterator':next_n(FileIter, 1)), 267: ok; 268: true -> 269: ok 270: end, 271: ?line ?match(ok, 'CosFileTransfer_FileIterator':destroy(FileIter)), 272: ?line ?match(false, corba_object:non_existent(FS)), 273: ?line ?match(ok, 'CosFileTransfer_FileTransferSession':logout(FS)), 274: %% To make sure Orber can remove it from mnesia. 275: timer:sleep(1000), 276: ?line ?match(true, corba_object:non_existent(FS)), 277: ?line ?match(ok, remote_apply(Node, ?MODULE, uninstall_data, ["fileIterator_api"])), 278: stop_orber_remote(Node, normal), 279: ok 280: end. 281: 282: 283: %%----------------------------------------------------------------- 284: %% FileTransferSession API tests 285: %%----------------------------------------------------------------- 286: fts_ftp_file_api(doc) -> ["CosFileTransfer FTP FileTransferSession API tests.", ""]; 287: fts_ftp_file_api(suite) -> []; 288: fts_ftp_file_api(Config) -> 289: ?line {ok, Node} = create_node("ftp_file_api", 4004, normal), 290: file_helper(Config, 'FTP', ?TEST_DIR, Node, 4004, "ftp_file_api", tcp). 291: 292: fts_ftp_file_ssl_api(doc) -> ["CosFileTransfer FTP FileTransferSession API tests.", ""]; 293: fts_ftp_file_ssl_api(suite) -> []; 294: fts_ftp_file_ssl_api(Config) -> 295: ?line {ok, Node} = create_node("ftp_file_api_ssl", {4005, 1}, ssl), 296: file_helper(Config, 'FTP', ?TEST_DIR, Node, 4005, "ftp_file_api_ssl", ssl). 297: 298: fts_native_file_api(doc) -> ["CosFileTransfer NATIVE FileTransferSession API tests.", ""]; 299: fts_native_file_api(suite) -> []; 300: fts_native_file_api(Config) -> 301: ?line {ok, Node} = create_node("native_file_api", 4006, normal), 302: {ok, Pwd} = file:get_cwd(), 303: file_helper(Config,{'NATIVE', 'cosFileTransferNATIVE_file'},filename:split(Pwd), 304: Node, 4006, "native_file_api", tcp). 305: 306: fts_native_file_ssl_api(doc) -> ["CosFileTransfer NATIVE FileTransferSession API tests.", ""]; 307: fts_native_file_ssl_api(suite) -> []; 308: fts_native_file_ssl_api(Config) -> 309: ?line {ok, Node} = create_node("native_file_ssl_api", {4007, 1}, ssl), 310: {ok, Pwd} = file:get_cwd(), 311: file_helper(Config,{'NATIVE', 'cosFileTransferNATIVE_file'},filename:split(Pwd), 312: Node, 4007, "native_file_ssl_api", ssl). 313: 314: 315: 316: file_helper(Config, WhichType, TEST_DIR, Node, Port, Name, Type) -> 317: case ftp_host(Config) of 318: {skipped, SkippedReason} -> 319: {skipped, SkippedReason}; 320: Host -> 321: TEST_SOURCE = TEST_DIR ++ [create_name(remove_me_source)], 322: TEST_SOURCE2 = TEST_DIR ++ [create_name(remove_me_source)], 323: TEST_TARGET = TEST_DIR ++ [create_name(remove_me_target)], 324: 325: io:format("<<<<<< CosFileTransfer Testing Configuration >>>>>>~n",[]), 326: io:format("Source: ~p~nTarget: ~p~n", [TEST_SOURCE, TEST_TARGET]), 327: 328: ?line ?match(ok, remote_apply(Node, ?MODULE, install_data, 329: [Type, {WhichType, Host, Name}])), 330: 331: ?line VFST = ?match({'IOP_IOR',"IDL:omg.org/CosFileTransfer/VirtualFileSystem:1.0",_}, 332: corba:string_to_object("corbaname::1.2@localhost:"++integer_to_list(Port)++"/NameService#"++Name)), 333: 334: 335: %% Create a Virtual File System. 336: ?line VFS = ?match({_,_,_,_,_,_}, 337: cosFileTransferApp:create_VFS(WhichType, [], Host, ?FTP_PORT, 338: [{protocol, Type}])), 339: %% Start two File Transfer Sessions (Source and Target). 340: ?line {FST, _DirT} = ?match({{_,_,_},{_,_,_}}, 341: 'CosFileTransfer_VirtualFileSystem':login(VFST, 342: ?FTP_USER, 343: ?FTP_PASS, 344: ?FTP_ACC)), 345: ?line {FSS, DirS} = ?match({{_,_,_,_,_,_},{_,_,_,_,_,_}}, 346: 'CosFileTransfer_VirtualFileSystem':login(VFS, 347: ?FTP_USER, 348: ?FTP_PASS, 349: ?FTP_ACC)), 350: 351: %% Do some basic test on one of the Directories attributes. 352: ?line ?match([_H|_], 'CosFileTransfer_Directory':'_get_name'(DirS)), 353: ?line ?match([_H|_], 'CosFileTransfer_Directory':'_get_complete_file_name'(DirS)), 354: ?line ?match({'IOP_IOR',[],[]}, 'CosFileTransfer_Directory':'_get_parent'(DirS)), 355: ?line ?match(FSS, 'CosFileTransfer_Directory':'_get_associated_session'(DirS)), 356: 357: %% Get a FileList before we create any new Files 358: ?line #'CosFileTransfer_FileWrapper'{the_file = Dir} = 359: ?match({'CosFileTransfer_FileWrapper', _, ndirectory}, 360: 'CosFileTransfer_FileTransferSession':get_file(FSS, TEST_DIR)), 361: ?line {ok,FileList, Iter1} = ?match({ok,_,_}, 'CosFileTransfer_Directory':list(Dir, 10)), 362: ?line loop_files(FileList), 363: 364: case Iter1 of 365: {'IOP_IOR',[],[]} -> 366: ok; 367: _-> 368: ?line ?match(ok, 'CosFileTransfer_FileIterator':destroy(Iter1)) 369: end, 370: 371: #any{value=Count1} = ?match({any, _, _}, 'CosPropertyService_PropertySet': 372: get_property_value(Dir, "num_children")), 373: 374: %% Now we want to transfer a file from source to target. First, we'll create 375: %% a a file to work with. 376: ?line create_file_on_source_node(WhichType, Config, Host, 377: filename:join(TEST_SOURCE), TEST_DIR, 378: ?TEST_FILE_DATA), 379: ?line create_file_on_source_node(WhichType, Config, Host, 380: filename:join(TEST_SOURCE2), TEST_DIR, 381: ?TEST_FILE_DATA2), 382: 383: ?line #'CosFileTransfer_FileWrapper'{the_file = FileS} = 384: ?matchnopr({'CosFileTransfer_FileWrapper', _, nfile}, 385: 'CosFileTransfer_FileTransferSession':get_file(FSS, TEST_SOURCE)), 386: ?line #'CosFileTransfer_FileWrapper'{the_file = FileS2} = 387: ?matchnopr({'CosFileTransfer_FileWrapper', _, nfile}, 388: 'CosFileTransfer_FileTransferSession':get_file(FSS, TEST_SOURCE2)), 389: 390: #any{value=Count2} = ?match({any, _, _}, 'CosPropertyService_PropertySet': 391: get_property_value(Dir, "num_children")), 392: timer:sleep(2000), 393: ?match(true, (Count1+2 == Count2)), 394: 395: %% Create a target File 396: ?line FileT = ?matchnopr({_,_,_}, 397: 'CosFileTransfer_FileTransferSession':create_file(FST, TEST_TARGET)), 398: %% Try to delete the non-existing file. 399: ?line ?match({'EXCEPTION', _}, 400: 'CosFileTransfer_FileTransferSession':delete(FST, FileT)), 401: 402: ?line ?match(ok, 'CosFileTransfer_FileTransferSession':transfer(FSS, FileS, FileT)), 403: 404: %% Remove this test when ftp supports append. 405: case WhichType of 406: {'NATIVE', 'cosFileTransferNATIVE_file'} -> 407: ?line ?match(ok, 'CosFileTransfer_FileTransferSession':append(FSS, FileS, FileT)), 408: ?line ?match(ok, 'CosFileTransfer_FileTransferSession':insert(FSS, FileS2, FileT, 7)); 409: _-> 410: ok 411: end, 412: 413: %% Delete source and target files 414: ?line ?match(ok, 'CosFileTransfer_FileTransferSession':delete(FSS, FileS)), 415: ?line ?match(ok, 'CosFileTransfer_FileTransferSession':delete(FSS, FileS2)), 416: ?line ?match(ok, 'CosFileTransfer_FileTransferSession':delete(FST, FileT)), 417: 418: %% Should be back where we started. 419: timer:sleep(2000), 420: #any{value=Count3} = ?match({any, _, _}, 'CosPropertyService_PropertySet': 421: get_property_value(Dir, "num_children")), 422: ?match(true, (Count1 == Count3)), 423: 424: 425: ?line ?match(false, corba_object:non_existent(FSS)), 426: ?line ?match(false, corba_object:non_existent(FST)), 427: ?line ?match(ok, 'CosFileTransfer_FileTransferSession':logout(FSS)), 428: ?line ?match(ok, 'CosFileTransfer_FileTransferSession':logout(FST)), 429: %% To make sure Orber can remove it from mnesia. 430: timer:sleep(2000), 431: ?line ?match(true, corba_object:non_existent(FSS)), 432: ?line ?match(true, corba_object:non_existent(FST)), 433: ?line ?match(ok, remote_apply(Node, ?MODULE, uninstall_data, [Name])), 434: stop_orber_remote(Node, normal), 435: ok 436: end. 437: 438: %%----------------------------------------------------------------- 439: %% FileTransferSession API tests 440: %%----------------------------------------------------------------- 441: fts_ftp_dir_api(doc) -> ["CosFileTransfer FTP FileTransferSession API tests.", ""]; 442: fts_ftp_dir_api(suite) -> []; 443: fts_ftp_dir_api(Config) -> 444: ?line {ok, Node} = create_node("ftp_dir_api", 4009, normal), 445: dir_helper(Config, 'FTP', ?TEST_DIR, Node, 4009, "ftp_dir_api"). 446: 447: 448: fts_native_dir_api(doc) -> ["CosFileTransfer NATIVE FileTransferSession API tests.", ""]; 449: fts_native_dir_api(suite) -> []; 450: fts_native_dir_api(Config) -> 451: ?line {ok, Node} = create_node("native_dir_api", 4010, normal), 452: {ok, Pwd} = file:get_cwd(), 453: dir_helper(Config, {'NATIVE', 'cosFileTransferNATIVE_file'}, 454: filename:split(Pwd), Node, 4010, "native_dir_api"). 455: 456: dir_helper(Config, WhichType, TEST_DIR, Node, Port, Name) -> 457: case ftp_host(Config) of 458: {skipped, SkippedReason} -> 459: {skipped, SkippedReason}; 460: Host -> 461: TEST_DIR_LEVEL1 = TEST_DIR ++ [create_name(remove_me_dir1)], 462: TEST_DIR_LEVEL2 = TEST_DIR_LEVEL1 ++ [create_name(remove_me_dir2)], 463: 464: io:format("<<<<<< CosFileTransfer Testing Configuration >>>>>>~n",[]), 465: io:format("Top Dir: ~p~nLevel2 Dir: ~p~n", [TEST_DIR_LEVEL1, TEST_DIR_LEVEL2]), 466: 467: ?line ?match(ok, remote_apply(Node, ?MODULE, install_data, 468: [tcp, {WhichType, Host, Name}])), 469: 470: ?line VFS = ?matchnopr({'IOP_IOR',"IDL:omg.org/CosFileTransfer/VirtualFileSystem:1.0",_}, 471: corba:string_to_object("corbaname::1.2@localhost:"++integer_to_list(Port)++"/NameService#"++Name)), 472: 473: %% Start two File Transfer Sessions (Source and Target). 474: ?line {FS, DirS} = ?matchnopr({{'IOP_IOR',_,_}, _}, 475: 'CosFileTransfer_VirtualFileSystem':login(VFS, 476: ?FTP_USER, 477: ?FTP_PASS, 478: ?FTP_ACC)), 479: 480: %% Do some basic test on one of the Directories attributes. 481: ?line ?match([_H|_], 'CosFileTransfer_Directory':'_get_name'(DirS)), 482: ?line ?match([_H|_], 'CosFileTransfer_Directory':'_get_complete_file_name'(DirS)), 483: ?line ?match({'IOP_IOR',[],[]}, 'CosFileTransfer_Directory':'_get_parent'(DirS)), 484: ?line ?matchnopr(FS, 'CosFileTransfer_Directory':'_get_associated_session'(DirS)), 485: 486: %% Create a Root Directory. Currently we only need to create one but 487: %% later on, when supporting other protocols than FTP it's not enough. 488: ?line Dir1 = 'CosFileTransfer_FileTransferSession':create_directory(FS, 489: TEST_DIR_LEVEL1), 490: io:format("<<<<<< CosFileTransfer Testing Properties >>>>>>~n",[]), 491: ?line ?match({ok, [tk_long, tk_boolean]}, 492: 'CosFileTransfer_Directory':get_allowed_property_types(Dir1)), 493: ?line ?match({ok, [_,_]}, 494: 'CosFileTransfer_Directory':get_allowed_properties(Dir1)), 495: ?line ?match({'EXCEPTION', _}, 496: 'CosFileTransfer_Directory':define_property_with_mode(Dir1, 497: "num_children", 498: #any{typecode=tk_long, value=0}, 499: fixed_readonly)), 500: ?line ?match({'EXCEPTION', _}, 501: 'CosFileTransfer_Directory':define_property_with_mode(Dir1, 502: "wrong", 503: #any{typecode=tk_long, value=0}, 504: fixed_readonly)), 505: ?line ?match({'EXCEPTION', _}, 506: 'CosFileTransfer_Directory':define_property_with_mode(Dir1, 507: "num_children", 508: #any{typecode=tk_short, value=0}, 509: fixed_readonly)), 510: ?line ?match({'EXCEPTION', _}, 511: 'CosFileTransfer_Directory':define_property_with_mode(Dir1, 512: "num_children", 513: #any{typecode=tk_long, value=0}, 514: fixed_normal)), 515: ?line ?match({'EXCEPTION', _}, 516: 'CosFileTransfer_Directory':define_properties_with_modes(Dir1, 517: [#'CosPropertyService_PropertyDef' 518: {property_name = "num_children", 519: property_value = #any{typecode=tk_long, value=0}, 520: property_mode = fixed_readonly}])), 521: ?line ?match(fixed_readonly, 522: 'CosFileTransfer_Directory':get_property_mode(Dir1, "num_children")), 523: ?line ?match({true, 524: [#'CosPropertyService_PropertyMode'{property_name = "num_children", 525: property_mode = fixed_readonly}]}, 526: 'CosFileTransfer_Directory':get_property_modes(Dir1, ["num_children"])), 527: ?line ?match({'EXCEPTION', _}, 528: 'CosFileTransfer_Directory':set_property_mode(Dir1, "num_children", fixed_readonly)), 529: 530: ?line ?match({'EXCEPTION', _}, 531: 'CosFileTransfer_Directory': 532: set_property_modes(Dir1, 533: [#'CosPropertyService_PropertyMode' 534: {property_name = "num_children", 535: property_mode = fixed_readonly}])), 536: ?line ?match({'EXCEPTION', _}, 537: 'CosFileTransfer_Directory': 538: set_property_modes(Dir1, 539: [#'CosPropertyService_PropertyMode' 540: {property_name = "wrong", 541: property_mode = fixed_readonly}])), 542: ?line ?match({'EXCEPTION', _}, 543: 'CosFileTransfer_Directory': 544: set_property_modes(Dir1, 545: [#'CosPropertyService_PropertyMode' 546: {property_name = "num_children", 547: property_mode = fixed_normal}])), 548: ?line ?match({'EXCEPTION', _}, 549: 'CosFileTransfer_Directory':define_property(Dir1, 550: "num_children", 551: #any{typecode=tk_long, value=0})), 552: ?line ?match({'EXCEPTION', _}, 553: 'CosFileTransfer_Directory':define_property(Dir1, 554: "wrong", 555: #any{typecode=tk_long, value=0})), 556: ?line ?match({'EXCEPTION', _}, 557: 'CosFileTransfer_Directory':define_property(Dir1, 558: "num_children", 559: #any{typecode=tk_short, value=0})), 560: 561: ?line ?match({'EXCEPTION', _}, 562: 'CosFileTransfer_Directory':define_property(Dir1, 563: "num_children", 564: #any{typecode=tk_long, value=0})), 565: 566: ?line ?match({'EXCEPTION', _}, 567: 'CosFileTransfer_Directory': 568: define_properties(Dir1, 569: [#'CosPropertyService_Property' 570: {property_name = "num_children", 571: property_value = #any{typecode=tk_long, 572: value=0}}])), 573: ?line ?match({'EXCEPTION', _}, 574: 'CosFileTransfer_Directory': 575: define_properties(Dir1, 576: [#'CosPropertyService_Property' 577: {property_name = "wrong", 578: property_value = #any{typecode=tk_long, 579: value=0}}])), 580: ?line ?match({'EXCEPTION', _}, 581: 'CosFileTransfer_Directory': 582: define_properties(Dir1, 583: [#'CosPropertyService_Property' 584: {property_name = "num_children", 585: property_value = #any{typecode=tk_short, 586: value=0}}])), 587: ?line ?match(2, 'CosFileTransfer_Directory':get_number_of_properties(Dir1)), 588: 589: ?line ?match({ok, ["num_children", "is_directory"], {'IOP_IOR',[],[]}}, 590: 'CosFileTransfer_Directory':get_all_property_names(Dir1, 2)), 591: ?line ?match({ok, ["is_directory"], _}, 592: 'CosFileTransfer_Directory':get_all_property_names(Dir1, 1)), 593: 594: ?line ?match(#any{}, 595: 'CosFileTransfer_Directory':get_property_value(Dir1, "num_children")), 596: ?line ?match(#any{}, 597: 'CosFileTransfer_Directory':get_property_value(Dir1, "is_directory")), 598: ?line ?match({'EXCEPTION', _}, 599: 'CosFileTransfer_Directory':get_property_value(Dir1, "wrong")), 600: 601: ?line ?match({true, 602: [#'CosPropertyService_Property'{property_name = "num_children"}]}, 603: 'CosFileTransfer_Directory':get_properties(Dir1, ["num_children"])), 604: ?line ?match({false, 605: [#'CosPropertyService_Property'{property_name = "wrong"}]}, 606: 'CosFileTransfer_Directory':get_properties(Dir1, ["wrong"])), 607: 608: ?line ?match({ok, [_],_}, 609: 'CosFileTransfer_Directory':get_all_properties(Dir1, 1)), 610: ?line ?match({ok, [_,_], {'IOP_IOR',[],[]}}, 611: 'CosFileTransfer_Directory':get_all_properties(Dir1, 2)), 612: 613: ?line ?match({'EXCEPTION', _}, 614: 'CosFileTransfer_Directory':delete_property(Dir1, "num_children")), 615: ?line ?match({'EXCEPTION', _}, 616: 'CosFileTransfer_Directory':delete_property(Dir1, "wrong")), 617: 618: 619: ?line ?match({'EXCEPTION', _}, 620: 'CosFileTransfer_Directory':delete_properties(Dir1, ["num_children"])), 621: ?line ?match({'EXCEPTION', _}, 622: 'CosFileTransfer_Directory':delete_properties(Dir1, ["wrong"])), 623: ?line ?match(false, 'CosFileTransfer_Directory':delete_all_properties(Dir1)), 624: ?line ?match(true, 625: 'CosFileTransfer_Directory':is_property_defined(Dir1, "num_children")), 626: ?line ?match(false, 627: 'CosFileTransfer_Directory':is_property_defined(Dir1, "wrong")), 628: 629: %% The Top Dir should be empty and ... 630: ?line ?match({ok,[],_}, 'CosFileTransfer_Directory':list(Dir1, 1000)), 631: ?line ?match( #any{value=0}, 632: 'CosPropertyService_PropertySet':get_property_value(Dir1, "num_children")), 633: %% Create a sub-directory. 634: ?line Dir2 = 'CosFileTransfer_FileTransferSession':create_directory(FS, 635: TEST_DIR_LEVEL2), 636: ?line ?match( #any{value=1}, 637: 'CosPropertyService_PropertySet':get_property_value(Dir1, "num_children")), 638: 639: ?line ?match({ok, [_,_], {'IOP_IOR',[],[]}}, 640: 'CosFileTransfer_Directory':get_all_properties(Dir1, 2)), 641: ?line {_,_,Iterator1} = ?match({ok, [_], _}, 642: 'CosFileTransfer_Directory':get_all_properties(Dir1, 1)), 643: ?line ?match({false, [_]}, 644: 'CosPropertyService_PropertiesIterator':next_n(Iterator1,4)), 645: 646: ?line {_,_,Iterator0} = ?match({ok, [], _}, 647: 'CosFileTransfer_Directory':get_all_properties(Dir1, 0)), 648: 649: ?line ?match({false, [_, {'CosPropertyService_Property', 650: "num_children",{any,tk_long,1}}]}, 651: 'CosPropertyService_PropertiesIterator':next_n(Iterator0,4)), 652: 653: ?line ?match({true, 654: [#'CosPropertyService_Property'{property_name = "num_children"}]}, 655: 'CosFileTransfer_Directory':get_properties(Dir1, ["num_children"])), 656: 657: %% The Top Directory is not emtpy any more and ... 658: ?line {ok,[#'CosFileTransfer_FileWrapper'{the_file = DirRef}],_} = 659: ?matchnopr({ok,[{'CosFileTransfer_FileWrapper', _, ndirectory}],_}, 660: 'CosFileTransfer_Directory':list(Dir1, 1000)), 661: %% ... its name eq. to 'TEST_DIR_LEVEL2' 662: ?line ?match(TEST_DIR_LEVEL2, 663: 'CosFileTransfer_Directory':'_get_complete_file_name'(DirRef)), 664: 665: ?line #'CosFileTransfer_FileWrapper'{the_file = Dir3} = 666: ?matchnopr({'CosFileTransfer_FileWrapper', _, ndirectory}, 667: 'CosFileTransfer_FileTransferSession':get_file(FS, TEST_DIR_LEVEL1)), 668: 669: %% Must get the same result for the 'get_file' operation. 670: ?line {ok,[#'CosFileTransfer_FileWrapper'{the_file = DirRef2}],_} = 671: ?matchnopr({ok,[{'CosFileTransfer_FileWrapper', _, ndirectory}],_}, 672: 'CosFileTransfer_Directory':list(Dir3,1000)), 673: ?line ?match(TEST_DIR_LEVEL2, 674: 'CosFileTransfer_Directory':'_get_complete_file_name'(DirRef2)), 675: 676: %% Since the top directory isn't empty deleting it must fail. 677: ?line ?match({'EXCEPTION', _}, 678: 'CosFileTransfer_FileTransferSession':delete(FS, Dir1)), 679: 680: %% Delete the sub-directory and ... 681: ?line ?match(ok, 'CosFileTransfer_FileTransferSession':delete(FS, Dir2)), 682: %% ... see if the top directory realyy is empty. 683: ?line ?match({ok,[],_}, 'CosFileTransfer_Directory':list(Dir1, 1000)), 684: 685: ?line ?match(ok, 'CosFileTransfer_FileTransferSession':delete(FS, Dir1)), 686: %% Test if the top directory been removed as intended. 687: ?line ?match({'EXCEPTION', {'CosFileTransfer_FileNotFoundException', _, _}}, 688: 'CosFileTransfer_FileTransferSession':get_file(FS, TEST_DIR_LEVEL1)), 689: 690: ?line ?match(false, corba_object:non_existent(FS)), 691: ?line ?match(ok, 'CosFileTransfer_FileTransferSession':logout(FS)), 692: %% To make sure Orber can remove it from mnesia. 693: timer:sleep(1000), 694: ?line ?match(true, corba_object:non_existent(FS)), 695: ?line ?match(ok, remote_apply(Node, ?MODULE, uninstall_data, [Name])), 696: stop_orber_remote(Node, normal), 697: ok 698: end. 699: 700: 701: %%----------------------------------------------------------------- 702: %% Internal functions 703: %%----------------------------------------------------------------- 704: ftp_host(Config) -> 705: case ?config(ftp_remote_host, Config) of 706: undefined -> 707: {skipped, "The configuration parameter 'ftp_remote_host' not defined."}; 708: Host -> 709: Host 710: end. 711: 712: loop_files([]) -> 713: io:format("@@@ DONE @@@~n", []); 714: loop_files([#'CosFileTransfer_FileWrapper'{the_file = H}|T]) -> 715: FullName = 'CosFileTransfer_File':'_get_complete_file_name'(H), 716: Name = 'CosFileTransfer_File':'_get_name'(H), 717: io:format("FULL NAME: ~p SHORT NAME: ~p~n", [FullName, Name]), 718: loop_files(T). 719: 720: 721: create_file_on_source_node('FTP', _Config, Host, FileName, Path, Data) -> 722: io:format("<<<<<< CosFileTransfer Testing File >>>>>>~n",[]), 723: io:format("Host: ~p~nPath: ~p~nFile: ~p~n", [Host, Path, FileName]), 724: {ok, Pid} = ?match({ok, _}, inets:start(ftpc, [{host, Host}], stand_alone)), 725: ?match(ok, ftp:user(Pid, ?FTP_USER, ?FTP_PASS)), 726: ?match(ok, ftp:cd(Pid, Path)), 727: ?match(ok, ftp:send_bin(Pid, list_to_binary(Data), FileName)), 728: ?match(ok, inets:stop(ftpc, Pid)); 729: create_file_on_source_node({'NATIVE', _}, _Config, Host, FileName, Path, Data) -> 730: io:format("<<<<<< CosFileTransfer Testing File >>>>>>~n",[]), 731: io:format("Host: ~p~nPath: ~p~nFile: ~p~n", [Host, Path, FileName]), 732: ?match(ok, file:write_file(FileName, list_to_binary(Data))). 733: 734: create_name(Type) -> 735: {MSec, Sec, USec} = erlang:now(), 736: lists:concat([Type,'_',MSec, '_', Sec, '_', USec]). 737: 738: 739: 740: 741: %%------------------------------------------------------------ 742: %% function : create_node/4 743: %% Arguments: Name - the name of the new node (atom()) 744: %% Port - which iiop_port (integer()) 745: %% Domain - which domain. 746: %% Type - if /4 used the types defines the extra arguments 747: %% to be used. 748: %% Returns : {ok, Node} | {error, _} 749: %% Effect : Starts a new slave-node with given (optinally) 750: %% extra arguments. If fails it retries 'Retries' times. 751: %%------------------------------------------------------------ 752: create_node(Name, Port, normal) -> 753: Args = basic_args(Name), 754: create_node(Name, Port, 10, normal, Args, []); 755: create_node(Name, {Port, _Depth}, ssl) -> 756: Dir = filename:join([code:lib_dir(ssl), "examples", "certs", "etc"]), 757: Args = basic_args(Name), 758: {ok, Node} = create_node(list_to_atom(Name), Port, 10, ssl, Args, []), 759: %% Client 760: rpc:call(Node, application, set_env, [cosFileTransfer, ssl_client_certfile, 761: filename:join([Dir, "client", "cert.pem"])]), 762: rpc:call(Node, application, set_env, [cosFileTransfer, ssl_client_cacertfile, 763: filename:join([Dir, "client", "cacerts.pem"])]), 764: rpc:call(Node, application, set_env, [cosFileTransfer, ssl_client_keyfile, 765: filename:join([Dir, "client", "key.pem"])]), 766: rpc:call(Node, application, set_env, [cosFileTransfer, ssl_client_verify, 1]), 767: rpc:call(Node, application, set_env, [cosFileTransfer, ssl_client_depth, 0]), 768: 769: %% Server 770: rpc:call(Node, application, set_env, [cosFileTransfer, ssl_server_certfile, 771: filename:join([Dir, "server", "cert.pem"])]), 772: rpc:call(Node, application, set_env, [cosFileTransfer, ssl_server_cacertfile, 773: filename:join([Dir, "server", "cacerts.pem"])]), 774: rpc:call(Node, application, set_env, [cosFileTransfer, ssl_server_keyfile, 775: filename:join([Dir, "server", "key.pem"])]), 776: rpc:call(Node, application, set_env, [cosFileTransfer, ssl_server_verify, 1]), 777: rpc:call(Node, application, set_env, [cosFileTransfer, ssl_server_depth, 0]), 778: {ok, Node}. 779: 780: %create_node(Name, {Port, Depth}, ssl) -> 781: % TestLibs = filename:join(filename:dirname(code:which(?MODULE)), "ssl_data"), 782: % Args = basic_args(Name), 783: % SArgs = basic_ssl_args(TestLibs, Args), 784: % LArgs = level_based_ssl(Depth, TestLibs, SArgs), 785: % create_node(list_to_atom(Name), Port, 10, ssl, LArgs, [{sslpath, TestLibs}]). 786: 787: create_node(Name, Port, Retries, Type, Args, Options) -> 788: [_, Host] = ?match([_,_],string:tokens(atom_to_list(node()), [$@])), 789: case starter(Host, Name, Args) of 790: {ok, NewNode} -> 791: ?line ?match(pong, net_adm:ping(NewNode)), 792: {ok, Cwd} = file:get_cwd(), 793: Path = code:get_path(), 794: ?line ?match(ok, rpc:call(NewNode, file, set_cwd, [Cwd])), 795: true = rpc:call(NewNode, code, set_path, [Path]), 796: ?match(ok, start_orber_remote(NewNode, Type, Options, Port)), 797: spawn_link(NewNode, ?MODULE, slave_sup, []), 798: rpc:multicall([node() | nodes()], global, sync, []), 799: {ok, NewNode}; 800: {error, Reason} when Retries == 0-> 801: {error, Reason}; 802: {error, Reason} -> 803: io:format("Could not start slavenode ~p ~p retrying~n", 804: [{Host, Name, Args}, Reason]), 805: timer:sleep(500), 806: create_node(Name, Port, Retries - 1, Type, Args, Options) 807: end. 808: 809: starter(Host, Name, Args) -> 810: slave:start(Host, Name, Args). 811: 812: slave_sup() -> 813: process_flag(trap_exit, true), 814: receive 815: {'EXIT', _, _} -> 816: ignore 817: end. 818: 819: 820: %%------------------------------------------------------------ 821: %% function : destroy_node 822: %% Arguments: Node - which node to destroy. 823: %% Type - normal | ssl 824: %% Returns : 825: %% Effect : 826: %%------------------------------------------------------------ 827: -ifdef(false). 828: destroy_node(Node, Type) -> 829: stopper(Node, Type). 830: 831: stopper(Node, Type) -> 832: catch stop_orber_remote(Node, Type), 833: slave:stop(Node). 834: -endif. 835: 836: %%------------------------------------------------------------ 837: %% function : remote_apply 838: %% Arguments: N - Node, M - Module, 839: %% F - Function, A - Arguments (list) 840: %% Returns : 841: %% Effect : 842: %%------------------------------------------------------------ 843: remote_apply(N, M,F,A) -> 844: case rpc:call(N, M, F, A) of 845: {badrpc, Reason} -> 846: exit(Reason); 847: Other -> 848: Other 849: end. 850: 851: %%------------------------------------------------------------ 852: %% function : stop_orber_remote 853: %% Arguments: Node - which node to stop orber on. 854: %% Type - normal | ssl | light | ....... 855: %% Returns : ok 856: %% Effect : Stops orber on given node and, if specified, 857: %% other applications or programs. 858: %%------------------------------------------------------------ 859: stop_orber_remote(Node, ssl) -> 860: rpc:call(Node, ssl, stop, []), 861: rpc:call(Node, crypto, stop, []), 862: orb_rpc_blast(Node, ssl); 863: stop_orber_remote(Node, Type) -> 864: orb_rpc_blast(Node, Type). 865: 866: orb_rpc_blast(Node, _) -> 867: rpc:call(Node, cosFileTransferApp, stop, []), 868: rpc:call(Node, cosProperty, stop, []), 869: rpc:call(Node, cosFileTransferApp, uninstall, []), 870: rpc:call(Node, cosProperty, uninstall, []), 871: rpc:call(Node, orber, jump_stop, []). 872: 873: %%------------------------------------------------------------ 874: %% function : start_orber_remote 875: %% Arguments: Node - which node to start orber on. 876: %% Type - normal | ssl | light | ....... 877: %% Returns : ok 878: %% Effect : Starts orber on given node and, if specified, 879: %% other applications or programs. 880: %%------------------------------------------------------------ 881: start_orber_remote(Node, ssl, _Options, Port) -> 882: rpc:call(Node, ssl, start, []), 883: rpc:call(Node, crypto, start, []), 884: rpc:call(Node, ssl, seed, ["testing"]), 885: orb_rpc_setup(Node, ssl, Port); 886: start_orber_remote(Node, Type, _, Port) -> 887: orb_rpc_setup(Node, Type, Port). 888: 889: orb_rpc_setup(Node, _, Port) -> 890: rpc:call(Node, orber, jump_start, [Port]), 891: rpc:call(Node, cosProperty, install, []), 892: rpc:call(Node, cosProperty, start, []), 893: rpc:call(Node, cosFileTransferApp, install, []). 894: 895: %%--------------- MISC FUNCTIONS ----------------------------- 896: basic_args(_Name) -> 897: TestLibs = filename:dirname(code:which(?MODULE)), 898: " -orber orber_debug_level 10" ++ 899: " -pa " ++ 900: TestLibs ++ 901: " -pa " ++ 902: filename:join(TestLibs, "all_SUITE_data") ++ 903: " -pa " ++ 904: filename:dirname(code:which(cosFileTransferApp)). 905: 906: -ifdef(false). 907: basic_ssl_args(TestLibs, Args) -> 908: % Args ++ 909: % " -cosFileTransfer ssl_client_certfile \\\"" ++ 910: % filename:join(TestLibs, "ssl_client_cert.pem") ++ 911: % "\\\" -cosFileTransfer ssl_server_certfile \\\""++ 912: % filename:join(TestLibs, "ssl_server_cert.pem")++"\\\"". 913: 914: io:format("<<<<<< SSL LIBS ~p >>>>>>~n",[TestLibs]), 915: NewArgs = Args ++ 916: " -cosFileTransfer ssl_client_certfile \\\"" ++ 917: filename:join(TestLibs, "ssl_client_cert.pem") ++ 918: "\\\" -cosFileTransfer ssl_server_certfile \\\""++ 919: filename:join(TestLibs, "ssl_server_cert.pem")++"\\\"", 920: io:format("<<<<<< SSL LIBS ARGS ~p >>>>>>~n",[NewArgs]), 921: NewArgs. 922: 923: level_based_ssl(1, _TestLibs, Args) -> 924: Args; 925: level_based_ssl(2, _TestLibs, Args) -> 926: Args.% ++ 927: % " -cosFileTransfer ssl_server_depth 2 " ++ 928: % " -cosFileTransfer ssl_client_depth 2 " ++ 929: % " -cosFileTransfer ssl_server_verify " ++ 930: % " -cosFileTransfer ssl_client_verify " ++ 931: % " -cosFileTransfer ssl_server_cacertfile " ++ 932: % " -cosFileTransfer ssl_client_cacertfile " ++ 933: 934: -endif. 935: 936: install_data(Protocol, {WhichType, Host, Name}) -> 937: io:format("<<<<<< Starting ~p/~p VFS at ~p/~p>>>>>>~n", 938: [Protocol, WhichType, Host, Name]), 939: %% Create a Virtual File System. 940: ?line VFS = ?match({_,_,_,_,_,_}, 941: cosFileTransferApp:create_VFS(WhichType, [], Host, ?FTP_PORT, 942: [{protocol, Protocol}])), 943: NS = corba:resolve_initial_references("NameService"), 944: NC1 = lname_component:set_id(lname_component:create(), Name), 945: N = lname:insert_component(lname:create(), 1, NC1), 946: 'CosNaming_NamingContext':rebind(NS, N, VFS). 947: 948: uninstall_data(Name) -> 949: ?line VFS = ?match({_,_,_,_,_,_}, 950: corba:string_to_object("corbaname:rir:/NameService#"++Name)), 951: ?line ?match(ok, corba:dispose(VFS)), 952: ok. 953: 954: 955: 956: %%------------------- EOF MODULE-----------------------------------