#include <stdio.h>
#include <kc.h>
#include <kc_dl.h>
#include <kc_ut.h>
#include <kc_assert.h>
#include "ut.h"
#if (KC_IS_WINDOWS)
#define FILENAME "test-lib/libtest.dll"
#else
#define FILENAME "test-lib/libtest.so"
#endif
// プロトタイプ宣言
static void test_dl(void);
/**
* KcDl 単体テストスイート
*/
void suite_dl(void)
{
KcUt *ut = KcUt_get_instance();
ut->add(ut, UT_TESTCASE, "dl", test_dl);
}
/**
* dl テスト。
*
* @process 動的ライブラリをロードする。
* @result ライブラリがロードされること。
*
* @process ロードしたライブラリの関数を実行する。
* @result 関数が実行されること。
*/
static void test_dl(void)
{
dl_handle_t handle = KcDl_open(FILENAME);
// add
int (*test_add)(int, int) = (int (*)(int, int))KcDl_sym(handle, "test_add");
int res = test_add(10, 20);
assert_equals(30, res);
// sub
int (*test_sub)(int, int) = (int (*)(int, int))KcDl_sym(handle, "test_sub");
res = test_sub(10, 20);
assert_equals(-10, res);
// mul
int (*test_mul)(int, int) = (int (*)(int, int))KcDl_sym(handle, "test_mul");
res = test_mul(10, 20);
assert_equals(200, res);
// mul
int (*test_div)(int, int) = (int (*)(int, int))KcDl_sym(handle, "test_div");
res = test_div(50, 10);
assert_equals(5, res);
KcDl_close(handle);
}