LCOV - code coverage report
Current view: top level - estd/examples - uncopyable.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 10 12 83.3 %
Date: 2025-01-20 13:53:09 Functions: 2 5 40.0 %

          Line data    Source code
       1             : // Copyright 2024 Accenture.
       2             : 
       3             : #include "estd/uncopyable.h"
       4             : 
       5             : #include <gtest/gtest.h>
       6             : 
       7             : /*Below code shows how to make a class uncopyable that cannot inherit
       8             :   from the uncopyable base class.
       9             :  */
      10             : // [EXAMPLE_BEGIN uncopyable macro]
      11             : class MyClass
      12             : {
      13             :     UNCOPYABLE(MyClass);
      14             : 
      15             : public:
      16           1 :     MyClass(int n) : n(n) {}
      17             : 
      18             : private:
      19             :     int n;
      20             : };
      21             : 
      22           1 : void example_uncopyable_macro()
      23             : {
      24           1 :     MyClass obj(10);
      25             :     // Usage of copy construction calls will result in compilation error.
      26             :     // MyClass obj1 = obj;
      27             :     // MyClass obj2(obj);
      28           0 : }
      29             : 
      30             : // [EXAMPLE_END uncopyable macro]
      31             : // Below code shows how to make a class uncopyable by inheriting from uncopyable
      32             : // [EXAMPLE_BEGIN uncopyable class]
      33             : class MyClass1 : public ::estd::uncopyable
      34             : {
      35             : public:
      36           1 :     MyClass1(int n) : n(n) {}
      37             : 
      38             : private:
      39             :     int n;
      40             : };
      41             : 
      42           1 : void example_uncopyable_inheritance()
      43             : {
      44           1 :     MyClass1 obj(10);
      45             :     // Usage of copy construction calls will result in compilation error.
      46             :     // MyClass1 obj1 = obj;
      47             :     // MyClass1 obj2(obj);
      48           0 : }
      49             : 
      50             : // [EXAMPLE_END uncopyable class]
      51             : 
      52           3 : TEST(uncopyable, run_examples)
      53             : {
      54           1 :     example_uncopyable_inheritance();
      55           1 :     example_uncopyable_macro();
      56           1 : }

Generated by: LCOV version 1.14