Newer
Older
libkc / modules / include / kc_ut.h
  1.  
  2. /**
  3. * @file kc_ut.h
  4. * @brief KC 単体テスト用モジュール
  5. * @copyright 2003 - 2023 Nomura Kei
  6. * @depends
  7. * kc.h
  8. */
  9. #ifndef KC_UT_H
  10. #define KC_UT_H
  11.  
  12. #include <kc.h>
  13.  
  14. #ifdef __cplusplus
  15. extern "C"
  16. {
  17. namespace kc
  18. {
  19. using namespace std;
  20. #endif
  21.  
  22. /**
  23. * 関数種別。
  24. */
  25. typedef enum
  26. {
  27. UT_TESTCASE, //!< テストケース
  28. UT_SETUP, //!< 事前処理
  29. UT_TEARDOWN, //!< 事後処理
  30. UT_OTHER //!< その他
  31. } UtType;
  32.  
  33. /**
  34. * UT実施用構造体
  35. *
  36. * @code
  37. * KcUt* ut = KcUt_get_instance();
  38. * ut->add(ut, UT_SETUP, "事前処理", UtList_setup)
  39. * ut->add(ut, UT_TESTCASE, "リスト追加", UtList_add);
  40. * ut->add(ut, UT_SETUP, "事後処理", UtList_teardown)
  41. *
  42. * ut->add(ut, UT_SETUP, "事前処理", UtList_setup)
  43. * ut->add(ut, UT_TESTCASE, "リストクリア", UtList_clear);
  44. * ut->add(ut, UT_SETUP, "事後処理", UtList_teardown)
  45. *
  46. * ut->run();
  47. * @endcode
  48. */
  49. typedef struct KcUt_
  50. {
  51. /**
  52. * テストケースまたは、事前処理/事後処理の関数を追加します。
  53. *
  54. * @param ut 単体テスト用インスタンス
  55. * @param type タイプ(UT_TESTCASE/UT_SETUP/UT_TEARDOWN/UT_OTHER)
  56. * @param title タイトル
  57. * @param func 追加する関数
  58. */
  59. void (*add)(struct KcUt_ *ut, UtType type, const char *title, void (*func)(void));
  60.  
  61. /**
  62. * テストケースを実行します。
  63. *
  64. * @param ut 単体テスト用インスタンス
  65. */
  66. void (*run)(struct KcUt_ *ut);
  67.  
  68. /**
  69. * 内部で扱うための情報格納用
  70. */
  71. void *_info;
  72. } KcUt;
  73.  
  74. /**
  75. * 単体テスト用のインスタンスを生成します。
  76. */
  77. KcUt *KcUt_get_instance(void);
  78.  
  79. #ifdef __cplusplus
  80. } // namespace kc
  81. } // extern "C"
  82. #endif
  83. #endif // KC_UT_H