Chinaunix首页 | 论坛 | 博客
  • 博客访问: 606612
  • 博文数量: 138
  • 博客积分: 3067
  • 博客等级: 中校
  • 技术积分: 1565
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-21 12:44
文章分类

全部博文(138)

文章存档

2016年(5)

2014年(4)

2012年(1)

2011年(2)

2010年(10)

2009年(19)

2008年(97)

我的朋友

分类: C/C++

2008-04-03 16:18:48

利用automake 生成 Makefile

STEP:
  1. autoscan  -> configure.scan
  2. vi configure.scan
  3. mv configure.scan configure.in
  4. aclocal
  5. autoconf
  6. vi Makefile.am
  7. libtoolize -f -c (用于生成共享库)
  8. automake --add-missing
  9. ./configure
  10. make
File:
1.configure.in

AC_PREREQ(2.57)
AC_INIT(test, 1.1, stone.pub@163.com)
AM_INIT_AUTOMAKE(test, 1.1)
# AC_CONFIG_SRCDIR([main.cpp])
# AC_CONFIG_HEADER([config.h])

AC_PROG_CXX
AC_OUTPUT(Makefile)





AC_PREREQ(2.57)
AC_INIT(test, 1.1, stone.pub@163.com)
AM_INIT_AUTOMAKE(test, 1.1)

AC_CONFIG_SRCDIR([mytest])
AC_PROG_RANLIB

AC_PROG_CXX
AC_PROG_LIBTOOL
AC_LTDL_DLLIB
AC_OUTPUT([
        Makefile
        mytest/Makefile])




2.Makefile.am

test_SOURCES=main.cpp MyTest.cpp
test_LDFLAGS=-lcppunit -ldl -L/usr/local/lib

# AM_CXXFLAGS = -D_LINUX

# INCLUDES=-IPassport

# SUBDIRS = dir1

# test_LDADD = libsub1.a




lib_LTLIBRARIES = libmytest.la
libmytest_la_SOURCES = MyTest.cpp
INCLUDES=-I../include



3. main.cpp


//#include

#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>
//#include

#include <cppunit/BriefTestProgressListener.h>
//#include

#include <cppunit/extensions/TestFactoryRegistry.h>
//#include

//#include

                                                        
int main( int argc, char **argv )
{
    // Create the event manager and test controller

    CPPUNIT_NS::TestResult controller;
                                                        
    // Add a listener that colllects test result

    CPPUNIT_NS::TestResultCollector result;
    controller.addListener( &result );
                                                        
    // Add a listener that print dots as test run.

    CPPUNIT_NS::BriefTestProgressListener progress;
    controller.addListener( &progress );
                                                        
    // Add the top suite to the test runner

    CPPUNIT_NS::TestRunner runner;
    runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
    runner.run( controller );
                                                        
    return result.wasSuccessful() ? 0 : 1;
}


4. MyTest.cpp

#include <cppunit/config/SourcePrefix.h>
#include "MyTest.h"
                                                        
CPPUNIT_TEST_SUITE_REGISTRATION( MyTest );
                                                        
MyTest::MyTest()
{
}
                                                        
                                                        
MyTest::~MyTest()
{
}
                                                        
void MyTest::test1()
{
        std::string expected = "1234.56";
        std::string actual = CPPUNIT_NS::StringTools::toString(1234.56);
                                                        
        CPPUNIT_ASSERT_EQUAL(expected, actual);
}



5. MyTest.h

#ifndef MYTEST_H
#define MYTEST_H
                                                        
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/tools/StringTools.h>
                                                        
class MyTest : public CPPUNIT_NS::TestCase
{
  CPPUNIT_TEST_SUITE( MyTest );
  CPPUNIT_TEST( test1 );
  CPPUNIT_TEST_SUITE_END();
                                                        
public:
        MyTest();
        virtual ~MyTest();
        void test1();
private:
        MyTest(const MyTest& other);
        void operator=(const MyTest &other);
};
                                                        
#endif





阅读(695) | 评论(0) | 转发(0) |
0

上一篇:pragma

下一篇:Test

给主人留下些什么吧!~~