Go to the documentation of this file.00001 #ifndef LIBGEODECOMP_IO_PARALLELTESTWRITER_H
00002 #define LIBGEODECOMP_IO_PARALLELTESTWRITER_H
00003
00004 #include <list>
00005 #include <libgeodecomp/io/parallelwriter.h>
00006 #include <libgeodecomp/misc/clonable.h>
00007 #include <libgeodecomp/misc/testcell.h>
00008 #include <libgeodecomp/misc/testhelper.h>
00009
00010 namespace LibGeoDecomp {
00011
00016 class ParallelTestWriter : public Clonable<ParallelWriter<TestCell<2> >, ParallelTestWriter>
00017 {
00018 public:
00019 typedef ParallelWriter<TestCell<2> >::GridType GridType;
00020 using ParallelWriter<TestCell<2> >::region;
00021
00022 ParallelTestWriter(
00023 const unsigned period,
00024 const std::vector<unsigned>& expectedSteps,
00025 const std::vector<WriterEvent> expectedEvents) :
00026 Clonable<ParallelWriter<TestCell<2> >, ParallelTestWriter>("", period),
00027 expectedSteps(expectedSteps),
00028 expectedEvents(expectedEvents),
00029 lastStep(-1)
00030 {}
00031
00032 virtual void stepFinished(
00033 const GridType& grid,
00034 const Region<Topology::DIM>& validRegion,
00035 const Coord<Topology::DIM>& globalDimensions,
00036 unsigned step,
00037 WriterEvent event,
00038 std::size_t rank,
00039 bool lastCall)
00040 {
00041
00042 TS_ASSERT(!region.empty());
00043
00044
00045 if (lastStep != step) {
00046 TS_ASSERT(unaccountedRegion.empty());
00047 unaccountedRegion = region;
00048 }
00049 unaccountedRegion -= validRegion;
00050
00051 unsigned myExpectedCycle = APITraits::SelectNanoSteps<TestCell<2> >::VALUE * step;
00052 TS_ASSERT_TEST_GRID_REGION(GridType, grid, validRegion, myExpectedCycle);
00053
00054 TS_ASSERT(!expectedSteps.empty());
00055 unsigned expectedStep = expectedSteps.front();
00056 WriterEvent expectedEvent = expectedEvents.front();
00057 if (lastCall) {
00058 expectedSteps.erase(expectedSteps.begin());
00059 expectedEvents.erase(expectedEvents.begin());
00060 }
00061 TS_ASSERT_EQUALS(expectedStep, step);
00062 TS_ASSERT_EQUALS(expectedEvent, event);
00063
00064
00065 TS_ASSERT(!region.empty());
00066
00067 if (!(validRegion - region).empty()) {
00068 std::cout << "deltaRegion: " << (validRegion - region) << "\n";
00069 }
00070 TS_ASSERT((validRegion - region).empty());
00071
00072 if (lastCall) {
00073 TS_ASSERT(unaccountedRegion.empty());
00074 }
00075
00076 lastStep = step;
00077 }
00078
00079 private:
00080 std::vector<unsigned> expectedSteps;
00081 std::vector<WriterEvent> expectedEvents;
00082 unsigned lastStep;
00083 Region<2> unaccountedRegion;
00084 };
00085
00086 }
00087
00088 #endif