-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit test done for all of our components. #12
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ restore_file() | |
} | ||
ret=0; | ||
out: | ||
clean_buff(&path); | ||
clean_buff(&path); | ||
return ret; | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
CFLAGS=$(shell pkg-config --libs --cflags cmockery2) | ||
|
||
all:block_test | ||
|
||
block_test:block.c block.h block_test.c clean_buff.c clean_buff.h block_Makefile | ||
gcc -o block_test block.c block.h block_test.c clean_buff.c clean_buff.h $(CFLAGS) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include <stdarg.h> | ||
#include <stddef.h> | ||
#include <setjmp.h> | ||
#include <inttypes.h> | ||
#include <cmockery/cmockery.h> | ||
extern int get_block(int pos); | ||
extern int init_block_store(); | ||
extern int insert_block(char *buffer,size_t length); | ||
extern int fini_block_store(); | ||
static void test_return_values(void **state) | ||
{ | ||
|
||
assert_int_equal(init_block_store(), 0); | ||
|
||
} | ||
|
||
/* Test case that fails as leak_memory() leaks a dynamically allocated block.*/ | ||
static void leak_memory_test(void **state) | ||
{ | ||
|
||
get_block(5); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests are confusing. Normally every test should follow the following concept:
But I do not see that in many of the tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ewen/Srinivas can we have this fixed asap. If u have a doubt please ask Luis about it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi luis, A gentle reminder about the doubt we had asked earlier. Regards, On Fri, May 8, 2015 at 11:56 AM, josephaug26 [email protected]
|
||
|
||
} | ||
/* Test case that fails as buffer_overflow() corrupts an allocated block.*/ | ||
static void buffer_overflow_test(void **state) | ||
{ | ||
|
||
get_block(5); | ||
|
||
} | ||
|
||
/* Test case that fails as buffer_underflow() corrupts an allocated block.*/ | ||
static void buffer_underflow_test(void **state) | ||
{ | ||
|
||
get_block(5); | ||
|
||
} | ||
|
||
/* Test case to test return value of fini_block_store.*/ | ||
static void test_fini_block_store(void **state) | ||
{ | ||
|
||
assert_int_equal(fini_block_store(), 0); | ||
|
||
} | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
|
||
const UnitTest tests[] = { | ||
unit_test(test_return_values), | ||
unit_test(leak_memory_test), | ||
unit_test(buffer_overflow_test), | ||
unit_test(buffer_underflow_test), | ||
unit_test(test_fini_block_store), | ||
}; | ||
return run_tests(tests, "Block_allocate_module_test"); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
CFLAGS=$(shell pkg-config --libs --cflags cmockery2) | ||
|
||
all:catalog_test | ||
|
||
catalog_test:catalog.c catalog.h catalog_test.c clean_buff.c clean_buff.h cat_Makefile | ||
gcc -o catalog_test catalog.c catalog.h catalog_test.c clean_buff.c clean_buff.h $(CFLAGS) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good. Nice, simple test.