小编Jes*_*hen的帖子

与谷歌测试纠缠在一起

我无法启动并运行Google测试.我已经阅读了Google 提出的建议步骤,我也看过上一篇文章,并阅读了其他一些例子,但它并没有说清楚.

为了简单起见,我正在尝试使用Android测试中的建议示例,该示例可以从Android ndk - sample1中的目录获得:

// main.cpp

#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#include "gtest/gtest.h"

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    testing::InitGoogleTest(&argc, argv);

    QtQuick2ApplicationViewer viewer;
    viewer.setMainQmlFile(QStringLiteral("qml/factorial/main.qml"));
    viewer.showExpanded();

    return RUN_ALL_TESTS();
}
Run Code Online (Sandbox Code Playgroud)

// sample1_unittest.cpp

#include <limits.h>
#include "sample1.h"
#include "gtest/gtest.h"

// Tests factorial of 0.
TEST(FactorialTest, Zero) {
  EXPECT_EQ(1, Factorial(0));
}
Run Code Online (Sandbox Code Playgroud)

文件sample1.h,sample1.cpp也在项目中,其中包含阶乘函数.Google测试同样通知了项目文件--factial.pro:

INCLUDEPATH += 
/opt/android-studio/ndk/sources/third_party/googletest/googletest/include
Run Code Online (Sandbox Code Playgroud)

当我按[Build> Build Project"factorial"]时,会出现以下错误:

main.cpp:8: error: undefined reference to 'testing::InitGoogleTest(int*, char**)'
sample1_unittest.cpp:17: error: undefined reference to 'testing::Test::Test()'
Run Code Online (Sandbox Code Playgroud)

我正在使用Ubuntu,QtCreator,Android和C++.事实上,我已经花了3天时间嘲笑,但到目前为止并没有太多.因此,我在这里发帖,希望有些大师可能对此提出任何暗示.任何帮助将主要受到赞赏.

c++ android unit-testing qt-creator android-ndk

9
推荐指数
2
解决办法
1303
查看次数

什么时候pthread_attr_t不是NULL?

除了pthread_attr_t之外,来自POSIX线程的pthread_create的所有参数都非常简单易懂.什么是pthread_attr_t,如何以及何时不应该由NULL初始化?

我浏览了Linux 手册页.我发现有关pthread_attr_t的描述是:

  • 句法:

    int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void*),void *arg);
    
    Run Code Online (Sandbox Code Playgroud)
  • 说明:

    The attr argument points to a pthread_attr_t structure whose contents
    are used at thread creation time to determine attributes for the new
    thread; this structure is initialized using pthread_attr_init(3) and
    related functions.  If attr is NULL, then the thread is created with
    default attributes.
    
    Run Code Online (Sandbox Code Playgroud)

这是非常不清楚的.我也在互联网上搜索,也没有任何明确的解释.那么,当pthread_attr_t不为NULL时?

有人可以对此有所了解吗?所有评论和反馈都非常感谢.

c multithreading posix arguments pthreads

4
推荐指数
1
解决办法
3998
查看次数

结构硬编码初始化中的C结构

我在C99做错了什么:

struct chess {
    struct coordinate {
        char piece;
        int alive;
    } pos[3];
}table[3] =
{
    {
      {'Q', (int)1},{'Q', (int)1},{'Q', (int)1},
      {'B', (int)1},{'B', (int)1},{'B', (int)1},
      {'K', (int)1},{'K', (int)1},{'K', (int)1},
    }
};
Run Code Online (Sandbox Code Playgroud)

它给出了错误:

error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘=’ token
Run Code Online (Sandbox Code Playgroud)

我希望能够访问数据,例如在结构中具有结构:

table[row].pos[column].piece
table[row].pos[column].alive
Run Code Online (Sandbox Code Playgroud)

我尝试了几种组合,似乎没有一种组合适用于这种情况.在此之前我已经完成了之前的struct硬编码初始化,但这次不是结构中的结构.

有什么建议?

c struct c99 hardcoded

2
推荐指数
1
解决办法
673
查看次数