Skip to content

Commit

Permalink
test: Add tests for json output format
Browse files Browse the repository at this point in the history
  • Loading branch information
abelcheung committed Dec 16, 2023
1 parent 07c9e83 commit 8059c70
Show file tree
Hide file tree
Showing 13 changed files with 209 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1155,23 +1155,21 @@ _print_xml_header (const metarecord *meta)
static void
_print_json_header (const metarecord *meta)
{
g_print ("{\n");
g_printf (" \"format\": \"%s\",\n",
g_print ("{\n \"format\": \"%s\",\n",
(meta->type == RECYCLE_BIN_TYPE_FILE) ? "file" : "dir");


if (meta->version >= 0) /* can be found and not error */
g_printf (" \"version\": %" PRId64 ",\n", meta->version);
g_print (" \"version\": %" PRId64 ",\n", meta->version);
else
g_print (" \"version\": null,\n");

if (meta->type == RECYCLE_BIN_TYPE_FILE && meta->total_entry > 0)
g_printf (" \"ever_existed\": %" PRIu32 ",\n", meta->total_entry);
g_print (" \"ever_existed\": %" PRIu32 ",\n", meta->total_entry);

{
char *s = g_filename_display_name (meta->filename);
char *rbin_path = json_escape_path (s);
g_printf (" \"path\": \"%s\",\n", rbin_path);
g_print (" \"path\": \"%s\",\n", rbin_path);
g_free (s);
g_free (rbin_path);
}
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ target_link_directories (test_glib_iconv PRIVATE ${GLIB_LIBRARY_DIRS})
include(cli-option)
include(crafted)
include(encoding)
include(json)
include(parse-info2)
include(parse-rdir)
include(read-write)
Expand Down
4 changes: 4 additions & 0 deletions test/cmake/_try_encoding.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ set(args -l ${encoding} ${INFO2})
if(DEFINED OUTFILE)
list(APPEND args -o ${OUTFILE})
endif()
if(DEFINED EXTRA_ARGS)
string(REPLACE "|" ";" EXTRA_ARGS "${EXTRA_ARGS}")
list(APPEND args ${EXTRA_ARGS})
endif()
execute_process(
COMMAND ${RIFIUTI} ${args}
# COMMAND_ECHO STDOUT
Expand Down
31 changes: 31 additions & 0 deletions test/cmake/encoding.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,34 @@ add_encoding_test_with_cwd(f_LegacyUNC_Prep

generate_simple_comparison_test("LegacyUNC" 1
"" "INFO2-2k-tw-uncpath.txt" "encoding")

#
# JSON output
#

add_encoding_test_with_cwd(f_JsonInfo2Win95_Prep
${sample_dir}
-DINFO2=INFO-95-ja-1
-DCHOICES=CP932|Windows-932|IBM-943|SJIS|JIS_X0208|SHIFT_JIS|SHIFT-JIS
-DOUTFILE=${bindir}/f_JsonInfo2Win95.output
-DEXTRA_ARGS=-f|json
)

generate_simple_comparison_test("JsonInfo2Win95" 1
"" "INFO-95-ja-1.json" "encoding|json")


add_encoding_test_with_cwd(f_JsonWin95WrongEnc_Prep
${sample_dir}
-DINFO2=INFO-95-ja-1
-DCHOICES=CP1255|MS-HEBR|WINDOWS-1255|HEBREW|ISO-8859-8|ISO-IR-138|ISO8859-8|ISO_8859-8|ISO_8859-8:1988|CSISOLATINHEBREW
-DOUTFILE=${bindir}/f_JsonWin95WrongEnc.output
-DEXTRA_ARGS=-f|json
)

set_tests_properties(f_JsonWin95WrongEnc_Prep
PROPERTIES
PASS_REGULAR_EXPRESSION "could not be interpreted in .+ encoding")

generate_simple_comparison_test("JsonWin95WrongEnc" 1
"" "INFO-95-ja-1-in-cp1255.json" "encoding|xfail|json")
41 changes: 41 additions & 0 deletions test/cmake/json.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (C) 2023, Abel Cheung
# rifiuti2 is released under Revised BSD License.
# Please see LICENSE file for more info.

#
# Verify JSON output works as intended
#

function(createJsonOutputTests)

set(ids
"JsonInfo2Empty" "JsonInfo2WinXP" "JsonInfo2Win98"
"JsonRdirVista" "JsonRdirWin10" "JsonRdirUNC19"
)

set(files
"INFO2-empty" "INFO2-sample1" "INFO2-sample2"
"dir-sample1" "dir-win10-01" "dir-2019-uncpath"
)

set(encs
"" "" "CP1252" "" ""
)

foreach(id file enc IN ZIP_LISTS ids files encs)
if (IS_DIRECTORY ${sample_dir}/${file})
set(is_info2 0)
else()
set(is_info2 1)
endif()
set(args -f json)
if(enc)
list(APPEND args -l ${enc})
endif()
generate_simple_comparison_test(${id} ${is_info2}
${file} ${file}.json "parse|json" ${args})
endforeach()

endfunction()

createJsonOutputTests()
19 changes: 19 additions & 0 deletions test/samples/INFO-95-ja-1-in-cp1255.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"format": "file",
"version": 0,
"ever_existed": 16,
"path": "INFO-95-ja-1",
"records": [
{"index": 1, "time": "2015-05-11T05:59:49Z", "gone": false, "size": 32768, "path": "D:\\WINDOWS\\ֳ<\\DE>½¸ִ¯ּ<\\DF>\\The Microsoft Network ‚ּ¾¯ִ±¯ּ<\\DF>.lnk"},
{"index": 2, "time": "2015-05-11T06:00:25Z", "gone": false, "size": 950272, "path": "D:\\WINDOWS\\ֳ<\\DE>½¸ִ¯ּ<\\DF>\\<\\90>V‹Kֻ<\\DE>¯ִֿ¯ּ<\\DF> ²ׂ°¼<\\DE>.bmp"},
{"index": 3, "time": "2015-05-11T07:19:25Z", "gone": false, "size": 32768, "path": "D:\\WINDOWS\\ֳ<\\DE>½¸ִ¯ּ<\\DF>\\<\\90>V‹Kֳ·½ִ•¶<\\8F>‘.txt"},
{"index": 4, "time": "2015-05-11T09:48:21Z", "gone": false, "size": 589824, "path": "D:\\My Documents\\DirectX-V8.0a\\bda.cab"},
{"index": 5, "time": "2015-05-11T09:48:21Z", "gone": false, "size": 589824, "path": "D:\\My Documents\\DirectX-V8.0a\\bdant.cab"},
{"index": 6, "time": "2015-05-11T09:48:21Z", "gone": false, "size": 65536, "path": "D:\\My Documents\\DirectX-V8.0a\\cfgmgr32.dll"},
{"index": 11, "time": "2015-05-11T09:48:23Z", "gone": false, "size": 163840, "path": "D:\\My Documents\\DirectX-V8.0a\\dxsetup.exe"},
{"index": 12, "time": "2015-05-11T09:48:23Z", "gone": false, "size": 360448, "path": "D:\\My Documents\\DirectX-V8.0a\\setupapi.dll"},
{"index": 13, "time": "2015-05-11T09:59:19Z", "gone": false, "size": 32768, "path": "D:\\WINDOWS\\ֳ<\\DE>½¸ִ¯ּ<\\DF>\\Connect to the Internet.LNK"},
{"index": 14, "time": "2015-05-11T09:59:22Z", "gone": false, "size": 32768, "path": "D:\\WINDOWS\\ֳ<\\DE>½¸ִ¯ּ<\\DF>\\Outlook Express.lnk"},
{"index": 15, "time": "2015-05-18T00:45:09Z", "gone": false, "size": 32768, "path": "D:\\WINDOWS\\ֳ<\\DE>½¸ִ¯ּ<\\DF>\\<\\90>V‹Kֳ·½ִ•¶<\\8F>‘.txt"},
]
}
19 changes: 19 additions & 0 deletions test/samples/INFO-95-ja-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"format": "file",
"version": 0,
"ever_existed": 16,
"path": "INFO-95-ja-1",
"records": [
{"index": 1, "time": "2015-05-11T05:59:49Z", "gone": false, "size": 32768, "path": "D:\\WINDOWS\\デスクトップ\\The Microsoft Network のセットアップ.lnk"},
{"index": 2, "time": "2015-05-11T06:00:25Z", "gone": false, "size": 950272, "path": "D:\\WINDOWS\\デスクトップ\\新規ビットマップ イメージ.bmp"},
{"index": 3, "time": "2015-05-11T07:19:25Z", "gone": false, "size": 32768, "path": "D:\\WINDOWS\\デスクトップ\\新規テキスト文書.txt"},
{"index": 4, "time": "2015-05-11T09:48:21Z", "gone": false, "size": 589824, "path": "D:\\My Documents\\DirectX-V8.0a\\bda.cab"},
{"index": 5, "time": "2015-05-11T09:48:21Z", "gone": false, "size": 589824, "path": "D:\\My Documents\\DirectX-V8.0a\\bdant.cab"},
{"index": 6, "time": "2015-05-11T09:48:21Z", "gone": false, "size": 65536, "path": "D:\\My Documents\\DirectX-V8.0a\\cfgmgr32.dll"},
{"index": 11, "time": "2015-05-11T09:48:23Z", "gone": false, "size": 163840, "path": "D:\\My Documents\\DirectX-V8.0a\\dxsetup.exe"},
{"index": 12, "time": "2015-05-11T09:48:23Z", "gone": false, "size": 360448, "path": "D:\\My Documents\\DirectX-V8.0a\\setupapi.dll"},
{"index": 13, "time": "2015-05-11T09:59:19Z", "gone": false, "size": 32768, "path": "D:\\WINDOWS\\デスクトップ\\Connect to the Internet.LNK"},
{"index": 14, "time": "2015-05-11T09:59:22Z", "gone": false, "size": 32768, "path": "D:\\WINDOWS\\デスクトップ\\Outlook Express.lnk"},
{"index": 15, "time": "2015-05-18T00:45:09Z", "gone": false, "size": 32768, "path": "D:\\WINDOWS\\デスクトップ\\新規テキスト文書.txt"},
]
}
7 changes: 7 additions & 0 deletions test/samples/INFO2-empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"format": "file",
"version": 5,
"path": "INFO2-empty",
"records": [
]
}
23 changes: 23 additions & 0 deletions test/samples/INFO2-sample1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"format": "file",
"version": 5,
"path": "INFO2-sample1",
"records": [
{"index": 44, "time": "2008-10-28T15:53:42Z", "gone": false, "size": 4096, "path": "C:\\Documents and Settings\\All Users\\Desktop\\有道桌面词典.lnk"},
{"index": 45, "time": "2008-11-03T15:01:59Z", "gone": false, "size": 4096, "path": "C:\\Documents and Settings\\Administrator\\Desktop\\wongsir_url.txt"},
{"index": 46, "time": "2008-11-06T09:20:58Z", "gone": false, "size": 2912256, "path": "C:\\Documents and Settings\\Administrator\\Desktop\\dd-wrt.v24_mini_wrt54g.bin"},
{"index": 47, "time": "2008-11-13T12:08:39Z", "gone": false, "size": 765952, "path": "C:\\Documents and Settings\\Administrator\\Desktop\\theme\\.svn"},
{"index": 48, "time": "2008-11-13T12:11:33Z", "gone": false, "size": 5812224, "path": "C:\\Documents and Settings\\Administrator\\Desktop\\Config Client"},
{"index": 49, "time": "2008-11-13T12:11:36Z", "gone": false, "size": 1847296, "path": "C:\\Documents and Settings\\Administrator\\Desktop\\Config Client.7z"},
{"index": 50, "time": "2008-11-19T04:42:04Z", "gone": false, "size": 4096, "path": "C:\\Documents and Settings\\All Users\\Desktop\\Wireshark.lnk"},
{"index": 57, "time": "2008-11-19T05:07:15Z", "gone": false, "size": 2727936, "path": "C:\\Documents and Settings\\Administrator\\Desktop\\GetDataBackforFAT-v3.63_PConline.rar"},
{"index": 64, "time": "2008-11-19T05:07:35Z", "gone": true, "size": 2727936, "path": "C:\\Documents and Settings\\Administrator\\Desktop\\GetDataBackforFAT-v3.63_PConline"},
{"index": 65, "time": "2008-11-19T05:17:12Z", "gone": false, "size": 4096, "path": "C:\\Documents and Settings\\Administrator\\Desktop\\360保险箱.lnk"},
{"index": 66, "time": "2008-11-19T05:21:37Z", "gone": false, "size": 2732032, "path": "C:\\Documents and Settings\\Administrator\\Desktop\\gdb"},
{"index": 67, "time": "2008-11-19T05:21:37Z", "gone": false, "size": 2723840, "path": "C:\\Documents and Settings\\Administrator\\Desktop\\gdb.zip"},
{"index": 68, "time": "2008-11-19T11:34:23Z", "gone": false, "size": 0, "path": "C:\\Documents and Settings\\Administrator\\Desktop\\recovered files"},
{"index": 69, "time": "2008-11-19T18:51:45Z", "gone": false, "size": 2727936, "path": "C:\\Documents and Settings\\Administrator\\Desktop\\GetDataBackforFAT-v3.63_PConline"},
{"index": 70, "time": "2008-11-19T18:51:45Z", "gone": false, "size": 5169152, "path": "C:\\Documents and Settings\\Administrator\\Desktop\\Uneraser_Setup(2).exe"},
{"index": 71, "time": "2008-11-19T18:51:45Z", "gone": false, "size": 5169152, "path": "C:\\Documents and Settings\\Administrator\\Desktop\\Uneraser_Setup.exe"},
]
}
14 changes: 14 additions & 0 deletions test/samples/INFO2-sample2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"format": "file",
"version": 4,
"path": "INFO2-sample2",
"records": [
{"index": 0, "time": "2015-04-20T00:07:36Z", "gone": false, "size": 32768, "path": "C:\\WINDOWS\\All Users\\Desktop\\Connect to the Internet.LNK"},
{"index": 1, "time": "2015-04-20T00:07:42Z", "gone": false, "size": 32768, "path": "C:\\WINDOWS\\Desktop\\Online Services"},
{"index": 2, "time": "2015-04-20T00:09:43Z", "gone": true, "size": 524288, "path": "C:\\WINDOWS\\Desktop\\IE9-WindowsVista-x64-enu.exe"},
{"index": 3, "time": "2015-04-20T01:04:33Z", "gone": false, "size": 32768, "path": "C:\\My Documents\\Résumé.txt.txt"},
{"index": 4, "time": "2015-04-20T01:05:01Z", "gone": false, "size": 6258688, "path": "C:\\WINDOWS\\Desktop\\winzip100.exe"},
{"index": 5, "time": "2015-04-20T01:05:41Z", "gone": true, "size": 32768, "path": "C:\\WINDOWS\\Desktop\\111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
{"index": 6, "time": "2015-04-20T01:06:12Z", "gone": false, "size": 32768, "path": "C:\\WINDOWS\\Desktop\\1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345"},
]
}
10 changes: 10 additions & 0 deletions test/samples/dir-2019-uncpath.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"format": "dir",
"version": 2,
"path": "dir-2019-uncpath",
"records": [
{"index": "$IW0RYW0.rtf", "time": "2019-05-07T20:56:04Z", "gone": true, "size": 7, "path": "\\\\WIN-163RLA0PH3N\\somewhere\\hahaha.rtf"},
{"index": "$I4OZLXW.bmp", "time": "2019-05-07T21:01:01Z", "gone": true, "size": 1714662, "path": "\\\\WIN-163RLA0PH3N\\somewhere\\পরীক্ষা.bmp"},
{"index": "$IYDW1CC.rtf", "time": "2019-05-07T21:08:55Z", "gone": true, "size": 7, "path": "\\\\WIN-163RLA0PH3N\\somewhere\\hahaha.rtf"},
]
}
22 changes: 22 additions & 0 deletions test/samples/dir-sample1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"format": "dir",
"version": 1,
"path": "dir-sample1",
"records": [
{"index": "$IUVFB0M.rtf", "time": "2007-09-21T06:32:46Z", "gone": false, "size": 155, "path": "C:\\Users\\student\\Desktop\\New Rich Text Document.rtf"},
{"index": "$I0JGHX7", "time": "2007-09-21T06:47:49Z", "gone": true, "size": 0, "path": "C:\\Users\\student\\Desktop\\New Folder 1"},
{"index": "$I1IS2OK.txt", "time": "2007-09-21T06:48:13Z", "gone": false, "size": 0, "path": "C:\\Users\\student\\Desktop\\New Text Document blah.txt"},
{"index": "$IYAR1YY.exe", "time": "2007-09-21T07:54:23Z", "gone": true, "size": null, "path": "C:\\dd.exe"},
{"index": "$I95CUKU", "time": "2007-09-21T08:02:59Z", "gone": true, "size": 4096, "path": "C:\\Users\\student\\Downloads\\fau-1.3.0.2355(rc3)\\fau\\FAU.x86\\sparsefile"},
{"index": "$IHMU3NR.zip", "time": "2007-09-21T08:17:19Z", "gone": true, "size": 5025829, "path": "C:\\Users\\student\\Downloads\\fau-1.3.0.2355(rc3).zip"},
{"index": "$I7FV8IY.exe", "time": "2007-09-21T08:23:18Z", "gone": true, "size": 153478296, "path": "C:\\Users\\student\\Downloads\\VMware-server-installer-1.0.4-56528.exe"},
{"index": "$IMG2SSB", "time": "2007-09-21T08:28:57Z", "gone": true, "size": 0, "path": "C:\\Users\\student\\Desktop\\123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012"},
{"index": "$IZK01YL.txt", "time": "2007-09-21T08:31:35Z", "gone": true, "size": 11, "path": "C:\\Users\\student\\Desktop\\123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012\\1234567.txt"},
{"index": "$I1TDH1G.exe", "time": "2007-09-21T08:38:30Z", "gone": true, "size": 704512, "path": "C:\\Users\\student\\Downloads\\fau-1.3.0.2355(rc3)\\fau\\FAU.x86\\nc.exe"},
{"index": "$IEQWWMF.exe", "time": "2007-09-21T08:38:30Z", "gone": true, "size": 679936, "path": "C:\\Users\\student\\Downloads\\fau-1.3.0.2355(rc3)\\fau\\FAU.x86\\fmdata.exe"},
{"index": "$IFRN1CZ.exe", "time": "2007-09-21T08:38:30Z", "gone": true, "size": 110592, "path": "C:\\Users\\student\\Downloads\\fau-1.3.0.2355(rc3)\\fau\\FAU.x86\\wipe.exe"},
{"index": "$IW527XU.exe", "time": "2007-09-21T08:38:30Z", "gone": true, "size": 331776, "path": "C:\\Users\\student\\Downloads\\fau-1.3.0.2355(rc3)\\fau\\FAU.x86\\volume_dump.exe"},
{"index": "$IC6GEAW.exe", "time": "2007-09-21T08:50:16Z", "gone": true, "size": null, "path": "C:\\Users\\student\\Downloads\\fau-1.3.0.2355(rc3)\\fau\\FAU.x86\\dd.exe"},
{"index": "$IZUFRX4.vmdk", "time": "2007-09-21T09:22:25Z", "gone": true, "size": 10737418240, "path": "C:\\Virtual Machines\\Windows XP Professional\\Windows XP Professional-flat.vmdk"},
]
}
14 changes: 14 additions & 0 deletions test/samples/dir-win10-01.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"format": "dir",
"version": 2,
"path": "dir-win10-01",
"records": [
{"index": "$IKEGS1G", "time": "2015-04-04T17:19:52Z", "gone": false, "size": 0, "path": "C:\\Users\\tester\\12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"},
{"index": "$IQ7LAXT.png", "time": "2015-04-04T17:20:01Z", "gone": false, "size": 6455, "path": "C:\\Users\\tester\\Pictures\\web-canvas.png"},
{"index": "$I7R52EG.txt", "time": "2015-04-04T17:24:09Z", "gone": false, "size": 14, "path": "C:\\Temp\\foobat.txt.txt"},
{"index": "$IBBFODN", "time": "2015-04-07T23:19:35Z", "gone": true, "size": 7, "path": "C:\\Temp\\𨳊𨶙閪邨鰂"},
{"index": "$IHO61YT", "time": "2015-04-07T23:32:07Z", "gone": true, "size": 12884901888, "path": "C:\\Temp\\largesparsefile"},
{"index": "$IROMPZ0.exe", "time": "2015-04-19T10:49:59Z", "gone": true, "size": 1761792, "path": "C:\\Temp\\FAU\\FAU.x64\\dd.exe"},
{"index": "$IDNLPD4.exe", "time": "2015-04-19T10:50:51Z", "gone": true, "size": 872448, "path": "C:\\Temp\\FAU\\FAU.x86\\dd.exe"},
]
}

0 comments on commit 8059c70

Please sign in to comment.