3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
19 /** @file testAliHLTBlockDataCollection.C
20 @author Matthias Richter
22 @brief Test macro/program for the AliHLTBlockDataCollection
28 #include "AliHLTBlockDataCollection.h"
29 #include "AliHLTComponent.h"
35 typedef struct init_t {
36 const char* arguments;
40 typedef struct select_t {
48 {"-datatype 'ESD_TREE' 'TPC ' ", 3},
49 {"-datatype 'ESD_TREE' 'TPC ' "
53 "-dataspec 0xdeadbeef ", 9},
54 {"-datatype 'ESD_TREE'", -EPROTO},
58 select_t gSelections[]={
59 {"ESD_TREE", "TPC ", 0, 1},
60 {"DDL_RAW ", "TPC ", 0xaffe, 0},
61 {"ESD_TREE", "TRD ", 0xaffe, 0},
62 {"ESD_TREE", "TRD ", 0xdeadbeef, 1},
68 int InitCollection(AliHLTBlockDataCollection& collection, const char* init)
70 // build argument vector
72 char* arguments=new char[strlen(init)+1];
73 strcpy(arguments, init);
74 vector<int> positions;
78 for (;arguments[i]!=0; i++) {
79 if (arguments[i]=='\'') {
80 if ((bQuote=(!bQuote))) {
81 // opening quote, set start
83 // closing quote, add argument
85 if (i-iStart>0) positions.push_back(iStart);
88 } else if ((arguments[i]==' ' && !bQuote) ||
91 if (i-iStart>0) positions.push_back(iStart);
95 if (i-iStart>0) positions.push_back(iStart);
97 int argc=positions.size();
98 const char** argv=new const char*[argc];
99 for (int j=0; j<argc ; j++) {
100 argv[j]=&arguments[positions[j]];
103 // test argument scan
104 for (i=0; i<argc; i++) {
105 if (gVerbosity>1) cout << "scanning " << argc-i << " arguments: " << argv[i] << endl;
106 int result=collection.ScanArgument(argc-i, &argv[i]);
110 } else if (result<0) {
123 int testAliHLTBlockDataCollection(int verbosity=0)
125 gVerbosity=verbosity;
126 AliHLTBlockDataCollection collection;
127 for (int initNo=0; gInits[initNo].arguments!=NULL; initNo++) {
128 if (gVerbosity>0) cout << "checking: " << gInits[initNo].arguments << endl;
129 int result=InitCollection(collection, gInits[initNo].arguments);
130 if (result!=gInits[initNo].result) {
131 cerr << "failed: " << initNo << " (" << gInits[initNo].arguments << ") " << ": result " << result << ", expected " << gInits[initNo].result << endl;
134 if (gVerbosity>1) cout << "init " << initNo << " (" << gInits[initNo].arguments << ") " << "succeeded: result " << result << endl;
138 AliHLTComponentBlockData bd;
139 AliHLTComponent::FillBlockData(bd);
141 for (int selectNo=0; gSelections[selectNo].id!=NULL; selectNo++) {
142 AliHLTComponent::SetDataType(bd.fDataType, gSelections[selectNo].id, gSelections[selectNo].origin );
143 bd.fSpecification=gSelections[selectNo].specification;
144 int result=collection.IsSelected(bd);
145 if (result!=gSelections[selectNo].result) {
146 cerr << "failed: block " << gSelections[selectNo].id << ":" << gSelections[selectNo].origin << " 0x" << hex << gSelections[selectNo].specification << ": result " << result << ", expected " << gSelections[selectNo].result << endl;
149 if (gVerbosity>0) cout << "checking: block " << gSelections[selectNo].id << ":" << gSelections[selectNo].origin << " 0x" << hex << gSelections[selectNo].specification << (result==1?" selected":" not selected") << " (correctly)" << endl;
156 int main(int /*argc*/, const char** /*argv*/)
159 if ((iResult=testAliHLTBlockDataCollection(1))<0) {
160 cerr << "<<<<< re-run with higher verbosity >>>>>>>" << endl;
161 testAliHLTBlockDataCollection(2);