From 07952fc9834adbf5f03c1548e93a52388618b9cc Mon Sep 17 00:00:00 2001 From: Christopher-Gutierrez Date: Thu, 20 Oct 2016 20:12:18 -0500 Subject: [PATCH] Add files via upload --- cjg2727-TestAllocator.c++ | 309 ++++++++++++++++++++++++++++++++++++++ cjg2727-TestAllocator.out | 185 +++++++++++++++++++++++ 2 files changed, 494 insertions(+) create mode 100644 cjg2727-TestAllocator.c++ create mode 100644 cjg2727-TestAllocator.out diff --git a/cjg2727-TestAllocator.c++ b/cjg2727-TestAllocator.c++ new file mode 100644 index 0000000..17ef964 --- /dev/null +++ b/cjg2727-TestAllocator.c++ @@ -0,0 +1,309 @@ +// ------------------------------------- +// projects/allocator/TestAllocator1.c++ +// Copyright (C) 2015 +// Glenn P. Downing +// ------------------------------------- + +// -------- +// includes +// -------- + +#include // count +#include // allocator + +#include "gtest/gtest.h" + +#include "Allocator.h" + +// -------------- +// TestAllocator1 +// -------------- + +template struct TestAllocator1 : testing::Test { + // -------- + // typedefs + // -------- + + typedef A allocator_type; + typedef typename A::value_type value_type; + typedef typename A::size_type size_type; + typedef typename A::pointer pointer; +}; + +typedef testing::Types, std::allocator, + my_allocator, my_allocator> + my_types_1; + +TYPED_TEST_CASE(TestAllocator1, my_types_1); + +TYPED_TEST(TestAllocator1, test_1) { + typedef typename TestFixture::allocator_type allocator_type; + typedef typename TestFixture::value_type value_type; + typedef typename TestFixture::size_type size_type; + typedef typename TestFixture::pointer pointer; + + allocator_type x; + const size_type s = 1; + const value_type v = 2; + const pointer p = x.allocate(s); + if (p != nullptr) { + x.construct(p, v); + ASSERT_EQ(v, *p); + x.destroy(p); + x.deallocate(p, s); + } +} + +TYPED_TEST(TestAllocator1, test_10) { + typedef typename TestFixture::allocator_type allocator_type; + typedef typename TestFixture::value_type value_type; + typedef typename TestFixture::size_type size_type; + typedef typename TestFixture::pointer pointer; + + allocator_type x; + const size_type s = 10; + const value_type v = 2; + const pointer b = x.allocate(s); + if (b != nullptr) { + pointer e = b + s; + pointer p = b; + try { + while (p != e) { + x.construct(p, v); + ++p; + } + } catch (...) { + while (b != p) { + --p; + x.destroy(p); + } + x.deallocate(b, s); + throw; + } + ASSERT_EQ(s, std::count(b, e, v)); + while (b != e) { + --e; + x.destroy(e); + } + x.deallocate(b, s); + } +} + +// -------------- +// TestAllocator2 +// -------------- + +TEST(TestAllocator2, const_index) { + const my_allocator x; + ASSERT_EQ(x[0], 92); +} + +TEST(TestAllocator2, index) { + my_allocator x; + ASSERT_EQ(x[0], 92); +} + +// -------------- +// TestAllocator3 +// -------------- + +template struct TestAllocator3 : testing::Test { + // -------- + // typedefs + // -------- + + typedef A allocator_type; + typedef typename A::value_type value_type; + typedef typename A::size_type size_type; + typedef typename A::pointer pointer; +}; + +typedef testing::Types, my_allocator> + my_types_2; + +TYPED_TEST_CASE(TestAllocator3, my_types_2); + +TYPED_TEST(TestAllocator3, test_1) { + typedef typename TestFixture::allocator_type allocator_type; + typedef typename TestFixture::value_type value_type; + typedef typename TestFixture::size_type size_type; + typedef typename TestFixture::pointer pointer; + + allocator_type x; + const size_type s = 1; + const value_type v = 2; + const pointer p = x.allocate(s); + if (p != nullptr) { + x.construct(p, v); + ASSERT_EQ(v, *p); + x.destroy(p); + x.deallocate(p, s); + } +} + +TYPED_TEST(TestAllocator3, test_10) { + typedef typename TestFixture::allocator_type allocator_type; + typedef typename TestFixture::value_type value_type; + typedef typename TestFixture::size_type size_type; + typedef typename TestFixture::pointer pointer; + + allocator_type x; + const size_type s = 10; + const value_type v = 2; + const pointer b = x.allocate(s); + if (b != nullptr) { + pointer e = b + s; + pointer p = b; + try { + while (p != e) { + x.construct(p, v); + ++p; + } + } catch (...) { + while (b != p) { + --p; + x.destroy(p); + } + x.deallocate(b, s); + throw; + } + ASSERT_EQ(s, std::count(b, e, v)); + while (b != e) { + --e; + x.destroy(e); + } + x.deallocate(b, s); + } +} + +// -------------- +// TestAllocator 4 +// -------------- + +TEST(TestAllocator4, odd_index) { + const my_allocator x; + ASSERT_EQ(x[0], 69); +} +TEST(TestAllocator4, odd_double_index) { + const my_allocator x; + ASSERT_EQ(x[0], 121); +} + +TEST(TestAllocator4, large_double_index) { + const my_allocator x; + ASSERT_EQ(x[0], 992); +} + +// -------------- +// TestAllocator5 +// -------------- + +template struct TestAllocator5 : testing::Test { + // -------- + // typedefs + // -------- + + typedef A allocator_type; + typedef typename A::value_type value_type; + typedef typename A::size_type size_type; + typedef typename A::pointer pointer; +}; + +typedef testing::Types, std::allocator, + my_allocator, my_allocator> + allocatetwo_deallocatetwo; + +TYPED_TEST_CASE(TestAllocator5, allocatetwo_deallocatetwo); + +TYPED_TEST(TestAllocator5, test_1) { + typedef typename TestFixture::allocator_type allocator_type; + typedef typename TestFixture::value_type value_type; + typedef typename TestFixture::size_type size_type; + typedef typename TestFixture::pointer pointer; + + allocator_type x; + const size_type s = 1; + const value_type v = 2; + const pointer p = x.allocate(s); + const pointer second = x.allocate(s); + + x.deallocate(second, s); + x.deallocate(p, s); +} + +TYPED_TEST_CASE(TestAllocator5, allocatetwo_deallocatetwo); + +TYPED_TEST(TestAllocator5, test_2) { + typedef typename TestFixture::allocator_type allocator_type; + typedef typename TestFixture::value_type value_type; + typedef typename TestFixture::size_type size_type; + typedef typename TestFixture::pointer pointer; + + allocator_type x; + const size_type s = 1; + const value_type v = 2; + const pointer p = x.allocate(s); + const pointer second = x.allocate(s); + + x.deallocate(p, s); + x.deallocate(second, s); +} + +// -------------- +// TestAllocator6 +// -------------- + +template struct TestAllocator6 : testing::Test { + // -------- + // typedefs + // -------- + + typedef A allocator_type; + typedef typename A::value_type value_type; + typedef typename A::size_type size_type; + typedef typename A::pointer pointer; +}; + +typedef testing::Types, std::allocator, + my_allocator, my_allocator> + allocatethree_deallocatethree; + +TYPED_TEST_CASE(TestAllocator6, allocatethree_deallocatethree); + +TYPED_TEST(TestAllocator6, test_1) { + typedef typename TestFixture::allocator_type allocator_type; + typedef typename TestFixture::value_type value_type; + typedef typename TestFixture::size_type size_type; + typedef typename TestFixture::pointer pointer; + + allocator_type x; + const size_type s = 2; + const value_type v = 2; + const pointer p = x.allocate(s); + const pointer second = x.allocate(s); + const pointer third = x.allocate(s); + + x.deallocate(third, s); + x.deallocate(second, s); + x.deallocate(p, s); +} + +TYPED_TEST_CASE(TestAllocator6, allocatethree_deallocatethree); + +TYPED_TEST(TestAllocator6, test_2) { + typedef typename TestFixture::allocator_type allocator_type; + typedef typename TestFixture::value_type value_type; + typedef typename TestFixture::size_type size_type; + typedef typename TestFixture::pointer pointer; + + allocator_type x; + const size_type s = 1; + const value_type v = 2; + const pointer p = x.allocate(s); + const pointer second = x.allocate(s); + const pointer third = x.allocate(s); + + x.deallocate(p, s); + x.deallocate(third, s); + x.deallocate(second, s); +} \ No newline at end of file diff --git a/cjg2727-TestAllocator.out b/cjg2727-TestAllocator.out new file mode 100644 index 0000000..e4b3f37 --- /dev/null +++ b/cjg2727-TestAllocator.out @@ -0,0 +1,185 @@ +==110299== Memcheck, a memory error detector +==110299== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. +==110299== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info +==110299== Command: ./TestAllocator +==110299== +Running main() from gtest_main.cc +[==========] Running 33 tests from 16 test cases. +[----------] Global test environment set-up. +[----------] 2 tests from TestAllocator1/0, where TypeParam = std::allocator +[ RUN ] TestAllocator1/0.test_1 +[ OK ] TestAllocator1/0.test_1 (11 ms) +[ RUN ] TestAllocator1/0.test_10 +[ OK ] TestAllocator1/0.test_10 (4 ms) +[----------] 2 tests from TestAllocator1/0 (24 ms total) + +[----------] 2 tests from TestAllocator1/1, where TypeParam = std::allocator +[ RUN ] TestAllocator1/1.test_1 +[ OK ] TestAllocator1/1.test_1 (6 ms) +[ RUN ] TestAllocator1/1.test_10 +[ OK ] TestAllocator1/1.test_10 (4 ms) +[----------] 2 tests from TestAllocator1/1 (10 ms total) + +[----------] 2 tests from TestAllocator1/2, where TypeParam = my_allocator +[ RUN ] TestAllocator1/2.test_1 +[ OK ] TestAllocator1/2.test_1 (10 ms) +[ RUN ] TestAllocator1/2.test_10 +[ OK ] TestAllocator1/2.test_10 (3 ms) +[----------] 2 tests from TestAllocator1/2 (13 ms total) + +[----------] 2 tests from TestAllocator1/3, where TypeParam = my_allocator +[ RUN ] TestAllocator1/3.test_1 +[ OK ] TestAllocator1/3.test_1 (10 ms) +[ RUN ] TestAllocator1/3.test_10 +[ OK ] TestAllocator1/3.test_10 (5 ms) +[----------] 2 tests from TestAllocator1/3 (15 ms total) + +[----------] 2 tests from TestAllocator2 +[ RUN ] TestAllocator2.const_index +[ OK ] TestAllocator2.const_index (3 ms) +[ RUN ] TestAllocator2.index +[ OK ] TestAllocator2.index (2 ms) +[----------] 2 tests from TestAllocator2 (5 ms total) + +[----------] 2 tests from TestAllocator3/0, where TypeParam = my_allocator +[ RUN ] TestAllocator3/0.test_1 +[ OK ] TestAllocator3/0.test_1 (3 ms) +[ RUN ] TestAllocator3/0.test_10 +[ OK ] TestAllocator3/0.test_10 (3 ms) +[----------] 2 tests from TestAllocator3/0 (7 ms total) + +[----------] 2 tests from TestAllocator3/1, where TypeParam = my_allocator +[ RUN ] TestAllocator3/1.test_1 +[ OK ] TestAllocator3/1.test_1 (3 ms) +[ RUN ] TestAllocator3/1.test_10 +[ OK ] TestAllocator3/1.test_10 (3 ms) +[----------] 2 tests from TestAllocator3/1 (7 ms total) + +[----------] 3 tests from TestAllocator4 +[ RUN ] TestAllocator4.odd_index +[ OK ] TestAllocator4.odd_index (5 ms) +[ RUN ] TestAllocator4.odd_double_index +[ OK ] TestAllocator4.odd_double_index (4 ms) +[ RUN ] TestAllocator4.large_double_index +[ OK ] TestAllocator4.large_double_index (5 ms) +[----------] 3 tests from TestAllocator4 (14 ms total) + +[----------] 2 tests from TestAllocator5/0, where TypeParam = std::allocator +[ RUN ] TestAllocator5/0.test_1 +[ OK ] TestAllocator5/0.test_1 (3 ms) +[ RUN ] TestAllocator5/0.test_2 +[ OK ] TestAllocator5/0.test_2 (2 ms) +[----------] 2 tests from TestAllocator5/0 (5 ms total) + +[----------] 2 tests from TestAllocator5/1, where TypeParam = std::allocator +[ RUN ] TestAllocator5/1.test_1 +[ OK ] TestAllocator5/1.test_1 (3 ms) +[ RUN ] TestAllocator5/1.test_2 +[ OK ] TestAllocator5/1.test_2 (2 ms) +[----------] 2 tests from TestAllocator5/1 (5 ms total) + +[----------] 2 tests from TestAllocator5/2, where TypeParam = my_allocator +[ RUN ] TestAllocator5/2.test_1 +[ OK ] TestAllocator5/2.test_1 (3 ms) +[ RUN ] TestAllocator5/2.test_2 +[ OK ] TestAllocator5/2.test_2 (3 ms) +[----------] 2 tests from TestAllocator5/2 (7 ms total) + +[----------] 2 tests from TestAllocator5/3, where TypeParam = my_allocator +[ RUN ] TestAllocator5/3.test_1 +[ OK ] TestAllocator5/3.test_1 (3 ms) +[ RUN ] TestAllocator5/3.test_2 +[ OK ] TestAllocator5/3.test_2 (3 ms) +[----------] 2 tests from TestAllocator5/3 (6 ms total) + +[----------] 2 tests from TestAllocator6/0, where TypeParam = std::allocator +[ RUN ] TestAllocator6/0.test_1 +[ OK ] TestAllocator6/0.test_1 (3 ms) +[ RUN ] TestAllocator6/0.test_2 +[ OK ] TestAllocator6/0.test_2 (3 ms) +[----------] 2 tests from TestAllocator6/0 (6 ms total) + +[----------] 2 tests from TestAllocator6/1, where TypeParam = std::allocator +[ RUN ] TestAllocator6/1.test_1 +[ OK ] TestAllocator6/1.test_1 (3 ms) +[ RUN ] TestAllocator6/1.test_2 +[ OK ] TestAllocator6/1.test_2 (3 ms) +[----------] 2 tests from TestAllocator6/1 (6 ms total) + +[----------] 2 tests from TestAllocator6/2, where TypeParam = my_allocator +[ RUN ] TestAllocator6/2.test_1 +[ OK ] TestAllocator6/2.test_1 (3 ms) +[ RUN ] TestAllocator6/2.test_2 +[ OK ] TestAllocator6/2.test_2 (3 ms) +[----------] 2 tests from TestAllocator6/2 (6 ms total) + +[----------] 2 tests from TestAllocator6/3, where TypeParam = my_allocator +[ RUN ] TestAllocator6/3.test_1 +==110299== Conditional jump or move depends on uninitialised value(s) +==110299== at 0x420E46: my_allocator::deallocate(double*, unsigned long) (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x41B6C0: TestAllocator6_test_1_Test >::TestBody() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x4432C2: void testing::internal::HandleExceptionsInMethodIfSupported(testing::Test*, void (testing::Test::*)(), char const*) (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x435DFC: testing::Test::Run() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x435E93: testing::TestInfo::Run() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x435F94: testing::TestCase::Run() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x43620C: testing::internal::UnitTestImpl::RunAllTests() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x4364ED: testing::UnitTest::Run() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x40522F: main (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== +==110299== Conditional jump or move depends on uninitialised value(s) +==110299== at 0x420F08: my_allocator::deallocate(double*, unsigned long) (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x41B6C0: TestAllocator6_test_1_Test >::TestBody() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x4432C2: void testing::internal::HandleExceptionsInMethodIfSupported(testing::Test*, void (testing::Test::*)(), char const*) (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x435DFC: testing::Test::Run() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x435E93: testing::TestInfo::Run() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x435F94: testing::TestCase::Run() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x43620C: testing::internal::UnitTestImpl::RunAllTests() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x4364ED: testing::UnitTest::Run() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x40522F: main (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== +==110299== Conditional jump or move depends on uninitialised value(s) +==110299== at 0x420E46: my_allocator::deallocate(double*, unsigned long) (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x41B71A: TestAllocator6_test_1_Test >::TestBody() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x4432C2: void testing::internal::HandleExceptionsInMethodIfSupported(testing::Test*, void (testing::Test::*)(), char const*) (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x435DFC: testing::Test::Run() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x435E93: testing::TestInfo::Run() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x435F94: testing::TestCase::Run() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x43620C: testing::internal::UnitTestImpl::RunAllTests() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x4364ED: testing::UnitTest::Run() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x40522F: main (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== +==110299== Conditional jump or move depends on uninitialised value(s) +==110299== at 0x420F08: my_allocator::deallocate(double*, unsigned long) (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x41B71A: TestAllocator6_test_1_Test >::TestBody() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x4432C2: void testing::internal::HandleExceptionsInMethodIfSupported(testing::Test*, void (testing::Test::*)(), char const*) (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x435DFC: testing::Test::Run() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x435E93: testing::TestInfo::Run() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x435F94: testing::TestCase::Run() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x43620C: testing::internal::UnitTestImpl::RunAllTests() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x4364ED: testing::UnitTest::Run() (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== by 0x40522F: main (in /v/filer4b/v38q001/chrisg/Documents/cs371p/allocator/allocator-cjg2727/TestAllocator) +==110299== +[ OK ] TestAllocator6/3.test_1 (3 ms) +[ RUN ] TestAllocator6/3.test_2 +[ OK ] TestAllocator6/3.test_2 (3 ms) +[----------] 2 tests from TestAllocator6/3 (6 ms total) + +[----------] Global test environment tear-down +[==========] 33 tests from 16 test cases ran. (168 ms total) +[ PASSED ] 33 tests. +==110299== +==110299== HEAP SUMMARY: +==110299== in use at exit: 0 bytes in 0 blocks +==110299== total heap usage: 1,427 allocs, 1,427 frees, 180,402 bytes allocated +==110299== +==110299== All heap blocks were freed -- no leaks are possible +==110299== +==110299== For counts of detected and suppressed errors, rerun with: -v +==110299== Use --track-origins=yes to see where uninitialised values come from +==110299== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0) +File 'TestAllocator.c++' +Lines executed:90.40% of 125 +Branches executed:76.21% of 622 +Taken at least once:40.03% of 622 +Calls executed:62.91% of 674 +Creating 'TestAllocator.c++.gcov'