All Projects → bigwhite → Lcut

bigwhite / Lcut

a Lightweight C Unit Testing framework

Programming Languages

c
50402 projects - #5 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to Lcut

vusbtiny
Small ISP programmer that uses an ATtiny running V-USB
Stars: ✭ 18 (-14.29%)
Mutual labels:  programmer
Developers-Portfolio
💼 This is a Social App for Developers to interact with other users through messages and sharing projects.
Stars: ✭ 101 (+380.95%)
Mutual labels:  programmer
Cnblogs
一些我在平时工作和学习中积累的编程相关的资源。如果大家有兴趣可以一起增加,修改。
Stars: ✭ 452 (+2052.38%)
Mutual labels:  programmer
micro-bmp
A small Black Magic Probe based on the pinout of the STLink V2 support firmware
Stars: ✭ 29 (+38.1%)
Mutual labels:  programmer
csr-spi-ftdi
USB SPI programmer/debugger for CSR BlueCore bluetooth chips, based on FTDI USB to UART converter, for Linux and Windows
Stars: ✭ 473 (+2152.38%)
Mutual labels:  programmer
reverse-enginnering
open source repository
Stars: ✭ 29 (+38.1%)
Mutual labels:  programmer
apollo
microcontroller-based FPGA / JTAG programmer
Stars: ✭ 32 (+52.38%)
Mutual labels:  programmer
Sourcerer App
🦄 Sourcerer app makes a visual profile from your GitHub and git repositories.
Stars: ✭ 6,645 (+31542.86%)
Mutual labels:  programmer
AVR-Programmer
Collection of AVR Programmers and Accessories
Stars: ✭ 25 (+19.05%)
Mutual labels:  programmer
Tobetopjavaer
To Be Top Javaer - Java工程师成神之路
Stars: ✭ 22,056 (+104928.57%)
Mutual labels:  programmer
hugo-hello-programmer-theme
This is a hugo theme for a programmer. It's simple and simple.
Stars: ✭ 40 (+90.48%)
Mutual labels:  programmer
cli
Nexss PROGRAMMER 2.x - innovative and evolutionary programming tool - over 50 programming languages
Stars: ✭ 15 (-28.57%)
Mutual labels:  programmer
Webapp Checklist
Technical details that a programmer of a web application should consider before making the site public.
Stars: ✭ 320 (+1423.81%)
Mutual labels:  programmer
Portfolio-Template
A portfolio website template for Geeks,Programmers and hackers.
Stars: ✭ 159 (+657.14%)
Mutual labels:  programmer
Package
Metaparticle/Package: Language Fluent Containerization and Deployment in Java, .NET and Javascript (and more coming soon)
Stars: ✭ 493 (+2247.62%)
Mutual labels:  programmer
cc-tool
Mirror of cc-tool from SourceForge
Stars: ✭ 144 (+585.71%)
Mutual labels:  programmer
mianshiya
干净免费的面试刷题网站,帮助大家拿到满意的 offer!
Stars: ✭ 190 (+804.76%)
Mutual labels:  programmer
Boostnote Mobile
Boostnote for iOS and Android 🚀
Stars: ✭ 844 (+3919.05%)
Mutual labels:  programmer
Programmers Oath
An oath for programmers, comparable to the Hippocratic Oath
Stars: ✭ 650 (+2995.24%)
Mutual labels:  programmer
Skill Map
程序员技能图谱
Stars: ✭ 18,549 (+88228.57%)
Mutual labels:  programmer

LCUT - Lightweight C Unit Test Framework

Recent News

  • 2013-04-02 fork a copy to https://github.com/bigwhite/lcut.git.
  • 2012-04-13 lcut 0.3.0 Released!
  • 2012-04-10 lcut 0.3.0-rc1 published!
    • add LCUT_ARG_RETURN_COUNT and LCUT_RETV_RETURN_COUNT macros.
  • 2010-12-16 lcut 0.2.0 Released!
  • 2010-10-29 lcut 0.2.0-beta1 published!
    • add mock support
  • 2010-09-30 The first verison of lcut - LCUT 0.1.0 Released.

Motivation

In late 2005,the "TDD" concept was so popular and there were many strong and mature unit testing framework available for Java programmers, C# programmers and even python programmers, But there were few for C programmers. I have googled some c unit testing framework and gave me a shot, but eventually none of them made me comfortable. so I decided to implement a new one for my daily work and then lcut born.

Introduction

lcut is short for "Lightweight C Unit Test framework". lightweight means it is very small and easy to learn&use. The framework is inspired by the well-known JUnit which is invented by Kent Beck.The structure of lcut could be illustrated as below:

A logical Test
      |  
      |  
  +-------------+
  TS-1    ...  TS-N
  |             |  
  |             |  
+-------+ ... +--------+
TC-1 TC-N TC-1 TC-N

TS - Test Suite,TC - Test Case

A unit test using lcut is divided into three levels: logical test, test suite and test case. A logical test contains several test suites and each test suite also contains several test cases. test case is the most basic and the smallest unit in this framework. And the three-level concept is helpful for you to organize your unit testing well.

Feature list

  • small and easy to learn&use
  • inspired by xUnit
  • three-level concepts to help organizing your test well and each level could have independent setup and teardown fixtures
  • provide mock support (inspired by cmockery)

For more information, please open and read the lcut project wiki. lcut_user_guide and its Chinese version are ready for you.

A Typical Example

/* calculator_test.c */
#include "lcut.h"

extern int add(int a, int b);
extern int subtract(int a, int b);
extern int multiply(int a, int b);
extern int divide(int a, int b);

void tc_add(lcut_tc_t *tc, void *data) {
    LCUT_INT_EQUAL(tc, 10, add(2, 8));
    LCUT_INT_EQUAL(tc, -6, add(2, -8));
    LCUT_INT_EQUAL(tc, 0, add(2, -2));
    LCUT_INT_NEQUAL(tc, 1, add(2, -2));

    LCUT_TRUE(tc, 0 == add(2, -2));
    LCUT_ASSERT(tc, "2 + (-2) should equal to 0", 0 == add(2, -2));
}

void tc_subtract(lcut_tc_t *tc, void *data) {
    LCUT_INT_EQUAL(tc, 6, subtract(8, 2));
    LCUT_INT_EQUAL(tc, 10, subtract(2, -8));
    LCUT_INT_EQUAL(tc, 0, subtract(2, 2));
}

void tc_multiply(lcut_tc_t *tc, void *data) {
    LCUT_INT_EQUAL(tc, 16, multiply(8, 2));
    LCUT_INT_EQUAL(tc, -16, multiply(2, -8));
    LCUT_INT_EQUAL(tc, 0, multiply(0, 2));
}

void tc_divide(lcut_tc_t *tc, void *data) {
    LCUT_INT_EQUAL(tc, 4, divide(8, 2));
    LCUT_INT_EQUAL(tc, 0, divide(0, 8));
    LCUT_INT_EQUAL(tc, 1, divide(2, 2));
}

int main() {
    lcut_ts_t   *suite = NULL;
    LCUT_TEST_BEGIN("a simple calculator test", NULL, NULL);

    LCUT_TS_INIT(suite, "a simple calculator unit test suite", NULL, NULL);
    LCUT_TC_ADD(suite, "add test case", tc_add, NULL, NULL, NULL);
    LCUT_TC_ADD(suite, "subtract test case", tc_subtract, NULL, NULL, NULL);
    LCUT_TC_ADD(suite, "multiply test case", tc_multiply, NULL, NULL, NULL);
    LCUT_TC_ADD(suite, "divide test case", tc_divide, NULL, NULL, NULL);
    LCUT_TS_ADD(suite);

    LCUT_TEST_RUN();
    LCUT_TEST_REPORT();
    LCUT_TEST_END();

    LCUT_TEST_RESULT();
}

The result of the example could be:

*********************************************************
     LCUT -- Lightweight C Unit Testing framework
	                By Tony Bai
********************************************************* 
Unit Test for 'a simple calculator test':

   Suite <a simple calculator unit test suite>: 
	    Case 'add test case': Passed
	    Case 'subtract test case': Passed
	    Case 'multiply test case': Passed
	    Case 'divide test case': Passed

Summary: 
    Total Suites: 1 
    Failed Suites: 0 
    Total Cases: 4 
    Failed Cases: 0 

==========================
       GREEN BAR!
==========================

Build

  • Download the source code package
  • unzip the package
  • configure->make->make install

if you want to compile in 64-bit mode, pass "CPPFLAGS=-m64 LDFLAGS=-m64" to configure. sometimes, you may encounter such error:

mv: cannot stat `.deps/lcut.Tpo': No such file or directory
make[1]: *** [lcut.lo] Error 1

a solution for this is execute "libtoolize -f" before "configure".

User Guide

For more information, please open and read the lcut_user_guide.And Chinese version is here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].