Skip to content

Commit

Permalink
Tests: update unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
YuLiu98 committed Jul 29, 2024
1 parent e831fce commit 4efde19
Showing 1 changed file with 42 additions and 20 deletions.
62 changes: 42 additions & 20 deletions source/module_io/test/read_exit_file_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,54 +30,76 @@ TEST_F(ReadStopFileTest, read_exit_file)
// case 1: no such file
int stop = ModuleIO::read_exit_file(GlobalV::MY_RANK, filename, ofs_running);
EXPECT_EQ(stop, 0);
MPI_Barrier(MPI_COMM_WORLD);

// case 2: no keywords in the file
std::ofstream ofs(filename.c_str(), std::ios::out);
ofs << "no keywords\n\ntest" << std::endl;
ofs.close();
std::ofstream ofs;
if (GlobalV::MY_RANK == 0)
{
ofs.open(filename.c_str(), std::ios::out);
ofs << "no keywords\n\ntest" << std::endl;
ofs.close();
}
MPI_Barrier(MPI_COMM_WORLD);
stop = ModuleIO::read_exit_file(GlobalV::MY_RANK, filename, ofs_running);
EXPECT_EQ(stop, 0);
MPI_Barrier(MPI_COMM_WORLD);
std::remove(filename.c_str());

// case 3: stop_ion = false stop_elec = false
ofs.open(filename.c_str(), std::ios::out);
ofs << "stop_ion false\nstop_elec 0" << std::endl;
ofs.close();
if (GlobalV::MY_RANK == 0)
{
std::remove(filename.c_str());
ofs.open(filename.c_str(), std::ios::out);
ofs << "stop_ion false\nstop_elec 0" << std::endl;
ofs.close();
}
MPI_Barrier(MPI_COMM_WORLD);
stop = ModuleIO::read_exit_file(GlobalV::MY_RANK, filename, ofs_running);
EXPECT_EQ(stop, 0);
MPI_Barrier(MPI_COMM_WORLD);
std::remove(filename.c_str());

// case 4: stop_ion = true stop_elec = false
ofs.open(filename.c_str(), std::ios::out);
ofs << "stop_ion true\nstop_elec f" << std::endl;
ofs.close();
if (GlobalV::MY_RANK == 0)
{
std::remove(filename.c_str());
ofs.open(filename.c_str(), std::ios::out);
ofs << "stop_ion true\nstop_elec f" << std::endl;
ofs.close();
}
MPI_Barrier(MPI_COMM_WORLD);
stop = ModuleIO::read_exit_file(GlobalV::MY_RANK, filename, ofs_running);
EXPECT_EQ(stop, 1);
MPI_Barrier(MPI_COMM_WORLD);
std::remove(filename.c_str());

// case 5: stop_ion = false stop_elec = true
ofs.open(filename.c_str(), std::ios::out);
ofs << "stop_ion F\nstop_elec 1" << std::endl;
ofs.close();
if (GlobalV::MY_RANK == 0)
{
std::remove(filename.c_str());
ofs.open(filename.c_str(), std::ios::out);
ofs << "stop_ion F\nstop_elec 1" << std::endl;
ofs.close();
}
MPI_Barrier(MPI_COMM_WORLD);
stop = ModuleIO::read_exit_file(GlobalV::MY_RANK, filename, ofs_running);
EXPECT_EQ(stop, 2);
MPI_Barrier(MPI_COMM_WORLD);
std::remove(filename.c_str());

// case 6: stop_ion = true stop_elec = true
ofs.open(filename.c_str(), std::ios::out);
ofs << "stop_ion T\nstop_elec t" << std::endl;
ofs.close();
if (GlobalV::MY_RANK == 0)
{
std::remove(filename.c_str());
ofs.open(filename.c_str(), std::ios::out);
ofs << "stop_ion T\nstop_elec t" << std::endl;
ofs.close();
}
MPI_Barrier(MPI_COMM_WORLD);
stop = ModuleIO::read_exit_file(GlobalV::MY_RANK, filename, ofs_running);
EXPECT_EQ(stop, 2);
MPI_Barrier(MPI_COMM_WORLD);
std::remove(filename.c_str());

ofs_running.close();
std::remove(output.c_str());
std::remove(filename.c_str());
}

int main(int argc, char** argv)
Expand Down

0 comments on commit 4efde19

Please sign in to comment.