Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8ca0f01
fixed the return values of functions in steam-shell
Siddhant085 Jul 6, 2016
809eff5
first attempt to establish a framework for testing
Siddhant085 Jul 7, 2016
9016195
structural changes and added readme
Siddhant085 Jul 7, 2016
efddba4
made the pike tests more modular
Siddhant085 Jul 7, 2016
a318f5d
structural changes to testing framework using pike scripts
Siddhant085 Jul 7, 2016
e4e02c0
removed swap files
Siddhant085 Jul 7, 2016
eebdb5d
adding second test case
Siddhant085 Jul 9, 2016
271fb16
Display the number of failed and passed cases
Siddhant085 Jul 12, 2016
8ddfb75
Added test cases for moving user and room inside container.
Siddhant085 Jul 13, 2016
deb8d59
Generalized the test case to pass any object to a test
Siddhant085 Jul 14, 2016
8981b85
Added checks to avoid calling functions on non objects
Siddhant085 Jul 17, 2016
14a952a
Added the test cases for create
Siddhant085 Jul 18, 2016
d4de0f2
Added function calls for create in the framework
Siddhant085 Jul 18, 2016
bb1d4b5
Generalized the test case for create and combined the create and move…
Siddhant085 Jul 18, 2016
96e9aea
Added support for testing creation of user and groups
Siddhant085 Jul 19, 2016
d3ff720
Added cases for creating valid user and group
Siddhant085 Jul 19, 2016
0973900
Added the test case for calls to get_environment
Siddhant085 Jul 21, 2016
ec94508
Added general case argument to all test cases
Siddhant085 Jul 22, 2016
17f26e5
Added test case for user permission
Siddhant085 Jul 23, 2016
0a6131c
Added documentation and minor code improvements
Siddhant085 Aug 11, 2016
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.
45 changes: 45 additions & 0 deletions tests/coal-pike/create.pike
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o)

// Generalized test case to create various types of objects
int generalCreate(object me,object _Server,object...args)
{
object code = ((program)"create_object.pike")(); //importing the file containing the generalized case
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;
}

//Creating object of a class that does not exists
int invalidClass(object me,object _Server,object...args)
{
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;
}

//Creating user
int createUser(object me,object _Server,object...args)
{
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;
}

15 changes: 15 additions & 0 deletions tests/coal-pike/create_object.pike
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o)

//generalized test case for creating objects
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;

}
15 changes: 15 additions & 0 deletions tests/coal-pike/getEnv.pike
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o)

// Tests the function getEnvironment
int callingFunction(object me,object _Server,object...args)
{
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;
}
85 changes: 85 additions & 0 deletions tests/coal-pike/move.pike
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o)

//Move the current user to a room
int testcase1(object me,object _Server,object...args)
{
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;
}

// Generalized test case to move objects to non exestential location
//Currently test Room and User.
int testcase2(object me,object _Server,object...args)
{
int pass = 1;
object code = ((program)"move_nonexistential.pike")(); //imports the file containing the generalized test case
array(function) foo = values(code);
_Server->get_factory("Room")->execute((["name":"move2Room"]))->move(OBJ("/TestRoom")); //Test Room to move
_Server->get_factory("User")->execute((["name":"move2User","pw":"testpass","email":"abc@example.com"])); //Test User to move
_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;
}

//Moving user into a container
int testcase3(object me,object _Server,object...args)
{
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;
}

//Moving a room inside a container
int testcase4(object me,object _Server,object...args)
{
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;
}
10 changes: 10 additions & 0 deletions tests/coal-pike/move_nonexistential.pike
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o)

// Generalized test case to move an object to a non exestential location
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;
}
90 changes: 90 additions & 0 deletions tests/coal-pike/test.pike
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o)

class Testcase{
string status;
object code;
int run(){

}
}

class Test{
string name; //Name of the the test case set

//variables used to establish connection and interact with the server
object _Server;
object me;
object conn;


//array(Testcase) cases;
int cases;
int failures;

//Initialize the test case name and the number of test cases and call the init method
void create(string name,int totalCases){
this.name=name;
cases = totalCases;
init();
}

//Delete the objects created by the test suite and exit
void destroy(){
me->move(OBJ("/home/steam"));
object obj = OBJ("/TestRoom");
if(obj!=0)
obj->delete();
// write("===============================\n");
}

//Establist a connection to the server and initialize the server variables
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/");
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"));
write("===============================\n");
}

//Fetch the file containing the code for the test.
//Get all the test cases and execute them one by one
//record the status of the test
int run(){
string n = name +".pike";
object code = ((program)n)(); // Fetch the code for test cases as an object
array(function) foo = values(code);
int success = 0;
for(int i=0;i< cases;i++){ //loop through the cases and execute them one by one
if(foo[i](me,_Server,conn)==1){
success+=1;
}

}
write("success: "+success+"\nfails: "+(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();

Test perm = Test("userPermission",1);
perm->run();
}
Loading