Newer
Older
snipet / libsc / trunk / tests / lib / create_unittest_main.sh
#!/bin/sh

UNITTEST_MAIN_H=src/unittest_main.h
UNITTEST_MAIN_C=src/unittest_main.c


# 登録関数
REGIST_FUNCS=`grep UT_regist_* src/ut_*.c | sed "s/.*UT_regist_\(.*\)\s*(\s*void\s*).*/UT_regist_\1/"`


# ======================================================================
# ヘッダファイル出力
# ======================================================================
cat <<EOF > ${UNITTEST_MAIN_H}
#ifndef __UNITTEST_MAIN_H__
#define __UNITTEST_MAIN_H__

EOF

for f in ${REGIST_FUNCS}; do
	echo "void ${f}(void);" >> ${UNITTEST_MAIN_H}
done

cat <<EOF >> ${UNITTEST_MAIN_H}

#endif /* __UNITTEST_MAIN_H__ */
EOF

# ======================================================================
# ソースファイル出力
# ======================================================================
cat <<EOF > ${UNITTEST_MAIN_C}
#include <sc_unittest.h>

#include "unittest_main.h"

/**
 * 単体テスト実行。
 *
 * @param argc 引数の数     (未使用)
 * @param argv コマンド引数 (未使用)
 */
int main(int argc, char* argv[])
{

EOF

for f in ${REGIST_FUNCS}; do
	echo "	${f}();" >> ${UNITTEST_MAIN_C}
done

cat <<EOF >> ${UNITTEST_MAIN_C}

	SC_Unittest_run();

	return 0;
}

EOF