从零开始的 JSON 库教程(一):启程 _学习笔记
2016-10-18 20:46
543 查看
原网址:https://zhuanlan.zhihu.com/json-tutorial
个人gitHub: https://github.com/mutiantong/json-tutorial/
单元测试
在单元测试中,老师主要讲了do ...while(0)在宏中的用法。
下面的代码,我自己按照老师的代码,写了一个单元测试的简单代码。
主要理解
1. 宏的编写技巧
2.关键字__LINE__
3.fpirntf
参考文档:
1、关于stdin, stdout, stderr, https://my.oschina.net/qihh/blog/55308
2、 fprintf http://www.cplusplus.com/reference/cstdio/fprintf/?kw=fprintf
个人gitHub: https://github.com/mutiantong/json-tutorial/
单元测试
在单元测试中,老师主要讲了do ...while(0)在宏中的用法。
下面的代码,我自己按照老师的代码,写了一个单元测试的简单代码。
主要理解
1. 宏的编写技巧
2.关键字__LINE__
3.fpirntf
#include <stdio.h> static int main_ret = 0; static int test_count = 0; static int test_pass = 0; #define EXPECT_EQ_BASE_EQUAL(equality, expect, actual, format) \ do {\ test_count++; \ if(equality)\ {\ test_pass++;\ } \ else \ {\ fprintf(stderr, "%s: line:%d except: "format" actual: "format"", __FILE__, __LINE__, expect, actual );\ main_ret = 1;\ }\ }while (0) // __LINE__ 表示的是调用的行 // "format" 需要加双引号,这样才能表示format是一个变量 // 宏,一行写不下,要用, '\' 分隔开 // fprint 是文件输出 // stderr 在这里代表 输出屏幕 // when in the macro, the '\' is the end of the line. We can not add any letter or backspace following the '\' #define EXPECT_EQ(expect, actual) EXPECT_EQ_BASE_EQUAL((expect) == (actual), expect, actual, "%d") int main() { EXPECT_EQ(5,4); return main_ret; }
参考文档:
1、关于stdin, stdout, stderr, https://my.oschina.net/qihh/blog/55308
2、 fprintf http://www.cplusplus.com/reference/cstdio/fprintf/?kw=fprintf
相关文章推荐
- 学习廖雪峰Python3教程的python序列化json模块的小笔记
- Spring MVC 3学习笔记+教程(三)返回JSON数据
- Spring MVC 3学习笔记+教程(三)返回JSON数据
- 【coder-pig 教程学习笔记5】Json 解析
- Spring MVC 3学习笔记+教程(三)返回JSON数据
- 从零开始的 JSON 库教程 笔记
- Objective-C基础教程学习笔记(一)启程
- Android笔记:Android后台接口教程一(从零开始学习Android后台接口)Android 前后台通信
- 黑客学习笔记教程之四:嗅探技术
- xpath 教程学习笔记
- Javascript教程,javascript入门,javascript学习笔记(经典实例)
- C#学习笔记(4)_C#教程
- 黑客学习笔记教程三:扫描和信息收集(下)
- ETL高级教程学习笔记
- JSON学习个人笔记(一)
- 孙鑫VC教程学习笔记1
- 孙鑫VC教程学习笔记1
- 黑客学习笔记教程六:木马传播技术
- 黑客学习笔记教程五:木马技术
- [系统分析师教程][学习笔记] 第一章 概述