LCOV - code coverage report
Current view: top level - firmware/libfirmware/util/test - test_arrays.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 23 23 100.0 %
Date: 2024-04-25 02:23:43 Functions: 12 12 100.0 %

          Line data    Source code
       1             : #include <rusefi/arrays.h>
       2             : 
       3             : #include <gtest/gtest.h>
       4             : #include <gmock/gmock.h>
       5             : 
       6             : using testing::ElementsAre;
       7             : 
       8           4 : TEST(Util_Arrays, CopyArray) {
       9           1 :         int arr[2];
      10             : 
      11             :         // Copy from an initializer list
      12           1 :         copyArray(arr, { 10, 20 });
      13           1 :         ASSERT_THAT(arr, ElementsAre(10, 20));
      14             : 
      15             :         // Copy from another array
      16           1 :         int arr2[] = { 30, 40 };
      17           1 :         copyArray(arr, arr2);
      18           1 :         ASSERT_THAT(arr, ElementsAre(30, 40));
      19             : 
      20             :         // Copy to a scaled channel
      21           1 :         scaled_channel<int, 10, 1> arr3[2];
      22           1 :         copyArray(arr3, { 100, 200 });
      23           1 :         ASSERT_THAT(arr3, ElementsAre(100, 200));
      24             : }
      25             : 
      26           4 : TEST(Util_Arrays, CopyArrayPartial) {
      27           1 :         int arr[4];
      28           1 :         copyArray(arr, { 1, 2, 3, 4 });
      29           1 :         ASSERT_THAT(arr, ElementsAre(1, 2, 3, 4));
      30             : 
      31             :         // Copy a smaller array over the beginning of arr
      32           1 :         copyArrayPartial(arr, { 100, 200 });
      33           1 :         ASSERT_THAT(arr, ElementsAre(100, 200, 3, 4));
      34             : }
      35             : 
      36           4 : TEST(Util_Arrays, Size) {
      37           1 :         int arr1[2];
      38           1 :         uint8_t arr2[17];
      39           1 :         scaled_channel<uint16_t, 3, 1> arr3[21];
      40             : 
      41           1 :         ASSERT_EQ(2,  efi::size(arr1));
      42           1 :         ASSERT_EQ(17, efi::size(arr2));
      43           1 :         ASSERT_EQ(21, efi::size(arr3));
      44             : }

Generated by: LCOV version 1.14