Updated and added some tests.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2850 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Phipps 2003-02-27 04:40:34 +00:00
parent 8fb205f2b6
commit 7c9135c008
7 changed files with 270 additions and 10 deletions

View File

@ -11,4 +11,9 @@ BinCommand mmapTest1 : mmapTest1.C : root be libvm.so ;
BinCommand mmapTest2 : mmapTest2.C : root be libvm.so ;
BinCommand mmapTest3 : mmapTest3.C : root be libvm.so ;
BinCommand createAreaFails : createAreaFails.C : root be libvm.so ;
BinCommand freeAreaFails : freeAreaFails.C : root be libvm.so ;
BinCommand getAreaInfoFails : getAreaInfoFails.C : root be libvm.so ;
BinCommand getAreaByName : getAreaByName.C : root be libvm.so ;
BinCommand getAreaByAddress : getAreaByAddress.C : root be libvm.so ;
BinCommand resizeArea : resizeArea.C : root be libvm.so ;
BinCommand createAreaTestsGood : createAreaTestsGood.C : root be libvm.so ;

View File

@ -0,0 +1,40 @@
#include "vmInterface.h"
#include <stdio.h>
#include <unistd.h>
#include <mman.h>
#include <errno.h>
#include <string.h>
#include <OS.h>
vmInterface *vm;
int main(int argc,char **argv)
{
void *location;
char *testName;
int areaNumber;
location=NULL;
testName="vmInterface construction";
try { vm = new vmInterface (30); }
catch (const char *t) { error ("Exception thrown in %s! %s\n",testName,t); exit(1); }
try {
testName="delete_area on invalid area test";
if (vm->delete_area(999999)==B_OK)
error ("%s failed!\n",testName) ;
else
error ("%s passed!\n",testName);
testName="delete_area twice on same area test";
if (areaNumber=vm->createArea("sampleArea",1,&location)>=0) {
if (vm->delete_area(areaNumber)!=B_OK) error("%s:Initial free failed!\n",testName);
if (vm->delete_area(areaNumber)==B_OK)
error("%s:Second free succeeded!\n",testName);
else
error ("%s passed\n",testName);
}
}
catch (const char *t) { error ("Exception thrown in %s, while trying to run !\n",t,testName); }
return 0;
}

View File

@ -0,0 +1,53 @@
#include "vmInterface.h"
#include <stdio.h>
#include <unistd.h>
#include <mman.h>
#include <errno.h>
#include <string.h>
#include <OS.h>
vmInterface *vm;
int main(int argc,char **argv)
{
int areaNum,found;
char *testName;
void *foo;
testName="vmInterface construction";
try { vm = new vmInterface (30); }
catch (const char *t) { error ("Exception thrown in %s! %s\n",testName,t); exit(1); }
try {
testName="getAreaByAddress with NULL address test";
if (vm->getAreaByAddress(NULL)>=0)
error ("%s failed!\n",testName);
else
error ("%s passed!\n",testName);
if ((areaNum=vm->createArea("test",1,&foo))<0)
throw (testName);
testName="getAreaByAddress with out of bounds address test";
if (vm->getAreaByAddress((void *)(((long)foo)+100000))>=0)
error ("%s failed!\n",testName);
else
error ("%s passed!\n",testName);
testName="getAreaByAddress with existant area test";
if ((found=vm->getAreaByAddress((void *)(((long)foo)+2)))==areaNum)
error ("%s passed!\n",testName);
else
error ("%s failed! areaNum = %d, found = %d \n",testName,areaNum,found);
}
catch (const char *t) {
error ("Exception thrown! %s\n",t);
exit(1);
}
catch (...) {
error ("Unknown Exception thrown!\n");
exit(1);
}
return 0;
}

View File

@ -0,0 +1,53 @@
#include "vmInterface.h"
#include <stdio.h>
#include <unistd.h>
#include <mman.h>
#include <errno.h>
#include <string.h>
#include <OS.h>
vmInterface *vm;
int main(int argc,char **argv)
{
area_info ai;
char *testName;
void *foo;
testName="vmInterface construction";
try { vm = new vmInterface (30); }
catch (const char *t) { error ("Exception thrown in %s! %s\n",testName,t); exit(1); }
try {
testName="getAreaByName with NULL area test";
if (vm->getAreaByName(NULL)>=0)
error ("%s failed!\n",testName);
else
error ("%s passed!\n",testName);
testName="getAreaByName with unknown area name test";
if (vm->getAreaByName("MOO COW")>=0)
error ("%s failed!\n",testName);
else
error ("%s passed!\n",testName);
testName="getAreaByName with existant area test";
int areaNum,found;
if ((areaNum=vm->createArea("test",1,&foo))<0)
throw (testName);
if ((found=vm->getAreaByName("test"))==areaNum)
error ("%s passed!\n",testName);
else
error ("%s failed! areaNum = %d, found = %d \n",testName,areaNum,found);
}
catch (const char *t) {
error ("Exception thrown! %s\n",t);
exit(1);
}
catch (...) {
error ("Unknown Exception thrown!\n");
exit(1);
}
return 0;
}

View File

@ -0,0 +1,47 @@
#include "vmInterface.h"
#include <stdio.h>
#include <unistd.h>
#include <mman.h>
#include <errno.h>
#include <string.h>
#include <OS.h>
vmInterface *vm;
int main(int argc,char **argv)
{
area_info ai;
char *testName;
void *foo;
testName="vmInterface construction";
try { vm = new vmInterface (30); }
catch (const char *t) { error ("Exception thrown in %s! %s\n",testName,t); exit(1); }
try {
testName="getAreaInfo with non-existant areatest";
if (vm->getAreaInfo(999999,&ai)>=0)
error ("%s failed!\n",testName);
else
error ("%s passed!\n",testName);
int areaNum;
testName="getAreaInfo with NULL area_info areatest";
if (areaNum=vm->createArea("test",1,&foo)<0)
throw (testName);
if (vm->getAreaInfo(areaNum,&ai)>=0)
error ("%s failed!\n",testName);
else
error ("%s passed!\n",testName);
}
catch (const char *t) {
error ("Exception thrown! %s\n",t);
exit(1);
}
catch (...) {
error ("Unknown Exception thrown!\n");
exit(1);
}
return 0;
}

View File

@ -0,0 +1,68 @@
#include "vmInterface.h"
#include <stdio.h>
#include <unistd.h>
#include <mman.h>
#include <errno.h>
#include <string.h>
#include <OS.h>
vmInterface *vm;
int main(int argc,char **argv)
{
int areaNum;
char *testName;
void *foo;
unsigned long baseAddress;
testName="vmInterface construction";
try { vm = new vmInterface (30); }
catch (const char *t) { error ("Exception thrown in %s! %s\n",testName,t); exit(1); }
try {
testName="resizeArea with unknown area test";
if (vm->resizeArea(54,8192)>=0)
error ("%s failed!\n",testName);
else
error ("%s passed!\n",testName);
if ((areaNum=vm->createArea("test",1,&foo))<0)
throw (testName);
baseAddress=(unsigned long)foo;
testName="initial test sizes of area";
try {vm->setInt(baseAddress-1,25); error ("%s lower bounds test failed!\n",testName); } catch (char *t) {error ("%s lower bounds test passed!\n",testName);}
try {vm->setInt(baseAddress+8192,25); error ("%s upper bounds test failed!\n",testName);} catch (char *t) {error ("%s upper bounds test passed!\n",testName);}
testName="enlarging size of area";
if (vm->resizeArea(areaNum,16384)!=B_OK)
error ("%s failed!\n",testName);
else
error ("%s passed!\n",testName);
testName=" test enlarged sizes of area";
try {vm->setInt(baseAddress-1,25); error ("%s lower bounds test failed!\n",testName); } catch (char *t) {error ("%s lower bounds test passed!\n",testName);}
try {vm->setInt(baseAddress+8192,25); error ("%s middle bounds test passed!\n",testName);} catch (char *t) {error ("%s middle bounds test failed!\n",testName);}
try {vm->setInt(baseAddress+16385,25); error ("%s upper bounds test failed!\n",testName);} catch (char *t) {error ("%s upper bounds test passed!\n",testName);}
testName="reducing size of area";
if (vm->resizeArea(areaNum,4096)!=B_OK)
error ("%s failed!\n",testName);
else
error ("%s passed!\n",testName);
testName=" test enlarged sizes of area";
try {vm->setInt(baseAddress-1,25); error ("%s lower bounds test failed!\n",testName); } catch (char *t) {error ("%s lower bounds test passed!\n",testName);}
try {vm->setInt(baseAddress+4097,25); error ("%s upper bounds test failed!\n",testName);} catch (char *t) {error ("%s upper bounds test passed!\n",testName);}
}
catch (const char *t) {
error ("Exception thrown! %s\n",t);
exit(1);
}
catch (...) {
error ("Unknown Exception thrown!\n");
exit(1);
}
return 0;
}

View File

@ -4,26 +4,20 @@ createArea
- improve some of the successful tests.
freeArea
- on invalid area
- twice on same area
- successful tests
getAreaInfo
- on non-existant area
- with NULL pointer
- successful tests
getNextAreaInfo
- on first area
- on last area
getAreaByName
- with NULL
- with unknown name
- with valid name
- more successful tests
getAreaByAddress
- with good address
- with bad address
- with NULL address
- more successful tests
cloneArea
- invalid area to clone