testRawFile.cc
Go to the documentation of this file.
1 
9 #include <io/RawCorsikaFile.h>
10 #include <io/CorsikaBlock.h>
11 #include <io/CorsikaIOException.h>
12 
13 #include <cppunit/extensions/HelperMacros.h>
14 
15 #include <iostream>
16 
17 #include <tst/Verify.h>
18 
20 using io::Corsika::Block;
21 using tst::Expected;
22 
23 
24 class testRawFile : public CppUnit::TestFixture {
25 
38 // CPPUNIT_TEST_EXCEPTION(testIDThrow, io::CorsikaIOException);
39 // CPPUNIT_TEST(testSizeBlock);
41 
42 public:
43  // shared data for tests
44 
45  static const int kBlockSize = sizeof(Block);
46 
48 
49  void setUp()
50  {
51  f = new RawFile();
52  }
53 
54  void tearDown()
55  {
56  delete f;
57  }
58 
59  void testSize()
60  {
61  CPPUNIT_ASSERT(sizeof(RawFile::ThinnedDiskBlock) ==
62  kBlockSize*RawFile::kBlocksInDiskBlock);
63  }
64 
66  {
67  RawFile f1;
68  RawFile f2(TESTFILE);
69  }
70 
72  {
73  Expected();
74  RawFile f1("NoSuchCorsikaFile.part");
75  }
76 
77  void testOpen()
78  {
79  CPPUNIT_ASSERT(!f->IsOpen());
80  f->Open(TESTFILE);
81  CPPUNIT_ASSERT(f->IsOpen());
82  }
83 
85  {
86  Expected();
87  f->Open("NoSuchCorsikaFile.part");
88  }
89 
91  {
92  f->Open(TESTFILE);
93  Expected();
94  f->Open(TESTFILE);
95  }
96 
97  void testClose()
98  {
99  f->Close(); // No-op on closed file
100  f->Open(TESTFILE);
101  f->Close();
102  }
103 
105  {
106  f->Open(TESTFILE);
107  f->Close();
108  f->Open(TESTFILE);
109  }
110 
112  {
113  f->Open(TESTFILE);
114  Block b;
115  CPPUNIT_ASSERT(f->GetNextBlock(b));
116  CPPUNIT_ASSERT(b.IsRunHeader());
117 
118  CPPUNIT_ASSERT(f->GetNextBlock(b));
119  CPPUNIT_ASSERT(b.IsEventHeader());
120  }
121 
123  {
124  f->Open(TESTFILE);
125  Block b;
126  bool trailerFound = false;
127  while (!trailerFound) {
128  CPPUNIT_ASSERT(f->GetNextBlock(b));
129  trailerFound = b.IsRunTrailer();
130  }
131  }
132 
134  {
135  f->Open(TESTFILE);
136  Block b;
137  RawFile::PositionType posTrailer;
138 
139  bool trailerFound = false;
140 
141  while (!trailerFound) {
142  f->GetNextBlock(b);
143  trailerFound = b.IsRunTrailer();
144  posTrailer = f->GetNextPosition() - 1;
145  }
146 
147  f->SeekTo(1); // 2nd block
148  CPPUNIT_ASSERT(f->GetNextBlock(b));
149  CPPUNIT_ASSERT(b.IsEventHeader());
150 
151  f->SeekTo(posTrailer);
152  CPPUNIT_ASSERT(f->GetNextBlock(b));
153  CPPUNIT_ASSERT(b.IsRunTrailer());
154 
155  f->SeekTo(posTrailer-1);
156  CPPUNIT_ASSERT(f->GetNextBlock(b));
157  CPPUNIT_ASSERT(b.IsEventTrailer());
158 
159  f->SeekTo(0);
160  CPPUNIT_ASSERT(f->GetNextBlock(b));
161  CPPUNIT_ASSERT(b.IsRunHeader());
162 
163  }
164 
165 };
166 
167 
169 
170 
171 // Configure (x)emacs for this file ...
172 // Local Variables:
173 // mode: c++
174 // compile-command: "make -C .. -k testCorsika && (cd ..; testCorsika)"
175 // End:
CPPUNIT_TEST_EXCEPTION(testConstructorThrow, io::CorsikaIOException)
void testReadHeader()
Definition: testRawFile.cc:111
void testOpenThrowNonExistent()
Definition: testRawFile.cc:84
void setUp()
Definition: testRawFile.cc:49
static const int kBlockSize
Definition: testRawFile.cc:45
void testSize()
Definition: testRawFile.cc:59
void Close()
Close file (no-op for closed file).
CPPUNIT_TEST_SUITE(testRawFile)
void testRandomAccess()
Definition: testRawFile.cc:133
void testOpenThrowReOpen()
Definition: testRawFile.cc:90
Raw disk file.
bool GetNextBlock(Block &block)
Read one block and advance.
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
bool IsOpen() const
Check if the file is open.
void testOpenCloseOpen()
Definition: testRawFile.cc:104
Base for exceptions in the CORSIKA reader.
void testReadToTrailer()
Definition: testRawFile.cc:122
void Expected()
Print `Expected&#39; for expected failures.
Definition: Verify.h:85
void tearDown()
Definition: testRawFile.cc:54
BasicBlock< ParticleData, CherenkovData, kParticlesInBlock, 39 > Block
Definition: CorsikaBlock.h:443
void SeekTo(const PositionType position, const bool reset=false)
Seek to a given block, the next block will be thePosition.
CPPUNIT_TEST(testSize)
PositionType GetNextPosition() const
Number of the block read by the next call to GetNextBlock.
RawFile * f
Definition: testRawFile.cc:47
void testConstructorThrow()
Definition: testRawFile.cc:71
bool Open(const std::string &name, const bool noException=false)
void testConstructor()
Definition: testRawFile.cc:65
CPPUNIT_TEST_SUITE_END()
void testOpen()
Definition: testRawFile.cc:77
void testClose()
Definition: testRawFile.cc:97
This class represents a corsika block. It deals with all the different sub-types of blocks...

, generated on Tue Sep 26 2023.