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

          Line data    Source code
       1             : // Copyright 2024 Accenture.
       2             : 
       3             : #include "estd/singleton.h"
       4             : 
       5             : #include <platform/estdint.h>
       6             : 
       7             : #include <gtest/gtest.h>
       8             : 
       9             : using namespace ::testing;
      10             : 
      11             : // [EXAMPLE_SINGLETON_STRUCTURE_START]
      12             : 
      13           0 : struct Foo : ::estd::singleton<Foo>
      14             : {
      15             :     // initialize singleton instance
      16           2 :     Foo() : ::estd::singleton<Foo>(*this), _v(0) {}
      17             : 
      18             :     int32_t _v; // internal variable
      19             : };
      20             : 
      21           3 : TEST(Singleton, TestInstance)
      22             : {
      23             :     // check Foo is not instantiated
      24           1 :     ASSERT_FALSE(Foo::instantiated());
      25           2 :     Foo f;                            // instance
      26           1 :     ASSERT_EQ(&f, &Foo::instance());  // check the singleton instance's match
      27           2 :     ASSERT_TRUE(Foo::instantiated()); // verify Foo is instantiated
      28             : }
      29             : 
      30             : // [EXAMPLE_SINGLETON_STRUCTURE_END]

Generated by: LCOV version 1.14