??xml version="1.0" encoding="utf-8" standalone="yes"?>久久这里有精品视频,国产精品美女久久久久AV福利,久久久一本精品99久久精品88http://www.shnenglu.com/volant/category/8093.htmlzh-cnThu, 15 Aug 2013 17:21:30 GMTThu, 15 Aug 2013 17:21:30 GMT60gtest的一个简单扩展(q行旉试Q的实例http://www.shnenglu.com/volant/archive/2008/08/27/60203.htmlWed, 27 Aug 2008 15:34:00 GMThttp://www.shnenglu.com/volant/archive/2008/08/27/60203.htmlhttp://www.shnenglu.com/volant/comments/60203.htmlhttp://www.shnenglu.com/volant/archive/2008/08/27/60203.html#Feedback0http://www.shnenglu.com/volant/comments/commentRss/60203.htmlhttp://www.shnenglu.com/volant/services/trackbacks/60203.html上一中对gtestq行了一个简单的扩展Q本文通过实例试q介l这个扩展的用法?/p>

首先实现两个Fibonacci函数Q然后对q两个函数进行测试:

Fibonacci_1Q用@环实玎ͼ

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_2Q用递归实现Q?/p>

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);
    }

}


试用例Q?/p>

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!";
}


试l果Q?/p>

 

[==========] 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

 

实例中测试了四个试用例Q分别测试了两个函数分别计算Fibonacci(30)和Fibonacci(40)所p的时间。测试用??比较单,仅有一个ASSERT_TIME断言用于试q行到此该测试用例花费的旉。测试用??Q增加了两条语句QTEST_T_SHOWTIME()Q测试用例结束后打印执行旉QEXCEPT_TIME断言Q这里只是测试以下EXCEPT_TIME和ASSERT_TIME的区别,前者l执行后l语句,后者则l束当前的测试用例?img src ="http://www.shnenglu.com/volant/aggbug/60203.html" width = "1" height = "1" />

2008-08-27 23:34 发表评论
]]>
gtest的一个简单扩?/title><link>http://www.shnenglu.com/volant/archive/2008/08/27/60201.html</link><dc:creator>夜</dc:creator><author>夜</author><pubDate>Wed, 27 Aug 2008 15:14:00 GMT</pubDate><guid>http://www.shnenglu.com/volant/archive/2008/08/27/60201.html</guid><wfw:comment>http://www.shnenglu.com/volant/comments/60201.html</wfw:comment><comments>http://www.shnenglu.com/volant/archive/2008/08/27/60201.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/volant/comments/commentRss/60201.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/volant/services/trackbacks/60201.html</trackback:ping><description><![CDATA[<p>看了gtest的一个simpleQ其中有试q行旉的方法,但用v来稍微负责,因此做了一个简单的扩展?/p> <p>扩展内容Q?br />1. TEST_T(test_case_name, test_name)Q用于定义运行时间测试用例?br />2. TEST_T_SHOWTIME()Q打开打印试用例q行旉打印开兟?br />3. EXCEPT_TIME(second)和ASSERT_TIME(second)Q断aQsecond为doublecdQ测试运行时间是否小于second?/p> <p>使用说明Q?br />向正怋用一P只是在需要时间测试时include “gtest_e.h”卛_Q当然也得把相应的库链接到执行文件中?/p> <p>具体实现Q?br />源文件gtest_e.h----</p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img id="Codehighlighter1_0_19_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_19_Open_Text.style.display='none'; Codehighlighter1_0_19_Closed_Image.style.display='inline'; Codehighlighter1_0_19_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_0_19_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_0_19_Closed_Text.style.display='none'; Codehighlighter1_0_19_Open_Image.style.display='inline'; Codehighlighter1_0_19_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align="top"><span id="Codehighlighter1_0_19_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/**/</span><span id="Codehighlighter1_0_19_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000">*<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * gtest_e.h<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" /> </span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" />#ifndef GTEST_E_H_<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">#define</span><span style="color: #000000"> GTEST_E_H_</span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" />#include </span><span style="color: #000000">"</span><span style="color: #000000">gtest_time.h</span><span style="color: #000000">"</span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">#define</span><span style="color: #000000"> TEST_T(test_case_name, test_name)\</span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" />    GTEST_TEST(TIME_##test_case_name, test_name, ::TimeTest)<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">#define</span><span style="color: #000000"> TEST_T_SHOWTIME() TimeTest_setShowFlag(1)</span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">#define</span><span style="color: #000000"> ASSERT_TIME(time) if(TimeTest_setTimePoint() - time > 0) \</span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" />    FAIL() </span><span style="color: #000000"><<</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">Time: running </span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000"><<</span><span style="color: #000000"> TimeTest_getTime() </span><span style="color: #000000"><<</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">(s) > </span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000"><<</span><span style="color: #000000"> time </span><span style="color: #000000"><<</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">(s)</span><span style="color: #000000">"</span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">#define</span><span style="color: #000000"> EXCEPT_TIME(time) if(TimeTest_setTimePoint() - time > 0) \</span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" />    ADD_FAILURE() </span><span style="color: #000000"><<</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">Time: running </span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000"><<</span><span style="color: #000000"> TimeTest_getTime() </span><span style="color: #000000"><<</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">(s) > </span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000"><<</span><span style="color: #000000"> time </span><span style="color: #000000"><<</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">(s)</span><span style="color: #000000">"</span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">#endif</span><span style="color: #000000"> /* GTEST_E_H_ */</span></div> 源文件gtest_time.h----<br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img id="Codehighlighter1_0_22_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_22_Open_Text.style.display='none'; Codehighlighter1_0_22_Closed_Image.style.display='inline'; Codehighlighter1_0_22_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_0_22_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_0_22_Closed_Text.style.display='none'; Codehighlighter1_0_22_Open_Image.style.display='inline'; Codehighlighter1_0_22_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align="top"><span id="Codehighlighter1_0_22_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/**/</span><span id="Codehighlighter1_0_22_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000">*<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * gtest_time.h<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" /> </span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" />#ifndef GTEST_TIME_H_<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">#define</span><span style="color: #000000"> GTEST_TIME_H_</span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" />#include </span><span style="color: #000000"><</span><span style="color: #000000">gtest</span><span style="color: #000000">/</span><span style="color: #000000">gtest.h</span><span style="color: #000000">></span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">class</span><span style="color: #000000"> TimeTest: </span><span style="color: #0000ff">public</span><span style="color: #000000"> testing::Test<br /><img id="Codehighlighter1_133_490_Open_Image" onclick="this.style.display='none'; Codehighlighter1_133_490_Open_Text.style.display='none'; Codehighlighter1_133_490_Closed_Image.style.display='inline'; Codehighlighter1_133_490_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_133_490_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_133_490_Closed_Text.style.display='none'; Codehighlighter1_133_490_Open_Image.style.display='inline'; Codehighlighter1_133_490_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_133_490_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_133_490_Open_Text"><span style="color: #000000">{<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000">:<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    inline </span><span style="color: #0000ff">void</span><span style="color: #000000"> TimeTest_setShowFlag(</span><span style="color: #0000ff">int</span><span style="color: #000000"> flag)<br /><img id="Codehighlighter1_194_227_Open_Image" onclick="this.style.display='none'; Codehighlighter1_194_227_Open_Text.style.display='none'; Codehighlighter1_194_227_Closed_Image.style.display='inline'; Codehighlighter1_194_227_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_194_227_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_194_227_Closed_Text.style.display='none'; Codehighlighter1_194_227_Open_Image.style.display='inline'; Codehighlighter1_194_227_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top">    </span><span id="Codehighlighter1_194_227_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_194_227_Open_Text"><span style="color: #000000">{<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />        show_time_ </span><span style="color: #000000">=</span><span style="color: #000000"> flag;<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    inline </span><span style="color: #0000ff">double</span><span style="color: #000000"> TimeTest_getTime()<br /><img id="Codehighlighter1_271_317_Open_Image" onclick="this.style.display='none'; Codehighlighter1_271_317_Open_Text.style.display='none'; Codehighlighter1_271_317_Closed_Image.style.display='inline'; Codehighlighter1_271_317_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_271_317_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_271_317_Closed_Text.style.display='none'; Codehighlighter1_271_317_Open_Image.style.display='inline'; Codehighlighter1_271_317_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top">    </span><span id="Codehighlighter1_271_317_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_271_317_Open_Text"><span style="color: #000000">{<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> end_time_ </span><span style="color: #000000">-</span><span style="color: #000000"> start_time_;<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">double</span><span style="color: #000000"> TimeTest_setTimePoint();<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">protected</span><span style="color: #000000">:<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">double</span><span style="color: #000000"> start_time_;<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">double</span><span style="color: #000000"> end_time_;<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> show_time_;<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">virtual</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> SetUp();<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">virtual</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> TearDown();<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000">;<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">#endif</span><span style="color: #000000"> /* GTEST_TIME_H_ */</span></div> 源文件gtest_time.cpp----<br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img id="Codehighlighter1_0_24_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_24_Open_Text.style.display='none'; Codehighlighter1_0_24_Closed_Image.style.display='inline'; Codehighlighter1_0_24_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_0_24_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_0_24_Closed_Text.style.display='none'; Codehighlighter1_0_24_Open_Image.style.display='inline'; Codehighlighter1_0_24_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align="top"><span id="Codehighlighter1_0_24_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/**/</span><span id="Codehighlighter1_0_24_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000">*<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * gtest_time.cpp<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" /> </span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" />#include </span><span style="color: #000000"><</span><span style="color: #000000">iostream</span><span style="color: #000000">></span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" />#include </span><span style="color: #000000">"</span><span style="color: #000000">gtest_time.h</span><span style="color: #000000">"</span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000"> </span><span style="color: #0000ff">namespace</span><span style="color: #000000"> std;<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">#if</span><span style="color: #000000"> defined(WIN32)</span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" />#include </span><span style="color: #000000"><</span><span style="color: #000000">sys</span><span style="color: #000000">/</span><span style="color: #000000">timeb.h</span><span style="color: #000000">></span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">double</span><span style="color: #000000"> now()<br /><img id="Codehighlighter1_149_275_Open_Image" onclick="this.style.display='none'; Codehighlighter1_149_275_Open_Text.style.display='none'; Codehighlighter1_149_275_Closed_Image.style.display='inline'; Codehighlighter1_149_275_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_149_275_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_149_275_Closed_Text.style.display='none'; Codehighlighter1_149_275_Open_Image.style.display='inline'; Codehighlighter1_149_275_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_149_275_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_149_275_Open_Text"><span style="color: #000000">{<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">struct</span><span style="color: #000000"> _timeb current;<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    _ftime(</span><span style="color: #000000">&</span><span style="color: #000000">current);<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> (((</span><span style="color: #0000ff">double</span><span style="color: #000000">) current.time) </span><span style="color: #000000">+</span><span style="color: #000000"> (</span><span style="color: #000000">1.0</span><span style="color: #000000"> </span><span style="color: #000000">*</span><span style="color: #000000"> current.millitm) </span><span style="color: #000000">*</span><span style="color: #000000"> </span><span style="color: #000000">0.000001</span><span style="color: #000000">);<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">#else</span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">double</span><span style="color: #000000"> now()<br /><img id="Codehighlighter1_296_438_Open_Image" onclick="this.style.display='none'; Codehighlighter1_296_438_Open_Text.style.display='none'; Codehighlighter1_296_438_Closed_Image.style.display='inline'; Codehighlighter1_296_438_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_296_438_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_296_438_Closed_Text.style.display='none'; Codehighlighter1_296_438_Open_Image.style.display='inline'; Codehighlighter1_296_438_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_296_438_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_296_438_Open_Text"><span style="color: #000000">{<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">struct</span><span style="color: #000000"> timeval current;<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    gettimeofday(</span><span style="color: #000000">&</span><span style="color: #000000">current, NULL);<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> (((</span><span style="color: #0000ff">double</span><span style="color: #000000">) current.tv_sec) </span><span style="color: #000000">+</span><span style="color: #000000"> </span><span style="color: #000000">1.0e-6</span><span style="color: #000000"> </span><span style="color: #000000">*</span><span style="color: #000000"> ((</span><span style="color: #0000ff">double</span><span style="color: #000000">) current.tv_usec));<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">#endif</span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">void</span><span style="color: #000000"> TimeTest::SetUp()<br /><img id="Codehighlighter1_471_546_Open_Image" onclick="this.style.display='none'; Codehighlighter1_471_546_Open_Text.style.display='none'; Codehighlighter1_471_546_Closed_Image.style.display='inline'; Codehighlighter1_471_546_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_471_546_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_471_546_Closed_Text.style.display='none'; Codehighlighter1_471_546_Open_Image.style.display='inline'; Codehighlighter1_471_546_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_471_546_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_471_546_Open_Text"><span style="color: #000000">{<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    start_time_ </span><span style="color: #000000">=</span><span style="color: #000000"> now();<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    end_time_ </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    TimeTest_setShowFlag(</span><span style="color: #000000">0</span><span style="color: #000000">);<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">void</span><span style="color: #000000"> TimeTest::TearDown()<br /><img id="Codehighlighter1_575_751_Open_Image" onclick="this.style.display='none'; Codehighlighter1_575_751_Open_Text.style.display='none'; Codehighlighter1_575_751_Closed_Image.style.display='inline'; Codehighlighter1_575_751_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_575_751_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_575_751_Closed_Text.style.display='none'; Codehighlighter1_575_751_Open_Image.style.display='inline'; Codehighlighter1_575_751_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_575_751_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_575_751_Open_Text"><span style="color: #000000">{<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (show_time_)<br /><img id="Codehighlighter1_601_749_Open_Image" onclick="this.style.display='none'; Codehighlighter1_601_749_Open_Text.style.display='none'; Codehighlighter1_601_749_Closed_Image.style.display='inline'; Codehighlighter1_601_749_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_601_749_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_601_749_Closed_Text.style.display='none'; Codehighlighter1_601_749_Open_Image.style.display='inline'; Codehighlighter1_601_749_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top">    </span><span id="Codehighlighter1_601_749_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_601_749_Open_Text"><span style="color: #000000">{<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">double</span><span style="color: #000000"> used_time </span><span style="color: #000000">=</span><span style="color: #000000"> TimeTest_setTimePoint();<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />        cout </span><span style="color: #000000"><<</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">[   TIME   ] used time: </span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000"><<</span><span style="color: #000000"> used_time </span><span style="color: #000000"><<</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">(s)</span><span style="color: #000000">"</span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />                </span><span style="color: #000000"><<</span><span style="color: #000000"> endl;<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">double</span><span style="color: #000000"> TimeTest::TimeTest_setTimePoint()<br /><img id="Codehighlighter1_795_851_Open_Image" onclick="this.style.display='none'; Codehighlighter1_795_851_Open_Text.style.display='none'; Codehighlighter1_795_851_Closed_Image.style.display='inline'; Codehighlighter1_795_851_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_795_851_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_795_851_Closed_Text.style.display='none'; Codehighlighter1_795_851_Open_Image.style.display='inline'; Codehighlighter1_795_851_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_795_851_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_795_851_Open_Text"><span style="color: #000000">{<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    end_time_ </span><span style="color: #000000">=</span><span style="color: #000000"> now();<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> TimeTest_getTime();<br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"><br /><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align="top" alt="" /></span></div> <br />以上内容只是一个简单的实现Q没有过多的试Q且旉_ֺ不够Q误差较大?img src ="http://www.shnenglu.com/volant/aggbug/60201.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/volant/" target="_blank">夜</a> 2008-08-27 23:14 <a href="http://www.shnenglu.com/volant/archive/2008/08/27/60201.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>gtestQgoogle的c++单元试Q试?/title><link>http://www.shnenglu.com/volant/archive/2008/07/31/57620.html</link><dc:creator>夜</dc:creator><author>夜</author><pubDate>Thu, 31 Jul 2008 04:52:00 GMT</pubDate><guid>http://www.shnenglu.com/volant/archive/2008/07/31/57620.html</guid><wfw:comment>http://www.shnenglu.com/volant/comments/57620.html</wfw:comment><comments>http://www.shnenglu.com/volant/archive/2008/07/31/57620.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.shnenglu.com/volant/comments/commentRss/57620.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/volant/services/trackbacks/57620.html</trackback:ping><description><![CDATA[google开源了c++单元试框架Q真让h兴奋。安装的q程比较单,在eclipse+mingw+cygwin下很easy搞定了。用也很容易,按照sample不用看文也能很快上手。过E就不多了Q记点东西备忘?br /><br />断言Q?br />ASSERT_TRUE(condition); EXPECT_TRUE(condition); condition为真<br />ASSERT_FALSE(condition);    EXPECT_FALSE(condition);    condition为假<br /><br />ASSERT_EQ(expected, actual);    EXPECT_EQ(expected, actual);    expected == actual<br />ASSERT_NE(val1, val2);  EXPECT_NE(val1, val2);  val1 != val2<br />ASSERT_LT(val1, val2);  EXPECT_LT(val1, val2);  val1 < val2<br />ASSERT_LE(val1, val2);  EXPECT_LE(val1, val2);  val1 <= val2<br />ASSERT_GT(val1, val2);  EXPECT_GT(val1, val2);  val1 > val2<br />ASSERT_GE(val1, val2);  EXPECT_GE(val1, val2);  val1 >= val2<br /><br />ASSERT_STREQ(expected_str, actual_str); EXPECT_STREQ(expected_str, actual_str); 两个C字符串有相同的内?br />ASSERT_STRNE(str1, str2);   EXPECT_STRNE(str1, str2); 两个C字符串有不同的内?br />ASSERT_STRCASEEQ(expected_str, actual_str); EXPECT_STRCASEEQ(expected_str, actual_str); 两个C字符串有相同的内容,忽略大小?br />ASSERT_STRCASENE(str1, str2);   EXPECT_STRCASENE(str1, str2);   两个C字符串有不同的内容,忽略大小?br /><br />头文Ӟ<br />#include <gtest/gtest.h><br /><br />mainQ?br />    testing::InitGoogleTest(&argc, argv);<br />    return RUN_ALL_TESTS();<br /><br />库:<br />    -lgtest<br /><br /><img src ="http://www.shnenglu.com/volant/aggbug/57620.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/volant/" target="_blank">夜</a> 2008-07-31 12:52 <a href="http://www.shnenglu.com/volant/archive/2008/07/31/57620.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[导入]搭徏cppunit单元试环境http://www.shnenglu.com/volant/archive/2008/06/02/57611.htmlMon, 02 Jun 2008 10:30:00 GMThttp://www.shnenglu.com/volant/archive/2008/06/02/57611.htmlhttp://www.shnenglu.com/volant/comments/57611.htmlhttp://www.shnenglu.com/volant/archive/2008/06/02/57611.html#Feedback0http://www.shnenglu.com/volant/comments/commentRss/57611.htmlhttp://www.shnenglu.com/volant/services/trackbacks/57611.html
文章来源:http://blog.csdn.net/volant_hoo/archive/2008/06/02/2502339.aspx

2008-06-02 18:30 发表评论
]]>
ձɫվWWWþ| ĻþþƷˮ | ަvþþ| ŷ޹Ʒþ| ɫۺϾþĻ| ѹۿ˾þѹۿ| þseƷһ| ŷþһ| ޾Ʒþþþþο | þۺϳDž| þù¶ƷӰ| þþƷһ| ŷսպ91ۺһþþ| ѾþþƷ99reѾy| ھƷþþþþҰ| þsmȤ| þ91˳ɵӰվ| ˾þþƷһ| ŷպĻþ| þþƷ99Ʒ| LƷþ| Ļþи| þþþ99ƷƬ| Ʒþۺ| ݺݾƷþþĻ| ҹƷþþþþž| þ99ۺϾƷ| պһþ | ŷƷƵһþþþƷ| ˾þô߽ۺAv | þAëƬѹۿ| һ97ձ˾þۺӰԺ| ھƷþþþþòӰԺ | ëƬŷëƬþþ| ձþĻ| þۺɫ99žak| ƷۺϾþþþþ88С˵| Ʒþþþþùţţapp| þù޾ƷӰԺ| þþþƷһ| aaþ|