xyjzsh

2013年2月6日

first demo for gtest

1.  首先给出第一个运用gtest的demo
#include "stdafx.h"
#include 
"gmock/gmock-actions.h"

using namespace testing;

class Calculate
{
public:
    Calculate()
{}
    
long add(long a,long b){return a+b;}
}
;

class CalculateMock:public Calculate
{
public:
    CalculateMock():Calculate()
{}
    MOCK_METHOD2(add,
long(long a,long b));
}
;

long testFun(Calculate& cal)
{
    
return cal.add(2,3);
}

TEST(testMock,testAdd)
{
    CalculateMock obj;
    
long len = 10;
    ON_CALL(obj,add(
2,3)).WillByDefault(Return(len)); 
    EXPECT_CALL(obj,add(
2,3)).Times(1);
    
//obj.add(2,3);
    EXPECT_EQ(10, obj.add(2,3));
}


int _tmain(int argc, _TCHAR* argv[])
{
    testing::InitGoogleMock(
&argc, argv);  
    RUN_ALL_TESTS();
    
return 0;
}



做第一个demo需要注意的事项:
1. 将用到的gtest,gmock,和你自己运用的project用同样的code generation 的形式一致,将 project property->C++->Code Generation: 设置为:Multi-threaded Debug(/MTd)
2. 添加 using namespace testing, 否则会出现‘Return’Identifier not found.这样的错误

So excited to make it work after so much confusion, anxiety.
Fighting!!

posted @ 2013-02-06 17:14 呆人 阅读(444) | 评论 (0)编辑 收藏

2012年4月26日

Failed to retrieve paths under VSTemplate for the specified registry hive[转载]

最近更换开发机的环境,从Windows XP换到Windows 7,结果以前在XP下的一个VS2008的一个插件项目在新环境中编译老是出错:

AnswerFailed to retrieve paths under VSTemplate for the specified registry hive

在网上搜索了一番,终于找到一篇文章介绍的解决方案:

运行Vs2008 SDK-〉Tools-〉Reset the Microsoft Visual Studio 2008 SP1 Experimental hive

然后重新编译就OK了。

http://www.cnblogs.com/tubo/archive/2009/09/14/1566654.html

posted @ 2012-04-26 11:13 呆人 阅读(313) | 评论 (0)编辑 收藏

2012年2月20日

在VS中 build 和rebuild的区别

Build只编译工程中上次修改过的文件,并链接程序生成可执行文件。
如果以前没有作过编译,它会自动调用Rebuild操作,依次编译资源文件、源程序文件等;
Rebuild不管文件是否作过修改,都会编译工程中的所有源文件。
Visual Studio的智能性还不够,它有时不能非常准确地判断出都有哪些文件需要重新编译。
于是,当你Build时,它仅仅把它认为需要重新编译的重新编译一下,而有时候它的判断实际是不够的。
但Rebuild就不同了,它把所有的东西都重新编译,不管改过的,没改过的;还是它认为有依赖的,没依赖的,统统重来。

posted @ 2012-02-20 10:54 呆人 阅读(1252) | 评论 (0)编辑 收藏

2011年12月29日

用TortoiseGit第一次checkout

首先安装msysgit,然后安装TortoiseGit。
可以在程序中看到GitGUI和TortoiseGit。
使用GitGUI进行checkout。
步骤为:
1. 在电脑上create folder,命名为demo.
2.选中demo。在菜单中选择git clone.
就可以checkout下来代码。

posted @ 2011-12-29 17:26 呆人 阅读(2899) | 评论 (0)编辑 收藏

2011年11月3日

sqlserver2008里面的游标

 SQL是一种基于集合的语言(a set-based language) ,他更擅长操作和提出一组数据,而不是对
 数据进行一行一行的处理。
 SQL is a set-based language ,meaning that is excels at mantipulating and retrieving
 set of rows ,rather than performing single row-by-row processing.
 如果你的程序里一定要一条一条的执行,那么一定要先考虑使用如while循环,子查询,
 临时表,表变量等等,如果这些都不能满足要求,在考虑使用游标。
 
 T-SQL中游标的生存周期:
 1.用返回一个有效结果集的sql语句来定义一个游标。
  a cursor is defined via a SQL statement that returns a valid result set.
 2. 打开游标
 3. 一旦游标被打开就可以从游标中每次取出一行数据,要根据游标的定义可以向前去数据或
 向后取数据
 the rows can be fetched moving forword or backword ,depending on the original cursor definition.
 4. 根据游标的类型,数据可以被修改或者只能读。
 5.最后,用完游标后,必须被显示的关闭,并且从内存中移除。
 
 游标定义格式:
 declare cursor_name cursor
 [local|global]
 [forword_only|scroll]
 [static|keyset|dynamic|fast_forword]
 [read_only| scroll_locks|optimistic]
 [type_warning]
 for select_statement[for update [of column[,...]]]
 
The select_statement argument is the query used to define the data within the cursor. Avoid
using a query that hasmore columns and rows than will actually be used, because cursors, while
open, are kept inmemory. The UPDATE [OF column_name [,...n]] is used to specify those columns
that are allowed to be updated by the cursor.
 

posted @ 2011-11-03 16:28 呆人 阅读(1651) | 评论 (0)编辑 收藏

sqlserver2008 条件循环

条件处理:condtional processing
1.case函数以一个表达式作为输入,一个值作为输出
格式:case 后面有输入表达式,when后面的的每一个表达式都会和case后面的输入表达式进行比较运算
如果相等,则返回,否则返回else后面的表达式,如果没有else则返回NULL。
case input_expression
     when when_expression then result_expression
     [...n]
     [else else_result_expression]
end

case的第二种情况:
case后面没有表达式,when后面跟的是bool表达式。返回第一个when后面计算为true的表达式
格式为:
case
 when bool_expression then result_expression
 [...n]
 else result_expression
end

2. if....else...的格式
if bool_expression
{sql_statement|sql_block}
[else
{sql_statement|sql_block}
]

3.begin ....end 相当于c++中的{...}用来形成一个代码块

4.条件循环
return,while,goto,waitfor

return
return 用于结束当前的sql块,查询,存储过程。
类似于c++中的return。
return 可以返回一个数字

while 类似c++中的while,同样支持break,continue,break来结束当前内层循环,continue继续当前循环

waitfor格式
waitfor
 delay 'time_to_pass'//执行前等待的时间:格式为00:00:00小时:分钟:秒
 |time 'time_to_execute'//设置实际执行的时间
 |(receive_statement)[,TimeOUT timeout]
 可以利用waitfor将某些复杂的执行设定为在相对空闲的时间内进行。

posted @ 2011-11-03 16:27 呆人 阅读(1877) | 评论 (0)编辑 收藏

2011年11月1日

printf 输出int64

__int64 long a=10;
printf("%i64u",a);

posted @ 2011-11-01 14:29 呆人 阅读(406) | 评论 (0)编辑 收藏

2011年10月31日

sqlserver2008中数据类型的优先级

当两个不同数据类型的表达式用运算符组合后,数据类型优先级规则指定将优先级较低的数据类型转换为优先级较高的数据类型。如果此转换不是所支持的隐式转换,则返回错误。当两个操作数表达式具有相同的数据类型时,运算的结果便为该数据类型。

SQL Server 对数据类型使用以下优先级顺序:

  1. 用户定义数据类型(最高)

  2. sql_variant

  3. xml

  4. datetimeoffset

  5. datetime2

  6. datetime

  7. smalldatetime

  8. date

  9. time

  10. float

  11. real

  12. decimal

  13. money

  14. smallmoney

  15. bigint

  16. int

  17. smallint

  18. tinyint

  19. bit

  20. ntext

  21. text

  22. image

  23. timestamp

  24. uniqueidentifier

  25. nvarchar(包括 nvarchar(max)

  26. nchar

  27. varchar(包括 varchar(max)

  28. char

  29. varbinary(包括 varbinary(max)

  30. binary(最低)

posted @ 2011-10-31 11:25 呆人 阅读(398) | 评论 (0)编辑 收藏

2011年8月10日

一种类型的字符拷贝函数

1.函数原型:
LPTSTR lstrcpyn(     

    LPTSTR lpString1,
    LPCTSTR lpString2,//指向一个以NULL结束的字符串
    int iMaxLength   //从lpString2拷贝到lpString1的字符串个数,包括NULL字符
);
成功返回指向lpString1的指针,否则返回NULL。

如果lpString2的长度大于iMaxLength,该方法实际上是将lpString2中的前iMaxLength-1个字符一个NULL字符拷贝到lpString1中。
如果该方法成功,则lpString1一定是以NULL结束的字符串。

2._tcsncpy是一个宏,考虑在unicode的情况下
define _tcsncpy wcsncpy

wchar_t *wcsncpy(
   wchar_t *strDest,
   const wchar_t *strSource,
   size_t count
);

Parameters
strDest

Destination string.

strSource

Source string.

count

Number of characters to be copied.

Return Value

Returns strDest. No return value is reserved to indicate an error.
不能保证NULL结束,将count个字符拷贝到strDest中。




posted @ 2011-08-10 14:02 呆人 阅读(374) | 评论 (0)编辑 收藏

重载标准输出符号operator<<

CString是我自己定义的一个类
为了实现:
CString str("123abvc");
cout<<str<<endl;


声明:
 ostream& operator<<(ostream& os,const CString& str);
实现:

ostream& operator<<(ostream& os,const CString& str)
{
 long multiBytes = WideCharToMultiByte(CP_ACP,0,str._pData,-1,NULL,0,NULL,NULL);//获得将宽字节转换成多自己时,所需要的字节个数,注意蓝色部分
 char *lpMultiBytes = new char[multiBytes+10];//分配多字节时所需要的内存
 memset(lpMultiBytes,0,multiBytes+10);

 WideCharToMultiByte(CP_ACP,0,str._pData,-1,lpMultiBytes,multiBytes+10,NULL,NULL);//调用win32api函数将宽字节的表示转换成为多字节的表示,注意蓝色部分

 os<<lpMultiBytes;

 return os;//注意返回值
}

posted @ 2011-08-10 13:43 呆人 阅读(486) | 评论 (0)编辑 收藏

仅列出标题  下一页
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

常用链接

留言簿(1)

随笔分类

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜