LCOV - code coverage report
Current view: top level - estd/examples - indestructible.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 8 8 100.0 %
Date: 2025-01-20 13:53:09 Functions: 2 3 66.7 %

          Line data    Source code
       1             : // Copyright 2024 Accenture.
       2             : 
       3             : #include <estd/assert.h>
       4             : #include <estd/indestructible.h>
       5             : #include <estd/static_assert.h>
       6             : 
       7             : #include <gtest/gtest.h>
       8             : 
       9             : #include <type_traits>
      10             : 
      11             : using estd::indestructible;
      12             : 
      13           3 : TEST(IndestructibleExample, CanBeConstructed)
      14             : {
      15             :     // [EXAMPLE_INDESTRUCTIBLE_START]
      16             :     // Creating a structure 'Constructible'.
      17           1 :     struct Constructible
      18             :     {
      19             :         uint8_t _data;
      20             : 
      21           1 :         explicit Constructible(uint8_t data) : _data(data) {}
      22             :     };
      23             : 
      24             :     // Creating an instance of indestructible class.
      25           1 :     indestructible<Constructible> instance(0xAA);
      26             : 
      27             :     // Dereferencing the value using 'operator->()'.
      28           1 :     ASSERT_EQ(instance->_data, 0xAA);
      29             : 
      30             :     // Dereferencing the value using 'get()'
      31           1 :     ASSERT_EQ(instance.get()._data, 0xAA);
      32             :     // Dereferencing the value using 'operator T&()'
      33           1 :     Constructible& ref = instance;
      34           2 :     EXPECT_EQ(&ref, &instance.get());
      35             :     // [EXAMPLE_INDESTRUCTIBLE_END]
      36             : }

Generated by: LCOV version 1.14