Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: eliminate compilaton error due to the #define private public macro in all unittests #4733

Merged
merged 7 commits into from
Jul 19, 2024
2 changes: 1 addition & 1 deletion source/module_base/global_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#endif

#include <unistd.h>

#include <sstream>
#include "global_function.h"
#include "global_variable.h"
#include "module_base/parallel_common.h"
Expand Down
1 change: 0 additions & 1 deletion source/module_base/global_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <string>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>

//==========================================================
Expand Down
1 change: 0 additions & 1 deletion source/module_base/global_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

Expand Down
2 changes: 1 addition & 1 deletion source/module_base/test/memory_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace GlobalV

#define private public
#include "../memory.h"
#undef private

class MemoryTest : public testing::Test
{
Expand Down Expand Up @@ -151,4 +152,3 @@ TEST_F(MemoryTest, finish)
ofs.close();
EXPECT_FALSE(ModuleBase::Memory::init_flag);
}
#undef private
1 change: 0 additions & 1 deletion source/module_base/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <iomanip>
#include <iostream>
#include <map>
#include <sstream>
#include <string>

namespace ModuleBase
Expand Down
1 change: 0 additions & 1 deletion source/module_base/tool_check.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "tool_check.h"

#include "tool_quit.h"

namespace ModuleBase
Expand Down
1 change: 0 additions & 1 deletion source/module_base/tool_check.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <valarray>
#include <vector>
Expand Down
1 change: 0 additions & 1 deletion source/module_base/tool_quit.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <valarray>
#include <vector>
Expand Down
1 change: 0 additions & 1 deletion source/module_base/tool_title.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <string>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <cassert>
Expand Down
6 changes: 4 additions & 2 deletions source/module_basis/module_pw/test_serial/pw_basis_k_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include "../pw_basis_k.h"
#include "../pw_basis.h"
#include "../fft.h"
#undef private
#undef protected

class PWBasisKTEST: public testing::Test
{
public:
Expand Down Expand Up @@ -188,5 +191,4 @@ TEST_F(PWBasisKTEST, CollectLocalPW)
EXPECT_EQ(basis_k.npwk_max,2721);
}

#undef private
#undef protected

5 changes: 3 additions & 2 deletions source/module_basis/module_pw/test_serial/pw_basis_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#define private public
#include "../pw_basis.h"
#include "../fft.h"
#undef private
#undef protected

class PWBasisTEST: public testing::Test
{
public:
Expand Down Expand Up @@ -360,5 +363,3 @@ TEST_F(PWBasisTEST,CollectUniqgg)
pwb.collect_uniqgg();
EXPECT_EQ(pwb.ngg,78);
}
#undef private
#undef protected
4 changes: 1 addition & 3 deletions source/module_cell/module_neighbor/test/sltk_grid_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define private public
#include "../sltk_grid.h"
#include "prepare_unitcell.h"

#undef private
#ifdef __LCAO
InfoNonlocal::InfoNonlocal()
{
Expand Down Expand Up @@ -174,5 +174,3 @@ TEST_F(SltkGridTest, InitNoExpand)
ofs.close();
}
*/

#undef private
5 changes: 3 additions & 2 deletions source/module_cell/module_paw/paw_element.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "paw_element.h"
#include "module_base/tool_title.h"
#include "module_base/tool_quit.h"
#include <sstream>

void Paw_Element::init_paw_element(const double ecutwfc_in, const double cell_factor_in)
{
Expand Down Expand Up @@ -172,7 +173,7 @@ std::string Paw_Element::scan_file(std::ifstream &ifs, std::string pattern)
}

ModuleBase::WARNING_QUIT("Paw_Element::scan_file","pattern not found in xml file!");
return 0;
return nullptr;
}

double Paw_Element::extract_double(std::string line, std::string key)
Expand Down Expand Up @@ -212,7 +213,7 @@ std::string Paw_Element::extract_string(std::string line, std::string key)
ModuleBase::WARNING_QUIT("Paw_Element::extract_double","key not found in line!");
}

return 0;
return nullptr;
}

int Paw_Element::extract_int(std::string line, std::string key)
Expand Down
1 change: 0 additions & 1 deletion source/module_cell/module_paw/paw_element.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <vector>
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>

class Paw_Element
Expand Down
3 changes: 1 addition & 2 deletions source/module_cell/test/atom_pseudo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "module_cell/read_pp.h"
#include "module_cell/pseudo.h"
#include "module_cell/atom_pseudo.h"

#undef private
class AtomPseudoTest : public testing::Test
{
protected:
Expand Down Expand Up @@ -99,4 +99,3 @@ int main(int argc, char **argv)
return result;
}
#endif
#undef private
4 changes: 2 additions & 2 deletions source/module_cell/test/atom_spec_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "module_cell/pseudo.h"
#include "module_cell/atom_pseudo.h"
#include "module_cell/atom_spec.h"

#undef private
class AtomSpecTest : public testing::Test
{
protected:
Expand Down Expand Up @@ -218,4 +218,4 @@ int main(int argc, char **argv)
return result;
}
#endif
#undef private

26 changes: 12 additions & 14 deletions source/module_cell/test/klist_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include "module_hamilt_pw/hamilt_pwdft/VNL_in_pw.h"
#include "module_hamilt_pw/hamilt_pwdft/parallel_grid.h"
#include "module_io/berryphase.h"

bool berryphase::berry_phase_flag = 0;
#undef private
bool berryphase::berry_phase_flag = false;

pseudo::pseudo()
{
Expand Down Expand Up @@ -296,7 +296,7 @@ TEST_F(KlistTest, MP)

TEST_F(KlistTest, ReadKpointsGammaOnlyLocal)
{
GlobalV::GAMMA_ONLY_LOCAL = 1;
GlobalV::GAMMA_ONLY_LOCAL = true;
std::string kfile = "KPT_GO";
kv->nspin = 1;
kv->read_kpoints(kfile);
Expand All @@ -305,7 +305,7 @@ TEST_F(KlistTest, ReadKpointsGammaOnlyLocal)
EXPECT_THAT(str, testing::HasSubstr("Gamma"));
EXPECT_THAT(str, testing::HasSubstr("1 1 1 0 0 0"));
ifs.close();
GlobalV::GAMMA_ONLY_LOCAL = 0; // this is important for the following tests because it is global
GlobalV::GAMMA_ONLY_LOCAL = false; // this is important for the following tests because it is global
}

TEST_F(KlistTest, ReadKpointsKspacing)
Expand Down Expand Up @@ -651,9 +651,9 @@ TEST_F(KlistTest, SetBothKvecFinalSCF)
kv->kvec_c[0].y = 0.0;
kv->kvec_c[0].z = 0.0;
std::string skpt;
GlobalV::FINAL_SCF = 1;
kv->kd_done = 0;
kv->kc_done = 0;
GlobalV::FINAL_SCF = true;
kv->kd_done = false;
kv->kc_done = false;
// case 1
kv->k_nkstot = 0;
kv->set_both_kvec(GlobalC::ucell.G, GlobalC::ucell.latvec, skpt);
Expand Down Expand Up @@ -691,14 +691,14 @@ TEST_F(KlistTest, SetBothKvec)
kv->kvec_d[0].x = 0.0;
kv->kvec_d[0].y = 0.0;
kv->kvec_d[0].z = 0.0;
kv->kc_done = 0;
kv->kd_done = 1;
kv->kc_done = false;
kv->kd_done = true;
std::string skpt;
GlobalV::FINAL_SCF = 0;
GlobalV::FINAL_SCF = false;
kv->set_both_kvec(GlobalC::ucell.G, GlobalC::ucell.latvec, skpt);
EXPECT_TRUE(kv->kc_done);
kv->kc_done = 1;
kv->kd_done = 0;
kv->kc_done = true;
kv->kd_done = false;
kv->set_both_kvec(GlobalC::ucell.G, GlobalC::ucell.latvec, skpt);
EXPECT_TRUE(kv->kd_done);
}
Expand Down Expand Up @@ -778,5 +778,3 @@ TEST_F(KlistTest, IbzKpointIsMP)
ClearUcell();
remove("tmp_klist_4");
}

#undef private
37 changes: 23 additions & 14 deletions source/module_cell/test/klist_test_para.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include "module_hamilt_pw/hamilt_pwdft/VNL_in_pw.h"
#include "module_hamilt_pw/hamilt_pwdft/parallel_grid.h"
#include "module_io/berryphase.h"

bool berryphase::berry_phase_flag = 0;
#undef private
bool berryphase::berry_phase_flag = false;

pseudo::pseudo()
{
Expand Down Expand Up @@ -213,8 +213,9 @@ TEST_F(KlistParaTest, Set)
// construct cell and symmetry
ModuleSymmetry::Symmetry symm;
construct_ucell(stru_lib[0]);
if (GlobalV::MY_RANK == 0)
if (GlobalV::MY_RANK == 0) {
GlobalV::ofs_running.open("tmp_klist_5");
}
symm.analy_sys(GlobalC::ucell.lat, GlobalC::ucell.st, GlobalC::ucell.atoms, GlobalV::ofs_running);
// read KPT
std::string k_file = "./support/KPT1";
Expand Down Expand Up @@ -242,14 +243,18 @@ TEST_F(KlistParaTest, Set)
EXPECT_TRUE(kv->kd_done);
if (GlobalV::NPROC == 4)
{
if (GlobalV::MY_RANK == 0)
if (GlobalV::MY_RANK == 0) {
EXPECT_EQ(kv->get_nks(), 18);
if (GlobalV::MY_RANK == 1)
}
if (GlobalV::MY_RANK == 1) {
EXPECT_EQ(kv->get_nks(), 18);
if (GlobalV::MY_RANK == 2)
}
if (GlobalV::MY_RANK == 2) {
EXPECT_EQ(kv->get_nks(), 17);
if (GlobalV::MY_RANK == 3)
}
if (GlobalV::MY_RANK == 3) {
EXPECT_EQ(kv->get_nks(), 17);
}
}
ClearUcell();
if (GlobalV::MY_RANK == 0)
Expand All @@ -265,8 +270,9 @@ TEST_F(KlistParaTest, SetAfterVC)
// construct cell and symmetry
ModuleSymmetry::Symmetry symm;
construct_ucell(stru_lib[0]);
if (GlobalV::MY_RANK == 0)
if (GlobalV::MY_RANK == 0) {
GlobalV::ofs_running.open("tmp_klist_6");
}
symm.analy_sys(GlobalC::ucell.lat, GlobalC::ucell.st, GlobalC::ucell.atoms, GlobalV::ofs_running);
// read KPT
std::string k_file = "./support/KPT1";
Expand Down Expand Up @@ -294,17 +300,21 @@ TEST_F(KlistParaTest, SetAfterVC)
EXPECT_TRUE(kv->kd_done);
if (GlobalV::NPROC == 4)
{
if (GlobalV::MY_RANK == 0)
if (GlobalV::MY_RANK == 0) {
EXPECT_EQ(kv->get_nks(), 35);
if (GlobalV::MY_RANK == 1)
}
if (GlobalV::MY_RANK == 1) {
EXPECT_EQ(kv->get_nks(), 35);
if (GlobalV::MY_RANK == 2)
}
if (GlobalV::MY_RANK == 2) {
EXPECT_EQ(kv->get_nks(), 35);
if (GlobalV::MY_RANK == 3)
}
if (GlobalV::MY_RANK == 3) {
EXPECT_EQ(kv->get_nks(), 35);
}
}
// call set_after_vc here
kv->kc_done = 0;
kv->kc_done = false;
kv->set_after_vc(kv->nspin, GlobalC::ucell.G, GlobalC::ucell.latvec);
EXPECT_TRUE(kv->kc_done);
EXPECT_TRUE(kv->kd_done);
Expand All @@ -331,4 +341,3 @@ int main(int argc, char** argv)
return result;
}
#endif
#undef private
3 changes: 1 addition & 2 deletions source/module_cell/test/pseudo_nc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#define private public
#include "module_cell/read_pp.h"
#include "module_cell/atom_pseudo.h"

#undef private
class NCPPTest : public testing::Test
{
protected:
Expand Down Expand Up @@ -126,4 +126,3 @@ TEST_F(NCPPTest, PrintNC)
ifs.close();
remove("./tmp_log");
}
#undef private
3 changes: 1 addition & 2 deletions source/module_cell/test/read_pp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
#define private public
#include "module_cell/read_pp.h"
#include "module_cell/atom_pseudo.h"

#undef private
class ReadPPTest : public testing::Test
{
protected:
Expand Down Expand Up @@ -807,4 +807,3 @@ TEST_F(ReadPPTest, AverageLSPINORB1)
EXPECT_EQ(upf->nbeta,6);
EXPECT_TRUE(upf->has_so); // has soc info
}
#undef private
2 changes: 1 addition & 1 deletion source/module_elecstate/module_dm/test/test_dm_R_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "module_elecstate/module_dm/density_matrix.h"
#include "module_hamilt_lcao/module_hcontainer/hcontainer.h"
#include "module_cell/klist.h"

#undef private
K_Vectors::K_Vectors()
{
}
Expand Down
3 changes: 2 additions & 1 deletion source/module_elecstate/test/charge_extra_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#define protected public
#include "module_elecstate/module_charge/charge_extra.h"
#include "prepare_unitcell.h"

#undef private
#undef protected
// mock functions for UnitCell
#ifdef __LCAO
InfoNonlocal::InfoNonlocal()
Expand Down
Loading
Loading