S.l.e!ep.¢%

像打了激速一样,以四倍的速度运转,开心的工作
简单、开放、平等的公司文化;尊重个性、自由与个人价值;
posts - 1098, comments - 335, trackbacks - 0, articles - 1
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

安装CUNIT出现的 libtool.m4 version mismatch

Posted on 2011-01-20 10:53 S.l.e!ep.¢% 阅读(717) 评论(0)  编辑 收藏 引用 所属分类: Unix
按以下的步骤在 make时出现 libtool.m4 version mismatch
先运行 autoreconf --force --install --symlink
然后
#automake
#chmod u+x configure
#./configure --prefix <Your choice of directory for installation>
(对上一句进行解释,<Your choice of directory for installation>这个位置,需要你输入要安装的目录,目录的格式举例如下:/usr/unittest/)
#make
#make install
编译成功

--------------------------- 下面是引用的内容

CUnit在Linux下的配置说明
关键字:CUnit Linux 配置 xml
      由于项目需要,对于C语言的单元测试工具CUnit在Linux下如何使用进行了调查,在网上对相关内容进行搜索发现,很多内容都很相近,甚至完全一样,在这篇争相转载的文章中,虽有详细的说明,但也有描述的不甚清晰之处,对于刚刚接触Linux的同学,往往是一头雾水,不能很顺利的配置出来。籍着此次的调查机会,现将具体的步骤和配置过程中需要注意的地方进行了补充说明,希望能对以后需要进行同样工作的同学有些帮助。

1、首先在http://cunit.sourceforge.net/index.html链接处,下载最新版本的CUnit源码包(CUnit-2.1-0-src.tar.gz)。
2、将CUnit源码包(CUnit-2.1-0-src.tar.gz)复制到Linux的目标目录下,比如我在这里放到了/usr/unittest目录下。
3、CUnit源码包的解压。打开[System Tools]-〉[Terminal],进入到/usr/unittest目录下,
输入如下命令:
#tar xzvf CUnit-2.1-0-src.tar.gz
执行结束后,将会在当前目录下生成一个解压后的文件夹(CUnit-2.1-0)。
4、解压结束后,开始进行编译和安装。
#cd CUnit-2.1-0
#aclocal
#autoconf
#automake
#chmod u+x configure
#./configure --prefix <Your choice of directory for installation>
(对上一句进行解释,<Your choice of directory for installation>这个位置,需要你输入要安装的目录,目录的格式举例如下:/usr/unittest/)
#make
#make install
这里需要一段时间...
#cd /usr/unittest/lib
#ldconfig
最后这两句,感觉像是没什么用,有时间证实一下。
到此处为止,CUnit的安装基本上就到一段落了。
接下来是来测试我们的代码工作流程。
将要测试的代码复制到/usr/unittest目录下,
输入如下命令:
#export LD_LIBRARY_PATH=/usr/unittest/lib
#gcc -o test -I/usr/unittest/include -L/usr/unittest/lib -lcunit run_test.c test_func.c func.c
这样,即可在/usr/unittest目录下生成可执行文件test。
#./test
执行该文件,执行成功后,会在当前目录下产生两个xml文件。
①TestMax-Listing.xml :对测试用例的报告
②TestMax-Results.xml :对测试结果的报告

要查看这两个文件,还需要使用如下xsl和dtd文件:
CUnit-List.dtd和CUnit-List.xsl用于解析列表文件,
CUnit-Run.dtd和CUnit-Run.xsl用于解析结果文件。
这四个文件在CUnit包里面有提供,安装之后在unittest/share/CUnit目录下,
默认安装的话在/home/usr/local/share/CUnit目录下。
在查看结果之前,需要把这六个文件:
TestMax-Listing.xml, TestMax-Results.xml, CUnit-List.dtd, CUnit-List.xsl, CUnit-Run.dtd, CUnit-Run.xsl拷贝到一个目录下,然后用浏览器打开两个结果的xml文件就可以了。

--------------------------------------------------
示例代码如下:
func.c
--------
int maxi(int i, int j)
{
    return i>j?i:j;
//        return i;
}
--------
test_func.c
--------
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "include/CUnit/CUnit.h"
#include "include/CUnit/Automated.h"

/**//*---- functions to be tested ------*/
extern int maxi(int i, int j);

/**//*---- test cases ------------------*/
void testIQJ()
{
        CU_ASSERT_EQUAL(maxi(1,1),1);
        CU_ASSERT_EQUAL(maxi(0,-0),0);
}

void testIGJ()
{
        CU_ASSERT_EQUAL(maxi(2,1),2);
        CU_ASSERT_EQUAL(maxi(0,-1),0);
        CU_ASSERT_EQUAL(maxi(-1,-2),-1);
}

void testILJ()
{
        CU_ASSERT_EQUAL(maxi(1,2),2);
        CU_ASSERT_EQUAL(maxi(-1,0),0);
        CU_ASSERT_EQUAL(maxi(-2,-1),-1);
}

CU_TestInfo testcases[] = {
        {"Testing i equals j:", testIQJ},
        {"Testing i greater than j:", testIGJ},
        {"Testing i less than j:", testILJ},
        CU_TEST_INFO_NULL
};
/**//*---- test suites ------------------*/
int suite_success_init(void) { return 0; }
int suite_success_clean(void) { return 0; }

CU_SuiteInfo suites[] = {
        {"Testing the function maxi:", suite_success_init, suite_success_clean, testcases},
        CU_SUITE_INFO_NULL
};
/**//*---- setting enviroment -----------*/
void AddTests(void)
{
        assert(NULL != CU_get_registry());
        assert(!CU_is_test_running());
        /**//* shortcut regitry */

        if(CUE_SUCCESS != CU_register_suites(suites)){
                fprintf(stderr, "Register suites failed - %s ", CU_get_error_msg());
                exit(EXIT_FAILURE);
        }
}
--------
run_test.c
--------
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

int main( int argc, char *argv[] )
{
       printf("hello");
       if(CU_initialize_registry()){
                fprintf(stderr, " Initialization of Test Registry failed. ");
                exit(EXIT_FAILURE);
        }else{
                AddTests();
                CU_set_output_filename("TestMax");
                CU_list_tests_to_file();
                CU_automated_run_tests();
                CU_cleanup_registry();
        }
        return 0;
}
-----------------------end--------------------------------
来自: http://hi.baidu.com/danielkwok/blog/item/c94bfb5cd5f53e4afaf2c05d.html

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理