From 8ca0f01295f1871d4f2d748503a72ea5ca7e438e Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Wed, 6 Jul 2016 14:28:53 +0530 Subject: [PATCH 01/17] 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 02/17] 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 03/17] 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 04/17] 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 05/17] 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 06/17] 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 07/17] 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 08/17] 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 09/17] 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(); } From deb8d59a95a83358a5a2497a099ed4b05ebfdc61 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Thu, 14 Jul 2016 18:41:07 +0530 Subject: [PATCH 10/17] Generalized the test case to pass any object to a test --- tests/coal-pike/.move.pike.swp | Bin 12288 -> 0 bytes tests/coal-pike/move.pike | 34 +++++++++++++++++++---- tests/coal-pike/move_nonexistential.pike | 9 ++++++ 3 files changed, 38 insertions(+), 5 deletions(-) delete mode 100644 tests/coal-pike/.move.pike.swp create mode 100644 tests/coal-pike/move_nonexistential.pike diff --git a/tests/coal-pike/.move.pike.swp b/tests/coal-pike/.move.pike.swp deleted file mode 100644 index 91987aaa54a42c7ca510397f47fa9818bc2002f3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 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 diff --git a/tests/coal-pike/move.pike b/tests/coal-pike/move.pike index e47d1c8..84b9068 100644 --- a/tests/coal-pike/move.pike +++ b/tests/coal-pike/move.pike @@ -5,22 +5,42 @@ int testcase1(object me,object _Server) int pass = 0; _Server->get_factory("Room")->execute((["name":"TestsubRoom"]))->move(OBJ("/TestRoom")); mixed result = catch{me->move(OBJ("/TestRoom/TestsubRoom"));}; - write("Moving user\n"); + write("Moving user: "); if(result == 0)pass=1; + if(pass==1)write("passed\n"); + else write("failed\n"); me->move(OBJ("/TestRoom")); OBJ("/TestRoom/TestsubRoom")->delete(); return pass; } - +/* int testcase2(object me,object _Server) { int pass = 0; mixed result = catch{me->move(OBJ("nopath"));}; - write("Moving to a non existential location nopath.\n"); + write("Moving to a non existential location nopath.: "); if(result !=0)pass=1; + if(pass==1)write("passed\n"); + else write("failed\n"); me->move(OBJ("/TestRoom")); return pass; } +*/ + +int testcase2(object me,object _Server) +{ + int pass = 1; + object code = ((program)"move_nonexistential.pike")(); + array(function) foo = values(code); + _Server->get_factory("Room")->execute((["name":"move2Room"]))->move(OBJ("/TestRoom")); + int success = foo[0](me,_Server,OBJ("/TestRoom/move2Room")); + write("Moving room to a non existential path: "); + if(success==0)pass=0; + if(pass == 1)write("passed\n"); + else write("failed\n"); + OBJ("/TestRoom/move2Room")->delete(); + return pass; +} int testcase3(object me,object _Server) { @@ -28,8 +48,10 @@ int testcase3(object me,object _Server) 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"); + write("Moving user into a container: "); if(result != 0)pass=1; + if(pass==1)write("passed\n"); + else write("failed\n"); OBJ("/TestRoom/Testmove3")->delete(); return pass; } @@ -42,8 +64,10 @@ int testcase4(object me,object _Server) object room = OBJ("/TestRoom/Testmove4"); object container = OBJ("/TestRoom/Testcontmove4"); mixed result = catch{room->move(container);}; - write("Moving room inside container\n"); + write("Moving room inside container: "); if(result!=0)pass=1; + if(pass==1)write("passed\n"); + else write("failed\n"); room->delete(); container->delete(); return pass; diff --git a/tests/coal-pike/move_nonexistential.pike b/tests/coal-pike/move_nonexistential.pike new file mode 100644 index 0000000..f02905a --- /dev/null +++ b/tests/coal-pike/move_nonexistential.pike @@ -0,0 +1,9 @@ +#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) + +int testcase(object me,object _Server,object x) +{ + int pass = 0; + mixed result = catch{x->move(OBJ("non-existential-path"));}; + if(result!=0)pass=1; + return pass; +} From 8981b85a54ea35618cf759244095d84cb7128943 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Sun, 17 Jul 2016 17:03:07 +0530 Subject: [PATCH 11/17] Added checks to avoid calling functions on non objects --- tests/coal-pike/move.pike | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/tests/coal-pike/move.pike b/tests/coal-pike/move.pike index 84b9068..a40a52f 100644 --- a/tests/coal-pike/move.pike +++ b/tests/coal-pike/move.pike @@ -4,13 +4,14 @@ int testcase1(object me,object _Server) { int pass = 0; _Server->get_factory("Room")->execute((["name":"TestsubRoom"]))->move(OBJ("/TestRoom")); - mixed result = catch{me->move(OBJ("/TestRoom/TestsubRoom"));}; + object obj = OBJ("/TestRoom/TestsubRoom"); + mixed result = catch{me->move(obj);}; write("Moving user: "); if(result == 0)pass=1; if(pass==1)write("passed\n"); else write("failed\n"); me->move(OBJ("/TestRoom")); - OBJ("/TestRoom/TestsubRoom")->delete(); + if(obj!=0)obj->delete(); return pass; } /* @@ -33,12 +34,27 @@ int testcase2(object me,object _Server) object code = ((program)"move_nonexistential.pike")(); array(function) foo = values(code); _Server->get_factory("Room")->execute((["name":"move2Room"]))->move(OBJ("/TestRoom")); - int success = foo[0](me,_Server,OBJ("/TestRoom/move2Room")); - write("Moving room to a non existential path: "); + _Server->get_factory("User")->execute((["name":"move2User","pw":"testpass","email":"abc@example.com"])); + _Server->get_module("users")->get_user("move2User")->activate_user(); + array(object) testObjects = allocate(2); + do{ + testObjects[0]=OBJ("/TestRoom/move2Room"); + }while(testObjects[0]==0); + do{ + testObjects[1]=_Server->get_module("users")->get_user("move2User"); + }while(testObjects[1]==0); + int success = 1; + for(int i = 0;iget_class()+ " to a non existential path: "); + int ctr = foo[0](me,_Server,testObjects[i]); + if(ctr == 0)success =0; + if(success == 1)write("passed\n"); + else write("failed\n"); + } + if(success==0)pass=0; - if(pass == 1)write("passed\n"); - else write("failed\n"); - OBJ("/TestRoom/move2Room")->delete(); + if(testObjects[1]!=0) + testObjects[1]->delete(); return pass; } @@ -47,12 +63,13 @@ 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"));}; + object obj = OBJ("/TestRoom/Testmove3"); + result = catch{me->move(obj);}; write("Moving user into a container: "); if(result != 0)pass=1; if(pass==1)write("passed\n"); else write("failed\n"); - OBJ("/TestRoom/Testmove3")->delete(); + if(obj!=0)obj->delete(); return pass; } @@ -68,7 +85,9 @@ int testcase4(object me,object _Server) if(result!=0)pass=1; if(pass==1)write("passed\n"); else write("failed\n"); + if(room!=0) room->delete(); + if(container!=0) container->delete(); return pass; } From 14a952aae56433b96bee63c8a2c5e618362dcf6f Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Mon, 18 Jul 2016 17:37:23 +0530 Subject: [PATCH 12/17] Added the test cases for create --- tests/coal-pike/create.pike | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/coal-pike/create.pike diff --git a/tests/coal-pike/create.pike b/tests/coal-pike/create.pike new file mode 100644 index 0000000..e6d1502 --- /dev/null +++ b/tests/coal-pike/create.pike @@ -0,0 +1,62 @@ +#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) + +int testcase1(object me,object _Server) +{ + int pass = 0; + write ("creating a new Calendar\n"); + object room = OBJ("/TestRoom"); + int result =_Server->get_factory("Calendar")->execute((["name":"TestCalendar"]))->move(room); + if(result == 1) pass = 1; + if(pass == 1) + OBJ("TestRoom/TestCalendar")->query_attribute("OBJ_NAME"); + return pass; +} + +int testcase2(object me,object _Server) +{ + int pass = 0; + write("creating a new Container\n"); + object room = OBJ("/TestRoom"); + int result =_Server->get_factory("Container")->execute((["name":"TestContainer"]))->move(room); + if(result == 1) pass = 1; + if(pass == 1) + OBJ("TestRoom/TestContainer")->query_attribute("OBJ_NAME"); + return pass; + +} + +int testcase3(object me,object _Server) +{ + int pass = 0; + write("creating a new Date\n"); + object room = OBJ("/TestRoom"); + int result =_Server->get_factory("Date")->execute((["name":"TestDate"]))->move(room); + if(result == 1) pass = 1; + if(pass == 1) + OBJ("TestRoom/TestDate")->query_attribute("OBJ_NAME"); + return pass; + +} + +int testcase4(object me,object _Server) +{ + int pass = 0; + write("creating a new Document\n"); + object room = OBJ("/TestRoom"); + int result =_Server->get_factory("Document")->execute((["name":"TestDocument"]))->move(room); + if(result == 1) pass = 1; + if(pass == 1) + OBJ("TestRoom/TestDocument")->query_attribute("OBJ_NAME"); + return pass; + +} + +int testcase5(object me,object _Server) +{ + int pass=0; + write("Creating a class that does not exists\n"); + mixed result = _Server->get_factory("NoClass"); + if(result == 0) pass =1; + return pass; +} + From d4de0f20e5f69271cd43917a9a68bf4753846eae Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Mon, 18 Jul 2016 17:39:06 +0530 Subject: [PATCH 13/17] Added function calls for create in the framework --- tests/coal-pike/test.pike | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index a2a35e2..95df5c8 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -60,4 +60,6 @@ class Test{ int main(){ Test move = Test("move",4); move->run(); + Test create = Test("create",5); + create->run(); } From bb1d4b5c59ec99b74a308230ccf8b4695d699ed2 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Mon, 18 Jul 2016 19:44:30 +0530 Subject: [PATCH 14/17] Generalized the test case for create and combined the create and move testcases in the framework --- tests/coal-pike/create.pike | 39 +++++++++++++++++++++++------- tests/coal-pike/create_object.pike | 13 ++++++++++ tests/coal-pike/move.pike | 2 +- tests/coal-pike/test.pike | 6 +++-- 4 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 tests/coal-pike/create_object.pike diff --git a/tests/coal-pike/create.pike b/tests/coal-pike/create.pike index e6d1502..e6bdb6a 100644 --- a/tests/coal-pike/create.pike +++ b/tests/coal-pike/create.pike @@ -1,5 +1,22 @@ #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) +int testcase1(object me,object _Server) +{ + object code = ((program)"create_object.pike")(); + array(function) foo = values(code); + int success = 1; + array(string) testClass = ({"Container","Document","Room"}); + for(int i =0;iget_factory("Calendar")->execute((["name":"TestCalendar"]))->move(room); if(result == 1) pass = 1; - if(pass == 1) - OBJ("TestRoom/TestCalendar")->query_attribute("OBJ_NAME"); + object obj = OBJ("TestRoom/TestCalendar"); + if(obj!=0) + obj->delete(); return pass; } @@ -18,9 +36,10 @@ int testcase2(object me,object _Server) write("creating a new Container\n"); object room = OBJ("/TestRoom"); int result =_Server->get_factory("Container")->execute((["name":"TestContainer"]))->move(room); + object obj = OBJ("TestRoom/TestContainer"); if(result == 1) pass = 1; - if(pass == 1) - OBJ("TestRoom/TestContainer")->query_attribute("OBJ_NAME"); + if(obj != 0) + obj->delete(); return pass; } @@ -32,8 +51,9 @@ int testcase3(object me,object _Server) object room = OBJ("/TestRoom"); int result =_Server->get_factory("Date")->execute((["name":"TestDate"]))->move(room); if(result == 1) pass = 1; - if(pass == 1) - OBJ("TestRoom/TestDate")->query_attribute("OBJ_NAME"); + object obj = OBJ("TestRoom/TestDate"); + if(obj != 0) + obj->delete(); return pass; } @@ -44,13 +64,14 @@ int testcase4(object me,object _Server) write("creating a new Document\n"); object room = OBJ("/TestRoom"); int result =_Server->get_factory("Document")->execute((["name":"TestDocument"]))->move(room); + object obj = OBJ("TestRoom/TestDocument"); if(result == 1) pass = 1; - if(pass == 1) - OBJ("TestRoom/TestDocument")->query_attribute("OBJ_NAME"); + if(obj != 0) + obj->delete(); return pass; } - +*/ int testcase5(object me,object _Server) { int pass=0; diff --git a/tests/coal-pike/create_object.pike b/tests/coal-pike/create_object.pike new file mode 100644 index 0000000..7f156b6 --- /dev/null +++ b/tests/coal-pike/create_object.pike @@ -0,0 +1,13 @@ +#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) + +int testcase(object me,object _Server,string type) +{ + int pass = 0; + object room = OBJ("/TestRoom"); + mixed result =catch{ _Server->get_factory(type)->execute((["name":"TestObj"+type]))->move(room); }; + if(result ==0)pass=1; + object ref = OBJ("/TestRoom/TestObj"); + if(ref!=0)ref->delete(); + return pass; + +} diff --git a/tests/coal-pike/move.pike b/tests/coal-pike/move.pike index a40a52f..773afad 100644 --- a/tests/coal-pike/move.pike +++ b/tests/coal-pike/move.pike @@ -48,7 +48,7 @@ int testcase2(object me,object _Server) write("Moving "+testObjects[i]->get_class()+ " to a non existential path: "); int ctr = foo[0](me,_Server,testObjects[i]); if(ctr == 0)success =0; - if(success == 1)write("passed\n"); + if(ctr == 1)write("passed\n"); else write("failed\n"); } diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index 95df5c8..12f3243 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -21,7 +21,9 @@ class Test{ } void destroy(){ me->move(OBJ("/home/steam")); - OBJ("/TestRoom")->delete(); + object obj = OBJ("/TestRoom"); + if(obj!=0) + obj->delete(); } void init(){ string host = "127.0.0.1"; @@ -60,6 +62,6 @@ class Test{ int main(){ Test move = Test("move",4); move->run(); - Test create = Test("create",5); + Test create = Test("create",2); create->run(); } From 96e9aea2b8a5292b42fbba66a618af696d3dc4bd Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Tue, 19 Jul 2016 18:44:48 +0530 Subject: [PATCH 15/17] Added support for testing creation of user and groups --- tests/coal-pike/create.pike | 61 ++---------------------------- tests/coal-pike/create_object.pike | 1 + 2 files changed, 4 insertions(+), 58 deletions(-) diff --git a/tests/coal-pike/create.pike b/tests/coal-pike/create.pike index e6bdb6a..0529170 100644 --- a/tests/coal-pike/create.pike +++ b/tests/coal-pike/create.pike @@ -5,74 +5,18 @@ int testcase1(object me,object _Server) object code = ((program)"create_object.pike")(); array(function) foo = values(code); int success = 1; - array(string) testClass = ({"Container","Document","Room"}); + array(string) testClass = ({"Container","Document","Room","Exit","User","Group"}); for(int i =0;iget_factory("Calendar")->execute((["name":"TestCalendar"]))->move(room); - if(result == 1) pass = 1; - object obj = OBJ("TestRoom/TestCalendar"); - if(obj!=0) - obj->delete(); - return pass; -} - int testcase2(object me,object _Server) -{ - int pass = 0; - write("creating a new Container\n"); - object room = OBJ("/TestRoom"); - int result =_Server->get_factory("Container")->execute((["name":"TestContainer"]))->move(room); - object obj = OBJ("TestRoom/TestContainer"); - if(result == 1) pass = 1; - if(obj != 0) - obj->delete(); - return pass; - -} - -int testcase3(object me,object _Server) -{ - int pass = 0; - write("creating a new Date\n"); - object room = OBJ("/TestRoom"); - int result =_Server->get_factory("Date")->execute((["name":"TestDate"]))->move(room); - if(result == 1) pass = 1; - object obj = OBJ("TestRoom/TestDate"); - if(obj != 0) - obj->delete(); - return pass; - -} - -int testcase4(object me,object _Server) -{ - int pass = 0; - write("creating a new Document\n"); - object room = OBJ("/TestRoom"); - int result =_Server->get_factory("Document")->execute((["name":"TestDocument"]))->move(room); - object obj = OBJ("TestRoom/TestDocument"); - if(result == 1) pass = 1; - if(obj != 0) - obj->delete(); - return pass; - -} -*/ -int testcase5(object me,object _Server) { int pass=0; write("Creating a class that does not exists\n"); @@ -81,3 +25,4 @@ int testcase5(object me,object _Server) return pass; } + diff --git a/tests/coal-pike/create_object.pike b/tests/coal-pike/create_object.pike index 7f156b6..70f9c7c 100644 --- a/tests/coal-pike/create_object.pike +++ b/tests/coal-pike/create_object.pike @@ -6,6 +6,7 @@ int testcase(object me,object _Server,string type) object room = OBJ("/TestRoom"); mixed result =catch{ _Server->get_factory(type)->execute((["name":"TestObj"+type]))->move(room); }; if(result ==0)pass=1; + else if((type=="User"||type=="Group")&& result!=0)pass=1; object ref = OBJ("/TestRoom/TestObj"); if(ref!=0)ref->delete(); return pass; From d3ff720b77929bf745b99ddb761251deb05a2414 Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Tue, 19 Jul 2016 19:59:36 +0530 Subject: [PATCH 16/17] Added cases for creating valid user and group --- tests/coal-pike/create.pike | 18 ++++++++++++++++-- tests/coal-pike/create_object.pike | 4 ++-- tests/coal-pike/test.pike | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/coal-pike/create.pike b/tests/coal-pike/create.pike index 0529170..477c23f 100644 --- a/tests/coal-pike/create.pike +++ b/tests/coal-pike/create.pike @@ -1,6 +1,6 @@ #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) -int testcase1(object me,object _Server) +int generalCreate(object me,object _Server) { object code = ((program)"create_object.pike")(); array(function) foo = values(code); @@ -16,7 +16,7 @@ int testcase1(object me,object _Server) return success; } -int testcase2(object me,object _Server) +int invalidClass(object me,object _Server) { int pass=0; write("Creating a class that does not exists\n"); @@ -25,4 +25,18 @@ int testcase2(object me,object _Server) return pass; } +int createUser(object me,object _Server) +{ + int pass = 0; + write("Creating a new user: "); + mixed result = catch{_Server->get_factory("User")->execute((["name":"testUser1","pw":"password","email":"user@steam.com"])); }; + if(result ==0)pass=1; + if(pass == 1) + { + write("passed\n"); + _Server->get_module("users")->get_user("testUser1")->delete(); + } + else write("failed\n"); + return pass; +} diff --git a/tests/coal-pike/create_object.pike b/tests/coal-pike/create_object.pike index 70f9c7c..6fa7bc2 100644 --- a/tests/coal-pike/create_object.pike +++ b/tests/coal-pike/create_object.pike @@ -6,8 +6,8 @@ int testcase(object me,object _Server,string type) object room = OBJ("/TestRoom"); mixed result =catch{ _Server->get_factory(type)->execute((["name":"TestObj"+type]))->move(room); }; if(result ==0)pass=1; - else if((type=="User"||type=="Group")&& result!=0)pass=1; - object ref = OBJ("/TestRoom/TestObj"); + else if((type=="User")&& result!=0)pass=1; + object ref = OBJ("/TestRoom/TestObj"+type); if(ref!=0)ref->delete(); return pass; diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index 12f3243..5b07c53 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -62,6 +62,6 @@ class Test{ int main(){ Test move = Test("move",4); move->run(); - Test create = Test("create",2); + Test create = Test("create",3); create->run(); } From 0973900da30044886771f4de8e4428c7a290268b Mon Sep 17 00:00:00 2001 From: Siddhant085 Date: Thu, 21 Jul 2016 16:52:33 +0530 Subject: [PATCH 17/17] Added the test case for calls to get_environment --- tests/coal-pike/getEnv.pike | 14 ++++++++++++++ tests/coal-pike/test.pike | 2 ++ 2 files changed, 16 insertions(+) create mode 100644 tests/coal-pike/getEnv.pike diff --git a/tests/coal-pike/getEnv.pike b/tests/coal-pike/getEnv.pike new file mode 100644 index 0000000..4714234 --- /dev/null +++ b/tests/coal-pike/getEnv.pike @@ -0,0 +1,14 @@ +#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o) + +int callingFunction(object me,object _Server) +{ + object parent = OBJ("/TestRoom"); + _Server->get_factory("Room")->execute((["name":"getEnv"]))->move(parent); + object obj = OBJ("/TestRoom/getEnv"); + int pass = 0; + write("Calling get_environment: "); + if(parent==obj->get_environment()) pass=1; + if(pass == 1) write("passed\n"); + else write("failed\n"); + return pass; +} diff --git a/tests/coal-pike/test.pike b/tests/coal-pike/test.pike index 5b07c53..84d68a0 100644 --- a/tests/coal-pike/test.pike +++ b/tests/coal-pike/test.pike @@ -64,4 +64,6 @@ int main(){ move->run(); Test create = Test("create",3); create->run(); + Test getEnv = Test("getEnv",1); + getEnv->run(); }