English -->
SourceForge.jp 200x40(8244bytes)

CUnit for Mr.Ando.

  『CUnit for Mr.Ando』は CppUnit-x をベースにしたC言語なんちゃってテスティングフレームワークです。 これは、C言語のソースコードを単体テストのために供給します。
  "CUnit for Mr.Ando" is CppUnit-x based C langage testing framework for Mr.Ando. It provide the C source code for unit testing.

イントロダクション
Introduction.

  JUnit は非常に強力なJava単体テストツールです。 しかしながら、多くのC言語技術者はJava言語を理解することができません。
  JUnit is a very powerful Java simple unit test tool. However, many C language engineers cannot understand a Java language.

  そのような技術者のために、 C/C++言語用にCppUnitが開発されました。 しかしながらCppUnitはGUIに対する知識が必要でした。 従って多くの(特に組み込み分野の)C言語技術者は CppUnitをコンパイルすることができません。
  To a such an engineer sake, CppUnit was developed for C/C++ languages. However, the knowledge over GUI was required for CppUnit. Therefore, many C language engineers cannot compile CppUnit.

  そのような技術者のために、 Tornadoなどのよりプアな環境で動作するCppUnit-xが開発されました。 しかしながら、多くのC言語技術者はC++言語を理解することなどできません。
  従って多くの(特に組み込み分野の)C言語技術者は CppUnit-xをコンパイルすることもできません。
  To a such an engineer sake, CppUnit-x was developed which operates in a poor environment such as Tornado. However, many C language engineers cannot do understanding C++ language etc. Therefore, many C language engineers cannot compile CppUnit-x too.

  そうです。 驚くべきことに日本では COBOLを第一機械語とするコンピュータエンジニアがいまだわらわらいるのです!!
  That's right. To a surprising thing,In Japan, many computer engineers' first machine language is still COBOL!!


  安藤はしかしなんとしてもC言語技術者にテストさせたいと考えました。 なので安藤はC言語技術者のC言語技術者によるC言語技術者のための C言語テスティングフレームワーク を作成する必要性を感じました。
  それが『CUnit for Mr.Ando』です。
  Mr.Ando wanted a C language engineer to test!! So,Mr.Ando felt the necessity of creating the C language testing framework by the C language engineers of the C language engineers for the C language engineers.
  It is "CUnit for Mr.Ando".

  『CUnit for Mr.Ando』は、 以下のことに特に注意して作成されました。
  Especially "CUnit for Mr.Ando" was noticed about the following things, and was created.

ダウンロード
Download.

  以下からダウンロードしてください。
  Please download from the following.

構成
Composition.

  これは以下のファイルとフォルダで構成されます。
  It is forrowing files and folders.
  『CUnit for Mr.Ando』は、以下のデファイン空間を使用します。
  "CUnit for Mr.Ando" uses the following #define space.   『CUnit for Mr.Ando』は、以下の関数を使用します。
  "CUnit for Mr.Ando" uses the following function space.

テストサンプル
Test Sample.

  もっとも簡単な使い方は以下の通りです。 ここではtestEasySample()の中でaとbが等価であることを2回確認しています。
  But the easy usage is as follows. It is checking twice that a and b are equivalent in testEasySample().
#include <stdio.h>
 #include <testRunner.h> /* ... (1) */

static unsigned int testEasySample(void);
static unsigned int testManyFunction(void);

/** Main function. */
int main(void) {
    return (int) testRunner(testManyFunction); /* ... (2) */
}

unsigned int testEasySample(void) { /* ... (3) */
    int a = 1 + 1;
    int b = 2;
    
    TEST_ASSERT_EQUALS(a,b); /* .... (4) */
 
    return 0; /* ... (5) */
}

unsigned int testManyFunction(void) {

    TEST_ASSERT(! testEasySample()); /* ... (6) */
    TEST_ASSERT(! testEasySample());
 
    return 0;
}
  1. テストファイルはtestRunner.hとstdio.hを必ずインクルードする必要があります。 プログラムは必ずtestRunner.cをコンパイルしリンクする必要があります。
    A test file needs to include testRunner.h and stdio.h. A program needs to compile and link testRunner.c.
  2. テストを実施するために、main()文にはtestRunner()を記述します。 testRunner()の引数には、テスト関数を記述します。
    In order to test, testRunner() is described in a main() sentence. The argument of testRunner() describes a test function.
  3. テスト関数の引数はvoid型とし、unsigned intを返すようにします。
    0で成功、0以外で失敗です。

    The argument of a test function is a void type. A test function returns unsigned int.
    "0" is a success. "Except 0" is failure.
  4. このサンプルでは1+1が2であることを確認します。
    等価の確認を行うには、TEST_ASSERT_EQUALS(,)マクロを使用します。
    非等価の確認を行うには、TEST_ASSERT_NOT_EQUALS(,)マクロを使用します。
    答えが意図したものでなかった場合、その内容を表示して、関数はリターンします。

    As for this sample, 1+1 checks that it is 2.
    TEST_ASSERT_EQUALS(,) is used when an equal result is desired.
    TEST_ASSERT_NOT_EQUALS(,) is used when a not equal result is desired.
    When an answer is mistaken, the contents are displayed and the return of the function is carried out.
  5. 関数は最後に0を返します。
    Finally a function returns 0.
  6. 複数の関数に分離してテストを行いたい場合には、このように記載します。 TEST_ASSERT()は0の場合、テストが失敗であったとみなします。 ここでは、testEasySample()を2回実施しています。
    When you want to test by separating into two functions, it indicates. When the contents of TEST_ASSERT() are 0,test was failure. In this example,testEasySample() is carried out twice.
  7. テストの結果は、必ずOKまたはNGで表示されます。
    これはどのようなC言語技術者であっても テストが正しく実行されたかを確認することができるようにするためです。
    一度書けばどこでも何度でも利用できます。

    The result of a test is only displayed by O.K. or NG.
    This is because anyone can check whether the test has been performed correctly.
    Write once,run anyway and run anywhere.
  実際には、これらのテストコードは、 テストする対象ファイルにインクルードしては*いけません*。 テストコードと被テストコードは分けるべきです。
  被テストコードに対してテストを実施するサンプルを以下に示します。 順番、選択、繰り返しの3つの異なる基本的なパターンです。
  これらの技法を習得することにより、 どのようなC言語技術者であっても、 テストを正しく行うことができでしょう。
  When this library is employed, MUST NOT include these test codes in the object file to test. A test code and the code for a test should divide.
  The separated sample is shown below. They are three different fundamental patterns, sequence, selection, and a foreach.
  If such techniques are mastered, anyone can do the test of higher quality. (*) JUnit (Javaテスティングフレームワーク)は単体テストのために『オーバライト』を使いますが、 しかし『CUnit for Mr.Ando』は単体テストのために『スタブ』を使います。
(*) JUnit (Java testing framework) is used for "override" for unit testing, but "CUnit for Mr.Ando" is "stub" for unit testing.

279x374(14402bytes)
図1 -- CUnit for Mr.Ando テスティングイメージ
Fig.1 -- CUnit for Mr.Ando testing image.

ライセンス
Licence

   GNU Lesser General Public License

参考文献
Bibliography.

作者
Auther.

  安藤利和
  Toshikazu Ando.

変更ログ

P.S.

  このファイルは日本人が書いてます。 もし異常な英語があったら、私に流暢な英訳を教えてください。
  Japanese are writing this file. If abnormalities are looked at by English, please gime me fluenet English translation!!