''&size(24){&color(olive){CppUnitをVC++で使用する方法};};''
''&size(24){&color(olive){C};};''
#topicpath
#contents
#br

** CppUnitをVC++で使用する方法 [#g954ceec]

*** はじめに [#ide2649e]

- CppUnitの基本的な使用方法については[[CppUnit 入門>http://www.ogis-ri.co.jp/otc/hiroba/technical/CppUnit/]]に詳しいです。
- CppUnitの基本的な使用方法についてはCppUnit 入門 http://www.ogis-ri.co.jp/otc/hiroba/technical/CppUnit/ に詳しいです。
- このサイトでVC++についても言及してあるのですがVC++のバージョンが古い模様。
- Visual C++ 2003以降を用いた場合の方法を示します。

*** CppUnitの準備 [#oeb5b645]

- [[Source Forge>https://sourceforge.jp/projects/cppunit-x/]]からcppunit-xxxx.zipファイルを取得します。
- Source Forge https://sourceforge.jp/projects/cppunit-x/ からcppunit-xxxx.zipファイルを取得します。
- 適当なフォルダ,例えばC:\cppunit-x-20020331などに展開します。
- C:\cppunit-x-20020331\msvc\cppunit.dswを開いてビルドし,cppunit.libを作ります。

*** テスト [#g24cfc90]

- CppUnit 入門サイトにて配布されているdicegame-0.2.zipを例に説明します。
- 同ファイルを展開し,dicegame-0.2\msvc\dicegame.dswを開きます。
- 古い形式を新しい形式に変換するかどうか聞かれるのですべてイエスと答えます。
- ソリューションエクスプローラのdicegame_testsのコンテキストメニューでプロパティを選択します。
- 構成プロパティのC/C++の全般で,追加のインクルードディレクトリにC:\cppunit-x-20020331を入力します。
- 構成プロパティのリンカの入力で,追加の依存ファイルにC:\cppunit-x-20020331/msvc/cppunit.libを追加します。
- ソリューションをビルドするとdicegame-0.2\msvc\dicegame_tests\Debugにdicegame_tests.exeが生成されます。
- cmdから実行すると以下の出力が得られます。
 D:\>dicegame_tests.exe
 .F
 .F
 .F
 
 !!!FAILURES!!!
 Test Results:
 Run: 3, Failures: 3, Errors: 0
 There were 3 failures:
 1) DiceGamePlayerTest::testCreate (dicegameplayertest.cpp:16)
 expected:<0> but was:<-858993460>
 2) DiceGamePlayerTest::testWinGame (dicegameplayertest.cpp:27)
 expected:<0> but was:<-858993460>
 3) DiceGamePlayerTest::testLoseGame (dicegameplayertest.cpp:37)
 expected:<0> but was:<-858993460>

** 疑似C++クラス [#ae7e8e16]

- test.c
 #include <stdio.h>
 
 typedef struct _class_hoge {
   int member;
   int (*get_member)(void* this);
 } class_hoge;
 
 int get_member(void* this) {
   return (class_hoge*)this->member;
 }
 
 void class_hoge_init(class_hoge* this) {
   this->member = 123;
   this->get_member = get_member;
 }
 
 int main(void) {
   class_hoge hoge;
   hoge.get_member(&hoge);
 }


トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS