From 8ca0f01295f1871d4f2d748503a72ea5ca7e438e Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Wed, 6 Jul 2016 14:28:53 +0530 Subject: [PATCH 1/9] fixed the return values of functions in steam-shell --- tools/steam-shell.pike | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/tools/steam-shell.pike b/tools/steam-shell.pike index 7470e7a..e55da52 100755 --- a/tools/steam-shell.pike +++ b/tools/steam-shell.pike @@ -477,7 +477,7 @@ int list(string what) } if(flag==0) write(toappend+a+"\n\n"); - return 0; + return !flag;//flag = 1 when str = Invalid command that means execution failed } array(string) get_list(string what,string|object|void lpath) @@ -574,24 +574,28 @@ int goto_room(string where) { write("Please specify path to room. Not a "+((factory/".")[0])+"\n"); me->move(OBJ(oldpath)); + return 0; } else if(error) { write("Please specify correct path to a room.\n"); + return 0; } // } // roomname = pathobj->query_attribute("OBJ_NAME"); // write("You are now inside "+roomname+"\n"); - return 0; + return 1; } int set_title(string desc) { if(users->lookup(options->user)->set_attribute("OBJ_DESC",desc)) write("You are now described as - "+desc+"\n"); - else + else{ write("Cannot set description.\n"); - return 0; + return 0; + } + return 1; } int desc_room() @@ -603,7 +607,7 @@ int desc_room() if((desc=="")||(Regexp.match("^ +$",desc))) desc = "This room does not have a description yet.\n"; write("You are currently in "+pathobj->query_attribute("OBJ_NAME")+"\n"+desc+"\n"); - return 0; + return 1; } int look(string|void str) @@ -622,7 +626,7 @@ int look(string|void str) write("---------------\n"); list("rooms"); write("---------------\n"); - return 0; + return 1; } int take(string name) @@ -639,9 +643,11 @@ int take(string name) dup_file->move(me); write(name+" copied to your rucksack.\n"); } - else + else{ write("Please mention a file in this room."); - return 0; + return 0; + } + return 1; } int gothrough(string gatename) @@ -669,8 +675,11 @@ int gothrough(string gatename) goto_room(exit_path1); } else + { write(gatename+" is not reachable from current room\n"); - return 0; + return 0; + } + return 1; } int delete(string file_cont_name) @@ -705,7 +714,7 @@ int create_ob(string type,string name) if(type=="Room") myobj->move(OBJ(getpath())); - return 0; + return 1; } int peek(string container) @@ -731,6 +740,7 @@ int peek(string container) write("You peek into "+container+"\n\n"); display("containers", conts); display("files", files); + return 1; } void display(string type, array(string) strs) @@ -757,6 +767,7 @@ int inventory() display("containers", conts); display("files", files); display("other files", others); + return 1; } int editfile(string filename) @@ -769,9 +780,11 @@ int editfile(string filename) string pathfact = _Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME"); if(pathfact=="Document.factory") applaunch(OBJ(fullpath),exitnow); - else + else{ write("You can't edit a "+pathfact[0..sizeof(pathfact)-8]); - return 0; + return 0; + } + return 1; } void exitnow() From 809eff52ed0ffc7ffdfc5fb74f29061efdbf76a8 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Thu, 7 Jul 2016 11:29:04 +0530 Subject: [PATCH 2/9] first attempt to establish a framework for testing --- tools/tests/test | 45 +++++++++++++++++++++++++++++++++++++++++++ tools/tests/test.in | 38 ++++++++++++++++++++++++++++++++++++ tools/tests/test.pike | 36 ++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 tools/tests/test create mode 100644 tools/tests/test.in create mode 100644 tools/tests/test.pike diff --git a/tools/tests/test b/tools/tests/test new file mode 100644 index 0000000..0a94d9b --- /dev/null +++ b/tools/tests/test @@ -0,0 +1,45 @@ +/home/siddhant/Documents/sTeam/tools/test.in:1: test 1, expected result: RUN +mixed a() { add_constant("host","127.0.0.1"); + add_constant("port",1900); + add_constant("server_path","/usr/local/lib/steam"); +; } +.... +/home/siddhant/Documents/sTeam/tools/test.in:6: test 2, expected result: RUN +mixed a() { + + master()->add_include_path(server_path+"/server/include"); + master()->add_program_path(server_path+"/server/"); + master()->add_program_path(server_path+"/conf/"); + master()->add_program_path(server_path+"/spm/"); + master()->add_program_path(server_path+"/server/net/coal/"); +; } +.... +/home/siddhant/Documents/sTeam/tools/test.in:15: test 3, expected result: RUN +mixed a() { add_constant("conn",((program)"../spm/client_base.pike")());; } +.... +/home/siddhant/Documents/sTeam/tools/test.in:17: test 4, expected result: RUN +mixed a() { + conn->connect_server(host,port); + conn->login("root","steam",1); +; } +.... +/home/siddhant/Documents/sTeam/tools/test.in:22: test 5, expected result: RUN +mixed a() { add_constant("_Server",conn->SteamObj(0)); +; } +.... +/home/siddhant/Documents/sTeam/tools/test.in:25: test 6, expected result: RUN +mixed a() { add_constant("me",_Server->get_module("users")->lookup("root")); +; } +.... +/home/siddhant/Documents/sTeam/tools/test.in:29: test 7, expected result: EQ +mixed a() { + #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) + me->move(OBJ("/home/root")); + string oldpath = me->get_last_trail()->query_attribute("OBJ_PATH"); + me->move(OBJ("/new1")); + string newpath = me->get_last_trail()->query_attribute("OBJ_PATH"); + if(oldpath=="/home/root" && newpath=="/new1") return 1; + else return 0; +; } +mixed b() { return 1; } +.... diff --git a/tools/tests/test.in b/tools/tests/test.in new file mode 100644 index 0000000..6641155 --- /dev/null +++ b/tools/tests/test.in @@ -0,0 +1,38 @@ +test_do(add_constant("host","127.0.0.1"); + add_constant("port",1900); + add_constant("server_path","/usr/local/lib/steam"); +) + +test_do([[ + + master()->add_include_path(server_path+"/server/include"); + master()->add_program_path(server_path+"/server/"); + master()->add_program_path(server_path+"/conf/"); + master()->add_program_path(server_path+"/spm/"); + master()->add_program_path(server_path+"/server/net/coal/"); +]]) + +test_do(add_constant("conn",((program)"../spm/client_base.pike")());) + +test_do([[ + conn->connect_server(host,port); + conn->login("root","steam",1); +]]) + +test_do( + add_constant("_Server",conn->SteamObj(0)); +) +test_do( + add_constant("me",_Server->get_module("users")->lookup("root")); +) + +test_any([[ + #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) + me->move(OBJ("/home/root")); + string oldpath = me->get_last_trail()->query_attribute("OBJ_PATH"); + me->move(OBJ("/new1")); + string newpath = me->get_last_trail()->query_attribute("OBJ_PATH"); + if(oldpath=="/home/root" && newpath=="/new1") return 1; + else return 0; +]],1) + diff --git a/tools/tests/test.pike b/tools/tests/test.pike new file mode 100644 index 0000000..afdd245 --- /dev/null +++ b/tools/tests/test.pike @@ -0,0 +1,36 @@ +#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) + +object _Server; +object me; + +void init(){ + string host = "127.0.0.1"; + int port = 1900; + string server_path = "/usr/local/lib/steam"; + master()->add_include_path(server_path+"/server/include"); + master()->add_program_path(server_path+"/server/"); + master()->add_program_path(server_path+"/conf/"); + master()->add_program_path(server_path+"/spm/"); + master()->add_program_path(server_path+"/server/net/coal/"); + object conn = ((program)"../spm/client_base.pike")(); + conn->connect_server(host,port); + conn->login("root","steam",1); + _Server = conn->SteamObj(0); + me = _Server->get_module("users")->lookup("root"); + +} + +int main(){ + init(); + int pass = 0; + string path = me->get_last_trail()->query_attribute("OBJ_PATH"); + write("Current location of user: "+path+"\n"); + me->move(OBJ("/new1")); + write("Moving user to /new1\n"); + path = me->get_last_trail()->query_attribute("OBJ_PATH"); + write("New location of user: "+path+"\n"); + if(path=="/new1")pass=1; + string result = (pass==1)?"passed\n":"fail\n"; + write("Test case 1: move user - "+result); + me->move(OBJ("/home/root")); +} From 9016195eba65f1a038d9c791aeb1e6cbdcf091aa Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Thu, 7 Jul 2016 18:56:12 +0530 Subject: [PATCH 3/9] structural changes and added readme --- tests/coal-m4/Readme | 22 ++++++++++++++++++++++ {tools/tests => tests/coal-m4}/test | 0 {tools/tests => tests/coal-m4}/test.in | 0 tests/coal-pike/Readme | 2 ++ {tools/tests => tests/coal-pike}/test.pike | 0 5 files changed, 24 insertions(+) create mode 100644 tests/coal-m4/Readme rename {tools/tests => tests/coal-m4}/test (100%) rename {tools/tests => tests/coal-m4}/test.in (100%) create mode 100644 tests/coal-pike/Readme rename {tools/tests => tests/coal-pike}/test.pike (100%) diff --git a/tests/coal-m4/Readme b/tests/coal-m4/Readme new file mode 100644 index 0000000..343dda1 --- /dev/null +++ b/tests/coal-m4/Readme @@ -0,0 +1,22 @@ +The tests here use the pike scripts included to generate and run testsuites. + +mktestsuite +The mktestsuite script is a simple shell script that uses M4 to convert a testsuite input file into a testsuite that can be run by test_pike.pike. This script is found in $PIKE/include/pike. + +Usage: + +mktestsuite testsuite.in > testsuite + +The input file is simply a series of test invocations; any code outside of a test invocation will be ignored and will not appear in the final testsuite file. + + +test_pike + +The most important part of the regression testing infrastructure is test_pike, which is the pike script that performs the actual testing. Included in $PIKE/include/pike for Pike releases before 7.7, and as the builtin tool pike -x test_pike in releases 7.7 and higher, test_pike includes a large number of options for performing testing. + +Usage: + + pike -x test_pike testuitefile + +The first few cases are used to initialize the client and define global variables which are then used to execute tests. +We have written these initialization code as tests as there is no other way to execute simple pike code before running the tests. \ No newline at end of file diff --git a/tools/tests/test b/tests/coal-m4/test similarity index 100% rename from tools/tests/test rename to tests/coal-m4/test diff --git a/tools/tests/test.in b/tests/coal-m4/test.in similarity index 100% rename from tools/tests/test.in rename to tests/coal-m4/test.in diff --git a/tests/coal-pike/Readme b/tests/coal-pike/Readme new file mode 100644 index 0000000..a0ac151 --- /dev/null +++ b/tests/coal-pike/Readme @@ -0,0 +1,2 @@ +The tests in this folder are simple pike script. These scripts aim to develop its own testing framework. +To run the tests start the server and then execute the pike script in this folder. \ No newline at end of file diff --git a/tools/tests/test.pike b/tests/coal-pike/test.pike similarity index 100% rename from tools/tests/test.pike rename to tests/coal-pike/test.pike From efddba40525fd5b5a8122a9bc6575972505d22a8 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Thu, 7 Jul 2016 19:22:18 +0530 Subject: [PATCH 4/9] made the pike tests more modular --- tests/coal-pike/move.pike | 17 +++++++++++++++++ tests/coal-pike/test.pike | 13 ++----------- 2 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 tests/coal-pike/move.pike diff --git a/tests/coal-pike/move.pike b/tests/coal-pike/move.pike new file mode 100644 index 0000000..287ab7e --- /dev/null +++ b/tests/coal-pike/move.pike @@ -0,0 +1,17 @@ +#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) + +int testcase_move(object me,object _Server) +{ + int pass = 0; + me->move(OBJ("/home/root")); + string oldpath = me->get_last_trail()->query_attribute("OBJ_PATH"); + write("Current location of user: "+oldpath+"\n"); + me->move(OBJ("/new1")); + write("Moving user to /new1\n"); + string newpath = me->get_last_trail()->query_attribute("OBJ_PATH"); + write("New location of user: "+newpath+"\n"); + if(newpath=="/new1" && oldpath=="/home/root")pass=1; + string result = (pass==1)?"passed\n":"fail\n"; + me->move(OBJ("/home/root")); + return pass; +} \ No newline at end of file diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index afdd245..9323a4b 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -22,15 +22,6 @@ void init(){ int main(){ init(); - int pass = 0; - string path = me->get_last_trail()->query_attribute("OBJ_PATH"); - write("Current location of user: "+path+"\n"); - me->move(OBJ("/new1")); - write("Moving user to /new1\n"); - path = me->get_last_trail()->query_attribute("OBJ_PATH"); - write("New location of user: "+path+"\n"); - if(path=="/new1")pass=1; - string result = (pass==1)?"passed\n":"fail\n"; - write("Test case 1: move user - "+result); - me->move(OBJ("/home/root")); + object test1 = ((program)"move.pike")(); + int res = test1->testcase_move(me,_Server); } From a318f5dec06c8d27d6bc030786a351a52393c190 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Thu, 7 Jul 2016 23:45:33 +0530 Subject: [PATCH 5/9] structural changes to testing framework using pike scripts --- tests/coal-m4/Readme | 4 +- tests/coal-pike/.test.pike.swp | Bin 0 -> 12288 bytes tests/coal-pike/move.pike | 2 +- tests/coal-pike/test.pike | 69 +++++++++++++++++++++++---------- 4 files changed, 52 insertions(+), 23 deletions(-) create mode 100644 tests/coal-pike/.test.pike.swp diff --git a/tests/coal-m4/Readme b/tests/coal-m4/Readme index 343dda1..b23cf9c 100644 --- a/tests/coal-m4/Readme +++ b/tests/coal-m4/Readme @@ -5,7 +5,7 @@ The mktestsuite script is a simple shell script that uses M4 to convert a testsu Usage: -mktestsuite testsuite.in > testsuite +mktestsuite test.in > test The input file is simply a series of test invocations; any code outside of a test invocation will be ignored and will not appear in the final testsuite file. @@ -16,7 +16,7 @@ The most important part of the regression testing infrastructure is test_pike, w Usage: - pike -x test_pike testuitefile + pike -x test_pike test The first few cases are used to initialize the client and define global variables which are then used to execute tests. We have written these initialization code as tests as there is no other way to execute simple pike code before running the tests. \ No newline at end of file diff --git a/tests/coal-pike/.test.pike.swp b/tests/coal-pike/.test.pike.swp new file mode 100644 index 0000000000000000000000000000000000000000..4b371b383cea478928391fd7e26b1296dac80f0b GIT binary patch literal 12288 zcmeI2zmMER6vyX~QW%neprLe}0k0XbknC9q2dINwwagdih`iOn?b60Vco%m;e)a;0fFo zNfPMNg_W}5Zb&bdj`|ZirP8WtVb&@xRBw7sRclps#$;}0dn$F_7Cv#js?4I2MJFQj z<~`J?6T>#3c7IaUWz)KjQA4@~C%TRs`=~d9DWyD}R2Uka^$UzvGK_1Ml>ce@Ay?<4M`qXA@9$y@QfE>ovX z*$I&b@?OilRyL;4RN#gMwGW{vJ%GTvN|%eUL}w`r6?P-f2fht;LbLCSMelCdg6>Zi z%7K1X=PHhBt126H`jgz4oAoM=Dq~#K#Bc54nVPcfPp&zu2%T+b3eOSHsjozP^!X!P80NVnP%Xr9P*bm8J)h|efO=i2Bj z)TMU+EiB(4zh)1>L*^97sn{7O^B4WjK)+jRJD_#COFx^z(n^u-W+|hmM>%cz?)%j| zmpZTUAc3RbJ+#XyW+!YS<9_?>Xa;Yu+a-+7tq5b0=F-~cIe{mFe;yp(Gp##qy}Q2F wNmnC*yWSKTBb?9FT$d`mdihFhI``gZbDb+%pU=BWDcWz;m^w4{q2MR}1%nOiRR910 literal 0 HcmV?d00001 diff --git a/tests/coal-pike/move.pike b/tests/coal-pike/move.pike index 287ab7e..109a3e1 100644 --- a/tests/coal-pike/move.pike +++ b/tests/coal-pike/move.pike @@ -1,6 +1,6 @@ #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) -int testcase_move(object me,object _Server) +int testcase1(object me,object _Server) { int pass = 0; me->move(OBJ("/home/root")); diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index 9323a4b..c6161c6 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -1,27 +1,56 @@ #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) -object _Server; -object me; - -void init(){ - string host = "127.0.0.1"; - int port = 1900; - string server_path = "/usr/local/lib/steam"; - master()->add_include_path(server_path+"/server/include"); - master()->add_program_path(server_path+"/server/"); - master()->add_program_path(server_path+"/conf/"); - master()->add_program_path(server_path+"/spm/"); - master()->add_program_path(server_path+"/server/net/coal/"); - object conn = ((program)"../spm/client_base.pike")(); - conn->connect_server(host,port); - conn->login("root","steam",1); - _Server = conn->SteamObj(0); - me = _Server->get_module("users")->lookup("root"); +class Testcase{ + string status; + object code; + int run(){ + + } +} +class Test{ + string name; + object _Server; + object me; + array(Testcase) cases; + int failures; + void create(string name,int totalCases){ + this.name=name; + cases = allocate(totalCases); + init(); + } + void init(){ + string host = "127.0.0.1"; + int port = 1900; + string server_path = "/usr/local/lib/steam"; + master()->add_include_path(server_path+"/server/include"); + master()->add_program_path(server_path+"/server/"); + master()->add_program_path(server_path+"/conf/"); + master()->add_program_path(server_path+"/spm/"); + master()->add_program_path(server_path+"/server/net/coal/"); + object conn = ((program)"../spm/client_base.pike")(); + conn->connect_server(host,port); + conn->login("root","steam",1); + _Server = conn->SteamObj(0); + me = _Server->get_module("users")->lookup("root"); + } + int run(){ + string n = name +".pike"; + object code = ((program)n)(); + array(function) foo = values(code); +// code->testcase1(me,_Server); + for(int i=0;i< sizeof(cases);i++){ + // code->testcase+"i"(); + foo[i](me,_Server); + } + } } + + int main(){ - init(); - object test1 = ((program)"move.pike")(); - int res = test1->testcase_move(me,_Server); + Test move = Test("move",1); + move->run(); +// object test1 = ((program)"move.pike")(); +// int res = test1->testcase_move(me,_Server); } From e4e02c095a1aaec7e06d6fac4c1100a1d17d7e5c Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Thu, 7 Jul 2016 23:46:30 +0530 Subject: [PATCH 6/9] removed swap files --- tests/coal-pike/.test.pike.swp | Bin 12288 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/coal-pike/.test.pike.swp diff --git a/tests/coal-pike/.test.pike.swp b/tests/coal-pike/.test.pike.swp deleted file mode 100644 index 4b371b383cea478928391fd7e26b1296dac80f0b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2zmMER6vyX~QW%neprLe}0k0XbknC9q2dINwwagdih`iOn?b60Vco%m;e)a;0fFo zNfPMNg_W}5Zb&bdj`|ZirP8WtVb&@xRBw7sRclps#$;}0dn$F_7Cv#js?4I2MJFQj z<~`J?6T>#3c7IaUWz)KjQA4@~C%TRs`=~d9DWyD}R2Uka^$UzvGK_1Ml>ce@Ay?<4M`qXA@9$y@QfE>ovX z*$I&b@?OilRyL;4RN#gMwGW{vJ%GTvN|%eUL}w`r6?P-f2fht;LbLCSMelCdg6>Zi z%7K1X=PHhBt126H`jgz4oAoM=Dq~#K#Bc54nVPcfPp&zu2%T+b3eOSHsjozP^!X!P80NVnP%Xr9P*bm8J)h|efO=i2Bj z)TMU+EiB(4zh)1>L*^97sn{7O^B4WjK)+jRJD_#COFx^z(n^u-W+|hmM>%cz?)%j| zmpZTUAc3RbJ+#XyW+!YS<9_?>Xa;Yu+a-+7tq5b0=F-~cIe{mFe;yp(Gp##qy}Q2F wNmnC*yWSKTBb?9FT$d`mdihFhI``gZbDb+%pU=BWDcWz;m^w4{q2MR}1%nOiRR910 From eebdb5d1882db375be7a81e63b91d261ed58bea8 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Sat, 9 Jul 2016 10:18:31 +0530 Subject: [PATCH 7/9] adding second test case --- tests/coal-pike/move.pike | 14 +++++++++++++- tests/coal-pike/test.pike | 6 +----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/coal-pike/move.pike b/tests/coal-pike/move.pike index 109a3e1..d5be1f0 100644 --- a/tests/coal-pike/move.pike +++ b/tests/coal-pike/move.pike @@ -14,4 +14,16 @@ int testcase1(object me,object _Server) string result = (pass==1)?"passed\n":"fail\n"; me->move(OBJ("/home/root")); return pass; -} \ No newline at end of file +} + +int testcase2(object me,object _Server) +{ + int pass = 0; + me->move("/home/root"); + string oldpath = me->get_last_trail()->query_attribute("OBJ_PATH"); + write("Current location of user: "+oldpath+"\n"); + mixed result = catch{me->move(OBJ("nopath"));}; + write("Moving to a non existential location nopath.\n"); + if(result ==0)pass=1; + return pass; +} diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index c6161c6..eafcf73 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -38,9 +38,7 @@ class Test{ string n = name +".pike"; object code = ((program)n)(); array(function) foo = values(code); -// code->testcase1(me,_Server); for(int i=0;i< sizeof(cases);i++){ - // code->testcase+"i"(); foo[i](me,_Server); } } @@ -49,8 +47,6 @@ class Test{ int main(){ - Test move = Test("move",1); + Test move = Test("move",2); move->run(); -// object test1 = ((program)"move.pike")(); -// int res = test1->testcase_move(me,_Server); } From 271fb169792001be54d8f5e47894371ad514f4fa Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Tue, 12 Jul 2016 15:10:13 +0530 Subject: [PATCH 8/9] Display the number of failed and passed cases --- tests/coal-pike/test.pike | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index eafcf73..71ef647 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -38,9 +38,11 @@ class Test{ string n = name +".pike"; object code = ((program)n)(); array(function) foo = values(code); + int success = 0; for(int i=0;i< sizeof(cases);i++){ - foo[i](me,_Server); + success += foo[i](me,_Server); } + write("success: "+success+"\nfails: "+(sizeof(cases)-success)+"\n"); } } From 8ddfb75477d0895cd759feb1b40b232c12f402f7 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Wed, 13 Jul 2016 08:34:32 +0530 Subject: [PATCH 9/9] Added test cases for moving user and room inside container. --- tests/coal-pike/.move.pike.swp | Bin 0 -> 12288 bytes tests/coal-pike/move.pike | 49 +++++++++++++++++++++++---------- tests/coal-pike/test.pike | 13 +++++++-- 3 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 tests/coal-pike/.move.pike.swp diff --git a/tests/coal-pike/.move.pike.swp b/tests/coal-pike/.move.pike.swp new file mode 100644 index 0000000000000000000000000000000000000000..91987aaa54a42c7ca510397f47fa9818bc2002f3 GIT binary patch literal 12288 zcmeI2J#W)M7{{+{0ow8+fsi^}T~KX_Hfd9Y)RGQ>gbFH1P+;ICxb~$r#JZ4UELI%h{e+C9wd3vg(%Z?eN{Pd~&{Z*qxf8&K^bZ`2WBC`+sMcvCrT=*aDm20{A(^*f;PAd;kG>2A+Z^;1Vc<^We`QV>@6Q zya6qsKm=}q1uzT7!B^}zcn7NB2H@Z%7zRV&*D=O^fbU=fjDX*W`3u+rF1QUUU>uwS zI;S&$4l+On$N(8217v^$gt-BwWL&efZyQCz}?(!1yOB#*bjmA2Rcp4RWcbQ7uC-Md*2KJ66HXJ!nU9RX_JuKP=&rjxKCw_J4!t)p!_w(y zcc25`zwIQv{C2%S#RCT)r8&0F^u69=>)4T)F;fG+xR_q0VOaQT-8=3DR_F~o_NgN% z>i~DngwDY8QS`ar&^IFyV(69Rc6ZRyq2Dv;zR2{pJAh;k=-g13SF&aHFwF4nwAVQaN#*LhuH0eN^B$cC*}C-W9r zZwyHV9e`eDd6`ZhD$|VF6g8LI6Molx>J6u}o|9$MHBvcXvh|;Fr;GTa6I3D~dup}A z&VC29o5-J6d1|Nf)Q-8LhWBy&zLOU3iO`pBvyK;T&8rJN@UtouLN8c-Q&qB>tb0>h F>@S>#DA)i1 literal 0 HcmV?d00001 diff --git a/tests/coal-pike/move.pike b/tests/coal-pike/move.pike index d5be1f0..e47d1c8 100644 --- a/tests/coal-pike/move.pike +++ b/tests/coal-pike/move.pike @@ -3,27 +3,48 @@ int testcase1(object me,object _Server) { int pass = 0; - me->move(OBJ("/home/root")); - string oldpath = me->get_last_trail()->query_attribute("OBJ_PATH"); - write("Current location of user: "+oldpath+"\n"); - me->move(OBJ("/new1")); - write("Moving user to /new1\n"); - string newpath = me->get_last_trail()->query_attribute("OBJ_PATH"); - write("New location of user: "+newpath+"\n"); - if(newpath=="/new1" && oldpath=="/home/root")pass=1; - string result = (pass==1)?"passed\n":"fail\n"; - me->move(OBJ("/home/root")); + _Server->get_factory("Room")->execute((["name":"TestsubRoom"]))->move(OBJ("/TestRoom")); + mixed result = catch{me->move(OBJ("/TestRoom/TestsubRoom"));}; + write("Moving user\n"); + if(result == 0)pass=1; + me->move(OBJ("/TestRoom")); + OBJ("/TestRoom/TestsubRoom")->delete(); return pass; } int testcase2(object me,object _Server) { int pass = 0; - me->move("/home/root"); - string oldpath = me->get_last_trail()->query_attribute("OBJ_PATH"); - write("Current location of user: "+oldpath+"\n"); mixed result = catch{me->move(OBJ("nopath"));}; write("Moving to a non existential location nopath.\n"); - if(result ==0)pass=1; + if(result !=0)pass=1; + me->move(OBJ("/TestRoom")); + return pass; +} + +int testcase3(object me,object _Server) +{ + int pass = 0; + mixed result = 0; + int res =_Server->get_factory("Container")->execute((["name":"Testmove3"]))->move(OBJ("/TestRoom")); + result = catch{me->move(OBJ("/TestRoom/Testmove3"));}; + write("Moving user into a container\n"); + if(result != 0)pass=1; + OBJ("/TestRoom/Testmove3")->delete(); + return pass; +} + +int testcase4(object me,object _Server) +{ + int pass = 0; + _Server->get_factory("Room")->execute((["name":"Testmove4"]))->move(OBJ("/TestRoom")); + _Server->get_factory("Container")->execute((["name":"Testcontmove4"]))->move(OBJ("/TestRoom")); + object room = OBJ("/TestRoom/Testmove4"); + object container = OBJ("/TestRoom/Testcontmove4"); + mixed result = catch{room->move(container);}; + write("Moving room inside container\n"); + if(result!=0)pass=1; + room->delete(); + container->delete(); return pass; } diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index 71ef647..a2a35e2 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -19,6 +19,10 @@ class Test{ cases = allocate(totalCases); init(); } + void destroy(){ + me->move(OBJ("/home/steam")); + OBJ("/TestRoom")->delete(); + } void init(){ string host = "127.0.0.1"; int port = 1900; @@ -33,6 +37,8 @@ class Test{ conn->login("root","steam",1); _Server = conn->SteamObj(0); me = _Server->get_module("users")->lookup("root"); + _Server->get_factory("Room")->execute((["name":"TestRoom"]))->move(OBJ("/")); + me->move(OBJ("/TestRoom")); } int run(){ string n = name +".pike"; @@ -40,7 +46,10 @@ class Test{ array(function) foo = values(code); int success = 0; for(int i=0;i< sizeof(cases);i++){ - success += foo[i](me,_Server); + if(foo[i](me,_Server)==1){ + success+=1; + } + } write("success: "+success+"\nfails: "+(sizeof(cases)-success)+"\n"); } @@ -49,6 +58,6 @@ class Test{ int main(){ - Test move = Test("move",2); + Test move = Test("move",4); move->run(); }