Commit 1452f722 authored by LEGEARD Luc's avatar LEGEARD Luc
Browse files

First Unit Test , see MFMtest.exe -test or make test

parent 05577af2
......@@ -2,6 +2,12 @@
cmake_minimum_required(VERSION 2.8.12)
project(MFMlib)
# Prepare test sets
include ( CTest )
ENABLE_TESTING()
ADD_TEST ( MFMlibrary MFMtest.exe "-test -v=6")
if(DEBUG)
set(CMAKE_BUILD_TYPE Debug)
message(STATUS "CMake in DEBUG mode")
......@@ -10,8 +16,7 @@ else()
message(STATUS "CMake in RELEASE mode")
endif()
#set(CMAKE_BUILD_TYPE Release)
#set(CMAKE_BUILD_TYPE Debug)
macro(DATE RESULT)
if(UNIX)
......
......@@ -130,6 +130,7 @@ void MFMBasicFrame::MFM_fill_header(int unitBlock_size, int dataSource,
SetHeaderSize(headerSize);
fHeaderSize = headerSize*unitBlock_size;
SetItemSize(itemSize);
SetNbItem(nItems);
}
......@@ -222,3 +223,31 @@ void MFMBasicFrame::SetHeaderSizeFromFrameData(){
fHeaderSize = (int)tmp*fSizeOfUnitBlock;
}
//_______________________________________________________________________________
bool MFMBasicFrame::IsSame(MFMBasicFrame* testframe,int verbose){
// test if testframe have same attibuts
string display("");
stringstream ss("");
bool test= true;
bool testloc= true;
int i=0;
ss << " Test for "<< MyClassName()<<" :" ;
testframe->MFMBasicFrame::SetAttributs();
MFMBasicFrame::SetAttributs();
test= MFMCommonFrame::IsSame((MFMCommonFrame*)testframe,verbose);
testloc = ( GetNbItems() == testframe->GetNbItems());
ss << testloc ; test = test and testloc;
testloc = ( GetItemSize() == testframe-> GetItemSize());
ss << testloc ; test = test and testloc;
display = ss.str();
if ((verbose>5) )
cout << display <<" (NbI ItS)" <<endl;
return test;
}
//_______________________________________________________________________________
......@@ -31,6 +31,7 @@ MFMBasicFrame(int unitBlock_size, int dataSource,
int frameType, int revision, int frameSize,int headerSize,
int itemSize, int nItems);
virtual ~MFMBasicFrame();
char* MyClassName()const{ return (char*)"MFMBasicFrame";};
int GetItemSize(int type=0) const;
virtual int GetNbItems() const;
......@@ -60,6 +61,8 @@ virtual const char * GetTypeText()const {return (const char *)MFM_BASIC_TYPE_TX
virtual int GetDefinedUnitBlockSize()const {return MFM_UNIT_BLOCK_DEFAULT_SIZE;};
virtual int GetDefinedHeaderSize()const {return MFM_BASIC_DEFAULT_HEADERSIZE;};
virtual int GetDefinedNbItems()const{ return MFM_DEFAULT_NB_ITEMS;};
virtual bool IsSame(MFMBasicFrame* testframe,int verbose);
};
#pragma pack(pop) // free aligment
#endif
......@@ -306,6 +306,7 @@ void MFMCommonFrame::SetFrameSizeFromFrameData() {
//_______________________________________________________________________________
void SetHeaderSizeFromFrameData(){}
// have to be overloaded
//_______________________________________________________________________________
void MFMCommonFrame::SetMetaType(int unitBlock_size, bool isablob) {
......@@ -720,7 +721,7 @@ int MFMCommonFrame::ReadInFile(int *fLun, char** vector, int * vectorsize) {
int framesize = 0;
char* vectornew = NULL;
static long long int sumread =0;
int sizetoread = MFM_BLOB_HEADER_SIZE; // =8 count = read(fLun, (void*) vector, minsizeheader);
int sizetoread = MFM_BLOB_HEADER_SIZE; // =8
count = read(*fLun, (void*) (*vector), sizetoread);
if (count <= 0) {
cout << endl<<" ** End of read file **\n";
......@@ -730,7 +731,7 @@ int MFMCommonFrame::ReadInFile(int *fLun, char** vector, int * vectorsize) {
cout << " Error in read file\n";
return count;
}
SetAttributs((*vector));
MFMCommonFrame::SetAttributs((*vector));
framesize = GetFrameSize();
if (framesize > 1000000000)
fError.TreatError(2, framesize, "Crazy Frame size > 1000000000");
......@@ -1302,27 +1303,42 @@ for (i=0; i<size; i++) {
return test;
}
//_______________________________________________________________________________
bool MFMCommonFrame::IsSame(MFMCommonFrame* testframe){
bool MFMCommonFrame::IsSame(MFMCommonFrame* testframe,int verbose){
// test if testframe have same attibuts
string display("");
stringstream ss("");
bool test= true;
int i=0;
char* pttest;
char* thispttest;
testframe->SetAttributs();
int size = testframe->GetFrameSize();
SetAttributs();
test = test and ( GetFrameSize() == testframe->GetFrameSize());
test = test and ( GetHeaderSize() == testframe->GetHeaderSize());
test = test and ( GetBlobNess() == testframe->GetBlobNess());
test = test and ( GetMetaType() == testframe->GetMetaType());
test = test and ( GetFrameEndianness() == testframe->GetFrameEndianness());
test = test and ( GetDataSource() == testframe->GetDataSource());
//test = test and ( GetUnitBlockSize() == testframe->GetUnitBlockSize());
test = test and ( GetRevision() == testframe->GetRevision());
test = test and ( GetEventNumberFromCommonFrameData() == testframe->GetEventNumberFromCommonFrameData());
test = test and ( GetTimeStampFromCommonFrameData() == testframe->GetTimeStampFromCommonFrameData());
bool testloc= true;
int i=0;
ss << " Test for "<< MyClassName()<<" :" ;
testframe-> MFMCommonFrame::SetAttributs();
MFMCommonFrame::SetAttributs();
testloc = ( GetFrameSize() == testframe->GetFrameSize());
ss << testloc ; test = test and testloc;
testloc = ( GetHeaderSize() == testframe->GetHeaderSize());
ss << testloc ; test = test and testloc;
testloc = ( GetBlobNess() == testframe->GetBlobNess());
ss << testloc ; test = test and testloc;
testloc = ( GetMetaType() == testframe->GetMetaType());
ss << testloc ; test = test and testloc;
testloc = ( GetFrameEndianness() == testframe->GetFrameEndianness());
ss << testloc ; test = test and testloc;
testloc = ( GetDataSource() == testframe->GetDataSource());
ss << testloc ; test = test and testloc;
testloc = ( GetUnitBlockSize() == testframe->GetUnitBlockSize());
ss << testloc ; test = test and testloc;
testloc = ( GetRevision() == testframe->GetRevision());
ss << testloc ; test = test and testloc;
testloc = ( GetEventNumberFromCommonFrameData() == testframe->GetEventNumberFromCommonFrameData());
ss << testloc ; test = test and testloc;
testloc = ( GetTimeStampFromCommonFrameData() == testframe->GetTimeStampFromCommonFrameData());
ss << testloc ; test = test and testloc;
display = ss.str();
if ((verbose>5))
cout << display <<" (Si Hs Bl Me En So Un Re En Ts)" <<endl;
return test;
}
//_______________________________________________________________________________
......
......@@ -102,6 +102,7 @@ int fWantedFrameType; ///< Wanted Frame type in case of generation of fra
int fFrameSize; ///< Frame size
uint64_t fTimeStamp; //<Time Stamp
uint32_t fEventNumber; //<EventNumber
private :
mutable int fIncrement; ///< memory of incrementation in case of dump.
int fBufferSize; ///< available buffer size, it can be higher than frame size.
......@@ -127,6 +128,7 @@ MFMCommonFrame(int unitBlock_size, int dataSource,
int frameType, int revision, int frameSize);
MFMCommonFrame(MFMCommonFrame* frame);
virtual ~MFMCommonFrame();
char* MyClassName()const{ return (char*)"MFMCommonFrame";};
virtual void Init();
virtual string WhichFrame(uint16_t type =0) const;
void SetMetaType(int unitBlock_size,bool isablob=false);
......@@ -162,6 +164,7 @@ MFMCommonFrame(MFMCommonFrame* frame);
int GetHeaderSize()const;
int GetBufferSize()const;
int GetFrameSize()const;
int GetUnitBlockSize() const {return fSizeOfUnitBlock;}
void SetFrameTypeFromFrameData();
void SetFrameSizeFromFrameData();
void SetTimeStampFromFrameData(){};
......@@ -183,7 +186,7 @@ MFMCommonFrame(MFMCommonFrame* frame);
virtual string GetHeaderDisplay(char* infotext=NULL)const;
void HeaderDisplay(char* infotext=NULL) const ;
virtual bool RawEqual(MFMCommonFrame* testframe)const;
virtual bool IsSame(MFMCommonFrame* testframe);
virtual bool IsSame(MFMCommonFrame* testframe,int verbose);
virtual void MFM_make_header(int unitBlock_size, int dataSource,
int frameType, int revision, int frameSize,bool blob=false);
......
......@@ -246,5 +246,31 @@ string MFMNumExoFrame::GetHeaderDisplay(char* infotext) const{
}
//________________________________________________________________________________
bool MFMNumExoFrame::IsSame(MFMNumExoFrame* testframe,int verbose){
// test if testframe have same attibut values
string display("");
stringstream ss("");
bool test= true;
bool testloc= true;
int i=0;
ss << " Test for "<< MyClassName()<<" :" ;
testframe->MFMNumExoFrame::SetAttributs();
MFMNumExoFrame::SetAttributs();
test= MFMCommonFrame::IsSame((MFMCommonFrame*)testframe,verbose);
ss << testloc ; test = test and testloc;
testloc = ( GetCristalId() == testframe->GetCristalId());
ss << testloc ; test = test and testloc;
testloc = ( GetChannelId() == testframe->GetChannelId());
ss << testloc ; test = test and testloc;
testloc = ( GetBoardId() == testframe->GetBoardId());
ss << testloc ; test = test and testloc;
display = ss.str();
if ((verbose>5))
cout << display <<" (Cristal Channel Board)" <<endl;
return test;
}
......@@ -57,6 +57,7 @@ MFMNumExoFrame();
MFMNumExoFrame(int unitBlock_size, int dataSource,
int frameType, int revision, int frameSize,int headerSize);
virtual ~MFMNumExoFrame();
char* MyClassName()const{ return (char*)"MFMNumExoFrame";};
virtual void SetAttributs(void * pt =NULL);
void SetUserDataPointer();
void SetTimeStampFromFrameData();
......@@ -86,7 +87,7 @@ virtual bool VerifyChecksum()const;
virtual void InitStat();
virtual void FillStat();
virtual string GetStat(string info)const;
virtual bool IsSame(MFMNumExoFrame* testframe,int verbose);
};
#pragma pack(pop) // free aligment
......
......@@ -292,4 +292,36 @@ string MFMReaGenericFrame::GetDumpData(char mode, bool nozero) const {
return display;
}
//_______________________________________________________________________________
bool MFMReaGenericFrame::IsSame(MFMReaGenericFrame* testframe,int verbose){
// test if testframe have same attibut values
string display("");
stringstream ss("");
bool test= true;
bool testloc= true;
int i=0;
ss << " Test for "<< MyClassName()<<" :" ;
testframe->MFMReaGenericFrame::SetAttributs();
MFMReaGenericFrame::SetAttributs();
test= MFMNumExoFrame::IsSame((MFMNumExoFrame*)testframe,verbose);
testloc = ( GetStatus(0) == testframe->GetStatus(0));
ss << testloc ; test = test and testloc;
testloc = ( GetStatus(1) == testframe->GetStatus(1));
ss << testloc ; test = test and testloc;
testloc = ( GetEnergy() == testframe->GetEnergy());
ss << testloc ; test = test and testloc;
testloc = ( GetTime() == testframe->GetTime());
ss << testloc ; test = test and testloc;
testloc = ( GetChecksum()== testframe->GetChecksum());
ss << testloc ; test = test and testloc;
display = ss.str();
if ((verbose>5))
cout << display <<" (St1 St2 Typ Ener Time Check)" <<endl;
return test;
}
//_______________________________________________________________________________
......@@ -60,6 +60,7 @@ class MFMReaGenericFrame : public MFMNumExoFrame
MFMReaGenericFrame();
~MFMReaGenericFrame();
char* MyClassName()const{ return (char*)"MFMReaGenericFrame";};
void SetStatus(int i, uint16_t status);
uint16_t GetStatus(int i)const;
void SetTypeTns(enum ReaTnsType type);
......@@ -77,7 +78,7 @@ class MFMReaGenericFrame : public MFMNumExoFrame
string GetDumpData(char mode, bool nozero) const;
void SetTabValues();
void ResetTabValues();
bool IsSame(MFMReaGenericFrame* testframe,int verbose);
};
#pragma pack(pop) // free aligment
#endif
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment