I am trying to call the function ElementsAreArray() inside another function. I was using it normally inside my tests, but I wanted to make the tests reports better and organize it on a function. So I created the following files:
gUnitTest_Test_Array.cpp where I have my function definition:
#include "gUnitTest_Test_Array.h"
void gtest_array::expect_that_size1(volatile signed long arrayA[CIC8_TABLE_SIZE],volatile signed long arrayB[CIC8_TABLE_SIZE], std::string msg1, std::string msg2)
{
using namespace testing;
bool HasError = false;
EXPECT_THAT(arrayA, ElementsAreArray(arrayB)) << (HasError = true);
if (HasError)
std::cout << msg1;
else
std::cout << msg2;
}
gUnitTest_Test_Array.h where I have my class declaration:
#pragma once
#ifndef GUNITTEST_TEST_ARRAY_H
#define GUNITTEST_TEST_ARRAY_H
#include "gUnitTest_Common_Defs.h"
using namespace std;
class gtest_array
{
public:
void expect_that_size1(volatile signed long arrayA[CIC8_TABLE_SIZE], volatile signed long arrayB[CIC8_TABLE_SIZE], std::string msg1, std::string msg2);
};
#endif
gUnitTest_Common_Defs.h where I include necessary libs and definitions
#pragma once
//#ifndef GUNITTEST_COMMON_DEFS_H
//#define GUNITTEST_COMMON_DEFS_H
#include <stdio.h>
#include <string>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#define ... //Whatever I need to define
Then in my Test file I call the function:
std::string msg1 = "failed";
std::string msg2 = "passed";
TestArray1.expect_that_size1(sG_Demodulation_Diagnostics_Buffers.WNLCPF_CIC8_Decim, s32L_CIC8_table, msg1, msg2);
The problem is that when I try to compile, the compiler complains that it does not find the function ElemetsAreArray(). which for me does not make sense since I included all the gtest necessary headers and before moving to the function I was using this function inline on my test as below:
EXPECT_THAT(sG_Demodulation_Diagnostics_Buffers.WNLCPF_CIC8_Decim, ElementsAreArray(s32L_CIC8_table)) << "The CIC8 block test failed. Failed at index: " << i;
Here are the error messages
Error C2672 'testing::ElementsAreArray': no matching overloaded function found GUnitTesting \GUnitTesting\gUnitTest_Test_Array.cpp 15
Error C2893 Failed to specialize function template 'testing::internal::ElementsAreArrayMatcherContainer::value_type testing::ElementsAreArray(const Container &)' GUnitTesting \GUnitTesting\gUnitTest_Test_Array.cpp 15
Error C2784 'testing::internal::ElementsAreArrayMatcher testing::ElementsAreArray(const T (&)[N])': could not deduce template argument for 'const T (&)[N]' from 'volatile long []' GUnitTesting \GUnitTesting\gUnitTest_Test_Array.cpp 15
Error C2780 'testing::internal::ElementsAreArrayMatcher testing::ElementsAreArray(const T *,size_t)': expects 2 arguments - 1 provided GUnitTesting \GUnitTesting\gUnitTest_Test_Array.cpp 15
Error C2780 'testing::internal::ElementsAreArrayMatcher<::std::iterator_traits<_Ty>::value_type> testing::ElementsAreArray(Iter,Iter)': expects 2 arguments - 1 provided GUnitTesting \GUnitTesting\gUnitTest_Test_Array.cpp 15
Error C2672 'testing::internal::MakePredicateFormatterFromMatcher': no matching overloaded function found GUnitTesting \GUnitTesting\gUnitTest_Test_Array.cpp 15
Error C2512 'testing::AssertionResult': no appropriate default constructor available GUnitTesting \GUnitTesting\gUnitTest_Test_Array.cpp 15