- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在调试我在 CLion 中使用 C++ 编写的应用程序,并使用 Google Test 对其进行测试。这是我发现的计算机视觉论文的实现,我将 OpenCV 用于其 Mat 类和图像处理函数。
我的三个测试函数的行为非常不稳定;这是一个。
/**
* Create a flat point cloud and flip it horizontally
*/
TEST_F(PointCloudTest, FlipHorizontal) {
// load image & set constants
cv::Mat image = omar::imreadAsGrayDouble(dirname + "uttower.png");
cv::Mat flippedImage = omar::imreadAsGrayDouble(dirname + "uttower_horz.png");
double fLength = 200.0; // for this, the flength is arbitrary as long as it's the same.
// build point cloud
omar::PointCloud pc(image, fLength);
/* Build the other camera pose
* Specifically, rotated pi over Y
* and 2 focal lengths out into Z+ space.
* It's written as 2.001 to test whether small variations affect point placement*/
omar::Pose otherCamera(0.0, 0.0, 2.001, 0.0, M_PI, 0.0);
// flip horizontally
omar::PointCloud newPc = pc.viewPoints(otherCamera);
cv::Mat newImage = newPc.renderToImage(fLength, image.rows, image.cols);
omar::assertMatEquals(flippedImage, newImage, 10 * DBL_EPSILON);
}
GTest 调试系统将提供完成时的输出:
[确定] PointCloudTest.FlipHorizontal(205 毫秒)
但图标从未更改为表明测试已完成的信号。
当我去调试它时,如果我在函数底部设置一个断点,它就会停止,然后每次我按下“Step Over”时,它都会向上 剩下的几行,一行一行,然后写完。结果证明这是所有测试的调试行为。
挂起测试与通过的不同测试仅略有不同。具体来说,该行是 viewPoints
行。相关代码如下:
PointCloud::PointCloud(const PointCloud& other) {
pointsAndIntensities = other.pointsAndIntensities.clone();
}
PointCloud PointCloud::viewPoints(omar::Pose otherCameraPose) {
PointCloud otherPointCloud = PointCloud(*this);
otherPointCloud.transform(otherCameraPose);
return otherPointCloud;
}
void PointCloud::transform(omar::Pose otherCameraPose) {
cv::Mat transformedPoints = otherCameraPose.world2camera(pointsAndIntensities(cv::Range(0, 3), cv::Range::all()));
cv::Mat replaceablePoints(pointsAndIntensities, cv::Range(0, 3));
transformedPoints.copyTo(replaceablePoints);
}
我想了解此排序的原因,但它可能与真正的问题(挂起测试)相关,也可能不相关。从技术上讲,所有三个测试都通过了,但我认为这个问题会在未来造成很多问题。我不知道该怎么做。感谢帮助和跟进问题!
最佳答案
TL;DR:确保以新行结束打印语句。
在描述问题时,我遗漏了一个非常非常重要的细节。我决定删掉我用来从我的描述中调试一些信息的 cout
行。原代码为:
void PointCloud::transform(omar::Pose otherCameraPose) {
//cv::Mat oldPoints(pointsAndIntensities, cv::Range(0, 3));
cv::Mat transformedPoints = otherCameraPose.world2camera(pointsAndIntensities(cv::Range(0, 3), cv::Range::all()));
cv::Mat replaceablePoints(pointsAndIntensities, cv::Range(0, 3));
std::cout << "Transformed: " << transformedPoints.col(3) << std::endl;
std::cout << "Original: " << replaceablePoints.col(3) << std::endl;
transformedPoints.copyTo(replaceablePoints);
std::cout << "Replaced?: " << pointsAndIntensities.col(3);
}
我决定深入研究代码以找到导致挂起的确切行,以防出现内存错误。我追踪到上面的 transform
方法,结果是我在那里的 std::cout
行。我不知道在测试中使用流是否会导致一些问题。事实证明,这是因为我没有以 std::endl
结束我的最后一个 print 语句。
我的直觉是,CLion 依赖于 GTest 的 cout
输出来确定测试是通过还是失败,并且因为 [ OK ] PointCloudTest.FlipHorizontal (205 ms)
不在新行上,它没有识别出测试已成功完成。
关于c++ - 通过一些 GTest TEST_F 的 CLion 执行挂起,逐步调试倒退?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36667584/
我在尝试使用 cmake 构建项目时遇到错误。 我在我的电脑上手动下载并安装了 gtest(即/usr/include 中提供了 gtest 头文件)和/usr/lib 中的 gtest、gtest_
我在构建我的项目时遇到以下错误 C:\gtest\gtest-1.6.0\include\gtest/gtest-printers.h(327) : error C2220: warning trea
你好, 我目前正在研究 CMake,以便在工作中使用 ExternalProject_add。因为我想测试 googletest,所以我尝试同时测试两者。我在编译单元测试代码时遇到问题。 所以我就按照
我一直在为这个问题苦苦挣扎一段时间:我在 Windows 10 下使用 CMake 和 GTest,但我得到一个 (Link target) -> LINK : fatal error LNK1104
如果内存不足,C++ 中的 new 关键字将抛出异常,但下面的代码会在 new 失败时尝试返回“NO_MEMORY”。这很糟糕,因为它会引发 std::bad_alloc 异常。 我正在写一个单元测试
我正在尝试运行一些Google测试,并且在每个测试装置中都有很多代码需要重复,因此我想使代码尽可能简短,我想使用的子类的SetUp方法Testing::test父类,但是TEST_F固定装置无法识别S
我正在尝试使用 gtest 类型参数化来确保我的类的基本功能。但是我被困在测试设置中。以下是示例: 我有两个名为 CatTest 和 DogTest 的类,以及一个名为 AnimalTest 的基类,
我想应用参数化测试并具有以下夹具: class MyTest: public ::testing::TestWithParam {...}; 我想设置两个参数化测试用例,其中一个小参数失败,但大参数成
如果我使用 g(oogle)Test,这些像 FRIEND_TEST(Test, Proc) 这样的小谷歌宏在我的代码中随处可见。是否有自动机制将它们从构建中排除,或者我真的必须用 #ifdefs 包
我有一个项目,我添加了一个 gtest 项目,然后将原始项目转换为 .lib 项目,并从第三个新项目调用其 main() 函数。这样,我就可以用项目 .exe 构建测试 .exe。除了,它不起作用。
注意:我知道这个问题以不同的方式被问到,但我无法根据我的限制解决它: 我正在使用谷歌测试版 1.7 使用平台工具集 V100 在 Visual Studio 2010 中编译 我正在为我创建的库编写
我的项目中有一个目录树: /project /build /src main.cpp student.cpp /include
在我们所知的 gtets 中,当控件找到 TEST 或 TEST_F 函数时,它会注册 测试用例 进入 gtest。但是按照我的要求,gtest注册完所有的测试用例之后我需要搜索 testcasena
我有一大套单元测试和一些集成测试是用谷歌测试框架或 gtest 实现的。 由于没有标记,我使用禁用约定将测试分成组或在它们前面加上 GROUPA_、GROUPB_ 等前缀。 这很好用。我可以过滤不同的
我想混合参数化测试和类型化测试。这是我的尝试: struct X {}; struct Y {}; template struct MyTestFixture: public ::testing::
我已阅读 this official document ,了解如何进行二进制比较和字符串比较。 ASSERT_EQ 和 ASSERT_STREQ 在数组比较情况下无法工作。 例如 li@li:~/po
我正在测试我的功能是否正确运行 bool Core::IsMeta(void) { return mProc->GetCode(mPC)->Meta; } 使用说明 EXPECT_EQ(true,
我想用 gtest 测试一个模板类。我在 Google Test manual 中阅读了有关 TYPED_TEST 的信息并查看了official example他们引用了,但我仍然无法全神贯注地获取
这是我的: /* Can't change 'base' struct. */ struct base { public: template void printVal() {
我想要等于 2 个对象,正好是卡片(使用 gtest 进行单元测试)。这是我的代码: #include "stdafx.h" #include #include class Card { p
我是一名优秀的程序员,十分优秀!