add unit tester for MyPage class

This commit is contained in:
Axel Kohlmeyer 2020-09-07 08:33:05 -04:00
parent 3089205a54
commit bbb81a8dd0
No known key found for this signature in database
GPG Key ID: D9B44E93BF0C375A
2 changed files with 100 additions and 0 deletions

View File

@ -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)

View File

@ -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<int> 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<int> 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);
}