Commit 5b68da5d authored by Andrea Bulgarelli's avatar Andrea Bulgarelli
Browse files

testpacketlib for InputPacketStreamFile unit test

parent ba6be2af
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
@@ -2,8 +2,8 @@
                          testpacketlib.h  -  description
                             -------------------
    begin                : Fri Feb 22 2002
    copyright            : (C) 2002 by Andrea Bulgarelli
    email                : bulgarelli@tesre.bo.cnr.it
    copyright            : (C) 2013 by Andrea Bulgarelli
    email                : bulgarelli@iasfbo.inaf.it
 ***************************************************************************/

/***************************************************************************
@@ -17,50 +17,28 @@

#ifndef TESTPACKETLIB_H
#define TESTPACKETLIB_H
#include "./packet/PacketLibDefinition.h"
#include "./packet/Utility.h"
#include "./packet/InputPacketStreamFile.h"
#include "./packet/FileStreamPointer.h"
#include "./packet/PacketExceptionFileFormat.h"
#include "PacketLibDefinition.h"
#include "Utility.h"
#include "InputPacketStreamFile.h"
#include "FileStreamPointer.h"
#include "PacketExceptionFileFormat.h"
#define OUTPUT 1

using namespace PacketLib;

/**
  *@author Andrea Bulgarelli
	\date $Date: 2003/09/03 11:53:30 $
	$Header: /home/repository/cvs/gtb/PacketLib/testpacketlib.h,v 1.1.1.1 2003/09/03 11:53:30 andrea Exp $
	$Id: testpacketlib.h,v 1.1.1.1 2003/09/03 11:53:30 andrea Exp $
	$Name:  $
	$Log: testpacketlib.h,v $
	Revision 1.1.1.1  2003/09/03 11:53:30  andrea
	The PacketLib

	Revision 1.4  2002/11/13 15:16:35  andrea
	PacketLib 1.2.1 (beta). See ChangeLog 4 November 2002
	
	Revision 1.3  2002/05/13 09:14:19  agile
	*** empty log message ***
	
	Revision 1.2  2002/05/13 09:13:22  agile
	*** empty log message ***
	
	\version $Revision: 1.1.1.1 $
	$Source: /home/repository/cvs/gtb/PacketLib/testpacketlib.h,v $
  */

class TestPacketLib {
public:
    TestPacketLib();
    ~TestPacketLib();

  /** Questa test suite consente di verificare file di test CAL-DFE-TE */

    bool TestSuiteType1(char* nameOfTestSuite, char* fileNameConfig, char** file);

private: // Private attributes
  /**  */

    InputPacketStreamFile* ips;
  /** Crea la struttura dello stream sulla quale effettare il test */
    char* initStructure(char* fileNameConfig);
    bool test(char* file);
    bool test2(char* file);

src/testpacketlib.cpp

0 → 100644
+156 −0
Original line number Diff line number Diff line
/***************************************************************************
                          testpacketlib.cpp  -  description
                             -------------------
    begin                : Fri Feb 22 2002
    copyright            : (C) 2013 by Andrea Bulgarelli
    email                : bulgarelli@iasbo.inaf.it
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "testpacketlib.h"



TestPacketLib::TestPacketLib() {
    ips = new InputPacketStreamFile();
}

TestPacketLib::~TestPacketLib() {
    delete ips;
}

char* TestPacketLib::initStructure(char* fileNameConfig) {
    try {

        ips->setFileNameConfig(fileNameConfig);
        ips->createStreamStructure();

        //delete this line
//	Packet* p = ips.getPacketType(1);
//  int dim = p->getDimension();


        return 0;
    }
    catch(PacketExceptionIO* e) {
        return (char*) e->geterror();
    }
    catch(PacketExceptionFileFormat* e) {
        return (char*) e->geterror();
    }


}


bool TestPacketLib::TestSuiteType1(char* nameOfTestSuite, char* fileNameConfig, char** file) {
    char* ret;
    bool ret2 = true;

    try {
        if(OUTPUT) cout << "--------------------------------------------------" << endl;
        if(OUTPUT) cout << "START OF " << nameOfTestSuite << " with the file " << fileNameConfig << endl;
        ret=initStructure(fileNameConfig);
        if(ret != 0) {
            cout << ret;
            return false;
        }
        if(OUTPUT) cout << "OK: Stream structure created" << endl;
        //for(int j=0; j<3; j++) {
        for(int i=0; file[i] != 0; i++)
            if(!test2(file[i]))
                ret2 = false;
        //}
        if(!ret2)
            return false;
        else
            return true;
    }
    catch(PacketExceptionIO* e) {
        if(OUTPUT) cout << "ERROR: " << (char*) e->geterror();
        return false;
    }
    catch(PacketExceptionFileFormat* e) {
        if(OUTPUT) cout << "ERROR: " << (char*) e->geterror();
        return false;
    }
}

bool TestPacketLib::test(char* file) {
    try {
        long index ;
        cout << "TEST: " << file << endl;
        ips->setFileNameStream(file);
        ips->setInitialPosition(0L);
        ips->openInputStream();
        if(OUTPUT) cout << "OK: Data file opened" << endl;
        if(!ips->freeRun()) {
            if(OUTPUT) cout << "ERROR: freeRun failed";
            return false;
        }
        index = ips->getNumberOfFileStreamPointer();
        if(OUTPUT) cout << "OK: construction of FileStreamPointer. Found " << index << " packet" << endl;
        for(int i=0; i< index; i++)  {
            FileStreamPointer* fsp = ips->getFileStreamPointer(i);
            if(!fsp->typeOfPacket) {
                if(OUTPUT) cout << "WARNING: packet not recognized" << endl;
                return false;
            }
        }
        if(OUTPUT) cout << "OK: all the packet are recognized" << endl;
        return true;
    }
    catch(PacketExceptionIO* e) {
        if(OUTPUT) cout << "ERROR: " << (char*) e->geterror();
        return false;
    }
    catch(PacketExceptionFileFormat* e) {
        if(OUTPUT) cout << "ERROR: " << (char*) e->geterror();
        return false;
    }
}


bool TestPacketLib::test2(char* file) {
    try {
        cout << "TEST: " << file << endl;
        ips->setFileNameStream(file);
        ips->setInitialPosition(0L);
        ips->openInputStream();
        if(OUTPUT) cout << "OK: Data file opened" << endl;
        long count = 0;
        long countbad = 0;
        Packet* p;
        while(!ips->isInputStreamEOF()) {
            p = ips->getPacketFromStream();
            if(p != 0) {
                count++;
                p->deleteExternalByteStream();
            }
            else if(!ips->isInputStreamEOF()) {
                countbad++;
            }
        }
        if(p != 0)
            p->deleteExternalByteStream();
        cout << "Bad: " << countbad << endl;
        cout << "OK: " << count << endl;
        return true;
    }
    catch(PacketExceptionIO* e) {
        if(OUTPUT) cout << "ERROR: " << (char*) e->geterror();
        return false;
    }
    catch(PacketExceptionFileFormat* e) {
        if(OUTPUT) cout << "ERROR: " << (char*) e->geterror();
        return false;
    }
}

testpacketlib.cpp

deleted100644 → 0
+0 −157
Original line number Diff line number Diff line
/***************************************************************************
                          testpacketlib.cpp  -  description
                             -------------------
    begin                : Fri Feb 22 2002
    copyright            : (C) 2002 by Andrea Bulgarelli
    email                : bulgarelli@tesre.bo.cnr.it
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "testpacketlib.h"



TestPacketLib::TestPacketLib(){
	ips = new InputPacketStreamFile();
}

TestPacketLib::~TestPacketLib(){
	delete ips;
}

char* TestPacketLib::initStructure(char* fileNameConfig){
try {
	
	ips->setFileNameConfig(fileNameConfig);
  ips->createStreamStructure();

	//delete this line
//	Packet* p = ips.getPacketType(1);
//  int dim = p->getDimension();


	return 0;
}
catch(PacketExceptionIO* e) {
	return (char*) e->geterror();
}
catch(PacketExceptionFileFormat* e) {
	return (char*) e->geterror();
}


}


bool TestPacketLib::TestSuiteType1(char* nameOfTestSuite, char* fileNameConfig, char** file){
char* ret;
bool ret2 = true;
//bool retb;
try {
	if(OUTPUT) cout << "--------------------------------------------------" << endl;
	if(OUTPUT) cout << "START OF " << nameOfTestSuite << " with the file " << fileNameConfig << endl;
	ret=initStructure(fileNameConfig);
	if(ret != 0) {
		cout << ret;
		return false;
	}
  if(OUTPUT) cout << "OK: Stream structure created" << endl;
	//for(int j=0; j<3; j++) {
		for(int i=0; file[i] != 0; i++)
		  if(!test2(file[i]))
				ret2 = false;		
	//}
	if(!ret2)
			return false;
		else          	
			return true;
}
catch(PacketExceptionIO* e) {
	if(OUTPUT) cout << "ERROR: " << (char*) e->geterror();
	return false;
}
catch(PacketExceptionFileFormat* e) {
	if(OUTPUT) cout << "ERROR: " << (char*) e->geterror();
	return false;
}
}

bool TestPacketLib::test(char* file) {
try{
long index ;
	cout << "TEST: " << file << endl;
	ips->setFileNameStream(file);
	ips->setInitialPosition(0L);
	ips->openInputStream();
	if(OUTPUT) cout << "OK: Data file opened" << endl;
	if(!ips->freeRun()) {
		if(OUTPUT) cout << "ERROR: freeRun failed";
		return false;
	}
	index = ips->getNumberOfFileStreamPointer();
	if(OUTPUT) cout << "OK: construction of FileStreamPointer. Found " << index << " packet" << endl;
	for(int i=0; i< index; i++)  {
		FileStreamPointer* fsp = ips->getFileStreamPointer(i); 	
		if(!fsp->typeOfPacket) {
			if(OUTPUT) cout << "ERROR: packet not recognized" << endl;
     	return false;
		}				
	}
	if(OUTPUT) cout << "OK: all the packet are recognized" << endl;
	return true;
}
catch(PacketExceptionIO* e) {
	if(OUTPUT) cout << "ERROR: " << (char*) e->geterror();
	return false;
}
catch(PacketExceptionFileFormat* e) {
	if(OUTPUT) cout << "ERROR: " << (char*) e->geterror();
	return false;
}
}


bool TestPacketLib::test2(char* file) {
try{
	cout << "TEST: " << file << endl;
	ips->setFileNameStream(file);
	ips->setInitialPosition(0L);
	ips->openInputStream();
	if(OUTPUT) cout << "OK: Data file opened" << endl;
	long count = 0;
	long countbad = 0;
	Packet* p;
	while(!ips->isInputStreamEOF()) {
		p = ips->getPacketFromStream();
   	if(p != 0) {
			count++;
			p->deleteExternalByteStream();	
		}
		else
			if(!ips->isInputStreamEOF()) {
				countbad++;
			}		
	}
	if(p != 0)
			p->deleteExternalByteStream();
	cout << "Bad: " << countbad << endl;
	cout << "OK: " << count << endl;	
	return true;
}
catch(PacketExceptionIO* e) {
	if(OUTPUT) cout << "ERROR: " << (char*) e->geterror();
	return false;
}
catch(PacketExceptionFileFormat* e) {
	if(OUTPUT) cout << "ERROR: " << (char*) e->geterror();
	return false;
}
}