crazyFinger

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  5 随笔 :: 0 文章 :: 1 评论 :: 0 引用

2008年9月24日 #

cURL介绍

  • 功能

cURL, 就是 client-side URL, 它包含两个使用URL的库, libcurl和curl

官方主页 :http://curl.haxx.se/

        libcurl是一个URL客户端的传输库, 它支持的协议包括FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS and FILE

同时它支持多种操作系统, 包括Windows, Unix, FreeBSD, Mac.... 居然有DOS。这个库应用广泛,曾经被许多大公司应用于他们的产品当中,其中包括:

git (Linux之父的版本控制系统), OpenOffice, wmget等等

  • HTTPS certificates
  • FTP uploading
  • Kerberos
  • HTTP form based upload
  • Proxies
  • Cookies
  • User password authentication

        curl是使用libcurl实现的一组互联网命令行工具,, 包括:FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, FILE, LDAP。

  • License

应该是比较好的的License, 至少我的感觉是这样, 很简单很自由.

“Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.”

posted @ 2008-09-24 16:19 crazyFinger 阅读(219) 评论(0) 编辑

一直以来我在Windows上都是用经典风格,之后无意中使用了一下XP风格,发现使用Visual Studio 2003写的MFC程序仍然是老样子仍然没有变化。

后来发现只要将manifest文件更名为 “$(ProjectName).exe".manifest并发在可执行文件的路径下,应用程序就会随着系统的设置而自动改变了。

但是这种方法不好之处在于,一旦你发布了应用程序,而你的manifest文件又丢失的话,你的程序就会恢复到以前的样子,不会变化了。

还好我们还有另外一种方法,就是将manifest文件做成应用程序的资源,具体操作如下:

    资源-> Insert Resource -> Curstom -> "type 填入 24” -> 将整个manifest文件内容贴进去 -> 设置Resource ID为1 编译链接->ok

 

注:

   manifest文件,看起来像这样  

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
       <assemblyIdentity
        type="win32"
         name="Put your descriptions here,shilyx"
         version="1.0.0.0" 
        processorArchitecture="*"/>
       <dependency>
         <dependentAssembly>
           <assemblyIdentity
             type="win32"
             name="Microsoft.Windows.Common-Controls"
             version="6.0.0.0"
             publicKeyToken="6595b64144ccf1df"
             language="*"
             processorArchitecture="*"/>
         </dependentAssembly>
       </dependency>
</assembly>
posted @ 2008-09-24 15:43 crazyFinger 阅读(95) 评论(0) 编辑

2008年8月28日 #

很不幸,我要使用C++操作XML.很久之前做过,但当时为了由于项目中的部分用到了.NET,因此我们使用了C++混合编程,但对于一个纯C++的工程来说,10+M的应用程序加上一个20M的.net platform很显然是不合理的。

其实在windows平台下还有一个选择就是msxml, 他是一个COM组件, 操作太复杂了,所以还是寻找一些OpenSource的工具吧。

 

终于还是找到一篇相关的文章, 里面提到很多Opensource的, commercial的工程。

http://www.ibm.com/developerworks/xml/library/x-ctlbx.html

 

posted @ 2008-08-28 10:37 crazyFinger 阅读(414) 评论(0) 编辑

2008年8月10日 #

 
deb http://Ubuntu.dormforce.net/ubuntu/ gutsy main restricted universe multiverse
deb http://Ubuntu.dormforce.net/ubuntu/ gutsy-backports main restricted universe multiverse
deb http://Ubuntu.dormforce.net/ubuntu/ gutsy-proposed main restricted universe multiverse
deb http://Ubuntu.dormforce.net/ubuntu/ gutsy-security main restricted universe multiverse
deb http://Ubuntu.dormforce.net/ubuntu/ gutsy-updates main restricted universe multiverse
deb-src http://Ubuntu.dormforce.net/ubuntu/ gutsy main restricted universe multiverse
deb-src http://Ubuntu.dormforce.net/ubuntu/ gutsy-backports main restricted universe multiverse
deb-src http://Ubuntu.dormforce.net/ubuntu/ gutsy-proposed main restricted universe multiverse
deb-src http://Ubuntu.dormforce.net/ubuntu/ gutsy-security main restricted universe multiverse

deb-src http://Ubuntu.dormforce.net/ubuntu/ gutsy-updates main restricted universe multiverse

 

成都市 电子科技大学更新服务器(教育网,推荐校园网和网通用户使用):

deb http://Ubuntu.uestc.edu.cn/ubuntu/ hardy-proposed main multiverse restricted universe

deb http://Ubuntu.uestc.edu.cn/ubuntu/ hardy-security main multiverse restricted universe
deb http://Ubuntu.uestc.edu.cn/ubuntu/ hardy-updates main multiverse restricted universe
deb-src http://Ubuntu.uestc.edu.cn/ubuntu/ hardy main multiverse restricted universe
deb-src http://Ubuntu.uestc.edu.cn/ubuntu/ hardy-backports main multiverse restricted universe
deb-src http://Ubuntu.uestc.edu.cn/ubuntu/ hardy-proposed main multiverse restricted universe
deb-src http://Ubuntu.uestc.edu.cn/ubuntu/ hardy-security main multiverse restricted universe
deb-src http://Ubuntu.uestc.edu.cn/ubuntu/ hardy-updates main multiverse restricted universe

== 如果无法解析uestc.edu.cn域名,请使用以下地址 ==

deb http://Ubuntu.dormforce.net/ubuntu/ hardy main multiverse restricted universe
deb http://Ubuntu.dormforce.net/ubuntu/ hardy-backports main multiverse restricted universe
deb http://Ubuntu.dormforce.net/ubuntu/ hardy-proposed main multiverse restricted universe
deb http://Ubuntu.dormforce.net/ubuntu/ hardy-security main multiverse restricted universe
deb http://Ubuntu.dormforce.net/ubuntu/ hardy-updates main multiverse restricted universe
deb-src http://Ubuntu.dormforce.net/ubuntu/ hardy main multiverse restricted universe
deb-src http://Ubuntu.dormforce.net/ubuntu/ hardy-backports main multiverse restricted universe
deb-src http://Ubuntu.dormforce.net/ubuntu/ hardy-proposed main multiverse restricted universe
deb-src http://Ubuntu.dormforce.net/ubuntu/ hardy-security main multiverse restricted universe
deb-src http://Ubuntu.dormforce.net/ubuntu/ hardy-updates main multiverse restricted universe

posted @ 2008-08-10 15:12 crazyFinger 阅读(408) 评论(0) 编辑

2008年7月31日 #

cppunit是C++的unit test工具,CppUnit测试框架的源代码可以到 http://sourceforge.net/projects/cppunit/ 上下载。

1. cppunit的编译


cppunit的编译很简单,直接打开编译就可以啦,好像只有addone会编译失败,它只是用于vc6!cppunit提供了debug、debug static、debug unicode等等版本,按照自己的需求选择就可以啦。
       

 2. 编写测试代码   

  •  TestCase

最简单的单元测试, 你可以实现一个继承自TestCase类,并重写他的runTest函数,在这个函数当中加入测试代码即可。对于值得判断可以使用CPPUNIT_ASSERT()例如
  
   class mytest : public CppUnit::TestCase {
       ..                                   
       void runTest() {                     
          CPPUNIT_ASSERT(myFunc() == 0);    
       }                                    
    }                                      
    编译执行即可,记得加上.h文件和lib文件。
  •  Fixture

TestCase只有一个测试用例,当我们需要编写多个测试时咋办呢, 可以用Fixture.
首先自己实现一个继承自Fixture的类,让后override他的两个成员函数, setUp和tearDown, 这两个函数用来自动分配和释放资源。之后你就可以自己写一个测试用例的,随便起个什么名字。
    class myfixture : public CppUnit::Fixture {
       ...                                     
       setUp() {                               
          alloc resouce.                       
        }                                      
        tearDown() {                           
            release resource...                
        }                                      
        ..                                     
        void textMyFunction1() { test code... }
        void textMyFunction2() { test code... }
    }.                                        

  • TestCaller


 写完了测试代码,还要让他运行。 自己写代码加到main函数里.
       CppUnit::TestCaller<myfixture> test( "textMyFunction1",                
&myfixture ::textMyFunction1);
CppUnit::TestResult result;
test.run( &result );
  •  TestSuite

TestCaller一次调用一次测试用例,而TestSuit可以一次调用多个。
        CppUnit::TestSuite suite;                            
CppUnit::TestResult result;
suite.addTest( new CppUnit::TestCaller<myfixture>(
"testMyFunction1",
&myfixture::testMyFunction1) );
suite.addTest( new CppUnit::TestCaller<fixture>(
"testMyFunction2",
&myfixture::testMyFunction2) );
suite.run( &result );
  • TestRunner

TestRunner可以时我们在执行测试的同时获得结果。
在你编写完一个TestSuit之后,你就可以运行它了。TestRunner就提供了观察测试结果的工具,你学要做的就是将运行TestSuite代码加入到一个类的静态函数suite当中,例如:
class myfixture { 
public:
....
static CppUnit::Test *suite() {

 CppUnit::TestSuite *suite = new CppUnit::TestSuite("mytestsuite");

suite->addTest( new CppUnit::TestCaller<myfixture>(
"testMyFunction1",
&myfixture::testMyFunction1) );
suite->addTest( new CppUnit::TestCaller<fixture>(
"testMyFunction2",
&myfixture::testMyFunction2) );

return suite;
}
};
最后在main函数中加入
  int main( int argc, char **argv) {         
CppUnit::TextUi::TestRunner runner;
runner.addTest( myfixture::suite() );
runner.addTest( ....::suite() );
runner.run();
return 0;
}

3.CppUnit帮助宏

如果像上面那样写测试代码,真的会累死人啊。还好CppUnit提供了一组宏,它可以减少代码量嘔!!使用这些宏我可以像这样编写一个测试类
    #include <cppunits/extensions/helperMacros>
class MyFixture : public CppUnit::TextFixture {
CPPUNIT_TEST_SUITE(MyFixture); // 告诉类的名称
CPPUNIT_TEST(MyTestFunction1); // 告诉测试函数的名称
CPPUNIT_TEST(MyTestFunction2);
CPPUNIT_TEST_EXCEPTION(MyTestFun3, Exception);
CPPUNIT_TEST_SUITE_END();
}
注意到CPPUNIT_TEST_EXCEPTION宏了吗,与CPPUNIT_TEST不同,它提供了捕捉异常的功能,如果MyTestFun3在执行结束后没有抛出Exception异常,则测试用例失败。

在编写完测试代码之后,我们仍然需要写我们的main函数,但是这次我们不需要一个一个的将Fixture加入到TestRunner当中了。只需要对每一个测试类进行注册:
CPPUNIT_TEST_SUITE_REGISTRATION(MyFixture)

main函数编程这样
	int main( int argc, char **argv) {
CppUnit::TextUi::TestRunner runner
  CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest( registry.makeTest() );
runner.run();
return 0;
}
所有的main函数都是这个样子,不用改了, 做个宏叫做CPPUNIT_RUN_ALLTEST()多好啊, 唉~~。
当然还要包含头文件
#include <cppunits/extensions/helperMacros>
#include <cppunits/ui/text/TestRunner>
#include <cppunits/extensions/TextFactoryRegistry>

4.CppUnit常用测试宏

  • 断言
        CPPUNIT_ASSERT()
        CPPUNIT_ASSERT_EQUAL()
       CPPUNIT_ASSERT_DOUBLES_EQUAL()
        CPPUNIT_FAIL("Failed reasion")   //
       我们还可以使用一些带有消息的断言, 如
       CPPUINT_ASSERT_MESSAGE(msg, condition)
       这些宏的定义可以在http://cppunit.sourceforge.net/doc/1.11.6/group___assertions.html#ga2上找到

5. 例子

在了解了CPPUNIT之后,做了一个基本的例子,只要修修补补就可以直接用啦
首先包含以下头文件
#include <cppunit"extensions"HelperMacros.h>
#include <cppunit"ui"text"TestRunner.h>
#include <cppunit"extensions"TestFactoryRegistry.h>
#include <cppunit"TestResult.h>
#include <cppunit"TestResultCollector.h>
#include <cppunit"BriefTestProgressListener.h>
#include <cppunit"CompilerOutputter.h>
#include <cppunit/extensions/HelperMacros.h>

还要包含以下库,如果是在vc下,可以这样
#ifdef _DEBUG
#    pragma comment(lib, "cppunitd.lib")
#    pragma comment(lib, "testrunnerd.lib")
#else
#    pragma comment(lib, "TestRunner.lib")
#    pragma comment(lib, "cppunit.lib")
#endif

添加一个测试类
class RuleCheckerTest : public TestFixture {
public:
    CPPUNIT_TEST_SUITE(RuleCheckerTest);
    CPPUNIT_TEST(TESTCheckIP);
    CPPUNIT_TEST(TESTUnCheck);
    CPPUNIT_TEST(TESTremoveDNS);
    CPPUNIT_TEST_SUITE_END();
public:
    virtual void setUp();
    virtual void tearDown();
protected:
    void TESTCheckIP();
    void TESTUnCheck();
    void TESTremoveDNS();

    IRulesChecker * pRulesChecker_;
    IRulesSettings * pRulesSetting_;
};

注册它
CPPUNIT_TEST_SUITE_REGISTRATION(RuleCheckerTest);

主函数:
int _tmain(int argc, _TCHAR* 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 );

    // Print test in a compiler compatible format.
    CPPUNIT_NS::CompilerOutputter outputter( &result, CPPUNIT_NS::stdCOut() );
    outputter.write();

    return result.wasSuccessful() ? 0 : 1;
}

这样就这可以了,只要根据自己的需要进行修补就OK啦

 

posted @ 2008-07-31 17:28 crazyFinger 阅读(962) 评论(0) 编辑