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

          Line data    Source code
       1             : // Copyright 2024 Accenture.
       2             : 
       3             : #include "estd/memory.h"
       4             : 
       5             : #include "estd/none.h"
       6             : 
       7             : #include <gmock/gmock.h>
       8             : 
       9             : using namespace ::testing;
      10             : 
      11             : // [EXAMPLE_START]
      12             : // Sets all elements of the destination to the given value.
      13           3 : TEST(Memory, set)
      14             : {
      15           1 :     uint8_t destination[5] = {0};
      16           1 :     ::estd::memory::set(destination, 0xAA);
      17             : 
      18           1 :     EXPECT_THAT(destination, Each(0xAA));
      19           1 : }
      20             : 
      21             : // Copy data from source slice to destination slice.
      22           3 : TEST(Memory, copy)
      23             : {
      24           1 :     uint8_t const source[]  = {1, 2, 3};
      25           1 :     uint8_t destination[10] = {0};
      26             : 
      27           1 :     ::estd::slice<uint8_t> r = ::estd::memory::copy(destination, source);
      28             : 
      29           1 :     EXPECT_EQ(1, destination[0]);
      30           1 :     EXPECT_THAT(r, ElementsAre(1, 2, 3));
      31             : 
      32           1 :     EXPECT_EQ(destination, r.data());
      33           1 :     EXPECT_EQ(3U, r.size());
      34           1 : }
      35             : 
      36             : // [EXAMPLE_END]
      37             : 
      38             : // [COMPARISON_EXAMPLE_START]
      39             : // Checks whether the memory referred to by two slices contains the same data.
      40           3 : TEST(Memory, is_equal)
      41             : {
      42           1 :     uint8_t const a[] = {10, 20, 45, 32, 60};
      43           1 :     uint8_t const b[] = {10, 20, 45, 32, 60};
      44           1 :     uint8_t const c[] = {10, 20, 35, 32, 60};
      45           1 :     uint8_t const d[] = {10, 20, 35, 32};
      46             : 
      47           1 :     EXPECT_TRUE(::estd::memory::is_equal(a, b));
      48           1 :     EXPECT_FALSE(::estd::memory::is_equal(a, c));
      49           1 :     EXPECT_FALSE(::estd::memory::is_equal(b, c));
      50           1 :     EXPECT_FALSE(::estd::memory::is_equal(c, d));
      51           1 :     EXPECT_FALSE(::estd::memory::is_equal(d, c));
      52           1 :     EXPECT_FALSE(::estd::memory::is_equal(d, ::estd::none));
      53           1 :     EXPECT_FALSE(::estd::memory::is_equal(::estd::none, a));
      54           1 :     EXPECT_TRUE(::estd::memory::is_equal(::estd::none, ::estd::none));
      55           1 : }
      56             : 
      57             : //[COMPARISON_EXAMPLE_END]

Generated by: LCOV version 1.14