diff --git a/unittest/utils/CMakeLists.txt b/unittest/utils/CMakeLists.txt index 67135deb11..30a834a126 100644 --- a/unittest/utils/CMakeLists.txt +++ b/unittest/utils/CMakeLists.txt @@ -2,6 +2,10 @@ add_executable(test_tokenizer test_tokenizer.cpp) target_link_libraries(test_tokenizer PRIVATE lammps GTest::GMockMain GTest::GMock GTest::GTest) add_test(Tokenizer test_tokenizer) +add_executable(test_my_page test_my_page.cpp) +target_link_libraries(test_my_page PRIVATE lammps GTest::GMockMain GTest::GMock GTest::GTest) +add_test(MyPage test_my_page) + add_executable(test_utils test_utils.cpp) target_link_libraries(test_utils PRIVATE lammps GTest::GMockMain GTest::GMock GTest::GTest) add_test(Utils test_utils) diff --git a/unittest/utils/test_my_page.cpp b/unittest/utils/test_my_page.cpp new file mode 100644 index 0000000000..2f56bea725 --- /dev/null +++ b/unittest/utils/test_my_page.cpp @@ -0,0 +1,96 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#include "lmptype.h" +#include "my_page.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using namespace LAMMPS_NS; + +TEST(MyPage, int_default) { + MyPage p; + + // default init. maxchunk=1, pagesize=1024 + int rv = p.init(); + ASSERT_EQ(rv,0); + + ASSERT_EQ(p.ndatum,0); + ASSERT_EQ(p.nchunk,0); + + int *iptr = p.vget(); + // second call to vget() should give same pointer without vgot() + ASSERT_EQ(iptr,p.vget()); + p.vgot(1); + ++iptr; + ASSERT_EQ(0,p.status()); + ASSERT_EQ(p.ndatum,1); + ASSERT_EQ(p.nchunk,1); + ASSERT_EQ(iptr,p.vget()); + // use too large chunk size + p.vgot(2); + ASSERT_EQ(1,p.status()); + + p.reset(); + ASSERT_EQ(p.ndatum,0); + ASSERT_EQ(p.nchunk,0); + + iptr = p.vget(); + p.vgot(1); + ++iptr; + ASSERT_EQ(iptr,p.get()); + ++iptr; + ASSERT_EQ(iptr,p.get(1)); + ASSERT_EQ(p.ndatum,3); + ASSERT_EQ(p.nchunk,3); +} + +TEST(MyPage, int_custom) { + MyPage p; + + // default init. maxchunk=16, pagesize=256 + int rv = p.init(16,256); + ASSERT_EQ(rv,0); + + ASSERT_EQ(p.ndatum,0); + ASSERT_EQ(p.nchunk,0); + + int *iptr = p.vget(); + // second call to vget() should give same pointer without vgot() + ASSERT_EQ(iptr,p.vget()); + p.vgot(16); + iptr += 16; + ASSERT_EQ(0,p.status()); + ASSERT_EQ(p.ndatum,16); + ASSERT_EQ(p.nchunk,1); + + // use too large chunk size + ASSERT_EQ(iptr,p.vget()); + p.vgot(32); + ASSERT_EQ(1,p.status()); + + p.reset(); + ASSERT_EQ(p.ndatum,0); + ASSERT_EQ(p.nchunk,0); + + iptr = p.vget(); + p.vgot(16); + iptr = p.vget(); + p.vgot(4); + iptr += 4; + ASSERT_EQ(iptr,p.get()); + ++iptr; + ASSERT_EQ(iptr,p.get(16)); + ASSERT_EQ(p.ndatum,37); + ASSERT_EQ(p.nchunk,4); +}