diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2006915f6..99878bc41 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,3 +4,4 @@ include_directories(SYSTEM add_subdirectory(gtest) add_subdirectory(libtransmission) +add_subdirectory(utils) diff --git a/tests/utils/CMakeLists.txt b/tests/utils/CMakeLists.txt new file mode 100644 index 000000000..540c4ede0 --- /dev/null +++ b/tests/utils/CMakeLists.txt @@ -0,0 +1,15 @@ +function(AddShowTest name file_basename) + add_test( + NAME ${name} + COMMAND ${CMAKE_COMMAND} + -D transmission_show:string=$ + -D torrent_file:string=assets/${file_basename}.torrent + -D reference_file:string=${CMAKE_CURRENT_SOURCE_DIR}/assets/${file_basename}.show + -P "${CMAKE_CURRENT_SOURCE_DIR}/run_transmission_show.cmake" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) +endfunction() + +AddShowTest(transmission-show-ubuntu ubuntu-20.04.3-desktop-amd64.iso) +AddShowTest(transmission-show-thor Thor_and_the_Amazon_Women.avi) +AddShowTest(transmission-show-inner-sanctum Inner_Sanctum_movie_archive) diff --git a/tests/utils/assets/Inner_Sanctum_movie_archive.show b/tests/utils/assets/Inner_Sanctum_movie_archive.show new file mode 100644 index 000000000..8a0bfb57f --- /dev/null +++ b/tests/utils/assets/Inner_Sanctum_movie_archive.show @@ -0,0 +1,68 @@ +Name: Inner_Sanctum_movie +File: assets/Inner_Sanctum_movie_archive.torrent + +GENERAL + + Name: Inner_Sanctum_movie + Hash: f735d5be075bdb8832e29c96e80e53fdace6178b + Created by: ia_make_torrent + Created on: Sat Oct 27 00:56:24 2018 + + Comment: This content hosted at the Internet Archive at https://archive.org/details/Inner_Sanctum_movie +Files may have changed, which prevents torrents from downloading correctly or completely; please check for an updated torrent at https://archive.org/download/Inner_Sanctum_movie/Inner_Sanctum_movie_archive.torrent +Note: retrieval usually requires a client that supports webseeding (GetRight style). +Note: many Internet Archive torrents contain a 'pad file' directory. This directory and the files within it may be erased once retrieval completes. +Note: the file Inner_Sanctum_movie_meta.xml contains metadata about this torrent's contents. + Piece Count: 1090 + Piece Size: 2.00 MiB + Total Size: 2.29 GB + Privacy: Public torrent + +TRACKERS + + Tier #1 + http://bt1.archive.org:6969/announce + + Tier #2 + http://bt2.archive.org:6969/announce + +WEBSEEDS + + https://archive.org/download/ + http://ia601406.us.archive.org/32/items/ + +FILES + + Inner_Sanctum_movie/.____padding_file/0 (1.23 MB) + Inner_Sanctum_movie/.____padding_file/1 (1.63 MB) + Inner_Sanctum_movie/.____padding_file/10 (2.08 MB) + Inner_Sanctum_movie/.____padding_file/11 (2.09 MB) + Inner_Sanctum_movie/.____padding_file/12 (2.09 MB) + Inner_Sanctum_movie/.____padding_file/14 (1.74 MB) + Inner_Sanctum_movie/.____padding_file/15 (2.05 MB) + Inner_Sanctum_movie/.____padding_file/16 (2.09 MB) + Inner_Sanctum_movie/.____padding_file/17 (2.09 MB) + Inner_Sanctum_movie/.____padding_file/2 (1.41 MB) + Inner_Sanctum_movie/.____padding_file/3 (1.10 MB) + Inner_Sanctum_movie/.____padding_file/4 (692.2 kB) + Inner_Sanctum_movie/.____padding_file/5 (790.1 kB) + Inner_Sanctum_movie/.____padding_file/6 (2.09 MB) + Inner_Sanctum_movie/.____padding_file/7 (222.6 kB) + Inner_Sanctum_movie/.____padding_file/9 (2.08 MB) + Inner_Sanctum_movie/Inner_Sanctum.asr.js (362.1 kB) + Inner_Sanctum_movie/Inner_Sanctum.asr.srt (46.41 kB) + Inner_Sanctum_movie/Inner_Sanctum.avi (414.0 MB) + Inner_Sanctum_movie/Inner_Sanctum.gif (462.5 kB) + Inner_Sanctum_movie/Inner_Sanctum.mp3 (44.73 MB) + Inner_Sanctum_movie/Inner_Sanctum.mp4 (386.9 MB) + Inner_Sanctum_movie/Inner_Sanctum.mpeg (854.9 MB) + Inner_Sanctum_movie/Inner_Sanctum.ogv (288.6 MB) + Inner_Sanctum_movie/Inner_Sanctum.png (10.83 kB) + Inner_Sanctum_movie/Inner_Sanctum_512kb.mp4 (270.3 MB) + Inner_Sanctum_movie/Inner_Sanctum_movie_meta.xml (3.62 kB) + Inner_Sanctum_movie/Inner_Sanctum_pic.jpg (14.31 kB) + Inner_Sanctum_movie/Inner_Sanctum_pic2.jpg (19.09 kB) + Inner_Sanctum_movie/Inner_Sanctum_pic2_thumb.jpg (3.54 kB) + Inner_Sanctum_movie/Inner_Sanctum_pic_thumb.jpg (2.94 kB) + Inner_Sanctum_movie/__ia_thumb.jpg (4.83 kB) + diff --git a/tests/utils/assets/Inner_Sanctum_movie_archive.torrent b/tests/utils/assets/Inner_Sanctum_movie_archive.torrent new file mode 100644 index 000000000..7db857b53 Binary files /dev/null and b/tests/utils/assets/Inner_Sanctum_movie_archive.torrent differ diff --git a/tests/utils/assets/Thor_and_the_Amazon_Women.avi.show b/tests/utils/assets/Thor_and_the_Amazon_Women.avi.show new file mode 100644 index 000000000..461381a0b --- /dev/null +++ b/tests/utils/assets/Thor_and_the_Amazon_Women.avi.show @@ -0,0 +1,24 @@ +Name: Thor_and_the_Amazon_Women.avi +File: assets/Thor_and_the_Amazon_Women.avi.torrent + +GENERAL + + Name: Thor_and_the_Amazon_Women.avi + Hash: 43fdd3e72588e9119c9c94c54332ee533cf80bd6 + Created by: Azureus/2.5.0.2 + Created on: Mon Jan 22 00:57:20 2007 + + Piece Count: 1493 + Piece Size: 512.0 KiB + Total Size: 782.3 MB + Privacy: Public torrent + +TRACKERS + + Tier #1 + http://files2.publicdomaintorrents.com/bt/announce.php + +FILES + + Thor_and_the_Amazon_Women.avi (782.3 MB) + diff --git a/tests/utils/assets/Thor_and_the_Amazon_Women.avi.torrent b/tests/utils/assets/Thor_and_the_Amazon_Women.avi.torrent new file mode 100644 index 000000000..6f88d433b Binary files /dev/null and b/tests/utils/assets/Thor_and_the_Amazon_Women.avi.torrent differ diff --git a/tests/utils/assets/ubuntu-20.04.3-desktop-amd64.iso.show b/tests/utils/assets/ubuntu-20.04.3-desktop-amd64.iso.show new file mode 100644 index 000000000..019b81c08 --- /dev/null +++ b/tests/utils/assets/ubuntu-20.04.3-desktop-amd64.iso.show @@ -0,0 +1,28 @@ +Name: ubuntu-20.04.3-desktop-amd64.iso +File: assets/ubuntu-20.04.3-desktop-amd64.iso.torrent + +GENERAL + + Name: ubuntu-20.04.3-desktop-amd64.iso + Hash: b26c81363ac1a236765385a702aec107a49581b5 + Created by: mktorrent 1.1 + Created on: Thu Aug 26 09:42:51 2021 + + Comment: Ubuntu CD releases.ubuntu.com + Piece Count: 11719 + Piece Size: 256.0 KiB + Total Size: 3.07 GB + Privacy: Public torrent + +TRACKERS + + Tier #1 + https://torrent.ubuntu.com/announce + + Tier #2 + https://ipv6.torrent.ubuntu.com/announce + +FILES + + ubuntu-20.04.3-desktop-amd64.iso (3.07 GB) + diff --git a/tests/utils/assets/ubuntu-20.04.3-desktop-amd64.iso.torrent b/tests/utils/assets/ubuntu-20.04.3-desktop-amd64.iso.torrent new file mode 100644 index 000000000..e957aec7b Binary files /dev/null and b/tests/utils/assets/ubuntu-20.04.3-desktop-amd64.iso.torrent differ diff --git a/tests/utils/run_transmission_show.cmake b/tests/utils/run_transmission_show.cmake new file mode 100644 index 000000000..f35df0b5c --- /dev/null +++ b/tests/utils/run_transmission_show.cmake @@ -0,0 +1,52 @@ +# compare the output of transmission-show to a reference file. +# returns 0 if the files match, nonzero otherwise. +## + +if (CMAKE_VERSION VERSION_LESS 3.14) + # --ignore-eol was introduced in CMake 3.14 + message(status "skipping transmission-show test; cmake version too old") +else() + get_filename_component(torrent_basename "${torrent_file}" NAME) + set(output_file ${CMAKE_CURRENT_BINARY_DIR}/${torrent_basename}.out) + + message(STATUS "transmission_show ${transmission_show}") + message(STATUS " input_file ${torrent_file}") + message(STATUS " output_file ${output_file}") + message(STATUS " reference_file ${reference_file}") + + # The app's output includes timestamps, so fake our TZ to ensure + # the test doesn't depend on the physical TZ of the test machine + set(ENV{TZ} "UTC") + execute_process( + COMMAND ${transmission_show} ${torrent_file} + OUTPUT_FILE ${output_file} + ) + + execute_process( + COMMAND ${CMAKE_COMMAND} -E compare_files --ignore-eol ${reference_file} ${output_file} + RESULT_VARIABLE STATUS + ) + + if(STATUS AND NOT STATUS EQUAL 0) + file(READ ${reference_file} CONTENTS) + message("EXPECTED CONTENTS (${reference_file}):") + message(${CONTENTS}) + + file(READ ${output_file} CONTENTS) + message("RECEIVED CONTENTS (${output_file}):") + message(${CONTENTS}) + + find_program(DIFF_EXEC diff) + if (DIFF_EXEC) + message("DIFF:") + execute_process(COMMAND ${DIFF_EXEC} ${output_file} ${reference_file}) + endif() + + file(REMOVE ${output_file}) + message(FATAL_ERROR "failed: files '${reference_file}' and '${output_file}' do not match") + else() + file(REMOVE ${output_file}) + message("passed") + endif() + +endif() diff --git a/utils/show.cc b/utils/show.cc index c4a44c3a4..0f8f20d3a 100644 --- a/utils/show.cc +++ b/utils/show.cc @@ -107,7 +107,7 @@ static char const* time_t_to_str(time_t timestamp) struct tm tm; tr_localtime_r(×tamp, &tm); static char buf[32]; - strftime(buf, sizeof(buf), "%a %b %2e %T %Y%n", &tm); /* ctime equiv */ + strftime(buf, sizeof(buf), "%a %b %d %T %Y%n", &tm); /* ctime equiv */ return buf; }