File indexing completed on 2024-05-12 04:22:23

0001 # SPDX-FileCopyrightText: 2019-2020 Johannes Zarl-Zierl <johannes@zarl-zierl.at>
0002 #
0003 # SPDX-License-Identifier: BSD-2-Clause
0004 
0005 _checks[check_recover-from-duplicates]="Recovery from duplicate image entries"
0006 _context[check_recover-from-duplicates]="<h2>What this test will do:</h2>
0007 <p><ul>
0008 <li>This test checks whether a version 7 database file with duplicate images is correctly de-duplicated when reading in.</li>
0009 <li>After you close this dialog, KPhotoAlbum will be started 4 times in a row.</li>
0010 </ul>
0011 </p>
0012 <h2>What you have to do:</h2>
0013 <ol>
0014 <li>Each time KPhotoAlbum starts, save the database and exit KPhotoAlbum.</li>
0015 </ol>"
0016 check_recover-from-duplicates()
0017 {
0018         local check_name="check_recover-from-duplicates"
0019         local check_dir="$TEMPDIR/$check_name"
0020         local data_dir="$mydir/db/recover-from-duplicates"
0021         setup_check "$check_dir" || return $result_err_setup
0022         # not needed in this scenario:
0023         rm -r "$check_dir/db"
0024 
0025         kdialog --msgbox "<h1>$check_name</h1>${_context[$check_name]}"
0026 
0027         for subcheck in compressed uncompressed uncompressed-to-compressed compressed-to-uncompressed
0028         do
0029                 local subcheck_dir="$check_dir/$subcheck"
0030                 mkdir "$subcheck_dir" || return $result_err_setup
0031 
0032                 local add_rc="[General]\nuntaggedCategory=\nuntaggedTag=\n"
0033                 if [[ "$subcheck" == "uncompressed" || "$subcheck" == "compressed-to-uncompressed" ]]
0034                 then
0035                         add_rc="$add_rc\nuseCompressedIndexXML=false\n"
0036                 fi
0037                 echo -e "$add_rc$BASE_RC" > "$subcheck_dir/kphotoalbumrc" || return $result_err_setup
0038 
0039                 # prepare database:
0040                 cp "$data_dir/$subcheck.orig.xml" "$subcheck_dir/index.xml" || return $result_err_setup
0041 
0042                 export XDG_CONFIG_HOME="$subcheck_dir"
0043                 kphotoalbum --db "$subcheck_dir/index.xml" > "$subcheck_dir/log" 2>&1 || return $result_err_crash
0044 
0045                 if ! diff -u "$data_dir/$subcheck.result.xml" "$subcheck_dir/index.xml"
0046                 then
0047                         log notice "$check_name/$subcheck: Mismatch in index.xml!"
0048                         return $result_failed
0049                 fi
0050                 if ! grep -q '^kphotoalbum.XMLDB: Merging duplicate entry for file "4.jpg"$' "$subcheck_dir/log"
0051                 then
0052                         log notice "$check_name/$subcheck: Missing expected log message!"
0053                         return $result_failed
0054                 fi
0055         done
0056         return $result_ok
0057 }