convert all tests to use epicsUnitTest
This commit is contained in:
@@ -14,87 +14,87 @@
|
||||
#include <stdio.h>
|
||||
#include <pv/bitSet.h>
|
||||
|
||||
#include <epicsAssert.h>
|
||||
#include <epicsExit.h>
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
using namespace epics::pvData;
|
||||
|
||||
void testGetSetClearFlip(FILE *fd) {
|
||||
fprintf(fd,"testGetSetClearFlip... ");
|
||||
static void testGetSetClearFlip()
|
||||
{
|
||||
printf("testGetSetClearFlip... ");
|
||||
|
||||
// empty
|
||||
BitSet* b1 = new BitSet();
|
||||
assert(b1->isEmpty());
|
||||
assert(b1->cardinality() == 0);
|
||||
testOk1(b1->isEmpty());
|
||||
testOk1(b1->cardinality() == 0);
|
||||
// to string check
|
||||
std::string str; b1->toString(&str);
|
||||
assert(str == "{}");
|
||||
testOk1(str == "{}");
|
||||
|
||||
// one
|
||||
b1->set(3);
|
||||
assert(b1->get(3));
|
||||
assert(!b1->isEmpty());
|
||||
assert(b1->cardinality() == 1);
|
||||
testOk1(b1->get(3));
|
||||
testOk1(!b1->isEmpty());
|
||||
testOk1(b1->cardinality() == 1);
|
||||
// to string check
|
||||
str.clear(); b1->toString(&str);
|
||||
assert(str == "{3}");
|
||||
testOk1(str == "{3}");
|
||||
|
||||
// grow
|
||||
b1->set(66);
|
||||
b1->set(67);
|
||||
b1->set(68);
|
||||
assert(b1->cardinality() == 4);
|
||||
testOk1(b1->cardinality() == 4);
|
||||
str.clear(); b1->toString(&str);
|
||||
assert(str == "{3, 66, 67, 68}");
|
||||
testOk1(str == "{3, 66, 67, 68}");
|
||||
|
||||
// clear one
|
||||
b1->clear(67);
|
||||
assert(b1->cardinality() == 3);
|
||||
testOk1(b1->cardinality() == 3);
|
||||
str.clear(); b1->toString(&str);
|
||||
assert(str == "{3, 66, 68}");
|
||||
testOk1(str == "{3, 66, 68}");
|
||||
|
||||
// flip
|
||||
b1->flip(66);
|
||||
b1->flip(130);
|
||||
assert(b1->cardinality() == 3);
|
||||
testOk1(b1->cardinality() == 3);
|
||||
str.clear(); b1->toString(&str);
|
||||
assert(str == "{3, 68, 130}");
|
||||
testOk1(str == "{3, 68, 130}");
|
||||
|
||||
// flip
|
||||
b1->set(130, false);
|
||||
b1->set(4, true);
|
||||
assert(b1->cardinality() == 3);
|
||||
testOk1(b1->cardinality() == 3);
|
||||
str.clear(); b1->toString(&str);
|
||||
assert(str == "{3, 4, 68}");
|
||||
testOk1(str == "{3, 4, 68}");
|
||||
|
||||
// clear all
|
||||
b1->clear();
|
||||
assert(b1->isEmpty());
|
||||
assert(b1->cardinality() == 0);
|
||||
testOk1(b1->isEmpty());
|
||||
testOk1(b1->cardinality() == 0);
|
||||
str.clear(); b1->toString(&str);
|
||||
assert(str == "{}");
|
||||
testOk1(str == "{}");
|
||||
|
||||
delete b1;
|
||||
fprintf(fd,"PASSED\n");
|
||||
|
||||
}
|
||||
|
||||
void testOperators(FILE *fd) {
|
||||
fprintf(fd,"testOperators... ");
|
||||
static void testOperators()
|
||||
{
|
||||
printf("testOperators... ");
|
||||
|
||||
BitSet b1;
|
||||
assert(b1 == b1);
|
||||
testOk1(b1 == b1);
|
||||
BitSet b2;
|
||||
assert(b1 == b2);
|
||||
testOk1(b1 == b2);
|
||||
|
||||
b1.set(1);
|
||||
assert(!(b1 == b2));
|
||||
testOk1(!(b1 == b2));
|
||||
|
||||
// different internal length, but the same
|
||||
b2.set(100);
|
||||
b2.set(1);
|
||||
b2.flip(100);
|
||||
assert(b1 == b2);
|
||||
testOk1(b1 == b2);
|
||||
|
||||
// OR test
|
||||
b2.set(65);
|
||||
@@ -102,32 +102,32 @@ void testOperators(FILE *fd) {
|
||||
b2.set(105);
|
||||
b1 |= b2;
|
||||
std::string str; b1.toString(&str);
|
||||
assert(str == "{1, 65, 105, 106}");
|
||||
testOk1(str == "{1, 65, 105, 106}");
|
||||
b1.clear();
|
||||
b1 |= b2;
|
||||
str.clear(); b1.toString(&str);
|
||||
assert(str == "{1, 65, 105, 106}");
|
||||
testOk1(str == "{1, 65, 105, 106}");
|
||||
|
||||
// AND test
|
||||
b1.set(128);
|
||||
b1 &= b2;
|
||||
assert(b1 == b2);
|
||||
testOk1(b1 == b2);
|
||||
|
||||
// XOR test
|
||||
b1.set(128);
|
||||
b1 ^= b2;
|
||||
assert(b1.cardinality() == 1 && b1.get(128) == true);
|
||||
testOk1((b1.cardinality() == 1 && b1.get(128) == true));
|
||||
b1.clear();
|
||||
b2.clear();
|
||||
b1.set(1);
|
||||
b2.set(256);
|
||||
b1 ^= b2;
|
||||
assert(b1.cardinality() == 2 && b1.get(1) == true && b1.get(256) == true);
|
||||
testOk1((b1.cardinality() == 2 && b1.get(1) == true && b1.get(256) == true));
|
||||
|
||||
|
||||
// assign
|
||||
b1 = b2;
|
||||
assert(b1 == b2);
|
||||
testOk1(b1 == b2);
|
||||
|
||||
// or_and
|
||||
b1.clear(); b1.set(2);
|
||||
@@ -135,23 +135,15 @@ void testOperators(FILE *fd) {
|
||||
BitSet b3; b3.set(128); b3.set(520);
|
||||
b1.or_and(b2, b3);
|
||||
str.clear(); b1.toString(&str);
|
||||
assert(str == "{2, 128}");
|
||||
|
||||
fprintf(fd,"PASSED\n");
|
||||
|
||||
testOk1(str == "{2, 128}");
|
||||
}
|
||||
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
MAIN(testBitSet)
|
||||
{
|
||||
char *fileName = 0;
|
||||
if(argc>1) fileName = argv[1];
|
||||
FILE * fd = stdout;
|
||||
if(fileName!=0 && fileName[0]!=0) {
|
||||
fd = fopen(fileName,"w+");
|
||||
}
|
||||
testGetSetClearFlip(fd);
|
||||
testOperators(fd);
|
||||
return(0);
|
||||
testPlan(29);
|
||||
testGetSetClearFlip();
|
||||
testOperators();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user