|
From: J. H. F. <jo...@gm...> - 2008-10-28 11:06:23
|
Hello,
How I can test a static funcion with cgreen?
-------- calc.c -----------
#include "calc.h"
static int add_one(int a) {
return a + 1;
}
static int add_two(int a) {
return a + 2;
}
int add_one_and_two(int a) {
printf("Adding: %d\n", add_one(a));
printf("Adding: %d\n", add_two(a));
}
--------- calc.h ----------
#include <stdio.h>
static int add_one(int a);
static int add_two(int a);
int add_one_and_two(int a);
--------- test_calc.c -------------
#include <cgreen.h>
#include "calc.h"
void test_add_one() {
assert_equal(2, add_one(1));
}
TestSuite *calc_test() {
TestSuite *suite = create_test_suite();
add_test( suite, test_add_one);
return suite;
}
----------- all_test.c --------------
#include <cgreen.h>
TestSuite *calc_test();
int main(int argc, char **argv) {
TestSuite *suite = create_test_suite();
add_suite(suite, calc_test());
if (argc > 1) {
return run_single_test(suite, argv[1], create_text_reporter());
}
return run_test_suite(suite, create_text_reporter());
}
--------------
Compiling:
gcc -c all_test.c
gcc -c calc_test.c
gcc -c calc.c
gcc all_test.o calc.o test_calc.o -lcgreen -o all_test
Thanks
--
-----------------------------------------------------------
João Henrique Freitas - joaohf_at_gmail.com
Campinas-SP-Brasil
BSD051283
LPI 1
http://www.joaohfreitas.eti.br
|