Commit 92d2579b authored by aorlati's avatar aorlati Committed by Giuseppe Carboni
Browse files

Fix #200: Rewritten class IRA::CDtaField in order not to rely on BACIValue...

Fix #200: Rewritten class IRA::CDtaField in order not to rely on BACIValue class anumore.This should solve the problem related to TotalPower configuration (#201)
parent 8b1ef470
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
/*                                                                                                      */
/* Who                                when            What                                              */
/* Andrea Orlati(aorlati@ira.inaf.it) 07/06/2006      Creation                                          */
/* Andrea Orlati(aorlati@ira.inaf.it) 26/01/2018      Rewritten in order to bypass an issue with 64bit ACS2017 */

#include <vector>
#include <baciValue.h>
@@ -115,12 +116,12 @@ protected:
	void Last();

	/**
	 * Sets the current field pointer to the next avilable position. If the pointer already points the last one, nothing happens.
	 * Sets the current field pointer to the next available position. If the pointer already points the last one, nothing happens.
	*/
	void Next();

	/**
	 * Sets the current field pointer to the previuos avilable position. If the pointer already points the first one, nothing happens.
	 * Sets the current field pointer to the previous available position. If the pointer already points the first one, nothing happens.
	*/
	void Prev();
	
@@ -134,7 +135,8 @@ private:
	CString m_title;
	TFieldType m_type;
	int m_listPointer;
	std::vector<baci::BACIValue *> m_valueList;	
	//std::vector<baci::BACIValue *> m_valueList;	
	std::vector<IRA::CString *> m_valueList;

  	CDataField(const CDataField& rSrc);    // no implementation given
   void operator=(const CDataField& rSrc);  // no implementation given
+27 −19
Original line number Diff line number Diff line
@@ -13,17 +13,17 @@ CDataField::CDataField(const CString& name,const TFieldType& type) : m_title(nam
CDataField::~CDataField()
{
	for(unsigned i=0;i<m_valueList.size();i++) {
		delete m_valueList[i];
		if (m_valueList[i]) delete m_valueList[i];
	}
	m_valueList.clear();
}

bool CDataField::isNull() const
{
	baci::BACIValue *tmp;
	if (m_listPointer>=0) {
		tmp=m_valueList[m_listPointer];
		return tmp->isNull();
		IRA::CString *tmp=m_valueList[m_listPointer];
		if ((*tmp)!="") return true;
		else return false;
	}
	else {
		return true;
@@ -37,12 +37,11 @@ IRA::CString CDataField::getColumnName() const

IRA::CString CDataField::asString() const
{
	baci::BACIValue *tmp;
	IRA::CString *tmp;
	if (m_listPointer>=0) {
		tmp=m_valueList[m_listPointer];
		const char *p=tmp->stringValue();
		if (p==NULL) return IRA::CString("");
		else return IRA::CString(p);
		if (tmp==NULL) return IRA::CString("");
		else return *tmp;
	}
	else {
		return IRA::CString("");
@@ -51,10 +50,12 @@ IRA::CString CDataField::asString() const

long long CDataField::asLongLong() const
{
	baci::BACIValue *tmp;
	IRA::CString *tmp;
	char *pend;
	if (m_listPointer>=0) {
		tmp=m_valueList[m_listPointer];
		return tmp->longLongValue();
		if (tmp==NULL) return 0;
		return (strtoll((const char *)(*tmp),&pend,10));
	}
	else {
		return 0;
@@ -63,10 +64,12 @@ long long CDataField::asLongLong() const

DDWORD CDataField::asDoubleDoubleWord() const
{
	baci::BACIValue *tmp;
	IRA::CString *tmp;
	char *pend;
	if (m_listPointer>=0) {
		tmp=m_valueList[m_listPointer];
		return (DWORD)tmp->uLongLongValue();
		if (tmp==NULL) return 0;
		return (strtoul((const char *)(*tmp),&pend,10));
	}
	else {
		return 0;
@@ -75,10 +78,12 @@ DDWORD CDataField::asDoubleDoubleWord() const

double CDataField::asDouble() const
{
	baci::BACIValue *tmp;
	IRA::CString *tmp;
	char *pend;
	if (m_listPointer>=0) {
		tmp=m_valueList[m_listPointer];
		return tmp->doubleValue();
		if (tmp==NULL) return 0.0;
		return (strtod((const char *)(*tmp),&pend));
	}
	else {
		return 0.0;
@@ -87,17 +92,20 @@ double CDataField::asDouble() const

void CDataField::addValue()
{
	m_valueList.push_back(new baci::BACIValue());
//	m_valueList.push_back(new baci::BACIValue());
	m_valueList.push_back(new IRA::CString(""));
}

void CDataField::setValue(const CString& value)
{
	if (value!="") {
	IRA::CString *tmp=m_valueList.back();
	(*tmp)=value;
	/*if (value!="") {
		m_valueList.back()->setValue((const char*)value);
		switch (m_type) {
			case LONGLONG : {
				m_valueList.back()->setType(baci::BACIValue::type_longLong);
				m_valueList.back()->setValue((const BACIlongLong)atoll((const char*)value));
				//m_valueList.back()->setValue((const BACIlongLong)atoll((const char*)value));
			}
			case DOUBLEDOUBLEWORD : {
				m_valueList.back()->setType(baci::BACIValue::type_uLongLong);
@@ -114,7 +122,7 @@ void CDataField::setValue(const CString& value)
				m_valueList.back()->setValue((const char*)value);
			}	
		}
	}
	}*/
}

void CDataField::setPointer(const WORD& pos)
+73 −0
Original line number Diff line number Diff line
#include "DataField.h"
#include "String.h"


#include <stdlib.h>

namespace IRALibraryTest {

class IRALibrary_CDataField : public ::testing::Test {
public:
	// this is the test that identifies issue #200.
	::testing::AssertionResult typeConversion_fail() {	
		CDBTestField fieldS("string",IRA::CDataField::STRING);
		CDBTestField fieldL("long",IRA::CDataField::LONGLONG);
		CDBTestField fieldD("double",IRA::CDataField::DOUBLE);
		CDBTestField fieldW("word",IRA::CDataField::DOUBLEDOUBLEWORD);
		fieldS.addValue();
		fieldL.addValue();
		fieldD.addValue();
		fieldW.addValue();			
		fieldS.setValue("dummy");
		fieldL.setValue("-456789");
		fieldD.setValue("12345.678");
		fieldW.setValue("9000");
		fieldS.First();
		fieldL.First();
		fieldD.First();;
		fieldW.First();				
		if (fieldS.asString()!="dummy") return ::testing::AssertionFailure() << " string not properly converted";
		if (fieldD.asDouble()!=12345.678) return ::testing::AssertionFailure() << " double not properly converted";
		if (fieldW.asDoubleDoubleWord()!=9000) return ::testing::AssertionFailure() << " unsigned long not properly converted";
		if (fieldL.asLongLong()!=-456789) return ::testing::AssertionFailure() << " signed long not properly converted";
		return ::testing::AssertionSuccess();
	}

private:
	// this is a fake class in order to manipulate the CDataField protected methods
	class CDBTestField: public IRA::CDataField {
	public:
		CDBTestField(const IRA::CString& name,const TFieldType& type): IRA::CDataField(name,type) {
		}
		void addValue() {
			IRA::CDataField::addValue();
		}
		void setValue(const IRA::CString& value) {
			IRA::CDataField::setValue(value);
		}
		void First() {
			IRA::CDataField::First();
		}
		void Next() {
			IRA::CDataField::Next();
		}
	};
		
protected:

	static void TearDownTestCase()
	{
	}

	static void SetUpTestCase()
	{
	}

	virtual void SetUp() {
	}
	
	virtual void TearDown() {
	}
};

}
+7 −2
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
#include "Socket_test.i"

#include "CError_regression.i"
#include "CDBTable_regression.i"

using namespace IRALibraryTest;

@@ -67,3 +68,7 @@ TEST_F(IRALibrary_Socket, sendWithoutConnection){
TEST_F(IRALibrary_CError,copyConstructor_segfault){
	EXPECT_TRUE(copyConstructor_segfault());
}

TEST_F(IRALibrary_CDataField,typeConversion_fail){
	EXPECT_TRUE(typeConversion_fail());
}