ken1714 / dehazing-sample

画像ファイルを入力し、ヘイズ(霧)を除去した画像ファイルを出力するc++プログラム。
0 stars 0 forks source link

ヘイズ除去サンプルプログラム: Google Testの導入 #8

Closed ken1714 closed 2 years ago

ken1714 commented 2 years ago

In GitLab by @ken1714 on Nov 7, 2021, 22:34

ヘイズ除去のサンプルプログラムにGoogle Testを導入する。簡単なテストプログラムを作成して動作確認するが、テストプログラムは本issueではリポジトリにpushしなくてよい。

ken1714 commented 2 years ago

In GitLab by @ken1714 on Nov 7, 2021, 22:46

Google test(https://github.com/google/googletest)の導入方法。タグを1.11.0に切り替えている。

$ cd tests
$ git submodule add https://github.com/google/googletest.git
$ pushd googletest               # GoogleTestのサブモジュールに入っている
$ git checkout release-1.11.0
$ popd                           # GoogleTestのサブモジュールから戻っている
ken1714 commented 2 years ago

In GitLab by @ken1714 on Nov 7, 2021, 23:19

GoogleTest導入に参考になりそうなサイト

ken1714 commented 2 years ago

In GitLab by @ken1714 on Nov 7, 2021, 23:22

04e73b621766abaaf1817fefb2f17999bc7746ff に対し、testsディレクトリいかに下記のファイルを用意し、ビルド。

$ mkdir build
$ cd build
$ cmake -DBUILD_TESTS=ON ..
$ make
$ ctest --verbose
UpdateCTestConfiguration  from :/root/projects/programming-training/dehazing-sample/build/DartConfiguration.tcl
UpdateCTestConfiguration  from :/root/projects/programming-training/dehazing-sample/build/DartConfiguration.tcl
Test project /root/projects/programming-training/dehazing-sample/build
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 1
    Start 1: GoogleTestTest

1: Test command: /root/projects/programming-training/dehazing-sample/build/tests/test-sample
1: Test timeout computed to be: 10000000
1: Running main() from gmock_main.cc
1: [==========] Running 1 test from 1 test suite.
1: [----------] Global test environment set-up.
1: [----------] 1 test from HogeTest
1: [ RUN      ] HogeTest.Add
1: /root/projects/programming-training/dehazing-sample/tests/test.cpp:5: Failure
1: Expected equality of these values:
1:   67
1:   33 + 35
1:     Which is: 68
1: [  FAILED  ] HogeTest.Add (0 ms)
1: [----------] 1 test from HogeTest (0 ms total)
1: 
1: [----------] Global test environment tear-down
1: [==========] 1 test from 1 test suite ran. (0 ms total)
1: [  PASSED  ] 0 tests.
1: [  FAILED  ] 1 test, listed below:
1: [  FAILED  ] HogeTest.Add
1: 
1:  1 FAILED TEST
1/1 Test #1: GoogleTestTest ...................***Failed    0.00 sec

0% tests passed, 1 tests failed out of 1

Total Test time (real) =   0.00 sec

The following tests FAILED:
      1 - GoogleTestTest (Failed)
Errors while running CTest

CMakeLists.txt

add_subdirectory(googletest)

# Executable file
add_executable(test-sample test.cpp)
target_link_libraries(test-sample ${OpenCV_LIBRARIES} ${Boost_LIBRARIES} gmock gtest gmock_main)
add_test(NAME GoogleTestTest COMMAND test-sample)

test.cpp

#include "gtest/gtest.h"  // gtest/gtest.hppだとビルド時にエラー(読み込めない)

TEST(HogeTest, Add) {
    EXPECT_EQ(68, 33 + 35);
    EXPECT_EQ(67, 33 + 35);
}
ken1714 commented 2 years ago

In GitLab by @ken1714 on Nov 7, 2021, 23:23

mentioned in merge request !3

ken1714 commented 2 years ago

In GitLab by @ken1714 on Nov 7, 2021, 23:24

mentioned in commit 166e32669503cd0148202ccd803880895b092cf5

ken1714 commented 2 years ago

In GitLab by @ken1714 on Jan 1, 2022, 22:54

mentioned in commit 9ae228a23bb4eb9a1b835ab9c97d039b746985f7

ken1714 commented 2 years ago

In GitLab by @ken1714 on Jan 1, 2022, 23:01

mentioned in commit 75a55d21e97db6dd209f777e78d7a8e975e9beea