@@ -0,0 +1,94 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <cmocka.h>
|
||||
|
||||
// #include "prntconsl.h" // Your library's header
|
||||
#include "klist.h"
|
||||
|
||||
/* ===== Setup and Teardown Functions ===== */
|
||||
static int setup(void **state)
|
||||
{
|
||||
int *test_data = malloc(sizeof(int));
|
||||
*test_data = 42;
|
||||
*state = test_data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int teardown(void **state)
|
||||
{
|
||||
free(*state);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ===== Test Cases ===== */
|
||||
static void test_simple(void **state)
|
||||
{
|
||||
const int a = 400;
|
||||
const int b = 20;
|
||||
assert_int_equal((a+b), 420);
|
||||
}
|
||||
/*
|
||||
static void test_addition_success(void **state)
|
||||
{
|
||||
const int result = 5 + 3;
|
||||
assert_int_equal(result, 8);
|
||||
}
|
||||
|
||||
static void test_with_fixture_data(void **state)
|
||||
{
|
||||
int *value = *state;
|
||||
assert_int_equal(*value, 42);
|
||||
|
||||
const int result = *value * 2;
|
||||
assert_int_equal(result, 84);
|
||||
}
|
||||
|
||||
static void test_print(void **state)
|
||||
{
|
||||
print("Hello", 0);
|
||||
print("Hello New line", 1);
|
||||
print("Another one", 1);
|
||||
}
|
||||
|
||||
static void test_print_multiple(void **state)
|
||||
{
|
||||
print_msg_multiple_times("Biscut", 10, 1);
|
||||
}
|
||||
*/
|
||||
|
||||
/* ===== Test with Mock Objects ===== */
|
||||
/* Mock function that returns values set by the test */
|
||||
int __wrap_dependency_function(int param)
|
||||
{
|
||||
check_expected(param); // Verifies param matches expectation
|
||||
return (int) mock(); // Returns value from will_return()
|
||||
}
|
||||
|
||||
static void test_with_mock(void **state)
|
||||
{
|
||||
/* Set up expectations: when called with 10, return 20 */
|
||||
// expect_value(__wrap_dependency_function, param, 10);
|
||||
// will_return(__wrap_dependency_function, 20);
|
||||
|
||||
// const int result = 20;
|
||||
// assert_int_equal(result, 20);
|
||||
}
|
||||
|
||||
/* ===== Run All Tests ===== */
|
||||
int main(void)
|
||||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_simple),
|
||||
// cmocka_unit_test(test_addition_success),
|
||||
// cmocka_unit_test(test_print_multiple),
|
||||
// cmocka_unit_test_setup_teardown(test_with_fixture_data,
|
||||
cmocka_unit_test(test_with_mock),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user