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#122: Add tests for call to get_environment #123

Open
wants to merge 17 commits into
base: societyserver-devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

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

int generalCreate(object me,object _Server)
{
object code = ((program)"create_object.pike")();
array(function) foo = values(code);
int success = 1;
array(string) testClass = ({"Container","Document","Room","Exit","User","Group"});
for(int i =0;i<sizeof(testClass);i++){
write("Creating a "+testClass[i]+": ");
int ctr = foo[0](me,_Server,testClass[i]);
if(ctr == 0)success=0;
if(ctr==1)write("passed\n");
else write("failed\n");
}
return success;
}

int invalidClass(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;
}

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":"[email protected]"])); };
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;
}

14 changes: 14 additions & 0 deletions tests/coal-pike/create_object.pike
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#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;
else if((type=="User")&& result!=0)pass=1;
object ref = OBJ("/TestRoom/TestObj"+type);
if(ref!=0)ref->delete();
return pass;

}
14 changes: 14 additions & 0 deletions tests/coal-pike/getEnv.pike
Original file line number Diff line number Diff line change
@@ -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;
}
93 changes: 93 additions & 0 deletions tests/coal-pike/move.pike
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#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"));
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"));
if(obj!=0)obj->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.: ");
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"));
_Server->get_factory("User")->execute((["name":"move2User","pw":"testpass","email":"[email protected]"]));
_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;i<sizeof(testObjects);i++){
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(ctr == 1)write("passed\n");
else write("failed\n");
}

if(success==0)pass=0;
if(testObjects[1]!=0)
testObjects[1]->delete();
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"));
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");
if(obj!=0)obj->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: ");
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;
}
9 changes: 9 additions & 0 deletions tests/coal-pike/move_nonexistential.pike
Original file line number Diff line number Diff line change
@@ -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;
}
69 changes: 69 additions & 0 deletions tests/coal-pike/test.pike
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#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"));
object obj = OBJ("/TestRoom");
if(obj!=0)
obj->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();
Test create = Test("create",3);
create->run();
Test getEnv = Test("getEnv",1);
getEnv->run();
}
Loading