• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 26, comments - 2, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            看開源的代碼中發(fā)現(xiàn)了一些靜態(tài)函數(shù)聲明后有如下內(nèi)容:__attribute__ ((constructor))這是gcc的擴(kuò)展屬性。
            文章來源:http://blog.csdn.net/volant_hoo/archive/2009/05/11/4169081.aspx

            posted @ 2009-06-18 14:38 小夜 閱讀(215) | 評(píng)論 (0)編輯 收藏

            前兩天看libsmi源代碼,里面對(duì)strncpy函數(shù)進(jìn)行了封裝,感覺有些缺陷,雖然內(nèi)部使用的函數(shù),滿足要求就可以了,但想了想發(fā)現(xiàn)自己它了解的也不是很多。 關(guān)于strncpy,《C程序設(shè)計(jì)語言》中是這樣介紹的:“char *strncpy(s, ct, n),strncpy用于把字符串ct中最多n個(gè)字符拷貝到字符串s中,并返回s。如果ct中少于n個(gè)字符,那么就用’\0’補(bǔ)充。” 寫了一個(gè)簡(jiǎn)單的程序?qū)trncpy進(jìn)行測(cè)試。
            文章來源:http://blog.csdn.net/volant_hoo/archive/2009/05/11/4167919.aspx

            posted @ 2009-06-18 14:38 小夜 閱讀(520) | 評(píng)論 (0)編輯 收藏

            上一篇中對(duì)gtest進(jìn)行了一個(gè)簡(jiǎn)單的擴(kuò)展,本文通過實(shí)例測(cè)試并介紹這個(gè)擴(kuò)展的用法。

            首先實(shí)現(xiàn)兩個(gè)Fibonacci函數(shù),然后對(duì)這兩個(gè)函數(shù)進(jìn)行測(cè)試:

            Fibonacci_1,使用循環(huán)實(shí)現(xiàn):

            unsigned int Fibonacci_1(unsigned int n)
            {
                unsigned 
            int i;
                unsigned 
            int f0 = 1, f1 = 1, f2;
                
            for (i = 1; i < n; i++)
                
            {
                    f2 
            = f0 + f1;
                    f0 
            = f1;
                    f1 
            = f2;
                }

                
            return f1;
            }


            Fibonacci_2,使用遞歸實(shí)現(xiàn):

            unsigned int Fibonacci_2(unsigned int n)
            {
                
            switch (n)
                
            {
                    
            case 0:
                        
            return 1;
                    
            case 1:
                        
            return 1;
                    
            default:
                        
            return Fibonacci_2(n - 1+ Fibonacci_2(n - 2);
                }

            }


            測(cè)試用例:

            TEST_T(Fibonacci_Recursive, 30)
            {
                Fibonacci_2(
            30);
                ASSERT_TIME(
            0.1);
            }


            TEST_T(Fibonacci_Loop, 
            30)
            {
                Fibonacci_1(
            30);
                ASSERT_TIME(
            0.1);
            }


            TEST_T(Fibonacci_Recursive, 
            40)
            {
                TEST_T_SHOWTIME();
                Fibonacci_2(
            40);
                EXCEPT_TIME(
            0.1);
                ASSERT_TIME(
            1<< "\nUsed too long time!";
            }


            TEST_T(Fibonacci_Loop, 
            40)
            {
                TEST_T_SHOWTIME();
                Fibonacci_1(
            40);
                EXCEPT_TIME(
            0.1);
                ASSERT_TIME(
            1<< "\nUsed too long time!";
            }


            測(cè)試結(jié)果:

             

            [==========] Running 4 tests from 2 test cases.
            [
            ----------] Global test environment set-up.
            [
            ----------2 tests from TIME_Fibonacci_Recursive
            [ RUN      ] TIME_Fibonacci_Recursive.
            30
            [       OK ] TIME_Fibonacci_Recursive.
            30
            [ RUN      ] TIME_Fibonacci_Recursive.
            40
            FibonacciTest.cpp:
            47: Failure
            Failed
            Time: running 
            2.9995(s) > 0.1(s)
            FibonacciTest.cpp:
            48: Failure
            Failed
            Time: running 
            2.9995(s) > 1(s)
            Used too 
            long time!
            [   TIME   ] used time: 
            2.9995(s)
            [  FAILED  ] TIME_Fibonacci_Recursive.
            40
            [
            ----------2 tests from TIME_Fibonacci_Loop
            [ RUN      ] TIME_Fibonacci_Loop.
            30
            [       OK ] TIME_Fibonacci_Loop.
            30
            [ RUN      ] TIME_Fibonacci_Loop.
            40
            [   TIME   ] used time: 
            0(s)
            [       OK ] TIME_Fibonacci_Loop.
            40
            [
            ----------] Global test environment tear-down
            [
            ==========4 tests from 2 test cases ran.
            [  PASSED  ] 
            3 tests.
            [  FAILED  ] 
            1 test, listed below:
            [  FAILED  ] TIME_Fibonacci_Recursive.
            40

             

            實(shí)例中測(cè)試了四個(gè)測(cè)試用例,分別測(cè)試了兩個(gè)函數(shù)分別計(jì)算Fibonacci(30)和Fibonacci(40)所花費(fèi)的時(shí)間。測(cè)試用例1、2比較簡(jiǎn)單,僅有一個(gè)ASSERT_TIME斷言用于測(cè)試運(yùn)行到此該測(cè)試用例花費(fèi)的時(shí)間。測(cè)試用例3、4,增加了兩條語句:TEST_T_SHOWTIME(),測(cè)試用例結(jié)束后打印執(zhí)行時(shí)間;EXCEPT_TIME斷言,這里只是測(cè)試以下EXCEPT_TIME和ASSERT_TIME的區(qū)別,前者繼續(xù)執(zhí)行后續(xù)語句,后者則結(jié)束當(dāng)前的測(cè)試用例。

            posted @ 2008-08-27 23:34 小夜 閱讀(3119) | 評(píng)論 (0)編輯 收藏

            看了gtest的一個(gè)simple,其中有測(cè)試運(yùn)行時(shí)間的方法,但使用起來稍微負(fù)責(zé),因此做了一個(gè)簡(jiǎn)單的擴(kuò)展。

            擴(kuò)展內(nèi)容:
            1. TEST_T(test_case_name, test_name),用于定義運(yùn)行時(shí)間測(cè)試用例。
            2. TEST_T_SHOWTIME(),打開打印測(cè)試用例運(yùn)行時(shí)間打印開關(guān)。
            3. EXCEPT_TIME(second)和ASSERT_TIME(second),斷言,second為double類型,測(cè)試運(yùn)行時(shí)間是否小于second。

            使用說明:
            向正常使用一樣,只是在需要時(shí)間測(cè)試時(shí)include “gtest_e.h”即可,當(dāng)然也得把相應(yīng)的庫鏈接到執(zhí)行文件中。

            具體實(shí)現(xiàn):
            源文件gtest_e.h----

            /**
             * gtest_e.h
             
            */


            #ifndef GTEST_E_H_
            #define GTEST_E_H_

            #include 
            "gtest_time.h"

            #define TEST_T(test_case_name, test_name)\
                GTEST_TEST(TIME_##test_case_name, test_name, ::TimeTest)

            #define TEST_T_SHOWTIME() TimeTest_setShowFlag(1)

            #define ASSERT_TIME(time) if(TimeTest_setTimePoint() - time > 0) \
                FAIL() 
            << "Time: running " << TimeTest_getTime() << "(s) > " << time << "(s)"

            #define EXCEPT_TIME(time) if(TimeTest_setTimePoint() - time > 0) \
                ADD_FAILURE() 
            << "Time: running " << TimeTest_getTime() << "(s) > " << time << "(s)"

            #endif /* GTEST_E_H_ */
            源文件gtest_time.h----
            /**
             * gtest_time.h
             
            */


            #ifndef GTEST_TIME_H_
            #define GTEST_TIME_H_

            #include 
            <gtest/gtest.h>

            class TimeTest: public testing::Test
            {
            public:
                inline 
            void TimeTest_setShowFlag(int flag)
                
            {
                    show_time_ 
            = flag;
                }


                inline 
            double TimeTest_getTime()
                
            {
                    
            return end_time_ - start_time_;
                }


                
            double TimeTest_setTimePoint();

            protected:
                
            double start_time_;
                
            double end_time_;
                
            int show_time_;

                
            virtual void SetUp();
                
            virtual void TearDown();
            }
            ;

            #endif /* GTEST_TIME_H_ */
            源文件gtest_time.cpp----
            /**
             * gtest_time.cpp
             
            */


            #include 
            <iostream>
            #include 
            "gtest_time.h"

            using namespace std;

            #if defined(WIN32)
            #include 
            <sys/timeb.h>
            double now()
            {
                
            struct _timeb current;
                _ftime(
            &current);
                
            return (((double) current.time) + (1.0 * current.millitm) * 0.000001);
            }

            #else
            double now()
            {
                
            struct timeval current;
                gettimeofday(
            &current, NULL);
                
            return (((double) current.tv_sec) + 1.0e-6 * ((double) current.tv_usec));
            }

            #endif

            void TimeTest::SetUp()
            {
                start_time_ 
            = now();
                end_time_ 
            = 0;
                TimeTest_setShowFlag(
            0);
            }


            void TimeTest::TearDown()
            {
                
            if (show_time_)
                
            {
                    
            double used_time = TimeTest_setTimePoint();
                    cout 
            << "[   TIME   ] used time: " << used_time << "(s)"
                            
            << endl;
                }

            }


            double TimeTest::TimeTest_setTimePoint()
            {
                end_time_ 
            = now();
                
            return TimeTest_getTime();
            }


            以上內(nèi)容只是一個(gè)簡(jiǎn)單的實(shí)現(xiàn),沒有過多的測(cè)試,且時(shí)間精度不夠,誤差較大。

            posted @ 2008-08-27 23:14 小夜 閱讀(2318) | 評(píng)論 (0)編輯 收藏

            奧運(yùn)會(huì)結(jié)束了,工作也要開始忙起來了。從開幕到閉幕,看了兩個(gè)星期的比賽,有高興,有驚喜,有震撼,也有失望。現(xiàn)在被比賽牽動(dòng)的心,又得趨于平淡。回歸現(xiàn)實(shí),還是工作的勞累和生活的奔波。
            前天查了系分考試的成績(jī),論文沒有過。成績(jī)?cè)谝饬现g,一篇字?jǐn)?shù)剛好、內(nèi)容跑題的論文,又怎么能過呢。失敗也是經(jīng)驗(yàn),感覺以下幾點(diǎn):
            1、系分沒有想象中那么難考。好好準(zhǔn)備一下,爭(zhēng)取基礎(chǔ)知識(shí)和案例成績(jī)?cè)偬岣咭恍?br />2、自己的文字組織能力有待提高。很長(zhǎng)時(shí)間沒有動(dòng)筆寫字了,兩個(gè)小時(shí)完成2000-3000字的論文和300-500的摘要,是個(gè)不小的挑戰(zhàn)。考試的時(shí)候,不敢多做思考,就一直寫呀寫的,結(jié)束前一分鐘剛好碼字到2000字那一行,慚愧啊!
            3、寫論文要學(xué)會(huì)說廢話。一直以來,自己都崇尚以“簡(jiǎn)”為美,經(jīng)常對(duì)外文書籍中動(dòng)輒“洋洋大論”的行為嗤之以鼻,直到考試的時(shí)候,才發(fā)現(xiàn)說廢話也是一種好習(xí)慣。
            4、把規(guī)劃細(xì)化也是一種好的方式。長(zhǎng)期以來,養(yǎng)成的習(xí)慣都是先寫好主干內(nèi)容,然后再逐步擴(kuò)充,呵呵,像XP一樣,錯(cuò)了可以改,少了可以加。唉,電子版可以如此,紙質(zhì)版又能如何,羨慕機(jī)試了。
            5、需要一塊手表。考場(chǎng)上沒有鐘,手機(jī)不能用,有時(shí)間規(guī)劃也不能落到實(shí)處。
            換了工作,又換了房子,需要時(shí)間去適應(yīng)新的環(huán)境。下半年的系分不打算考了,來年再度奮戰(zhàn)。阿門,祈禱一下,希望能夠順利通過。

            posted @ 2008-08-26 11:29 小夜 閱讀(179) | 評(píng)論 (0)編輯 收藏

            google開源了c++單元測(cè)試框架,真讓人興奮。安裝的過程比較簡(jiǎn)單,在eclipse+mingw+cygwin下很easy就搞定了。使用也很容易,按照sample不用看文檔也能很快上手。過程就不多少了,記點(diǎn)東西備忘。

            斷言:
            ASSERT_TRUE(condition); EXPECT_TRUE(condition); condition為真
            ASSERT_FALSE(condition);    EXPECT_FALSE(condition);    condition為假

            ASSERT_EQ(expected, actual);    EXPECT_EQ(expected, actual);    expected == actual
            ASSERT_NE(val1, val2);  EXPECT_NE(val1, val2);  val1 != val2
            ASSERT_LT(val1, val2);  EXPECT_LT(val1, val2);  val1 < val2
            ASSERT_LE(val1, val2);  EXPECT_LE(val1, val2);  val1 <= val2
            ASSERT_GT(val1, val2);  EXPECT_GT(val1, val2);  val1 > val2
            ASSERT_GE(val1, val2);  EXPECT_GE(val1, val2);  val1 >= val2

            ASSERT_STREQ(expected_str, actual_str); EXPECT_STREQ(expected_str, actual_str); 兩個(gè)C字符串有相同的內(nèi)容
            ASSERT_STRNE(str1, str2);   EXPECT_STRNE(str1, str2); 兩個(gè)C字符串有不同的內(nèi)容
            ASSERT_STRCASEEQ(expected_str, actual_str); EXPECT_STRCASEEQ(expected_str, actual_str); 兩個(gè)C字符串有相同的內(nèi)容,忽略大小寫
            ASSERT_STRCASENE(str1, str2);   EXPECT_STRCASENE(str1, str2);   兩個(gè)C字符串有不同的內(nèi)容,忽略大小寫

            頭文件:
            #include <gtest/gtest.h>

            main:
                testing::InitGoogleTest(&argc, argv);
                return RUN_ALL_TESTS();

            庫:
                -lgtest

            posted @ 2008-07-31 12:52 小夜 閱讀(2934) | 評(píng)論 (1)編輯 收藏

            eclipse的出現(xiàn)和每一次版本升級(jí),都讓人興奮,趕緊把公司和家里都升了上去。試用了兩天,總體感覺還是不錯(cuò)的。
            文章來源:http://blog.csdn.net/volant_hoo/archive/2008/07/17/2668471.aspx

            posted @ 2008-07-18 06:14 小夜 閱讀(524) | 評(píng)論 (1)編輯 收藏

            很久沒有接觸snort了,由于工作的原因,和它打了兩年多的交道,雖然有不少的認(rèn)識(shí),但缺少深入的研究。閑來時(shí)翻的幾篇手冊(cè),原來放在163上,偷懶放個(gè)總的上來。
            文章來源:http://blog.csdn.net/volant_hoo/archive/2008/07/07/2622733.aspx

            posted @ 2008-07-08 04:23 小夜 閱讀(172) | 評(píng)論 (0)編輯 收藏

            做了幾年C/C++開發(fā),一直想要把單元測(cè)試加上,因?yàn)楣ぷ靼才牛隽艘恍《螘r(shí)間的java,更堅(jiān)定了搭建c++單元測(cè)試環(huán)境的想法,但不得不說cppunit的配置實(shí)在是有些繁瑣,MinGW的安裝還好說,cygwin安裝實(shí)在是太慢,可憐的網(wǎng)速讓我數(shù)次終止了它的安裝,幸運(yùn)的是在公司的電腦上居然發(fā)現(xiàn)了cygwin的安裝包,于是就開始了我的cppunit的測(cè)試旅程。
            文章來源:http://blog.csdn.net/volant_hoo/archive/2008/06/02/2502339.aspx

            posted @ 2008-06-02 18:30 小夜 閱讀(542) | 評(píng)論 (0)編輯 收藏

            本文對(duì)一篇文中的三種方法進(jìn)行整理,并描述我面試時(shí)的解法。
            文章來源:http://blog.csdn.net/volant_hoo/archive/2008/04/12/2283902.aspx

            posted @ 2008-04-12 10:32 小夜 閱讀(492) | 評(píng)論 (0)編輯 收藏

            僅列出標(biāo)題
            共3頁: 1 2 3 
            亚洲国产精品一区二区久久| 久久这里只有精品久久| 久久亚洲中文字幕精品一区| 亚洲精品美女久久777777| 精品久久久久久国产| 久久丝袜精品中文字幕| 亚洲AV无码成人网站久久精品大| 粉嫩小泬无遮挡久久久久久| 久久久无码精品午夜| 久久er99热精品一区二区| 欧美激情精品久久久久久| 久久婷婷五月综合97色一本一本| 国産精品久久久久久久| 久久综合给合久久狠狠狠97色| 久久国产成人午夜AV影院| 久久亚洲AV成人无码电影| 欧美久久综合九色综合| 久久久精品午夜免费不卡| 久久免费看黄a级毛片| 久久五月精品中文字幕| aaa级精品久久久国产片| 精品国产乱码久久久久久呢| 久久se精品一区精品二区国产| 国内精品久久久久影院日本| 亚洲va久久久久| 久久97久久97精品免视看秋霞| 国产精品久久久久无码av| 精品国产乱码久久久久软件| 亚洲国产婷婷香蕉久久久久久| 国产精品99精品久久免费| 日产精品久久久一区二区| 久久99九九国产免费看小说| 久久人人爽人人爽AV片| 久久激情五月丁香伊人| 88久久精品无码一区二区毛片 | 99久久精品国产高清一区二区| 久久精品久久久久观看99水蜜桃| 日本精品久久久久久久久免费| 精品人妻伦九区久久AAA片69| 国产精品日韩深夜福利久久| 免费国产99久久久香蕉|