Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue#111: Add tests for moving user or room inside a container #112

Open
wants to merge 9 commits into
base: societyserver-devel
Choose a base branch
from
22 changes: 22 additions & 0 deletions tests/coal-m4/Readme
Original file line number Diff line number Diff line change
@@ -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 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.


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 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.
45 changes: 45 additions & 0 deletions tests/coal-m4/test
Original file line number Diff line number Diff line change
@@ -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; }
....
38 changes: 38 additions & 0 deletions tests/coal-m4/test.in
Original file line number Diff line number Diff line change
@@ -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)

Binary file added tests/coal-pike/.move.pike.swp
Binary file not shown.
2 changes: 2 additions & 0 deletions tests/coal-pike/Readme
Original file line number Diff line number Diff line change
@@ -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.
50 changes: 50 additions & 0 deletions tests/coal-pike/move.pike
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o)

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");
if(result == 0)pass=1;
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");
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;
}
63 changes: 63 additions & 0 deletions tests/coal-pike/test.pike
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o)

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 destroy(){
me->move(OBJ("/home/steam"));
OBJ("/TestRoom")->delete();
}
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");
_Server->get_factory("Room")->execute((["name":"TestRoom"]))->move(OBJ("/"));
me->move(OBJ("/TestRoom"));
}
int run(){
string n = name +".pike";
object code = ((program)n)();
array(function) foo = values(code);
int success = 0;
for(int i=0;i< sizeof(cases);i++){
if(foo[i](me,_Server)==1){
success+=1;
}

}
write("success: "+success+"\nfails: "+(sizeof(cases)-success)+"\n");
}
}



int main(){
Test move = Test("move",4);
move->run();
}
37 changes: 25 additions & 12 deletions tools/steam-shell.pike
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -622,7 +626,7 @@ int look(string|void str)
write("---------------\n");
list("rooms");
write("---------------\n");
return 0;
return 1;
}

int take(string name)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -757,6 +767,7 @@ int inventory()
display("containers", conts);
display("files", files);
display("other files", others);
return 1;
}

int editfile(string filename)
Expand All @@ -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()
Expand Down