CUnit断言断言`(((void *)0)!= f_pCurSuite'失败 [英] CUnit assertion Assertion `((void *)0) != f_pCurSuite' failed

查看:235
本文介绍了CUnit断言断言`(((void *)0)!= f_pCurSuite'失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下:

#include <CUnit/CUnit.h>


int maxi(int i1, int i2)
{
    return (i1 > i2) ? i1 : i2;
}

void test_maxi(void)
{
    CU_ASSERT(maxi(0,2) == 2);
}

int main() {
    test_maxi();
    return 0;
}

我在Ubuntu上使用gcc test.c -o test -lcunit对其进行了编译.

I compiled it using gcc test.c -o test -lcunit on Ubuntu.

尝试启动此错误消息:

test:TestRun.c:159:CU_assertImplementation:断言`((void *)0) != f_pCurSuite'失败.已中止(核心已弃用)

test: TestRun.c:159: CU_assertImplementation: Assertion `((void *)0) != f_pCurSuite' failed. Aborted (core dumped)

是什么意思?我在互联网上什么都没找到.

What does it mean? I found nothing about it on the internet.

推荐答案

CUnit适用于测试套件,需要先创建才能运行应用程序.

CUnit works on test suites, you need to create before you can run the application.

使测试正常运行的最基本方法如下:

A very basic way to make your test to work is like the following:

#include <CUnit/CUnit.h>
#include <CUnit/Basic.h>

int maxi(int i1, int i2)
{
    return (i1 > i2) ? i1 : i2;
}

void test_maxi(void)
{
    CU_ASSERT(maxi(0,2) == 2);
}

int main() {
    CU_initialize_registry();
    CU_pSuite suite = CU_add_suite("maxi_test", 0, 0);

    CU_add_test(suite, "maxi_fun", test_maxi);

    CU_basic_set_mode(CU_BRM_VERBOSE);
    CU_basic_run_tests();
    CU_cleanup_registry();

    return 0;
}

没有进行所有必需的检查,但是正如Joachim Pileborg在评论中建议的那样,遵循提供的示例代码更为安全.

without all the required checks, but as Joachim Pileborg suggested in the comments, it's safer to follow the example code provided.

这篇关于CUnit断言断言`(((void *)0)!= f_pCurSuite'失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆