Cambridge SMT System
hifst.task.stats.gtest.cpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use these files except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12 
13 // Copyright 2012 - Gonzalo Iglesias, AdriĆ  de Gispert, William Byrne
14 
21 #include <googletesting.h>
22 
23 #ifndef GMAINTEST
24 #include "main.custom_assert.hpp"
25 #include "main.logger.hpp"
26 #endif
27 
28 #include "addresshandler.hpp"
29 #include "taskinterface.hpp"
30 
31 #include "data.stats.hpp"
32 #include "task.stats.hpp"
33 
34 using boost::any_cast;
35 namespace bfs = boost::filesystem;
36 
37 namespace uf = ucam::fsttools;
38 
39 namespace googletesting {
40 
42 struct DataForStats {
44  sidx ( 0 ),
45  stats ( new uf::StatsData ) {
46  }
47 
48  unsigned sidx;
49  boost::scoped_ptr<uf::StatsData> stats;
50 };
51 
53 TEST ( HifstStatsTask, basic_test ) {
54  //Prepare RegistryPO object.
55  unordered_map<std::string, boost::any> v;
56  const std::string kStatsText = "stats.text";
57  v[HifstConstants::kStatsWrite] = std::string ( kStatsText );
58  DataForStats d;
59  //Hopefully these account for 0 time...
60  d.stats->setTimeStart ( "sirius" );
61  d.stats->setTimeEnd ( "sirius" );
62  d.stats->setTimeStart ( "black" );
63  d.stats->setTimeEnd ( "black" );
64  const uu::RegistryPO rg ( v );
65  {
67  st.run ( d );
68  }
69  uu::iszfstream aux ( kStatsText );
70  std::string line;
71  getline ( aux, line );
72  getline ( aux, line );
73  getline ( aux, line );
74  boost::algorithm::trim ( line );
75  // sorting has changed with boost:
76  EXPECT_TRUE ( line.substr ( 0, 14 ) == "sirius: "
77  || line.substr ( 0, 14 ) == "black: ");
78  getline ( aux, line );
79  boost::algorithm::trim ( line );
80  EXPECT_TRUE ( line.substr ( 0, 14 ) == "sirius: "
81  || line.substr ( 0, 14 ) == "black: ");
82  bfs::remove ( bfs::path ( kStatsText ) );
83 };
84 
85 };
86 
87 #ifndef GMAINTEST
88 
89 int main ( int argc, char **argv ) {
90  ::testing::InitGoogleTest ( &argc, argv );
91  return RUN_ALL_TESTS();
92 }
93 #endif
Handles simple wildcard expansion for strings.
Relative to Stats across the pipeline.
Task that dumps statistics stored by any previous task in the pipeline.
boost::scoped_ptr< uf::StatsData > stats
Interfaces with basic methods for iteration.
TEST(FstIo, basic_test)
Definition: fstio.gtest.cpp:38
iszfstream & getline(iszfstream &izs, std::string &line)
Definition: szfstream.hpp:178
Task that reads stats from data object and writes them to a [file].
Definition: task.stats.hpp:29
test-specific classes and functions
Definition: fstio.gtest.cpp:34
Static variables for logger. Include only once from main file.
int main(int argc, char **argv)
Public class with variables required by TextTask to compile and run.
bool run(Data &d)
General run method from TaskInterface. Dumps all stats to a file.
Definition: task.stats.hpp:51
Wrapper stream class that reads pipes, text files or gzipped files.
Definition: szfstream.hpp:34
std::string const kStatsWrite
Unit testing: google testing common header.
Static variable for custom_assert. Include only once from main file.