Skip to content

Commit

Permalink
fix: XML shows 95/NT total entry, closes #37
Browse files Browse the repository at this point in the history
  • Loading branch information
abelcheung committed Nov 30, 2023
1 parent b7c8f98 commit cbbe672
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 125 deletions.
30 changes: 24 additions & 6 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1283,16 +1283,34 @@ _print_csv_header (metarecord meta)
static void
_print_xml_header (metarecord meta)
{
char *rbin_path = g_filename_display_name (meta.filename);
char *rbin_path, *ever_existed;
GString *result;

result = g_string_new (
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");

if (meta.total_entry == 0)
ever_existed = "";
else
ever_existed = g_strdup_printf (
" ever_existed=\"%" G_GUINT32_FORMAT "\"", meta.total_entry);

/* No proper way to report wrong version info yet */
g_print (
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<recyclebin format=\"%s\" version=\"%" G_GINT64_FORMAT "\">\n"
" <filename><![CDATA[%s]]></filename>\n",
g_string_append_printf (result,
"<recyclebin format=\"%s\" version=\"%" G_GINT64_FORMAT "\"%s>\n",
( meta.type == RECYCLE_BIN_TYPE_FILE ) ? "file" : "dir",
MAX (meta.version, 0), rbin_path);
MAX (meta.version, 0),
ever_existed);
g_free (ever_existed);

rbin_path = g_filename_display_name (meta.filename);
g_string_append_printf (result,
" <filename><![CDATA[%s]]></filename>\n",
rbin_path);
g_free (rbin_path);

g_print ("%s", result->str);
g_string_free (result, TRUE);
}


Expand Down
216 changes: 97 additions & 119 deletions test/cmake/xml.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,125 +2,103 @@
# rifiuti2 is released under Revised BSD License.
# Please see LICENSE file for more info.

set(myDTD ${CMAKE_CURRENT_SOURCE_DIR}/rifiuti.dtd)

# XML well-formed and DTD validation for INFO2

add_test(NAME f_XmlWellForm_Prep
COMMAND rifiuti -o ${bindir}/f_XmlWellForm.xml -x INFO2-sample1
WORKING_DIRECTORY ${sample_dir})

add_test(NAME f_XmlWellForm
COMMAND ${XMLLINT} --noout f_XmlWellForm.xml)

add_test(NAME f_XmlDTDValidate
COMMAND ${XMLLINT} --noout f_XmlWellForm.xml --dtdvalid ${myDTD})

add_test(NAME f_XmlWellForm_Clean
COMMAND ${CMAKE_COMMAND} -E rm f_XmlWellForm.xml)

# f_XmlWellForm_Prep/Clean are used in multiple fixtures,
# properties set further down below
set_tests_properties(f_XmlWellForm PROPERTIES FIXTURES_REQUIRED F_XMLWELLFORM)
set_tests_properties(f_XmlDTDValidate PROPERTIES FIXTURES_REQUIRED F_XMLWELLFORM)

set_tests_properties(
f_XmlWellForm f_XmlDTDValidate
PROPERTIES LABELS "info2;xml")


# XML equality test for INFO2

# xmllint has a long known history that its --output option is broken.
# Have to use redirection instead.
# https://unix.stackexchange.com/q/492116

add_test_using_shell(f_XmlEqual_PrepAlt
"${XMLLINT} --c14n f_XmlWellForm.xml > ${bindir}/f_XmlEqual.output")
set_tests_properties(f_XmlEqual_PrepAlt
PROPERTIES DEPENDS f_XmlWellForm_Prep)

add_test_using_shell(f_XmlEqual_Prep
"${XMLLINT} --c14n INFO2-sample1.xml > ${bindir}/f_XmlEqual_r.xml"
WORKING_DIRECTORY ${sample_dir})

generate_simple_comparison_test("XmlEqual" 1
"" "${bindir}/f_XmlEqual_r.xml" "xml")

set_fixture_with_dep("f_XmlEqual")

set_tests_properties(f_XmlWellForm_Prep PROPERTIES FIXTURES_SETUP "F_XMLWELLFORM;F_XMLEQUAL")
set_tests_properties(f_XmlWellForm_Clean PROPERTIES FIXTURES_CLEANUP "F_XMLWELLFORM;F_XMLEQUAL")

if("${XMLLINT}" STREQUAL "XMLLINT-NOTFOUND")
set_tests_properties(
f_XmlDTDValidate
f_XmlEqual
f_XmlEqual_Clean
f_XmlEqual_PrepAlt
f_XmlEqual_Prep
f_XmlWellForm
f_XmlWellForm_Clean
f_XmlWellForm_Prep
PROPERTIES DISABLED true)
endif()

#
# $Recycle.bin counterpart for everything above
# XML well-formed, DTD validation, normalization checks
#

add_test(NAME d_XmlWellForm_Prep
COMMAND rifiuti-vista -o ${bindir}/d_XmlWellForm.xml -x dir-sample1
WORKING_DIRECTORY ${sample_dir})

add_test(NAME d_XmlWellForm
COMMAND ${XMLLINT} --noout d_XmlWellForm.xml)

add_test(NAME d_XmlDTDValidate
COMMAND ${XMLLINT} --noout d_XmlWellForm.xml --dtdvalid ${myDTD})

add_test(NAME d_XmlWellForm_Clean
COMMAND ${CMAKE_COMMAND} -E rm d_XmlWellForm.xml)

# d_XmlWellForm_Prep/Clean are used in multiple fixtures,
# properties set further down below
set_tests_properties(d_XmlWellForm PROPERTIES FIXTURES_REQUIRED D_XMLWELLFORM)
set_tests_properties(d_XmlDTDValidate PROPERTIES FIXTURES_REQUIRED D_XMLWELLFORM)

set_tests_properties(
d_XmlWellForm d_XmlDTDValidate
PROPERTIES LABELS "recycledir;xml")


# XML equality test for $Recycle.bin

add_test_using_shell(d_XmlEqual_PrepAlt
"${XMLLINT} --c14n d_XmlWellForm.xml > ${bindir}/d_XmlEqual.output")
set_tests_properties(d_XmlEqual_PrepAlt
PROPERTIES DEPENDS d_XmlWellForm_Prep)

add_test_using_shell(d_XmlEqual_Prep
"${XMLLINT} --c14n dir-sample1.xml > ${bindir}/d_XmlEqual_r.xml"
WORKING_DIRECTORY ${sample_dir})

generate_simple_comparison_test("XmlEqual" 0
"" "${bindir}/d_XmlEqual_r.xml" "xml")

set_fixture_with_dep("d_XmlEqual")

set_tests_properties(d_XmlWellForm_Prep PROPERTIES FIXTURES_SETUP "D_XMLWELLFORM;D_XMLEQUAL")
set_tests_properties(d_XmlWellForm_Clean PROPERTIES FIXTURES_CLEANUP "D_XMLWELLFORM;D_XMLEQUAL")

if("${XMLLINT}" STREQUAL "XMLLINT-NOTFOUND")
set_tests_properties(
d_XmlDTDValidate
d_XmlEqual
d_XmlEqual_Clean
d_XmlEqual_PrepAlt
d_XmlEqual_Prep
d_XmlWellForm
d_XmlWellForm_Clean
d_XmlWellForm_Prep
PROPERTIES DISABLED true)
endif()

function(createXmlTestSet id input) # $ARGN as extra rifiuti args

set(dtd ${CMAKE_CURRENT_SOURCE_DIR}/rifiuti.dtd)

if(NOT IS_ABSOLUTE ${input})
set(inputchk ${sample_dir}/${input})
else()
set(inputchk ${input})
endif()
if(IS_DIRECTORY ${inputchk})
set(is_info2 0)
set(add_label "recycledir")
set(prog rifiuti-vista)
set(prefix "d_Xml${id}")
else()
set(is_info2 1)
set(add_label "info2")
set(prog rifiuti)
set(prefix "f_Xml${id}")
endif()

set(wellform_pfx "${prefix}WellForm")
set(dtdvalid_pfx "${prefix}DTDValidate")
set(xmlequal_pfx "${prefix}Equal")

set(wellform_out "${bindir}/${wellform_pfx}.output")
set(wellform_fxt $<UPPER_CASE:${wellform_pfx}>)

set(xmlequal_out "${bindir}/${xmlequal_pfx}.output")
set(xmlequal_ref "${bindir}/${xmlequal_pfx}.refout")
set(xmlequal_fxt $<UPPER_CASE:${xmlequal_pfx}>)

# XML/DTD validation part
add_test(NAME ${wellform_pfx}_Prep
COMMAND ${prog} -o ${wellform_out} ${ARGN} -x ${input}
WORKING_DIRECTORY ${sample_dir})

add_test(NAME ${wellform_pfx}
COMMAND ${XMLLINT} --noout ${wellform_out})

add_test(NAME ${dtdvalid_pfx}
COMMAND ${XMLLINT} --noout ${wellform_out} --dtdvalid ${dtd})

add_test(NAME ${wellform_pfx}_Clean
COMMAND ${CMAKE_COMMAND} -E rm ${wellform_out})

# XmlWellForm fixtures are used in multiple fixtures,
# properties set further down below, not here
set_tests_properties(${wellform_pfx}
PROPERTIES FIXTURES_REQUIRED ${wellform_fxt})
set_tests_properties(${dtdvalid_pfx}
PROPERTIES FIXTURES_REQUIRED ${wellform_fxt})
set_tests_properties(${wellform_pfx} ${dtdvalid_pfx}
PROPERTIES LABELS "${add_label};xml")

# XML normalization and comparison
# xmllint has a long known history of broken --output option,
# have to use redirection instead.
# https://unix.stackexchange.com/q/492116

add_test_using_shell(${xmlequal_pfx}_PrepAlt
"${XMLLINT} --c14n ${wellform_out} > ${xmlequal_out}")
set_tests_properties(${xmlequal_pfx}_PrepAlt
PROPERTIES DEPENDS ${wellform_pfx}_Prep)

add_test_using_shell(${xmlequal_pfx}_Prep
"${XMLLINT} --c14n ${input}.xml > ${xmlequal_ref}"
WORKING_DIRECTORY ${sample_dir})

generate_simple_comparison_test("Xml${id}Equal" ${is_info2}
"" "${xmlequal_ref}" "xml")

set_fixture_with_dep("${xmlequal_pfx}")

set_tests_properties(${wellform_pfx}_Prep
PROPERTIES FIXTURES_SETUP "${wellform_fxt};${xmlequal_fxt}")
set_tests_properties(${wellform_pfx}_Clean
PROPERTIES FIXTURES_CLEANUP "${wellform_fxt};${xmlequal_fxt}")

if("${XMLLINT}" STREQUAL "XMLLINT-NOTFOUND")
set_tests_properties(
${dtdvalid_pfx}
${xmlequal_pfx}
${xmlequal_pfx}_Clean
${xmlequal_pfx}_PrepAlt
${xmlequal_pfx}_Prep
${wellform_pfx}
${wellform_pfx}_Clean
${wellform_pfx}_Prep
PROPERTIES DISABLED true)
endif()
endfunction()

createXmlTestSet(1 INFO2-sample1)
createXmlTestSet(2 dir-sample1)
createXmlTestSet(3 INFO-95-ja-1 -l CP932)
1 change: 1 addition & 0 deletions test/rifiuti.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<!ATTLIST recyclebin
format (file | dir) #REQUIRED
version NMTOKEN #REQUIRED
ever_existed NMTOKEN #IMPLIED
>
<!ELEMENT filename (#PCDATA)>

Expand Down
37 changes: 37 additions & 0 deletions test/samples/INFO-95-ja-1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<recyclebin format="file" version="0" ever_existed="16">
<filename><![CDATA[INFO-95-ja-1]]></filename>
<record index="1" time="2015-05-11T05:59:49Z" gone="false" size="32768">
<path><![CDATA[D:\WINDOWS\デスクトップ\The Microsoft Network のセットアップ.lnk]]></path>
</record>
<record index="2" time="2015-05-11T06:00:25Z" gone="false" size="950272">
<path><![CDATA[D:\WINDOWS\デスクトップ\新規ビットマップ イメージ.bmp]]></path>
</record>
<record index="3" time="2015-05-11T07:19:25Z" gone="false" size="32768">
<path><![CDATA[D:\WINDOWS\デスクトップ\新規テキスト文書.txt]]></path>
</record>
<record index="4" time="2015-05-11T09:48:21Z" gone="false" size="589824">
<path><![CDATA[D:\My Documents\DirectX-V8.0a\bda.cab]]></path>
</record>
<record index="5" time="2015-05-11T09:48:21Z" gone="false" size="589824">
<path><![CDATA[D:\My Documents\DirectX-V8.0a\bdant.cab]]></path>
</record>
<record index="6" time="2015-05-11T09:48:21Z" gone="false" size="65536">
<path><![CDATA[D:\My Documents\DirectX-V8.0a\cfgmgr32.dll]]></path>
</record>
<record index="11" time="2015-05-11T09:48:23Z" gone="false" size="163840">
<path><![CDATA[D:\My Documents\DirectX-V8.0a\dxsetup.exe]]></path>
</record>
<record index="12" time="2015-05-11T09:48:23Z" gone="false" size="360448">
<path><![CDATA[D:\My Documents\DirectX-V8.0a\setupapi.dll]]></path>
</record>
<record index="13" time="2015-05-11T09:59:19Z" gone="false" size="32768">
<path><![CDATA[D:\WINDOWS\デスクトップ\Connect to the Internet.LNK]]></path>
</record>
<record index="14" time="2015-05-11T09:59:22Z" gone="false" size="32768">
<path><![CDATA[D:\WINDOWS\デスクトップ\Outlook Express.lnk]]></path>
</record>
<record index="15" time="2015-05-18T00:45:09Z" gone="false" size="32768">
<path><![CDATA[D:\WINDOWS\デスクトップ\新規テキスト文書.txt]]></path>
</record>
</recyclebin>

0 comments on commit cbbe672

Please sign in to comment.