| 1 |
#include <gtest/gtest.h> |
| 2 |
#include <unistd.h> // for unlink |
| 3 |
#include <stk_io/StkMeshIoBroker.hpp> // for StkMeshIoBroker |
| 4 |
#include <stk_io/DatabasePurpose.hpp> // for DatabasePurpose::READ_MESH, etc |
| 5 |
#include <stk_mesh/base/Field.hpp> // for Field |
| 6 |
#include <stk_mesh/base/MetaData.hpp> // for MetaData, put_field |
| 7 |
#include <stk_topology/topology.hpp> // for topology, etc |
| 8 |
#include <stk_unit_test_utils/MeshFixture.hpp> |
| 9 |
#include <stk_unit_test_utils/meshCreationHelpers.hpp> |
| 10 |
|
| 11 |
namespace |
| 12 |
{ |
| 13 |
|
| 14 |
class StkIoHowToQaRecords : public stk::unit_test_util::MeshFixture |
| 15 |
{ |
| 16 |
protected: |
| 17 |
void write_qa_information() |
| 18 |
{ |
| 19 |
stk::io::StkMeshIoBroker stkIo(get_comm()); |
| 20 |
stkIo.set_bulk_data(get_bulk()); |
| 21 |
size_t fileId = stkIo.create_output_mesh(filename, stk::io::WRITE_RESULTS); |
| 22 |
stkIo.set_name_and_version_for_qa_record(fileId, codeName, codeVersion); |
| 23 |
stkIo.add_qa_records(fileId, qaRecords); |
| 24 |
stkIo.add_info_records(fileId, infos); |
| 25 |
stkIo.write_output_mesh(fileId); |
| 26 |
} |
| 27 |
|
| 28 |
void read_qa_information_and_verify() |
| 29 |
{ |
| 30 |
stk::io::StkMeshIoBroker stkIo(get_comm()); |
| 31 |
size_t fileId = stkIo.add_mesh_database(filename, stk::io::READ_MESH); |
| 32 |
stkIo.set_active_mesh(fileId); |
| 33 |
std::vector<stk::io::QaRecord> qas = stkIo.get_qa_records(); |
| 34 |
std::vector<std::string> infosGotten = stkIo.get_info_records(); |
| 35 |
|
| 36 |
verify_qa_information(qas, infosGotten); |
| 37 |
} |
| 38 |
void verify_qa_information(const std::vector<stk::io::QaRecord> &qas, const std::vector<std::string> &infosGotten) |
| 39 |
{ |
| 40 |
ASSERT_EQ(2u, qas.size()); |
| 41 |
EXPECT_EQ(qaRecords[0].name, qas[0].name); |
| 42 |
EXPECT_EQ(qaRecords[0].version, qas[0].version); |
| 43 |
EXPECT_EQ(qaRecords[0].date, qas[0].date); |
| 44 |
EXPECT_EQ(qaRecords[0].time, qas[0].time); |
| 45 |
EXPECT_EQ(codeName, qas[1].name); |
| 46 |
EXPECT_EQ(codeVersion, qas[1].version); |
| 47 |
EXPECT_NE(std::find(infosGotten.begin(), infosGotten.end(), infos[0]), infosGotten.end()); |
| 48 |
EXPECT_NE(std::find(infosGotten.begin(), infosGotten.end(), infos[1]), infosGotten.end()); |
| 49 |
} |
| 50 |
|
| 51 |
const std::string filename = "file.exo"; |
| 52 |
const std::string codeName = "Name" ; |
| 53 |
const std::string codeVersion = "Version"; |
| 54 |
const std::vector<stk::io::QaRecord> qaRecords = {{"codeName", "codeVersion", "Today", "RightNow"}}; |
| 55 |
const std::vector<std::string> infos = {"info0", "info1"}; |
| 56 |
}; |
| 57 |
|
| 58 |
TEST_F(StkIoHowToQaRecords, write_read) |
| 59 |
{ |
| 60 |
setup_mesh("generated:1x1x4", stk::mesh::BulkData::NO_AUTO_AURA); |
| 61 |
write_qa_information(); |
| 62 |
read_qa_information_and_verify(); |
| 63 |
unlink(filename.c_str()); |
| 64 |
} |
| 65 |
|
| 66 |
} |