Commit b0ddbe1b authored by ext-calvo_p's avatar ext-calvo_p

Merge branch '652-dumpfieldstest-and-dumpemfieldstest-failed' into 'master'

Resolve "DumpFieldsTest and DumpEMFieldsTest failed"

Closes #652

See merge request OPAL/src!495
parents ad2c6977 6132c8ef
......@@ -18,14 +18,16 @@
//
#include "BasicActions/DumpEMFields.h"
#include "AbsBeamline/Component.h"
#include "AbstractObjects/OpalData.h"
#include "AbsBeamline/Component.h"
#include "Attributes/Attributes.h"
#include "Fields/Interpolation/NDGrid.h"
#include "Physics/Physics.h"
#include "Utilities/OpalException.h"
#include "Utilities/Util.h"
#include <boost/filesystem.hpp>
#include <fstream>
#include <cmath>
......@@ -39,8 +41,7 @@ DumpEMFields::DumpEMFields() :
"field file, for checking that fields are generated correctly. "
"The fields are written out on a grid in space and time."),
grid_m(NULL),
filename_m(""),
coordinates_m(CoordinateSystem::CARTESIAN) {
filename_m("") {
// would be nice if "steps" could be integer
itsAttr[FILE_NAME] = Attributes::makeString
......@@ -107,7 +108,7 @@ DumpEMFields::DumpEMFields() :
}
DumpEMFields::DumpEMFields(const std::string& name, DumpEMFields* parent):
Action(name, parent)
Action(name, parent), grid_m(NULL)
{}
DumpEMFields::~DumpEMFields() {
......@@ -214,12 +215,12 @@ void DumpEMFields::checkInt(double real, std::string name, double tolerance) {
real += tolerance; // prevent rounding error
if (std::abs(std::floor(real) - real) > 2*tolerance) {
throw OpalException("DumpEMFields::checkInt",
"Value for "+name+
"Value for " + name +
" should be an integer but a real value was found");
}
if (std::floor(real) < 0.5) {
throw OpalException("DumpEMFields::checkInt",
"Value for "+name+" should be 1 or more");
"Value for " + name + " should be 1 or more");
}
}
......@@ -271,9 +272,9 @@ void DumpEMFields::writeFieldLine(Component* field,
Vector_t Eout = E;
if (coordinates_m == CoordinateSystem::CYLINDRICAL) {
// pointIn is r, phi, z
Bout[0] = B[0]*std::cos(pointIn[1])+B[1]*std::sin(pointIn[1]);
Bout[0] = B[0]*std::cos(pointIn[1])+B[1]*std::sin(pointIn[1]);
Bout[1] = -B[0]*std::sin(pointIn[1])+B[1]*std::cos(pointIn[1]);
Eout[0] = E[0]*std::cos(pointIn[1])+E[1]*std::sin(pointIn[1]);
Eout[0] = E[0]*std::cos(pointIn[1])+E[1]*std::sin(pointIn[1]);
Eout[1] = -E[0]*std::sin(pointIn[1])+E[1]*std::cos(pointIn[1]);
fout << pointIn[0] << " " << pointIn[1]*Physics::rad2deg << " " << pointIn[2] << " " << time << " ";
} else {
......@@ -296,22 +297,28 @@ void DumpEMFields::writeFieldThis(Component* field) {
*gmsg << *this << endl;
std::string fname = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(),
filename_m
});
std::string fname;
if (boost::filesystem::path(filename_m).is_absolute() == true) {
fname = filename_m;
} else {
fname = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(),
filename_m
});
}
std::vector<double> point_std(4);
Vector_t point(0., 0., 0.);
std::ofstream fout;
try {
fout.open(filename_m.c_str(), std::ofstream::out);
fout.open(fname.c_str(), std::ofstream::out);
} catch (std::exception& exc) {
throw OpalException("DumpEMFields::writeFieldThis",
"Failed to open DumpEMFields file "+filename_m);
"Failed to open DumpEMFields file " + filename_m);
}
if (!fout.good()) {
throw OpalException("DumpEMFields::writeFieldThis",
"Failed to open DumpEMFields file "+filename_m);
"Failed to open DumpEMFields file " + filename_m);
}
// set precision
writeHeader(fout);
......@@ -327,7 +334,7 @@ void DumpEMFields::writeFieldThis(Component* field) {
}
if (!fout.good()) {
throw OpalException("DumpEMFields::writeFieldThis",
"Something went wrong during writing "+filename_m);
"Something went wrong during writing " + filename_m);
}
fout.close();
}
......
......@@ -79,11 +79,6 @@ public:
SIZE
};
enum class CoordinateSystem {
CARTESIAN,
CYLINDRICAL
};
/** Constructor */
DumpEMFields();
......@@ -129,6 +124,12 @@ public:
void print(std::ostream& os) const;
private:
enum class CoordinateSystem {
CARTESIAN,
CYLINDRICAL
};
virtual void writeFieldThis(Component* field);
virtual void buildGrid();
void parseCoordinateSystem();
......
......@@ -17,13 +17,15 @@
//
#include "BasicActions/DumpFields.h"
#include "AbsBeamline/Component.h"
#include "AbstractObjects/OpalData.h"
#include "AbsBeamline/Component.h"
#include "Attributes/Attributes.h"
#include "Fields/Interpolation/ThreeDGrid.h"
#include "Utilities/OpalException.h"
#include "Utilities/Util.h"
#include <boost/filesystem.hpp>
#include <fstream>
extern Inform* gmsg;
......@@ -134,12 +136,12 @@ void DumpFields::writeFields(Component* field) {
void DumpFields::checkInt(double real, std::string name, double tolerance) {
if (std::abs(std::floor(real) - real) > tolerance) {
throw OpalException("DumpFields::checkInt",
"Value for "+name+
"Value for " + name +
" should be an integer but a real value was found");
}
if (std::floor(real) < 0.5) {
throw OpalException("DumpFields::checkInt",
"Value for "+name+" should be 1 or more");
"Value for " + name + " should be 1 or more");
}
}
......@@ -155,17 +157,23 @@ void DumpFields::writeFieldThis(Component* field) {
*gmsg << *this << endl;
std::string fname = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(),
filename_m
});
std::string fname;
if (boost::filesystem::path(filename_m).is_absolute() == true) {
fname = filename_m;
} else {
fname = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(),
filename_m
});
}
double time = 0.;
Vector_t point(0., 0., 0.);
Vector_t centroid(0., 0., 0.);
std::ofstream fout(fname.c_str(), std::ofstream::out);
if (!fout.good()) {
throw OpalException("DumpFields::writeFieldThis",
"Failed to open DumpFields file "+filename_m);
"Failed to open DumpFields file " + filename_m);
}
// set precision
fout << grid_m->end().toInteger() << "\n";
......@@ -188,22 +196,22 @@ void DumpFields::writeFieldThis(Component* field) {
}
if (!fout.good()) {
throw OpalException("DumpFields::writeFieldThis",
"Something went wrong during writing "+filename_m);
"Something went wrong during writing " + filename_m);
}
fout.close();
}
void DumpFields::print(std::ostream& os) const {
os << "* ************* D U M P F I E L D S *********************************************** " << std::endl;
os << "* File name: " << Attributes::getString(itsAttr[FILE_NAME]) << '\n'
<< "* X_START = " << Attributes::getReal(itsAttr[X_START]) << " [m]\n"
<< "* DX = " << Attributes::getReal(itsAttr[DX]) << " [m]\n"
<< "* X_STEPS = " << Attributes::getReal(itsAttr[X_STEPS]) << '\n'
<< "* Y_START = " << Attributes::getReal(itsAttr[Y_START]) << " [m]\n"
<< "* DY = " << Attributes::getReal(itsAttr[DY]) << " [m]\n"
<< "* Y_STEPS = " << Attributes::getReal(itsAttr[Y_STEPS]) << '\n'
<< "* Z_START = " << Attributes::getReal(itsAttr[Z_START]) << " [m]\n"
<< "* DZ = " << Attributes::getReal(itsAttr[DZ]) << " [m]\n"
<< "* Z_STEPS = " << Attributes::getReal(itsAttr[Z_STEPS]) << '\n';
os << "* File name: " << filename_m << '\n'
<< "* X_START = " << Attributes::getReal(itsAttr[X_START]) << " [m]\n"
<< "* DX = " << Attributes::getReal(itsAttr[DX]) << " [m]\n"
<< "* X_STEPS = " << Attributes::getReal(itsAttr[X_STEPS]) << '\n'
<< "* Y_START = " << Attributes::getReal(itsAttr[Y_START]) << " [m]\n"
<< "* DY = " << Attributes::getReal(itsAttr[DY]) << " [m]\n"
<< "* Y_STEPS = " << Attributes::getReal(itsAttr[Y_STEPS]) << '\n'
<< "* Z_START = " << Attributes::getReal(itsAttr[Z_START]) << " [m]\n"
<< "* DZ = " << Attributes::getReal(itsAttr[DZ]) << " [m]\n"
<< "* Z_STEPS = " << Attributes::getReal(itsAttr[Z_STEPS]) << '\n';
os << "* ********************************************************************************** " << std::endl;
}
......@@ -24,7 +24,6 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <fstream>
#include <iostream>
......@@ -32,9 +31,13 @@
#include "opal_src/Utilities/MockComponent.h"
#include "BasicActions/DumpEMFields.h"
#include "AbstractObjects/OpalData.h"
#include "Attributes/Attributes.h"
#include "Physics/Physics.h"
#include "Utilities/OpalException.h"
#include "BasicActions/DumpEMFields.h"
#include "Utilities/Util.h"
#include "opal_test_utilities/SilenceTest.h"
......@@ -64,7 +67,7 @@ void setAttributesCart(DumpEMFields* dump,
setOneAttribute(dump, "T_STEPS", nt);
Attributes::setString(*dump->findAttribute("FILE_NAME"), filename);
if (!defaultCoords) {
Attributes::setString(*dump->findAttribute("COORDINATE_SYSTEM"), "cARtesiAN");
Attributes::setUpperCaseString(*dump->findAttribute("COORDINATE_SYSTEM"), "cARtesiAN");
}
}
......@@ -87,7 +90,7 @@ void setAttributesCyl(DumpEMFields* dump,
setOneAttribute(dump, "DT", dt);
setOneAttribute(dump, "T_STEPS", nt);
Attributes::setString(*dump->findAttribute("FILE_NAME"), filename);
Attributes::setString(*dump->findAttribute("COORDINATE_SYSTEM"), "cYLindriCAL");
Attributes::setUpperCaseString(*dump->findAttribute("COORDINATE_SYSTEM"), "cYLindriCAL");
}
TEST(DumpEMFieldsTest, ConstructorDestructor) {
OpalTestUtilities::SilenceTest silencer;
......@@ -97,7 +100,7 @@ TEST(DumpEMFieldsTest, ConstructorDestructor) {
delete dump1;
// grid is not null and it is in the set
DumpEMFields* dump2 = new DumpEMFields();
setAttributesCart(dump2, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "/dev/null");
setAttributesCart(dump2, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "/dev/null");
dump2->execute();
delete dump2;
}
......@@ -117,30 +120,47 @@ TEST(DumpEMFieldsTest, executeTest) {
// dump the fields
DumpEMFields dump1;
execute_throws(&dump1, "should throw due to nsteps < 1");
setAttributesCart(&dump1, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "/dev/null", true);
setAttributesCart(&dump1, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "/dev/null", true);
dump1.execute(); // should be okay (normal)
setAttributesCart(&dump1, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "/dev/null", false);
setAttributesCart(&dump1, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "/dev/null", false);
dump1.execute(); // should be okay (normal)
setAttributesCart(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 1., 1., 1., 1., "/dev/null");
setAttributesCart(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 1., 1., 1., 1., "/dev/null");
dump1.execute(); // should be okay (-ve step is okay)
setAttributesCart(&dump1, -1., -1., 0., -1., -1., 1., -1., -1., 1., 1., 1., 1., "/dev/null");
setAttributesCart(&dump1, -1., -1., 0., -1., -1., 1., -1., -1., 1., 1., 1., 1., "/dev/null");
execute_throws(&dump1, "should throw due to nsteps x < 1");
setAttributesCart(&dump1, -1., -1., 1., -1., -1., 0., -1., -1., 1., 1., 1., 1., "/dev/null");
setAttributesCart(&dump1, -1., -1., 1., -1., -1., 0., -1., -1., 1., 1., 1., 1., "/dev/null");
execute_throws(&dump1, "should throw due to nsteps y < 1");
setAttributesCart(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 0., 1., 1., 1., "/dev/null");
setAttributesCart(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 0., 1., 1., 1., "/dev/null");
execute_throws(&dump1, "should throw due to nsteps z < 1");
setAttributesCart(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 1., 1., 1., 0., "/dev/null");
setAttributesCart(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 1., 1., 1., 0., "/dev/null");
execute_throws(&dump1, "should throw due to nsteps t < 1");
setAttributesCart(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 1.5, 1., 1., 1., "/dev/null");
setAttributesCart(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 1.5, 1., 1., 1., "/dev/null");
execute_throws(&dump1, "should throw due to nsteps not integer");
}
void clear_files() {
std::string fname1 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test1"
});
std::string fname2 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test2"
});
std::string fname3 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test3"
});
std::string fname4 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test4"
});
std::string fnameCyl = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "testCyl"
});
size_t n_str_array = 0;
std::string str_array[5] = {"test1", "test2", "test3", "test4", "testCyl"};
std::string str_array[5] = {fname1, fname2, fname3, fname4, fnameCyl};
for (size_t i = 0; i < n_str_array; ++i) {
if (fopen(str_array[i].c_str(), "r") != NULL) {
remove(str_array[i].c_str());
if (std::fopen(str_array[i].c_str(), "r") != NULL) {
std::remove(str_array[i].c_str());
}
}
}
......@@ -148,18 +168,31 @@ void clear_files() {
TEST(DumpEMFieldsTest, writeFieldsCartTest) {
OpalTestUtilities::SilenceTest silencer;
std::string fname1 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test1"
});
std::string fname2 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test2"
});
std::string fname3 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test3"
});
std::string fname4 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test4"
});
clear_files();
DumpEMFields dump1;
setAttributesCart(&dump1, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "test1");
setAttributesCart(&dump1, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "test1");
dump1.execute();
DumpEMFields dump2;
setAttributesCart(&dump2, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "test2");
setAttributesCart(&dump2, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "test2");
dump2.execute();
DumpEMFields dump3;
setAttributesCart(&dump3, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "test3");
setAttributesCart(&dump3, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "test3");
// note we don't execute dump3; so it should not be written
DumpEMFields dump4;
setAttributesCart(&dump4, 0.1, 0.1, 3., -0.1, 0.2, 2., 0.2, 0.3, 2., 1., 1., 2., "test4");
setAttributesCart(&dump4, 0.1, 0.1, 3., -0.1, 0.2, 2., 0.2, 0.3, 2., 1., 1., 2., "test4");
dump4.execute();
MockComponent comp;
try {
......@@ -167,13 +200,13 @@ TEST(DumpEMFieldsTest, writeFieldsCartTest) {
} catch (OpalException& exc) {
EXPECT_TRUE(false) << "Threw OpalException on writefields: " << exc.what() << std::endl;;
}
std::ifstream fin1("test1");
std::ifstream fin1(fname1);
EXPECT_TRUE(fin1.good());
std::ifstream fin2("test2");
std::ifstream fin2(fname2);
EXPECT_TRUE(fin2.good());
std::ifstream fin3("test3");
EXPECT_FALSE(fin3.good()); // does not exist
std::ifstream fin4("test4");
std::ifstream fin3(fname3);
EXPECT_FALSE(fin3.good()); // does not exist
std::ifstream fin4(fname4);
EXPECT_TRUE(fin4.good());
int n_lines;
fin4 >> n_lines;
......@@ -212,10 +245,14 @@ TEST(DumpEMFieldsTest, writeFieldsCartTest) {
TEST(DumpEMFieldsTest, writeFieldsCylTest) {
OpalTestUtilities::SilenceTest silencer;
const double rad = M_PI/180.;
std::string fnameCyl = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "testCyl"
});
clear_files();
DumpEMFields dump;
setAttributesCyl(&dump, 0.1, 0.1, 3., 90.*rad, 45.*rad, 16, 0.2, 0.3, 2., 1., 1., 2., "testCyl");
setAttributesCyl(&dump, 0.1, 0.1, 3., 90.*Physics::deg2rad, 45.*Physics::deg2rad, 16, 0.2, 0.3, 2., 1., 1., 2., "testCyl");
dump.execute();
// depending on execution order, this might write cartesian tests as well... never mind
MockComponent comp;
......@@ -224,7 +261,7 @@ TEST(DumpEMFieldsTest, writeFieldsCylTest) {
} catch (OpalException& exc) {
EXPECT_TRUE(false) << "Threw OpalException on writefields: " << exc.what() << std::endl;;
}
std::ifstream fin("testCyl");
std::ifstream fin(fnameCyl);
EXPECT_TRUE(fin.good());
int n_lines;
fin >> n_lines;
......@@ -264,4 +301,5 @@ TEST(DumpEMFieldsTest, writeFieldsCylTest) {
// EXPECT_TRUE(false) << "Do DumpEMFields cylindrical documentation!";
}
}
......@@ -24,16 +24,18 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <fstream>
#include "gtest/gtest.h"
#include "opal_src/Utilities/MockComponent.h"
#include "BasicActions/DumpFields.h"
#include "AbstractObjects/OpalData.h"
#include "Attributes/Attributes.h"
#include "Utilities/OpalException.h"
#include "BasicActions/DumpFields.h"
#include "Utilities/Util.h"
#include "opal_test_utilities/SilenceTest.h"
......@@ -70,7 +72,7 @@ TEST(DumpFieldsTest, ConstructorDestructor) {
delete dump1;
// grid is not null and it is in the set
DumpFields* dump2 = new DumpFields();
setAttributes(dump2, 1., 1., 1., 1., 1., 1., 1., 1., 1., "/dev/null");
setAttributes(dump2, 1., 1., 1., 1., 1., 1., 1., 1., 1., "/dev/null");
dump2->execute();
delete dump2;
}
......@@ -90,26 +92,40 @@ TEST(DumpFieldsTest, executeTest) {
// dump the fields
DumpFields dump1;
execute_throws(&dump1, "should throw due to nsteps < 1");
setAttributes(&dump1, 1., 1., 1., 1., 1., 1., 1., 1., 1., "/dev/null");
setAttributes(&dump1, 1., 1., 1., 1., 1., 1., 1., 1., 1., "/dev/null");
dump1.execute(); // should be okay (normal)
setAttributes(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 1., "/dev/null");
setAttributes(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 1., "/dev/null");
dump1.execute(); // should be okay (-ve step is okay)
setAttributes(&dump1, -1., -1., 0., -1., -1., 1., -1., -1., 1., "/dev/null");
setAttributes(&dump1, -1., -1., 0., -1., -1., 1., -1., -1., 1., "/dev/null");
execute_throws(&dump1, "should throw due to nsteps x < 1");
setAttributes(&dump1, -1., -1., 1., -1., -1., 0., -1., -1., 1., "/dev/null");
setAttributes(&dump1, -1., -1., 1., -1., -1., 0., -1., -1., 1., "/dev/null");
execute_throws(&dump1, "should throw due to nsteps y < 1");
setAttributes(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 0., "/dev/null");
setAttributes(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 0., "/dev/null");
execute_throws(&dump1, "should throw due to nsteps z < 1");
setAttributes(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 1.5, "/dev/null");
setAttributes(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 1.5, "/dev/null");
execute_throws(&dump1, "should throw due to nsteps not integer");
}
void clear_files() {
std::string fname1 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test1"
});
std::string fname2 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test2"
});
std::string fname3 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test3"
});
std::string fname4 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test4"
});
size_t n_str_array = 4;
std::string str_array[4] = {"test1", "test2", "test3", "test4"};
std::string str_array[4] = {fname1,fname2,fname3,fname4};
for (size_t i = 0; i < n_str_array; ++i) {
if (fopen(str_array[i].c_str(), "r") != NULL) {
remove(str_array[i].c_str());
if (std::fopen(str_array[i].c_str(), "r") != NULL) {
std::remove(str_array[i].c_str());
}
}
}
......@@ -117,18 +133,31 @@ void clear_files() {
TEST(DumpFieldsTest, writeFieldsTest) {
OpalTestUtilities::SilenceTest silencer;
std::string fname1 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test1"
});
std::string fname2 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test2"
});
std::string fname3 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test3"
});
std::string fname4 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test4"
});
clear_files();
DumpFields dump1;
setAttributes(&dump1, 1., 1., 1., 1., 1., 1., 1., 1., 1., "test1");
setAttributes(&dump1, 1., 1., 1., 1., 1., 1., 1., 1., 1., "test1");
dump1.execute();
DumpFields dump2;
setAttributes(&dump2, 1., 1., 1., 1., 1., 1., 1., 1., 1., "test2");
setAttributes(&dump2, 1., 1., 1., 1., 1., 1., 1., 1., 1., "test2");
dump2.execute();
DumpFields dump3;
setAttributes(&dump3, 1., 1., 1., 1., 1., 1., 1., 1., 1., "test3");
setAttributes(&dump3, 1., 1., 1., 1., 1., 1., 1., 1., 1., "test3");
// note we don't execute dump3; so it should not be written
DumpFields dump4;
setAttributes(&dump4, 0.1, 0.1, 3., -0.1, 0.2, 2., 0.2, 0.3, 2., "test4");
setAttributes(&dump4, 0.1, 0.1, 3., -0.1, 0.2, 2., 0.2, 0.3, 2., "test4");
dump4.execute();
MockComponent comp;
try {
......@@ -136,13 +165,13 @@ TEST(DumpFieldsTest, writeFieldsTest) {
} catch (OpalException& exc) {
EXPECT_TRUE(false) << "Threw OpalException on writefields: " << exc.what() << std::endl;;
}
std::ifstream fin1("test1");
std::ifstream fin1(fname1);
EXPECT_TRUE(fin1.good());
std::ifstream fin2("test2");
std::ifstream fin2(fname2);
EXPECT_TRUE(fin2.good());
std::ifstream fin3("test3");
std::ifstream fin3(fname3);
EXPECT_FALSE(fin3.good()); // does not exist
std::ifstream fin4("test4");
std::ifstream fin4(fname4);
EXPECT_TRUE(fin4.good());
int n_lines;
fin4 >> n_lines;
......@@ -175,4 +204,4 @@ TEST(DumpFieldsTest, writeFieldsTest) {
clear_files();
}
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment