How to use matcher in google test (error: undeclared identifier) - c++

I'm trying to use google test to test a C function. A simple test using ASSERT_NO_FATAL_FAILURE(); and also EXPECT_THAT();. But when I try to use matchers (like not null for example) the IDE says: Use of undeclared identifier 'NotNull'.
#include "gtest/gtest.h"
extern "C" {
#include "first_tdd.h"
}
TEST(sum, sum_has_return)
{
EXPECT_THAT(sum(), NotNull());
}
cmake_minimum_required(VERSION 3.19)
project(untitled C)
set(CMAKE_C_STANDARD 99)
add_executable(main.c sum.c)
# 'Google_test' is the subproject name
project(Google_tests)
# 'lib' is the folder with Google Test sources
add_subdirectory(googletest)
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}, ${gmock_SOURCE_DIR}/include ${gmock_SOURCE_DIR})
# 'Google_Tests_run' is the target name
# 'test1.cpp tests2.cpp' are source files with tests
set(Sources
sum.c
)
add_executable(Google_Tests_run sum_tests.cpp sum.c)
target_link_libraries(Google_Tests_run gtest gtest_main)
Message when I try to run the test.
error: use of undeclared identifier 'NotNull'
EXPECT_THAT(sum(), NotNull());
^
1 error generated.
make[3]: *** [CMakeFiles/Google_Tests_run.dir/sum_tests.cpp.o] Error 1
make[2]: *** [CMakeFiles/Google_Tests_run.dir/all] Error 2
make[1]: *** [CMakeFiles/Google_Tests_run.dir/rule] Error 2
make: *** [Google_Tests_run] Error 2
Folder Structure
Does any one know if I should include something else?
Thank you.

NotNull is declared in the namespace ::testing. Possible fixes
TEST(sum, sum_has_return)
{
EXPECT_THAT(sum(), ::testing::NotNull());
}
or
TEST(sum, sum_has_return)
{
using ::testing::NotNull;
EXPECT_THAT(sum(), NotNull());
}

Related

'is_trivial_v' is not a member of 'std' while build C++ project with conan

I'm trying to write C++ project with conan. I need to use qt/6.2.2 as dependency.
After I run
conan create . user/test
It comes out a long error message. The last few lines are:
/home/run/.conan/data/qt/6.2.2/_/_/package/e1b261f6f4c131503719b972012039d1853778f9/include/QtCore/qarraydatapointer.h:374:27: note: deduced conflicting types for parameter ‘const T’ (‘int’ and ‘qsizetype’ {aka ‘long long int’})
374 | ? n + qMax(0, (header->alloc - from.size - n) / 2)
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/Wuziqi.dir/build.make:63: CMakeFiles/Wuziqi.dir/Wuziqi.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/Wuziqi.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
Wuziqi/1.0.0#user/test:
Wuziqi/1.0.0#user/test: ERROR: Package '702f20c11c28f19fd5e1d929272b0f47e81fec21' build failed
Wuziqi/1.0.0#user/test: WARN: Build folder /home/run/.conan/data/Wuziqi/1.0.0/user/test/build/702f20c11c28f19fd5e1d929272b0f47e81fec21
ERROR: Wuziqi/1.0.0#user/test: Error in build() method, line 26
cmake.build()
ConanException: Error 2 while executing cmake --build '/home/run/.conan/data/Wuziqi/1.0.0/user/test/build/702f20c11c28f19fd5e1d929272b0f47e81fec21' '--' '-j12'
There are multiple errors in the middle, like:
error: ‘is_integral_v’ is not a member of ‘std’; did you mean ‘is_integral’?
170 | template <typename Int> std::enable_if_t<std::is_integral_v<Int>, iterator>
error: ‘compare_eq_result_container’ in namespace ‘QTypeTraits’ does not name a template type
306 | QTypeTraits::compare_eq_result_container<QList, U> operator==(const QList &other) const
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
error: ‘is_same_v’ is not a member of ‘std’; did you mean ‘is_same’?
285 | if constexpr (std::is_same_v<std::decay_t<InputIterator>, iterator> ||
| ^~~~~~~~~
| is_same
Does it seem that there is no xxx_v in std?
How could I fix it?
Thanks, guys, I solved this problem.
It is because of the version of dependencies, just like #康桓瑋 said, I need to use C++17.
However, C++17 will lead to other conflicts. So I set
requires = "qt/5.15.2"
in conanfile.py instead of the latest version.

How to fix an unknown error when cross compiling my QT application to raspberry-pi3

my program (QT/C++)is using a python module to download some video from google drive, it's work very well but I couldn't cross compile it for raspberry pi3.
I am new in QT Cross Compile for raspberry and I couldn't find a solution for this error in any place :
#define _POSIX_C_SOURCE 200112L
^
In file included from /opt/qtrpi/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/arm-linux-gnueabihf/bits/os_defines.h:39:0,
from /opt/qtrpi/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/arm-linux-gnueabihf/bits/c++config.h:426,
from /opt/qtrpi/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/cstddef:41,
from /opt/qtrpi/raspi/qt5pi/include/QtCore/qglobal.h:45,
from /opt/qtrpi/raspi/qt5pi/include/QtCore/qtimer.h:43,
from /opt/qtrpi/raspi/qt5pi/include/QtCore/QTimer:1,
from DigitalSignal.h:5,
from DigitalSignal.cpp:1:
/opt/qtrpi/raspbian/sysroot/usr/include/./features.h:230:0: note: ceci est l'emplacement d’une précédente définition
# define _POSIX_C_SOURCE 200809L
^
In file included from lib/python2.7/Include/Python.h:8:0,
from DigitalSignal.cpp:15:
lib/python2.7/Include/pyconfig.h:1242:0: warning: « _XOPEN_SOURCE » redéfini [enabled by default]
#define _XOPEN_SOURCE 600
^
In file included from /opt/qtrpi/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/arm-linux-gnueabihf/bits/os_defines.h:39:0,
from /opt/qtrpi/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/arm-linux-gnueabihf/bits/c++config.h:426,
from /opt/qtrpi/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/cstddef:41,
from /opt/qtrpi/raspi/qt5pi/include/QtCore/qglobal.h:45,
from /opt/qtrpi/raspi/qt5pi/include/QtCore/qtimer.h:43,
from /opt/qtrpi/raspi/qt5pi/include/QtCore/QTimer:1,
from DigitalSignal.h:5,
from DigitalSignal.cpp:1:
/opt/qtrpi/raspbian/sysroot/usr/include/./features.h:162:0: note: ceci est l'emplacement d’une précédente définition
# define _XOPEN_SOURCE 700
^
In file included from lib/python2.7/Include/Python.h:61:0,
from DigitalSignal.cpp:15:
lib/python2.7/Include/pyport.h:895:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
^
Makefile:1145: recipe for target 'DigitalSignal.o' failed
make: *** [DigitalSignal.o] Error 1
Basing on the solution of this problem Python compilation error: "LONG_BIT definition appears wrong for platform" .I changed in lib/python2.7/Include/pyconfig.h this line #define SIZEOF_LONG 8 bye this line #define SIZEOF_LONG 4 (explanation : '4' for 32 bits and '8' for 64 bits ).
but now I have a new error that i does't understand :::
t/usr/lib/arm-linux-gnueabihf -lQt5Widgets -lQt5Gui -lQt5Qml -lQt5Network -lQt5Xml -lQt5Core -Wl,-rpath-link,/opt/qtrpi/raspbian/sysroot/opt/vc/lib -lGLESv2 -lpthread
/home/Documents/project/digitalsignage/lib/python2.7//libpython2.7.a : erreur lors de l'ajout de symboles : Format de fichier non reconnu
collect2: error: ld a retourné le statut de sortie 1
Makefile:170: recipe for target 'DigitalSignal' failed
make: *** [DigitalSignal] Error 1
can anyone what is the meaning of this error ???

Execute C++ code in R

I am trying to execute c++ function using boost library in R. I've also installed boost header file package (BH). When I try to execute the code it give me the following error:
src <- '
#include <Rcpp.h>
#include <boost/math/special_functions/binomial.hpp>
for (unsigned long i = 0; i < 5; ++i) {
boost::math::binomial_coefficient<double>(25, i);
}'
sillyExp <- cfunction(signature(), src, convention = ".C")
Where I am going wrong?
Edit: Following is the error
Error in compileCode(f, code, language, verbose) : 
  Compilation ERROR, function(s)/method(s) not created! file68b0697546bd.cpp:11:54: fatal error: boost/math/special_functions/binomial.hpp: No such file or directory
 #include <boost/math/special_functions/binomial.hpp> 
                                                      ^
compilation terminated.
make: *** [C:/PROGRA~1/R/R-34~1.3/etc/x64/Makeconf:215: file68b0697546bd.o] Error 1
Warning message:
running command 'make -f "C:/PROGRA~1/R/R-34~1.3/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-34~1.3/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="file68b0697546bd.dll" WIN=64 TCLBIN=64 OBJECTS="file68b0697546bd.o"' had status 2 
If you really want to execute some C++ code, then you can use Rcpp::evalCpp:
Rcpp::evalCpp("boost::math::binomial_coefficient<double>(25, 3)",
depends="BH",
include="#include <boost/math/special_functions/binomial.hpp>")
#> [1] 2300

Popup in BlackBerry 10

How do I show a popup in Blackberry 10? I want to show popup when any contact is added /deleted/updated. I took one method like this---
void ContactEditor::showToast(QString text) {
bb::system::SystemToast toast;
toast.setBody(text);
toast.setPosition(bb::system::SystemUiPosition::MiddleCenter);
toast.exec();
}
and called like this---
showToast("contact added...");
included file for System Toast also.
but this is giving me error----
make[2]: *** [o-g/addressbook] Error 1
make[1]: *** [debug] Error 2
make: *** [Simulator-Debug] Error 2
can somebody tell me whats the problem ?
Add LIBS += -lbbsystem to your application pro file. and include
#include <bb/system/SystemToast>
SystemToast *toast = new SystemToast(this);
toast->setBody("Your Toast");
toast->setPosition(SystemUiPosition::MiddleCenter);
toast->show();

Function in if statement: error expected expression

I want to compile following file:
https://gist.github.com/bodokaiser/5382281
which does not succeed because I get following error:
CXX(target) Release/obj.target/parser/src/parser/parser.o
In file included from ../src/parser/parser.cc:2:
../src/parser/calc_head_size.cc:67:16: error: expected expression
if (mask || isMasking(masking)) {
^
1 error generated.
make: *** [Release/obj.target/parser/src/parser/parser.o] Error 1
This does not make sense to me. Can it be that there is something else wrong?
Bodo
You seem to have a strange character in your source code that looks like a space but isn't. In this line:
if (mask || isMasking(masking)) {
// ^ here
try to delete the "space" and add a real space.