LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
TestCase.cpp
Go to the documentation of this file.
1// Copyright 2002-2013 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6/***************************************************************************
7 * Copyright (C) 2004 by Benoit Mathieu *
8 * mathieub@zoe.cea.fr *
9 * *
10 ***************************************************************************/
12
14#include <sstream>
15#include <fstream>
16#include <algorithm>
17#include <iterator>
18
19
20using namespace std;
21
22namespace Lima
23{
24namespace Common
25{
26namespace TGV
27{
28std::ostream & operator << (std::ostream &os, const Lima::Common::TGV::TestCase& tc) {
29 tc.print(os);
30 return os;
31}
32
33void TestCase::print(std::ostream &os) const {
34 os << "<testcase id='" << id << "' type='" << type << "'>\n";
35 os << "<expl>" << explanation << "</expl>\n";
36 os << "<call-parameters>\n";
37 for( SimpleValCallParams::const_iterator paramIt = simpleValCallParams.begin() ;
38 paramIt != simpleValCallParams.end() ; paramIt++ ) {
39 os << "<param key='" << (*paramIt).first << "' value='" << (*paramIt).first << "'>\n";
40 }
41 for( MultiValCallParams::const_iterator paramIt = multiValCallParams.begin() ;
42 paramIt != multiValCallParams.end() ; paramIt++ ) {
43 const std::list<std::string>& list = (*paramIt).second;
44 os << "<list key='" << (*paramIt).first << "'>\n";
45 for( std::list<std::string>::const_iterator valueIt = list.begin() ;
46 valueIt != list.end() ; valueIt++ ) {
47 os << "<item value='" << (*valueIt) << "'/>\n";
48 }
49 os << "</list>\n";
50 }
51 for( MapValCallParams::const_iterator paramIt = mapValCallParams.begin() ;
52 paramIt != mapValCallParams.end() ; paramIt++ ) {
53 const std::map<std::string,std::string>& map = (*paramIt).second;
54 os << "<map key='" << (*paramIt).first << "'>\n";
55 for( std::map<std::string,std::string>::const_iterator valueIt = map.begin() ;
56 valueIt != map.end() ; valueIt++ ) {
57 os << "<item attr='" << (*valueIt).first << "' val='" << (*valueIt).second << "'/>\n";
58 }
59 os << "</list>\n";
60 }
61 os << "</call-parameters>\n";
62 for(std::list<TestCase::TestUnit>::const_iterator testUnitIt = tests.begin() ;
63 testUnitIt != tests.end() ; testUnitIt++ ) {
64 testUnitIt->print(os);
65 }
66 os << "</testcase>\n";
67}
68
69std::string TestCase::getParam( const std::string& key ) const
70{
71
72 SimpleValCallParams::const_iterator paramIt = simpleValCallParams.find(key);
73 if( paramIt == simpleValCallParams.end() ) {
75 // not ERROR: parameter may be optional
76 LDEBUG << "TestCaseProcessor::getParam: no '"
77 << key << "' attribute in call parameter of testCase "
78 << id;
79 return "";
80 }
81 string paramVal = (*paramIt).second;
82 return paramVal;
83
84}
85
86void TestCase::getList( const std::string& key, std::list<std::string >& list ) const
87{
88
89 MultiValCallParams::const_iterator paramIt = multiValCallParams.find(key);
90 if( paramIt == multiValCallParams.end() ) {
92 LWARN << "TestCaseProcessor::getList: no '"
93 << key << "' attribute in call parameter of testCase "
94 << id;
95 return;
96 }
97 list = (*paramIt).second;
98}
99
100void TestCase::getMap( const std::string& key, std::map<std::string,std::string >& map ) const
101{
102
103 MapValCallParams::const_iterator paramIt = mapValCallParams.find(key);
104 if( paramIt == mapValCallParams.end() ) {
106 LWARN << "TestCaseProcessor::getMap: no '"
107 << key << "' attribute in call parameter of testCase "
108 << id;
109 return;
110 }
111 map = (*paramIt).second;
112}
113
114std::ostream & operator << (std::ostream &os, const Lima::Common::TGV::TestCase::TestUnit& tcu) {
115 tcu.print(os);
116 return os;
117}
118
119void TestCase::TestUnit::print(std::ostream &os) const {
120 os << "<test id='" << id << "' trace='" << trace << "'\n"
121 << "comment='" << comment << "'\n"
122 << "left='" << left << "'\n"
123 << "operator='" << op << "'\n"
124 << "right='" << right << "'\n"
125 << "conditional='" << (conditional?"true":"false") << "'/>\n";
126}
127
128std::ostream& operator<<(std::ostream& out,const std::set<std::string>& s)
129{
130 out << "{";
131 copy(s.begin(),s.end(),ostream_iterator<std::string>(out,","));
132 out << "}";
133 return out;
134}
135
136} // TGV
137} // Common
138} // Lima
#define LWARN
Definition LimaCommon.h:160
#define TGVLOGINIT
Definition LimaCommon.h:216
#define LDEBUG
Definition LimaCommon.h:157
std::ostream & operator<<(std::ostream &os, const Lima::Common::TGV::TestCase &tc)
Definition TestCase.cpp:28
NAUTITIA.
STL namespace.
void print(std::ostream &os) const
Definition TestCase.cpp:119
MultiValCallParams multiValCallParams
Definition TestCase.h:62
void getMap(const std::string &key, std::map< std::string, std::string > &map) const
Definition TestCase.cpp:100
std::string getParam(const std::string &key) const
Definition TestCase.cpp:69
SimpleValCallParams simpleValCallParams
Definition TestCase.h:61
friend LIMA_TGV_EXPORT std::ostream & operator<<(std::ostream &os, const TestCase &tc)
Definition TestCase.cpp:28
MapValCallParams mapValCallParams
Definition TestCase.h:63
std::list< TestUnit > tests
Definition TestCase.h:68
void print(std::ostream &os) const
Definition TestCase.cpp:33
void getList(const std::string &key, std::list< std::string > &list) const
Definition TestCase.cpp:86