switch to git no-history version
This commit is contained in:
88
src/Core/testing/BoostAccumulatorTest.cpp
Normal file
88
src/Core/testing/BoostAccumulatorTest.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <Core/Object.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/accumulators/accumulators.hpp>
|
||||
#include <boost/accumulators/statistics/stats.hpp>
|
||||
#include <boost/accumulators/statistics/mean.hpp>
|
||||
#include <boost/accumulators/statistics/moment.hpp>
|
||||
#include <boost/accumulators/statistics/density.hpp>
|
||||
|
||||
|
||||
#include "testing-prototype.h"
|
||||
|
||||
using namespace boost::accumulators;
|
||||
|
||||
using namespace boost;
|
||||
using namespace boost::accumulators;
|
||||
|
||||
typedef accumulator_set<double, features<tag::density> > acc;
|
||||
typedef iterator_range<std::vector<std::pair<double, double> >::iterator > histogram_type;
|
||||
|
||||
template <typename T>
|
||||
class data_filler
|
||||
{
|
||||
public:
|
||||
data_filler(){}
|
||||
T operator()() { return rand()/(T)RAND_MAX; }
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
//create some random data
|
||||
std::vector<double> data(100);
|
||||
std::generate(data.begin(), data.end(), data_filler<double>());
|
||||
int c = data.size();//cache size for histogramm.
|
||||
|
||||
//create an accumulator
|
||||
acc myAccumulator( tag::density::num_bins = 20, tag::density::cache_size = 10);
|
||||
|
||||
//fill accumulator
|
||||
for (int j = 0; j < c; ++j)
|
||||
{
|
||||
myAccumulator(data[j]);
|
||||
}
|
||||
|
||||
histogram_type hist = density(myAccumulator);
|
||||
|
||||
double total = 0.0;
|
||||
|
||||
for( int i = 0; i < hist.size(); i++ )
|
||||
{
|
||||
std::cout << "Bin lower bound: " << hist[i].first << ", Value: " << hist[i].second << std::endl;
|
||||
total += hist[i].second;
|
||||
}
|
||||
|
||||
std::cout << "Total: " << total << std::endl; //should be 1 (and it is)
|
||||
|
||||
return 0;
|
||||
}
|
||||
64
src/Core/testing/BoostTest.cpp
Normal file
64
src/Core/testing/BoostTest.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "Core/Object.h"
|
||||
#include "Core/Options.h"
|
||||
|
||||
#include "Core/Singleton.h"
|
||||
|
||||
#include "testing-prototype.h"
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
struct A : Object {
|
||||
A() : a(0) {}
|
||||
int a;
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
BEGIN_TESTING(Boost Mock);
|
||||
|
||||
A &a = Singleton<A>::get_mutable_instance();
|
||||
a.a = 5552368;
|
||||
|
||||
const A &aa = Singleton<A>::get_const_instance();
|
||||
|
||||
std::cout << a.a << "\n";
|
||||
std::cout << aa.a << "\n";
|
||||
|
||||
TEST1( a.a == 5552368 );
|
||||
TEST1( aa.a == 5552368 );
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
33
src/Core/testing/CMakeLists.txt
Normal file
33
src/Core/testing/CMakeLists.txt
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
# TESTS
|
||||
set( TESTS
|
||||
SmartVectorTest
|
||||
VectorTest
|
||||
ObjectFlagsTest
|
||||
ObjectParametersTest
|
||||
ObjectCopyTest
|
||||
StaticInterfaceTest
|
||||
CommaInitTest
|
||||
DebugTTreeDumpTest
|
||||
BoostTest
|
||||
BoostAccumulatorTest
|
||||
PropertiesTest
|
||||
SignalTest
|
||||
SerializeTest
|
||||
SerializeDreadDiamondTest
|
||||
DreadDiamondParameters
|
||||
ObjectPropableTest
|
||||
UuidTest
|
||||
TypeIntrospectionTraversal
|
||||
OptionsTest
|
||||
)
|
||||
|
||||
set(LIBRARIES
|
||||
${PACKAGE_LIBPREFIX}Core
|
||||
${PACKAGE_LIBPREFIX}Math
|
||||
${Boost_SERIALIZATION_LIBRARY}
|
||||
${Boost_SIGNALS_LIBRARY}
|
||||
${Boost_PROGRAM_OPTIONS_LIBRARY}
|
||||
${ROOT_LIBRARIES}
|
||||
)
|
||||
uLib_add_tests(${uLib-module})
|
||||
57
src/Core/testing/CommaInitTest.cpp
Executable file
57
src/Core/testing/CommaInitTest.cpp
Executable file
@@ -0,0 +1,57 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "testing-prototype.h"
|
||||
#include "Core/Vector.h"
|
||||
|
||||
#include<stdio.h>
|
||||
|
||||
#define test_print(file,str,...) \
|
||||
printf(str,__VA_ARGS__)
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
int main()
|
||||
{
|
||||
BEGIN_TESTING( Comma Init );
|
||||
|
||||
Vector<int> test;
|
||||
|
||||
test << 1,2,3,4,5;
|
||||
|
||||
test.PrintSelf(std::cout);
|
||||
|
||||
|
||||
test_print(stdout,"ciao %d \n",5);
|
||||
|
||||
printf("ciao\n");
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
118
src/Core/testing/DebugTTreeDumpTest.cpp
Normal file
118
src/Core/testing/DebugTTreeDumpTest.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "testing-prototype.h"
|
||||
#include "Core/Debug.h"
|
||||
|
||||
#include <boost/any.hpp>
|
||||
#include <boost/fusion/sequence.hpp>
|
||||
#include <boost/fusion/include/sequence.hpp>
|
||||
|
||||
#include <boost/fusion/container.hpp>
|
||||
#include <boost/fusion/algorithm/transformation/push_back.hpp>
|
||||
#include <boost/fusion/include/push_back.hpp>
|
||||
|
||||
|
||||
#include <Rtypes.h>
|
||||
#include <TFile.h>
|
||||
#include <TObject.h>
|
||||
#include <TTree.h>
|
||||
#include <TApplication.h>
|
||||
#include <TBrowser.h>
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
|
||||
class DebugAdapterTTree : public detail::DebugAdapterInterface {
|
||||
TTree *m_tree;
|
||||
public:
|
||||
|
||||
DebugAdapterTTree(const char *name) : m_tree(new TTree(name,name)) {}
|
||||
~DebugAdapterTTree() { delete m_tree; }
|
||||
|
||||
void operator()(int val) {
|
||||
std::cout << "debugger 2 prints: " << val << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
{
|
||||
Debug debug;
|
||||
DebugAdapterText adapter(std::cout);
|
||||
DebugAdapterTTree treead("test");
|
||||
|
||||
debug.AddAdapter(adapter);
|
||||
debug.AddAdapter(treead);
|
||||
|
||||
int a = 5552368;
|
||||
debug("a",a);
|
||||
|
||||
std::string str = "ciao";
|
||||
debug("str",str);
|
||||
|
||||
debug.Update();
|
||||
}
|
||||
|
||||
|
||||
// TestTObject *test = new TestTObject;
|
||||
|
||||
|
||||
TFile *file = new TFile("test_file.root","RECREATE");
|
||||
file->cd();
|
||||
TTree *tree = new TTree;
|
||||
// tree->Branch("test",&test);
|
||||
|
||||
// for(int i=0;i<10;++i) {
|
||||
// test->a = i;
|
||||
// test->b = -i;
|
||||
// tree->Fill();
|
||||
// }
|
||||
tree->Write();
|
||||
|
||||
gApplication = new TApplication("My ROOT Application", &argc, argv);
|
||||
TBrowser *tbr = new TBrowser("test");
|
||||
tbr->Show();
|
||||
|
||||
|
||||
gApplication->Run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
80
src/Core/testing/DreadDiamondParameters.cpp
Normal file
80
src/Core/testing/DreadDiamondParameters.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <typeinfo>
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
#include "boost/archive/xml_oarchive.hpp"
|
||||
#include "boost/archive/xml_iarchive.hpp"
|
||||
|
||||
#include "testing-prototype.h"
|
||||
|
||||
#include "Core/Object.h"
|
||||
#include "Math/Dense.h"
|
||||
#include "Core/Mpl.h"
|
||||
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
76
src/Core/testing/Flags.h
Normal file
76
src/Core/testing/Flags.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef U_CORE_FLAGS_H
|
||||
#define U_CORE_FLAGS_H
|
||||
|
||||
namespace uLib {
|
||||
|
||||
template<typename T> class Flags
|
||||
{
|
||||
T i;
|
||||
public:
|
||||
typedef T EnumT;
|
||||
|
||||
inline Flags(const Flags &f) : i(f.i) {}
|
||||
inline Flags() : i((T)0) {}
|
||||
inline Flags(T f) : i(f) {}
|
||||
|
||||
inline Flags &operator=(const Flags &f) { i = f.i; return *this; }
|
||||
inline Flags &operator&=(T mask) { i &= mask; return *this; }
|
||||
|
||||
inline Flags &operator|=(const Flags f) { i |= f.i; return *this; }
|
||||
inline Flags &operator|=(const T f) { i |= f; return *this; }
|
||||
inline Flags &operator^=(const Flags f) { i ^= f.i; return *this; }
|
||||
inline Flags &operator^=(const T f) { i ^= f; return *this; }
|
||||
|
||||
inline Flags operator|(const Flags f) const { return Flags(i | f.i); }
|
||||
inline Flags operator|(const T f) const { return Flags(i | f); }
|
||||
inline Flags operator^(const Flags f) const { return Flags(i ^ f.i); }
|
||||
inline Flags operator^(const T f) const { return Flags(i ^ f); }
|
||||
inline Flags operator&(const Flags f) const { return Flags(i & f.i); }
|
||||
inline Flags operator&(const T f) const { return Flags(i & f); }
|
||||
inline Flags operator~() const { return Flags(~i); }
|
||||
|
||||
inline bool operator !() const { return !i; }
|
||||
inline bool testFlag(const T f) const
|
||||
{ return (i & f) == f && (f != 0 || i == f ); }
|
||||
// inline bool operator==(const T f) const { return i==f; }
|
||||
|
||||
inline T operator()() { return i; }
|
||||
inline operator T() const { return i; }
|
||||
};
|
||||
|
||||
|
||||
typedef Flags<unsigned short> Flags2B;
|
||||
typedef Flags<unsigned int> Flags4B;
|
||||
typedef Flags<unsigned long> Flags8B;
|
||||
|
||||
} // uLib
|
||||
|
||||
|
||||
#endif // FLAGS_H
|
||||
38
src/Core/testing/Makefile.am
Normal file
38
src/Core/testing/Makefile.am
Normal file
@@ -0,0 +1,38 @@
|
||||
include $(top_srcdir)/Common.am
|
||||
|
||||
#AM_DEFAULT_SOURCE_EXT = .cpp
|
||||
|
||||
# if HAVE_CHECK
|
||||
TESTS = SmartPointerTest \
|
||||
SmartVectorTest \
|
||||
VectorTest \
|
||||
ObjectFlagsTest \
|
||||
ObjectParametersTest \
|
||||
ObjectCopyTest \
|
||||
StaticInterfaceTest \
|
||||
CommaInitTest \
|
||||
DebugTTreeDumpTest \
|
||||
BoostTest \
|
||||
BoostAccumulatorTest \
|
||||
PropertiesTest \
|
||||
SignalTest \
|
||||
SerializeTest \
|
||||
SerializeDreadDiamondTest \
|
||||
DreadDiamondParameters \
|
||||
ObjectPropableTest \
|
||||
TypeIntrospectionTraversal \
|
||||
OptionsTest
|
||||
|
||||
# UuidTest
|
||||
|
||||
# else
|
||||
# TEST =
|
||||
# endif
|
||||
|
||||
LDADD = $(top_srcdir)/libmutom-${PACKAGE_VERSION}.la $(AM_LIBS_BOOST) $(AM_LIBS_ROOT)
|
||||
|
||||
check_PROGRAMS = $(TESTS)
|
||||
|
||||
|
||||
all: $(TESTS)
|
||||
|
||||
50
src/Core/testing/ObjectCopyTest.cpp
Normal file
50
src/Core/testing/ObjectCopyTest.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <typeinfo>
|
||||
|
||||
#include "testing-prototype.h"
|
||||
#include "Core/Types.h"
|
||||
#include "Core/Object.h"
|
||||
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
BEGIN_TESTING(ObjectParameters);
|
||||
|
||||
|
||||
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
69
src/Core/testing/ObjectFlagsTest.cpp
Normal file
69
src/Core/testing/ObjectFlagsTest.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#include "testing-prototype.h"
|
||||
#include "Core/Object.h"
|
||||
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
//class Derived : public uLib::Object {
|
||||
//public:
|
||||
// Derived(int flags) : uLib::Object(flags) {}
|
||||
// enum Flags {
|
||||
// a = 1<<0, // 1
|
||||
// b = 1<<1, // 2
|
||||
// c = 1<<2 // 4
|
||||
// };
|
||||
//};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
BEGIN_TESTING(ObjectFlags);
|
||||
|
||||
// Object o(2);
|
||||
// o.flags() = 4;
|
||||
// o.flags() |= 1;
|
||||
// TEST1( o.flags() == 5);
|
||||
// o.flags() &= 1;
|
||||
// TEST1( o.flags() == 1);
|
||||
// TEST1( o.flags().testFlag(1) );
|
||||
|
||||
// Derived d( Derived::a | Derived::b);
|
||||
// d.flags() = Derived::c;
|
||||
// d.flags() |= Derived::a;
|
||||
// TEST1( d.flags() == Derived::a | Derived::c);
|
||||
// d.flags() &= 1;
|
||||
// TEST1( d.flags() == Derived::a);
|
||||
// TEST1( d.flags().testFlag(Derived::a) );
|
||||
|
||||
END_TESTING
|
||||
}
|
||||
61
src/Core/testing/ObjectParametersTest.cpp
Normal file
61
src/Core/testing/ObjectParametersTest.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <typeinfo>
|
||||
#include <string>
|
||||
|
||||
#include "boost/archive/xml_oarchive.hpp"
|
||||
#include "boost/archive/xml_iarchive.hpp"
|
||||
|
||||
#include "Core/Object.h"
|
||||
#include "Math/Dense.h"
|
||||
|
||||
#include "testing-prototype.h"
|
||||
|
||||
|
||||
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
237
src/Core/testing/ObjectPropableTest.cpp
Normal file
237
src/Core/testing/ObjectPropableTest.cpp
Normal file
@@ -0,0 +1,237 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <typeinfo>
|
||||
#include <string>
|
||||
|
||||
|
||||
#include "Core/Types.h"
|
||||
#include "Core/Object.h"
|
||||
#include "Core/ObjectProps.h"
|
||||
#include "Core/StringReader.h"
|
||||
#include "Math/Dense.h"
|
||||
|
||||
#include "boost/archive/text_oarchive.hpp"
|
||||
#include "boost/archive/text_iarchive.hpp"
|
||||
|
||||
|
||||
#include "testing-prototype.h"
|
||||
|
||||
|
||||
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// STRUCTURES //
|
||||
|
||||
|
||||
struct A : virtual Object {
|
||||
|
||||
uLibTypeMacro(A, Object)
|
||||
|
||||
properties() {
|
||||
int p_a;
|
||||
Vector3f p_3f;
|
||||
};
|
||||
|
||||
int m_a;
|
||||
};
|
||||
|
||||
void A::init_properties() {
|
||||
$_init();
|
||||
$$.p_a = 0;
|
||||
$$.p_3f << 1,2,3;
|
||||
}
|
||||
|
||||
ULIB_SERIALIZABLE_OBJECT(A)
|
||||
ULIB_SERIALIZE_OBJECT(A, Object) { ar & AR(m_a); }
|
||||
ULIB_SERIALIZE_OBJECT_PROPS(A) { ar & AR(p_a) & AR(p_3f); }
|
||||
|
||||
|
||||
|
||||
|
||||
struct B : A {
|
||||
uLibTypeMacro(B,A)
|
||||
|
||||
properties() {
|
||||
std::string p;
|
||||
};
|
||||
|
||||
B() : m_b(324) {}
|
||||
|
||||
int m_b;
|
||||
};
|
||||
|
||||
|
||||
void B::init_properties() {
|
||||
$_init();
|
||||
$$.p = "ciao";
|
||||
}
|
||||
|
||||
ULIB_SERIALIZABLE_OBJECT(B)
|
||||
ULIB_SERIALIZE_OBJECT(B,A) { ar & AR(m_b); }
|
||||
ULIB_SERIALIZE_OBJECT_PROPS(B) { ar & AR(p); }
|
||||
|
||||
|
||||
|
||||
struct C {
|
||||
int m_c;
|
||||
std::string m_str;
|
||||
};
|
||||
|
||||
ULIB_SERIALIZABLE(C)
|
||||
ULIB_SERIALIZE(C) { ar & AR(m_c) & AR(m_str); }
|
||||
|
||||
|
||||
|
||||
struct D : virtual Object, B {
|
||||
uLibTypeMacro(D,Object,B)
|
||||
|
||||
properties() {
|
||||
C p_c;
|
||||
};
|
||||
};
|
||||
|
||||
void D::init_properties() {
|
||||
$_init();
|
||||
$$.p_c.m_c = 1234;
|
||||
}
|
||||
|
||||
ULIB_SERIALIZABLE_OBJECT(D)
|
||||
ULIB_SERIALIZE_OBJECT(D,Object) {}
|
||||
ULIB_SERIALIZE_OBJECT_PROPS(D) {
|
||||
ar & AR(p_c);
|
||||
}
|
||||
|
||||
|
||||
|
||||
class E : public C, public D {
|
||||
uLibTypeMacro(E,D,C)
|
||||
public:
|
||||
E() : m_Ea(5552368) {}
|
||||
int m_Ea;
|
||||
};
|
||||
|
||||
ULIB_SERIALIZABLE_OBJECT(E)
|
||||
ULIB_SERIALIZE_OBJECT(E,C,D) {
|
||||
ar & AR(m_Ea);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// TESTS //
|
||||
|
||||
|
||||
int test_xml_direct() {
|
||||
// TEST ARCHIVE SAVE AND LOAD direct //
|
||||
E o; o.init_properties();
|
||||
o.$$.p_c.m_str = "works";
|
||||
{
|
||||
std::ofstream file("test.xml");
|
||||
Archive::xml_oarchive ar(file);
|
||||
ar << NVP(o);
|
||||
}
|
||||
o.$$.p_c.m_str = "hola";
|
||||
{
|
||||
std::ifstream file("test.xml");
|
||||
Archive::xml_iarchive ar(file);
|
||||
ar >> NVP(o);
|
||||
}
|
||||
std::cout << o.$$.p_c.m_str << "\n";
|
||||
return ( o.$$.p_c.m_str == "works" );
|
||||
}
|
||||
|
||||
|
||||
int test_xml_pointer() {
|
||||
// TEST ARCHIVE SAVE AND LOAD from pointer //
|
||||
E *o = new E; o->init_properties();
|
||||
o->$$.p_c.m_str = "works";
|
||||
{
|
||||
std::ofstream file("test.xml");
|
||||
Archive::xml_oarchive ar(file);
|
||||
ar << NVP(o);
|
||||
}
|
||||
o->$$.p_c.m_str = "hola";
|
||||
{
|
||||
std::ifstream file("test.xml");
|
||||
Archive::xml_iarchive ar(file);
|
||||
ar >> NVP(o);
|
||||
}
|
||||
std::cout << o->$$.p_c.m_str << "\n";
|
||||
return ( o->$$.p_c.m_str == "works" );
|
||||
}
|
||||
|
||||
|
||||
int test_xml_objsave() {
|
||||
// TEST SELF SAVE
|
||||
E o; o.init_properties();
|
||||
o.$(B).p = "works";
|
||||
{
|
||||
std::ofstream file("test.xml");
|
||||
Object::SaveXml(file,o);
|
||||
}
|
||||
o.$(B).p = "hola";
|
||||
{
|
||||
std::ifstream file("test.xml");
|
||||
Object::LoadXml(file,o);
|
||||
}
|
||||
|
||||
std::cout << o.$(B).p << "\n";
|
||||
return ( o.$(B).p == "works" );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// MAIN //
|
||||
|
||||
int main()
|
||||
{
|
||||
BEGIN_TESTING(PropableTest);
|
||||
|
||||
TEST1( test_xml_direct() );
|
||||
TEST1( test_xml_pointer() );
|
||||
TEST1( test_xml_objsave() );
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
|
||||
|
||||
72
src/Core/testing/OptionsTest.cpp
Normal file
72
src/Core/testing/OptionsTest.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
|
||||
#include "Core/Object.h"
|
||||
#include "Core/Options.h"
|
||||
#include "testing-prototype.h"
|
||||
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
BEGIN_TESTING(Boost ProgramOptions);
|
||||
|
||||
|
||||
std::string optfile("configuration.ini");
|
||||
int a = 0;
|
||||
int b = 0;
|
||||
Options opt;
|
||||
|
||||
opt.add_options()
|
||||
("help", "printout help")
|
||||
("value",&a,"value")
|
||||
("config",&optfile,"config_file");
|
||||
|
||||
opt.add_config_options()
|
||||
("B.value",&b,"b vlaue");
|
||||
|
||||
opt.parse_command_line(argc,argv);
|
||||
opt.parse_config_file(optfile.c_str());
|
||||
|
||||
std::cout << "a = " << a << "\n";
|
||||
std::cout << "b = " << b << "\n";
|
||||
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
|
||||
|
||||
96
src/Core/testing/PropertiesTest.cpp
Normal file
96
src/Core/testing/PropertiesTest.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/signals2/signal.hpp>
|
||||
|
||||
|
||||
#include "Core/Object.h"
|
||||
#include "testing-prototype.h"
|
||||
|
||||
#define emit
|
||||
|
||||
|
||||
|
||||
|
||||
template <typename T, bool copyable = true>
|
||||
class property
|
||||
{
|
||||
typedef boost::signals2::signal<void(const property<T>& )> signal_t;
|
||||
|
||||
public:
|
||||
property() : m_changed(new signal_t) {}
|
||||
property(const T in) : value(in) , m_changed(new signal_t) {}
|
||||
|
||||
inline operator T const & () const { return value; }
|
||||
inline operator T & () { return value; }
|
||||
inline T & operator = (const T &i) { value = i; return value; }
|
||||
template <typename T2> T2 & operator = (const T2 &i) { T2 &guard = value; } // Assign exact identical types only.
|
||||
inline signal_t & valueChanged() { return *m_changed; }
|
||||
|
||||
private:
|
||||
T value;
|
||||
boost::shared_ptr<signal_t> m_changed;
|
||||
};
|
||||
|
||||
|
||||
//template <typename T>
|
||||
//class property <T,false> {
|
||||
// typedef boost::signals2::signal<void( T )> signal_t;
|
||||
|
||||
//public:
|
||||
// property() : m_changed() {}
|
||||
// property(const T in) : value(in) , m_changed() {}
|
||||
|
||||
// inline operator T const & () const { return value; }
|
||||
// inline operator T & () { valueChanged()(value); return value; }
|
||||
// inline T & operator = (const T &i) { value = i; valueChanged()(value); return value; }
|
||||
// template <typename T2> T2 & operator = (const T2 &i) { T2 &guard = value; } // Assign exact identical types only.
|
||||
// inline signal_t &valueChanged() { return m_changed; }
|
||||
|
||||
//private:
|
||||
// property(const property<T> &);
|
||||
// property<T> &operator = (const property<T>&);
|
||||
|
||||
// T value;
|
||||
// signal_t m_changed;
|
||||
//};
|
||||
|
||||
// test generic void function slot //
|
||||
void PrintSlot(const property<int> &i) { std::cout << "slot called, new value = " << i << "!\n"; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
114
src/Core/testing/SerializeDreadDiamondTest.cpp
Normal file
114
src/Core/testing/SerializeDreadDiamondTest.cpp
Normal file
@@ -0,0 +1,114 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <typeinfo>
|
||||
#include <string>
|
||||
|
||||
#include "Core/Object.h"
|
||||
|
||||
#include "testing-prototype.h"
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct A : Object {
|
||||
uLibTypeMacro(A,Object)
|
||||
A() : numa(5552368) {}
|
||||
int numa;
|
||||
};
|
||||
|
||||
|
||||
ULIB_SERIALIZABLE_OBJECT(A)
|
||||
ULIB_SERIALIZE_OBJECT(A,Object) {
|
||||
ar & AR(numa);
|
||||
}
|
||||
|
||||
struct B : virtual Object {
|
||||
uLibTypeMacro(B,Object)
|
||||
B() : numb(5552369) {}
|
||||
int numb;
|
||||
};
|
||||
|
||||
ULIB_SERIALIZABLE_OBJECT(B)
|
||||
ULIB_SERIALIZE_OBJECT(B,Object) { ar & AR(numb); }
|
||||
|
||||
|
||||
struct C : B {
|
||||
uLibTypeMacro(C,B)
|
||||
C() : numc(5552370) {}
|
||||
int numc;
|
||||
};
|
||||
|
||||
ULIB_SERIALIZABLE_OBJECT(C)
|
||||
ULIB_SERIALIZE_OBJECT(C,B) { ar & AR(numc); }
|
||||
|
||||
struct D : A,B {
|
||||
uLibTypeMacro(D,A,B)
|
||||
|
||||
D() : numd(5552371) {}
|
||||
int numd;
|
||||
};
|
||||
|
||||
ULIB_SERIALIZABLE_OBJECT(D)
|
||||
ULIB_SERIALIZE_OBJECT(D,A,B) { ar & AR(numd); }
|
||||
|
||||
|
||||
|
||||
main() {
|
||||
A o; o.init_properties();
|
||||
|
||||
Archive::xml_oarchive(std::cout) << NVP(o);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
249
src/Core/testing/SerializeTest.cpp
Normal file
249
src/Core/testing/SerializeTest.cpp
Normal file
@@ -0,0 +1,249 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "Core/Object.h"
|
||||
#include "Core/Archives.h"
|
||||
#include "ParticlePhysics/MuonTomography/MuonScatter.h"
|
||||
|
||||
#include "testing-prototype.h"
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// MANUAL SERIALIZATION //
|
||||
|
||||
struct V3f {
|
||||
|
||||
float x,y,z;
|
||||
V3f()
|
||||
{ x = y = z =0; }
|
||||
|
||||
V3f(float x, float y, float z) :
|
||||
x(x), y(y), z(z) {}
|
||||
|
||||
template <class Archive>
|
||||
void serialize (Archive &ar,unsigned int v) {
|
||||
ar
|
||||
& "<" & NVP(x) & NVP(y) & NVP(z) & ">";
|
||||
}
|
||||
};
|
||||
|
||||
ULIB_CLASS_EXPORT_KEY(V3f);
|
||||
ULIB_CLASS_EXPORT_IMPLEMENT(V3f);
|
||||
|
||||
|
||||
inline std::ostream &
|
||||
operator <<(std::ostream &o, const V3f &v) {
|
||||
Archive::hrt_oarchive(o) << v;
|
||||
return o;
|
||||
}
|
||||
|
||||
inline std::istream &
|
||||
operator >>(std::istream &is, V3f &v) {
|
||||
Archive::hrt_iarchive(is) >> v;
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int test_V3f() {
|
||||
// testing human readble archive with simple serializable structure //
|
||||
|
||||
V3f v1(1,2,3),v2,v3,v4;
|
||||
std::cout << "v --> " << v1 << "\n";
|
||||
|
||||
std::stringstream ss; ss << v1;
|
||||
std::cout << "ss.v --> " << ss.str() << "\n";
|
||||
|
||||
Archive::hrt_iarchive ar(ss); ar >> v2;
|
||||
std::cout << "v2 --> " << v2 << "\n";
|
||||
|
||||
std::stringstream("<2 3 4>") >> v3;
|
||||
std::cout << "v3 --> " << v3 << "\n";
|
||||
|
||||
// std::cout << "insert V3f string to parse: "; std::cin >> v4;
|
||||
// std::cout << "v4 --> " << v4 << "\n";
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// OBJECT SERIALIZATION //
|
||||
|
||||
class A : public virtual Object {
|
||||
uLibTypeMacro(A,Object)
|
||||
ULIB_SERIALIZE_ACCESS
|
||||
public:
|
||||
A() : m_a(5552368) {}
|
||||
|
||||
properties() {
|
||||
std::string p_a;
|
||||
};
|
||||
|
||||
uLibRefMacro (a,int);
|
||||
private:
|
||||
int m_a;
|
||||
};
|
||||
|
||||
void A::init_properties() {
|
||||
$_init();
|
||||
$$.p_a = "A property string";
|
||||
}
|
||||
|
||||
ULIB_SERIALIZABLE_OBJECT(A)
|
||||
ULIB_SERIALIZE_OBJECT(A,Object) {
|
||||
ar
|
||||
& "Object A : "
|
||||
& "--> m_a = " & AR(m_a)
|
||||
& "\n";
|
||||
}
|
||||
|
||||
ULIB_SERIALIZE_OBJECT_PROPS(A) {
|
||||
ar
|
||||
& "Object A properties: "
|
||||
& "---> p_a = " & AR(p_a) & "\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
int testing_xml_class() {
|
||||
|
||||
A a; a.init_properties();
|
||||
|
||||
{
|
||||
std::ofstream file("test.xml");
|
||||
Archive::xml_oarchive(file) << NVP(a);
|
||||
}
|
||||
a.a() = 0;
|
||||
a.$$.p_a = "zero string";
|
||||
{
|
||||
std::ifstream file("test.xml");
|
||||
Archive::xml_iarchive(file) >> NVP(a);
|
||||
}
|
||||
|
||||
Archive::xml_oarchive(std::cout) << NVP(a);
|
||||
return ( a.a() == 5552368 && a.$$.p_a == "A property string" );
|
||||
}
|
||||
|
||||
int testing_hrt_class() {
|
||||
|
||||
A a; a.init_properties();
|
||||
|
||||
{
|
||||
std::ofstream file("test.xml");
|
||||
Archive::hrt_oarchive(file) << NVP(a);
|
||||
}
|
||||
a.a() = 0;
|
||||
a.$$.p_a = "zero string";
|
||||
{
|
||||
// ERRORE FIX !
|
||||
// std::ifstream file("test.xml");
|
||||
// Archive::hrt_iarchive(file) >> NVP(a);
|
||||
}
|
||||
|
||||
Archive::hrt_oarchive(std::cout) << NVP(a);
|
||||
return ( a.a() == 5552368 && a.$$.p_a == "A property string" );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// MUON SCATTER EXAMPLE //
|
||||
|
||||
int testing_mu()
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
MuonScatter mu;
|
||||
mu.SetMomentumIn(555);
|
||||
mu.SetMomentumOut(2368);
|
||||
{
|
||||
std::ofstream file("test.txt");
|
||||
file << mu;
|
||||
}
|
||||
|
||||
mu.SetMomentumIn(0);
|
||||
mu.SetMomentumOut(0);
|
||||
{
|
||||
std::ifstream file("test.txt");
|
||||
file >> mu;
|
||||
}
|
||||
|
||||
std::cout << mu << "\n";
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
BEGIN_TESTING(Serialize Test);
|
||||
|
||||
TEST1( test_V3f() );
|
||||
TEST1( testing_xml_class() );
|
||||
// testing_hrt_class(); ///// << ERRORE in HRT with properties
|
||||
TEST1( testing_mu() );
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
115
src/Core/testing/SignalTest.cpp
Normal file
115
src/Core/testing/SignalTest.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <typeinfo>
|
||||
|
||||
|
||||
#include "testing-prototype.h"
|
||||
#include "Core/Types.h"
|
||||
#include "Core/Object.h"
|
||||
#include "Core/Signal.h"
|
||||
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
|
||||
|
||||
class Ob1 : public Object {
|
||||
public:
|
||||
|
||||
|
||||
signals:
|
||||
void V0();
|
||||
|
||||
int V1(int a);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// should be done by moc //
|
||||
void Ob1::V0() {
|
||||
ULIB_SIGNAL_EMIT(Ob1::V0);
|
||||
}
|
||||
|
||||
int Ob1::V1(int a) {
|
||||
ULIB_SIGNAL_EMIT(Ob1::V1,a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Ob2 : public Object {
|
||||
|
||||
public slots:
|
||||
void PrintV0() {
|
||||
std::cout << "Ob2 prints V0\n" << std::flush;
|
||||
}
|
||||
};
|
||||
|
||||
class Ob3 : public Object {
|
||||
|
||||
public slots:
|
||||
void PrintV0() {
|
||||
std::cout << "Ob3 prints V0\n" << std::flush;
|
||||
}
|
||||
|
||||
void PrintNumber(int n) {
|
||||
std::cout << "Ob3 is printing number: " << n << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
BEGIN_TESTING(Signals);
|
||||
|
||||
Ob1 ob1;
|
||||
Ob2 ob2;
|
||||
Ob3 ob3;
|
||||
|
||||
Object::connect(&ob1,&Ob1::V0,&ob2,&Ob2::PrintV0);
|
||||
Object::connect(&ob1,&Ob1::V0,&ob3,&Ob3::PrintV0);
|
||||
Object::connect(&ob1,&Ob1::V1,&ob3,&Ob3::PrintNumber);
|
||||
|
||||
// not working yet
|
||||
// Object::connect(&ob1,SIGNAL(V0(),&ob2,SLOT(PrintV0())
|
||||
|
||||
ob1.PrintSelf(std::cout);
|
||||
|
||||
emit ob1.V0();
|
||||
emit ob1.V1(5552368);
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
|
||||
|
||||
94
src/Core/testing/SmartPointerTest.cpp
Normal file
94
src/Core/testing/SmartPointerTest.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include "Core/SmartPointer.h"
|
||||
#include "testing-prototype.h"
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
namespace Test {
|
||||
|
||||
struct ObjectMockInterface {
|
||||
virtual void PrintValue()=0;
|
||||
virtual int& Value()=0;
|
||||
};
|
||||
|
||||
class ObjectMock : ObjectMockInterface {
|
||||
int value;
|
||||
public:
|
||||
int& Value() { return value; }
|
||||
void PrintValue() { std::cout << "Value: " << value << "\n"; }
|
||||
|
||||
};
|
||||
} // Test
|
||||
|
||||
|
||||
bool test_smpt(SmartPointer<Test::ObjectMock> &p) {
|
||||
|
||||
SmartPointer<Test::ObjectMock> spt = p;
|
||||
spt->Value() = 5552368;
|
||||
{
|
||||
SmartPointer<Test::ObjectMock> copy = spt;
|
||||
copy->Value() = 123;
|
||||
}
|
||||
return (spt->Value() == 123);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main () {
|
||||
BEGIN_TESTING(SmartPointer);
|
||||
|
||||
// HOLD REFERENCE //
|
||||
{
|
||||
SmartPointer<Test::ObjectMock> spt(new Test::ObjectMock);
|
||||
TEST1(test_smpt(spt));
|
||||
}
|
||||
{
|
||||
SmartPointer<Test::ObjectMock> spt;
|
||||
TEST1(test_smpt(spt));
|
||||
}
|
||||
{
|
||||
SmartPointer<Test::ObjectMock> spt = new SmartPointer<Test::ObjectMock>;
|
||||
TEST1(test_smpt(spt));
|
||||
}
|
||||
|
||||
// TAKE REFERENCE //
|
||||
{
|
||||
Test::ObjectMock obj;
|
||||
SmartPointer<Test::ObjectMock> spt(obj);
|
||||
TEST1(test_smpt(spt));
|
||||
}
|
||||
|
||||
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
120
src/Core/testing/SmartVectorTest.cpp
Normal file
120
src/Core/testing/SmartVectorTest.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "testing-prototype.h"
|
||||
#include "Core/Vector.h"
|
||||
#include "Core/Object.h"
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
static int instanziated_objects_number;
|
||||
|
||||
class ObjectTest : public Object {
|
||||
public:
|
||||
ObjectTest() {
|
||||
data[0] = 0;
|
||||
data[1] = 1;
|
||||
data[2] = 2;
|
||||
instanziated_objects_number++;
|
||||
}
|
||||
ObjectTest(const ObjectTest ©) {
|
||||
data[0] = copy.data[0];
|
||||
data[1] = copy.data[1];
|
||||
data[2] = copy.data[2];
|
||||
instanziated_objects_number++;
|
||||
}
|
||||
|
||||
~ObjectTest()
|
||||
{
|
||||
instanziated_objects_number--;
|
||||
}
|
||||
float data[3];
|
||||
};
|
||||
|
||||
int main() {
|
||||
BEGIN_TESTING(SmartVector);
|
||||
|
||||
instanziated_objects_number =0;
|
||||
|
||||
|
||||
///////////////////////// SMART POINTER FUNCIONALITY ///////////////////////
|
||||
|
||||
// int smart vector //
|
||||
SmartVector<int> sv(10);
|
||||
for (int i=0;i<10;++i)
|
||||
sv[i] = i;
|
||||
// new shallow copy inside a code block //
|
||||
{
|
||||
SmartVector<int> newsv = sv;
|
||||
newsv[5] = 5552368;
|
||||
TEST1(sv[5] == newsv[5]);
|
||||
}
|
||||
// verify that newsv destruction does not delete instance //
|
||||
TEST1( sv[5] == 5552368 );
|
||||
|
||||
SmartVector<ObjectTest> svo(10);
|
||||
for (int i=0;i<10;++i)
|
||||
svo[i] = ObjectTest();
|
||||
|
||||
TEST1(instanziated_objects_number == 10);
|
||||
{
|
||||
SmartVector<ObjectTest> newsvo = svo;
|
||||
newsvo[5].data[1] = 5552368.0;
|
||||
TEST1(svo[5].data[1] == newsvo[5].data[1]);
|
||||
TEST1(instanziated_objects_number == 10);
|
||||
}
|
||||
TEST1(instanziated_objects_number == 10);
|
||||
|
||||
|
||||
|
||||
/////////////////////////// ITERATOR FUNCIONALITY //////////////////////////
|
||||
|
||||
|
||||
Vector<int> v(10);
|
||||
Vector<int>::Iterator it;
|
||||
|
||||
int i=1;
|
||||
for(it=v.begin() ; it==v.end(); it++, i++)
|
||||
*it = i;
|
||||
|
||||
for(i = 0; i<v.size(); i++)
|
||||
TEST1( v[i] = i+1 );
|
||||
|
||||
Vector<int>::ConstIterator cit;
|
||||
i=1;
|
||||
for(cit=v.begin(); cit==v.end(); cit++, i++)
|
||||
TEST1( *cit == i+1 );
|
||||
|
||||
|
||||
END_TESTING
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
112
src/Core/testing/StaticInterfaceTest.cpp
Normal file
112
src/Core/testing/StaticInterfaceTest.cpp
Normal file
@@ -0,0 +1,112 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "testing-prototype.h"
|
||||
#include <Core/StaticInterface.h>
|
||||
|
||||
|
||||
|
||||
namespace uLib {
|
||||
|
||||
//// INTERFACE TO COMPLEX CLASS /////
|
||||
|
||||
namespace Interface {
|
||||
struct Test {
|
||||
MAKE_TRAITS
|
||||
template<class Self> void check_structural() {
|
||||
uLibCheckFunction(Self,test,bool,int,float);
|
||||
uLibCheckMember(Self,testmemb,int);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
struct Test {
|
||||
bool test(int i, float f){}
|
||||
int testmemb;
|
||||
};
|
||||
|
||||
|
||||
|
||||
//// INTERFAC TO SIMPLE CLASS ///////////
|
||||
|
||||
namespace Interface {
|
||||
struct Simple {
|
||||
MAKE_TRAITS
|
||||
template<class Self> void check_structural() {
|
||||
uLibCheckMember(Self,memb1,int);
|
||||
uLibCheckMember(Self,memb2,float);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
struct Simple {
|
||||
int memb1;
|
||||
float memb2;
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////
|
||||
|
||||
template <class T>
|
||||
class UseTest {
|
||||
public:
|
||||
UseTest() {
|
||||
Interface::IsA<T,Interface::Test>();
|
||||
T t;
|
||||
int i; float f;
|
||||
t.test(i,f);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class UseSimple {
|
||||
public:
|
||||
UseSimple() {
|
||||
Interface::IsA<T,Interface::Simple>();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
BEGIN_TESTING(Static Interface);
|
||||
|
||||
|
||||
|
||||
uLib::UseTest<uLib::Test> u;
|
||||
|
||||
uLib::UseSimple<uLib::Simple> s;
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
|
||||
52
src/Core/testing/TypeIntrospectionTraversal.cpp
Normal file
52
src/Core/testing/TypeIntrospectionTraversal.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <typeinfo>
|
||||
#include <string>
|
||||
|
||||
|
||||
#include "Core/Types.h"
|
||||
#include "Core/Object.h"
|
||||
|
||||
|
||||
#include "testing-prototype.h"
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
|
||||
|
||||
}
|
||||
45
src/Core/testing/UuidTest.cpp
Normal file
45
src/Core/testing/UuidTest.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "Core/Object.h"
|
||||
#include "Core/Uuid.h"
|
||||
|
||||
#include "testing-prototype.h"
|
||||
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
int main()
|
||||
{
|
||||
BEGIN_TESTING(uuid);
|
||||
|
||||
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
84
src/Core/testing/VectorTest.cpp
Normal file
84
src/Core/testing/VectorTest.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#include <Core/Vector.h>
|
||||
#include "testing-prototype.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
template < typename T >
|
||||
struct __Cmp {
|
||||
bool operator()(const T &data, const float value) {
|
||||
return data <= value;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename _Tp, typename _CmpT>
|
||||
inline const unsigned long
|
||||
VectorSplice(const _Tp &_it, const _Tp &_end, const float value, _CmpT _comp)
|
||||
{
|
||||
|
||||
_Tp it = _it;
|
||||
_Tp end = _end-1;
|
||||
for(it; it != end; )
|
||||
{
|
||||
if ( _comp(*it, value) ) it++;
|
||||
else if( _comp(*end, value) )
|
||||
{
|
||||
std::swap(*it,*end--);
|
||||
}
|
||||
else --end;
|
||||
}
|
||||
return it - _it;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
BEGIN_TESTING(Vector);
|
||||
|
||||
uLib::Vector<float> v;
|
||||
v << 5,4,3,2,6,1,2,3,65,7,32,23,4,3,45,4,34,3,4,4,3,3,4,2,2,3;
|
||||
|
||||
|
||||
|
||||
int id = VectorSplice(v.begin(),v.end(),3,__Cmp<float>());
|
||||
|
||||
std::cout << "id: " << id << "\n";
|
||||
std::cout << "vector: ";
|
||||
for(uLib::Vector<float>::Iterator it = v.begin(); it!=v.end(); it++)
|
||||
std::cout << *it <<" ";
|
||||
std::cout << std::endl;
|
||||
// std::sort(v.begin(),v.end(),LT<float>());
|
||||
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
|
||||
37
src/Core/testing/testing-prototype.h
Normal file
37
src/Core/testing/testing-prototype.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define BEGIN_TESTING(name) \
|
||||
static int _fail = 0; \
|
||||
printf("..:: Testing " #name " ::..\n");
|
||||
|
||||
#define TEST1(val) _fail += (val)==0
|
||||
#define TEST0(val) _fail += (val)!=0
|
||||
#define END_TESTING return _fail;
|
||||
|
||||
Reference in New Issue
Block a user