1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965
|
#include <sstream>
#include "gtest/gtest.h"
#include "zim/zim.h"
#include "zim/archive.h"
#include "../src/zimcheck/checks.h"
std::string getLine(std::string str) {
std::istringstream f(str);
std::string line;
std::getline(f, line);
return line;
}
TEST(zimfilechecks, test_checksum)
{
std::string fn = "data/zimfiles/wikibooks_be_all_nopic_2017-02.zim";
zim::Archive archive(fn);
ErrorLogger logger;
test_checksum(archive, logger);
ASSERT_TRUE(logger.overallStatus());
}
TEST(zimfilechecks, test_metadata)
{
std::string fn = "data/zimfiles/good.zim";
zim::Archive archive(fn);
ErrorLogger logger;
test_metadata(archive, logger);
ASSERT_TRUE(logger.overallStatus());
}
TEST(zimfilechecks, test_favicon)
{
std::string fn = "data/zimfiles/wikibooks_be_all_nopic_2017-02.zim";
zim::Archive archive(fn);
ErrorLogger logger;
test_favicon(archive, logger);
ASSERT_TRUE(logger.overallStatus());
}
TEST(zimfilechecks, test_mainpage)
{
std::string fn = "data/zimfiles/wikibooks_be_all_nopic_2017-02.zim";
zim::Archive archive(fn);
ErrorLogger logger;
test_mainpage(archive, logger);
ASSERT_TRUE(logger.overallStatus());
}
TEST(zimfilechecks, test_articles)
{
std::string fn = "data/zimfiles/wikibooks_be_all_nopic_2017-02.zim";
zim::Archive archive(fn);
ErrorLogger logger;
ProgressBar progress(1);
EnabledTests all_checks; all_checks.enableAll();
test_articles(archive, logger, progress, all_checks);
ASSERT_TRUE(logger.overallStatus());
}
TEST(zimfilechecks, test_redirect_loop_pass)
{
std::string fn = "data/zimfiles/wikibooks_be_all_nopic_2017-02.zim";
zim::Archive archive(fn);
ErrorLogger logger;
test_redirect_loop(archive, logger);
ASSERT_TRUE(logger.overallStatus());
}
TEST(zimfilechecks, test_redirect_loop_fail)
{
ErrorLogger logger;
std::string poor_zim = "data/zimfiles/poor.zim";
zim::Archive archive_poor(poor_zim);
test_redirect_loop(archive_poor, logger);
ASSERT_FALSE(logger.overallStatus());
}
class CapturedStdStream
{
std::ostream& stream;
std::ostringstream buffer;
std::streambuf* const sbuf;
public:
explicit CapturedStdStream(std::ostream& os)
: stream(os)
, sbuf(os.rdbuf())
{
stream.rdbuf(buffer.rdbuf());
}
CapturedStdStream(const CapturedStdStream&) = delete;
~CapturedStdStream()
{
stream.rdbuf(sbuf);
}
operator std::string() const { return buffer.str(); }
};
struct CapturedStdout : CapturedStdStream
{
CapturedStdout() : CapturedStdStream(std::cout) {}
};
struct CapturedStderr : CapturedStdStream
{
CapturedStderr() : CapturedStdStream(std::cerr) {}
};
int zimcheck (const std::vector<const char*>& args);
const std::string zimcheck_help_message(
R"(Zimcheck checks the quality of a ZIM file.
Usage:
zimcheck [options] [ZIMFILE]
Options:
-A --all run all tests. Default if no flags are given.
-0 --empty Empty content
-C --checksum Internal CheckSum Test
-I --integrity Low-level correctness/integrity checks
-M --metadata MetaData Entries
-F --favicon Favicon
-P --main Main page
-R --redundant Redundant data check
-U --url_internal URL check - Internal URLs
-X --url_external URL check - External URLs
-D --details Details of error
-B --progress Print progress report
-J --json Output in JSON format
-H --help Displays Help
-V --version Displays software version
-L --redirect_loop Checks for the existence of redirect loops
-W=<nb_thread> --threads=<nb_thread> count of threads to utilize [default: 1]
Examples:
zimcheck -A wikipedia.zim
zimcheck --checksum --redundant wikipedia.zim
zimcheck -F -R wikipedia.zim
zimcheck -M --favicon wikipedia.zim
)");
TEST(zimcheck, help)
{
{
CapturedStdout zimcheck_output;
ASSERT_EQ(-1, zimcheck({"zimcheck", "-H"}));
ASSERT_EQ(zimcheck_help_message, std::string(zimcheck_output));
}
{
CapturedStdout zimcheck_output;
ASSERT_EQ(-1, zimcheck({"zimcheck", "--help"}));
ASSERT_EQ(zimcheck_help_message, std::string(zimcheck_output));
}
}
TEST(zimcheck, version)
{
std::string version = "zim-tools " + std::string(VERSION);
{
CapturedStdout zimcheck_output;
ASSERT_EQ(0, zimcheck({"zimcheck", "-V"}));
ASSERT_EQ(version, getLine(std::string(zimcheck_output)));
}
{
CapturedStdout zimcheck_output;
ASSERT_EQ(0, zimcheck({"zimcheck", "--version"}));
ASSERT_EQ(version, getLine(std::string(zimcheck_output)));
}
}
TEST(zimcheck, nozimfile)
{
const std::string expected_stderr = "No file provided as argument\n";
{
CapturedStdout zimcheck_output;
CapturedStderr zimcheck_stderr;
ASSERT_EQ(-1, zimcheck({"zimcheck"}));
ASSERT_EQ(expected_stderr, std::string(zimcheck_stderr));
ASSERT_EQ(zimcheck_help_message, std::string(zimcheck_output));
}
}
const char GOOD_ZIMFILE[] = "data/zimfiles/good.zim";
const char POOR_ZIMFILE[] = "data/zimfiles/poor.zim";
const char BAD_CHECKSUM_ZIMFILE[] = "data/zimfiles/bad_checksum.zim";
using CmdLineImpl = std::vector<const char*>;
struct CmdLine : CmdLineImpl {
CmdLine(const std::initializer_list<value_type>& il)
: CmdLineImpl(il)
{}
};
std::ostream& operator<<(std::ostream& out, const CmdLine& c)
{
out << "Test context:\n";
for ( const auto& a : c )
out << " " << a;
out << std::endl;
return out;
}
const char EMPTY_STDERR[] = "";
void test_zimcheck_single_option(std::vector<const char*> optionAliases,
const char* zimfile,
int expected_exit_code,
const std::string& expected_stdout,
const std::string& expected_stderr)
{
for ( const char* opt : optionAliases )
{
CapturedStdout zimcheck_output;
CapturedStderr zimcheck_stderr;
const CmdLine cmdline{"zimcheck", opt, zimfile};
EXPECT_EQ(expected_exit_code, zimcheck(cmdline)) << cmdline;
EXPECT_EQ(expected_stderr, std::string(zimcheck_stderr)) << cmdline;
EXPECT_EQ(expected_stdout, std::string(zimcheck_output)) << cmdline;
}
}
TEST(zimcheck, integrity_goodzimfile)
{
const std::string expected_output(
"[INFO] Checking zim file data/zimfiles/good.zim" "\n"
"[INFO] Zimcheck version is " VERSION "\n"
"[INFO] Verifying ZIM-archive structure integrity..." "\n"
"[INFO] Overall Test Status: Pass" "\n"
"[INFO] Total time taken by zimcheck: <3 seconds." "\n"
);
test_zimcheck_single_option(
{"-I", "--integrity"},
GOOD_ZIMFILE,
0,
expected_output,
EMPTY_STDERR
);
}
TEST(zimcheck, checksum_goodzimfile)
{
const std::string expected_output(
"[INFO] Checking zim file data/zimfiles/good.zim" "\n"
"[INFO] Zimcheck version is " VERSION "\n"
"[WARNING] Integrity check is skipped. Any detected errors may in fact be due to corrupted/invalid data.\n"
"[INFO] Verifying Internal Checksum..." "\n"
"[INFO] Overall Test Status: Pass" "\n"
"[INFO] Total time taken by zimcheck: <3 seconds." "\n"
);
test_zimcheck_single_option(
{"-C", "--checksum"},
GOOD_ZIMFILE,
0,
expected_output,
EMPTY_STDERR
);
}
TEST(zimcheck, metadata_goodzimfile)
{
const std::string expected_output(
"[INFO] Checking zim file data/zimfiles/good.zim" "\n"
"[INFO] Zimcheck version is " VERSION "\n"
"[WARNING] Integrity check is skipped. Any detected errors may in fact be due to corrupted/invalid data.\n"
"[INFO] Checking metadata..." "\n"
"[INFO] Overall Test Status: Pass" "\n"
"[INFO] Total time taken by zimcheck: <3 seconds." "\n"
);
test_zimcheck_single_option(
{"-M", "--metadata"},
GOOD_ZIMFILE,
0,
expected_output,
EMPTY_STDERR
);
}
TEST(zimcheck, favicon_goodzimfile)
{
const std::string expected_output(
"[INFO] Checking zim file data/zimfiles/good.zim" "\n"
"[INFO] Zimcheck version is " VERSION "\n"
"[WARNING] Integrity check is skipped. Any detected errors may in fact be due to corrupted/invalid data.\n"
"[INFO] Searching for Favicon..." "\n"
"[INFO] Overall Test Status: Pass" "\n"
"[INFO] Total time taken by zimcheck: <3 seconds." "\n"
);
test_zimcheck_single_option(
{"-F", "--favicon"},
GOOD_ZIMFILE,
0,
expected_output,
EMPTY_STDERR
);
}
TEST(zimcheck, mainpage_goodzimfile)
{
const std::string expected_output(
"[INFO] Checking zim file data/zimfiles/good.zim" "\n"
"[INFO] Zimcheck version is " VERSION "\n"
"[WARNING] Integrity check is skipped. Any detected errors may in fact be due to corrupted/invalid data.\n"
"[INFO] Searching for main page..." "\n"
"[INFO] Overall Test Status: Pass" "\n"
"[INFO] Total time taken by zimcheck: <3 seconds." "\n"
);
test_zimcheck_single_option(
{"-P", "--main"},
GOOD_ZIMFILE,
0,
expected_output,
EMPTY_STDERR
);
}
TEST(zimcheck, article_content_goodzimfile)
{
const std::string expected_output(
"[INFO] Checking zim file data/zimfiles/good.zim" "\n"
"[INFO] Zimcheck version is " VERSION "\n"
"[WARNING] Integrity check is skipped. Any detected errors may in fact be due to corrupted/invalid data.\n"
"[INFO] Verifying Articles' content..." "\n"
"[INFO] Overall Test Status: Pass" "\n"
"[INFO] Total time taken by zimcheck: <3 seconds." "\n"
);
test_zimcheck_single_option(
{
"-0", "--empty", // Any of these options triggers
"-U", "--url_internal", // checking of the article contents.
"-X", "--url_external" // For a good ZIM file there is no
}, // difference in the output.
GOOD_ZIMFILE,
0,
expected_output,
EMPTY_STDERR
);
}
TEST(zimcheck, redundant_articles_goodzimfile)
{
const std::string expected_output(
"[INFO] Checking zim file data/zimfiles/good.zim" "\n"
"[INFO] Zimcheck version is " VERSION "\n"
"[WARNING] Integrity check is skipped. Any detected errors may in fact be due to corrupted/invalid data.\n"
"[INFO] Verifying Articles' content..." "\n"
"[INFO] Searching for redundant articles..." "\n"
" Verifying Similar Articles for redundancies..." "\n"
"[INFO] Overall Test Status: Pass" "\n"
"[INFO] Total time taken by zimcheck: <3 seconds." "\n"
);
test_zimcheck_single_option(
{"-R", "--redundant"},
GOOD_ZIMFILE,
0,
expected_output,
EMPTY_STDERR
);
}
TEST(zimcheck, redirect_loop_goodzimfile)
{
const std::string expected_output(
"[INFO] Checking zim file data/zimfiles/good.zim" "\n"
"[INFO] Zimcheck version is " VERSION "\n"
"[WARNING] Integrity check is skipped. Any detected errors may in fact be due to corrupted/invalid data.\n"
"[INFO] Checking for redirect loops..." "\n"
"[INFO] Overall Test Status: Pass" "\n"
"[INFO] Total time taken by zimcheck: <3 seconds." "\n"
);
test_zimcheck_single_option(
{"-L", "--redirect_loop"},
GOOD_ZIMFILE,
0,
expected_output,
EMPTY_STDERR
);
}
const std::string ALL_CHECKS_OUTPUT_ON_GOODZIMFILE(
"[INFO] Checking zim file data/zimfiles/good.zim" "\n"
"[INFO] Zimcheck version is " VERSION "\n"
"[INFO] Verifying ZIM-archive structure integrity..." "\n"
"[INFO] Avoiding redundant checksum test (already performed by the integrity check)." "\n"
"[INFO] Checking metadata..." "\n"
"[INFO] Searching for Favicon..." "\n"
"[INFO] Searching for main page..." "\n"
"[INFO] Verifying Articles' content..." "\n"
"[INFO] Searching for redundant articles..." "\n"
" Verifying Similar Articles for redundancies..." "\n"
"[INFO] Checking for redirect loops..." "\n"
"[INFO] Overall Test Status: Pass" "\n"
"[INFO] Total time taken by zimcheck: <3 seconds." "\n"
);
TEST(zimcheck, nooptions_goodzimfile)
{
CapturedStdout zimcheck_output;
ASSERT_EQ(0, zimcheck({"zimcheck", GOOD_ZIMFILE}));
ASSERT_EQ(ALL_CHECKS_OUTPUT_ON_GOODZIMFILE, std::string(zimcheck_output));
}
TEST(zimcheck, all_checks_goodzimfile)
{
test_zimcheck_single_option(
{"-A", "--all"},
GOOD_ZIMFILE,
0,
ALL_CHECKS_OUTPUT_ON_GOODZIMFILE,
EMPTY_STDERR
);
}
TEST(zimcheck, invalid_option)
{
{
CapturedStdout zimcheck_output;
CapturedStderr zimcheck_stderr;
ASSERT_EQ(1, zimcheck({"zimcheck", "-Z", GOOD_ZIMFILE}));
ASSERT_EQ("Unexpected argument: -Z, data/zimfiles/good.zim\n", std::string(zimcheck_stderr));
ASSERT_EQ(zimcheck_help_message, std::string(zimcheck_output));
}
}
TEST(zimcheck, invalid_long_option)
{
{
CapturedStdout zimcheck_output;
CapturedStderr zimcheck_stderr;
ASSERT_EQ(1, zimcheck({"zimcheck", "--oops", GOOD_ZIMFILE}));
ASSERT_EQ("Unexpected argument: --oops, data/zimfiles/good.zim\n", std::string(zimcheck_stderr));
ASSERT_EQ(zimcheck_help_message, std::string(zimcheck_output));
}
}
TEST(zimcheck, json_goodzimfile)
{
CapturedStdout zimcheck_output;
ASSERT_EQ(0, zimcheck({
"zimcheck",
"--json",
"data/zimfiles/good.zim"
}));
ASSERT_EQ(
"{" "\n"
" \"zimcheck_version\" : \"" VERSION "\"," "\n"
" \"checks\" : [" "\n"
" \"checksum\"," "\n"
" \"integrity\"," "\n"
" \"empty\"," "\n"
" \"metadata\"," "\n"
" \"favicon\"," "\n"
" \"main_page\"," "\n"
" \"redundant\"," "\n"
" \"url_internal\"," "\n"
" \"url_external\"," "\n"
" \"url_empty\"," "\n"
" \"redirect\"" "\n"
" ]," "\n"
" \"file_name\" : \"data/zimfiles/good.zim\"," "\n"
" \"file_uuid\" : \"00000000-0000-0000-0000-000000000000\"," "\n"
" \"status\" : true," "\n"
" \"logs\" : [" "\n"
" ]" "\n"
"}" "\n"
, std::string(zimcheck_output)
);
}
TEST(zimcheck, bad_checksum)
{
const std::string expected_output(
"[INFO] Checking zim file data/zimfiles/bad_checksum.zim" "\n"
"[INFO] Zimcheck version is " VERSION "\n"
"[WARNING] Integrity check is skipped. Any detected errors may in fact be due to corrupted/invalid data.\n"
"[INFO] Verifying Internal Checksum..." "\n"
" [ERROR] Wrong Checksum in ZIM archive" "\n"
"[ERROR] Invalid checksum:" "\n"
" ZIM Archive Checksum in archive: 00000000000000000000000000000000" "\n"
"" "\n"
"[INFO] Overall Test Status: Fail" "\n"
"[INFO] Total time taken by zimcheck: <3 seconds." "\n"
);
test_zimcheck_single_option(
{"-C", "--checksum"},
BAD_CHECKSUM_ZIMFILE,
1,
expected_output,
EMPTY_STDERR
);
}
TEST(zimcheck, metadata_poorzimfile)
{
const std::string expected_stdout(
"[INFO] Checking zim file data/zimfiles/poor.zim" "\n"
"[INFO] Zimcheck version is " VERSION "\n"
"[WARNING] Integrity check is skipped. Any detected errors may in fact be due to corrupted/invalid data.\n"
"[INFO] Checking metadata..." "\n"
"[ERROR] Metadata errors:" "\n"
" Missing mandatory metadata: Title" "\n"
" Missing mandatory metadata: Description" "\n"
" Missing mandatory metadata: Illustration_48x48@1" "\n"
" Language must contain at least 3 characters" "\n"
" Language doesn't match regex: ^\\w{3}(,\\w{3})*$" "\n"
"[INFO] Overall Test Status: Fail" "\n"
"[INFO] Total time taken by zimcheck: <3 seconds." "\n"
);
test_zimcheck_single_option(
{"-M", "--metadata"},
POOR_ZIMFILE,
1,
expected_stdout,
EMPTY_STDERR
);
}
TEST(zimcheck, favicon_poorzimfile)
{
const std::string expected_stdout(
"[INFO] Checking zim file data/zimfiles/poor.zim" "\n"
"[INFO] Zimcheck version is " VERSION "\n"
"[WARNING] Integrity check is skipped. Any detected errors may in fact be due to corrupted/invalid data.\n"
"[INFO] Searching for Favicon..." "\n"
"[ERROR] Favicon:" "\n"
" Favicon is missing" "\n"
"[INFO] Overall Test Status: Fail" "\n"
"[INFO] Total time taken by zimcheck: <3 seconds." "\n"
);
test_zimcheck_single_option(
{"-F", "--favicon"},
POOR_ZIMFILE,
1,
expected_stdout,
EMPTY_STDERR
);
}
TEST(zimcheck, mainpage_poorzimfile)
{
const std::string expected_stdout(
"[INFO] Checking zim file data/zimfiles/poor.zim" "\n"
"[INFO] Zimcheck version is " VERSION "\n"
"[WARNING] Integrity check is skipped. Any detected errors may in fact be due to corrupted/invalid data.\n"
"[INFO] Searching for main page..." "\n"
"[ERROR] Missing mainpage:" "\n"
" Main Page Index stored in Archive Header: 4294967295" "\n"
"[INFO] Overall Test Status: Fail" "\n"
"[INFO] Total time taken by zimcheck: <3 seconds." "\n"
);
test_zimcheck_single_option(
{"-P", "--main"},
POOR_ZIMFILE,
1,
expected_stdout,
EMPTY_STDERR
);
}
TEST(zimcheck, empty_items_poorzimfile)
{
const std::string expected_stdout(
"[INFO] Checking zim file data/zimfiles/poor.zim" "\n"
"[INFO] Zimcheck version is " VERSION "\n"
"[WARNING] Integrity check is skipped. Any detected errors may in fact be due to corrupted/invalid data.\n"
"[INFO] Verifying Articles' content..." "\n"
"[ERROR] Empty articles:" "\n"
" Entry empty.html is empty" "\n"
"[INFO] Overall Test Status: Fail" "\n"
"[INFO] Total time taken by zimcheck: <3 seconds." "\n"
);
test_zimcheck_single_option(
{"-0", "--empty"},
POOR_ZIMFILE,
1,
expected_stdout,
EMPTY_STDERR
);
}
TEST(zimcheck, internal_url_check_poorzimfile)
{
const std::string expected_stdout(
"[INFO] Checking zim file data/zimfiles/poor.zim" "\n"
"[INFO] Zimcheck version is " VERSION "\n"
"[WARNING] Integrity check is skipped. Any detected errors may in fact be due to corrupted/invalid data.\n"
"[INFO] Verifying Articles' content..." "\n"
"[ERROR] Invalid internal links found:" "\n"
" The following links:" "\n"
"- A/non_existent.html" "\n"
"(A/non_existent.html) were not found in article dangling_link.html" "\n"
" ../../oops.html is out of bounds. Article: outofbounds_link.html" "\n"
"[WARNING] Empty links found:" "\n"
" Found 1 empty links in article: empty_link.html" "\n"
"[INFO] Overall Test Status: Fail" "\n"
"[INFO] Total time taken by zimcheck: <3 seconds." "\n"
);
test_zimcheck_single_option(
{"-U", "--url_internal"},
POOR_ZIMFILE,
1,
expected_stdout,
EMPTY_STDERR
);
}
TEST(zimcheck, external_url_check_poorzimfile)
{
const std::string expected_stdout(
"[INFO] Checking zim file data/zimfiles/poor.zim" "\n"
"[INFO] Zimcheck version is " VERSION "\n"
"[WARNING] Integrity check is skipped. Any detected errors may in fact be due to corrupted/invalid data.\n"
"[INFO] Verifying Articles' content..." "\n"
"[ERROR] Invalid external links found:" "\n"
" http://a.io/pic.png is an external dependence in article external_image_http.html" "\n"
" https://a.io/pic.png is an external dependence in article external_image_https.html" "\n"
" //a.io/pic.png is an external dependence in article external_image_protocol_relative.html" "\n"
"[INFO] Overall Test Status: Fail" "\n"
"[INFO] Total time taken by zimcheck: <3 seconds." "\n"
);
test_zimcheck_single_option(
{"-X", "--url_external"},
POOR_ZIMFILE,
1,
expected_stdout,
EMPTY_STDERR
);
}
TEST(zimcheck, redundant_poorzimfile)
{
const std::string expected_stdout(
"[INFO] Checking zim file data/zimfiles/poor.zim" "\n"
"[INFO] Zimcheck version is " VERSION "\n"
"[WARNING] Integrity check is skipped. Any detected errors may in fact be due to corrupted/invalid data.\n"
"[INFO] Verifying Articles' content..." "\n"
"[INFO] Searching for redundant articles..." "\n"
" Verifying Similar Articles for redundancies..." "\n"
"[WARNING] Redundant data found:" "\n"
" article1.html and redundant_article.html" "\n"
"[INFO] Overall Test Status: Pass" "\n"
"[INFO] Total time taken by zimcheck: <3 seconds." "\n"
);
test_zimcheck_single_option(
{"-R", "--redundant"},
POOR_ZIMFILE,
0,
expected_stdout,
EMPTY_STDERR
);
}
TEST(zimcheck, redirect_loop_poorzimfile)
{
const std::string expected_output(
"[INFO] Checking zim file data/zimfiles/poor.zim" "\n"
"[INFO] Zimcheck version is " VERSION "\n"
"[WARNING] Integrity check is skipped. Any detected errors may in fact be due to corrupted/invalid data.\n"
"[INFO] Checking for redirect loops..." "\n"
"[ERROR] Redirect loop(s) exist:" "\n"
" Redirect loop exists from entry redirect_loop.html" "\n"
"" "\n"
" Redirect loop exists from entry redirect_loop2.html" "\n"
"" "\n"
" Redirect loop exists from entry redirect_loop3.html" "\n"
"" "\n"
"[INFO] Overall Test Status: Fail" "\n"
"[INFO] Total time taken by zimcheck: <3 seconds." "\n"
);
test_zimcheck_single_option(
{"-L", "--redirect_loop"},
POOR_ZIMFILE,
1,
expected_output,
EMPTY_STDERR
);
}
const std::string ALL_CHECKS_OUTPUT_ON_POORZIMFILE(
"[INFO] Checking zim file data/zimfiles/poor.zim" "\n"
"[INFO] Zimcheck version is " VERSION "\n"
"[INFO] Verifying ZIM-archive structure integrity..." "\n"
"[INFO] Avoiding redundant checksum test (already performed by the integrity check)." "\n"
"[INFO] Checking metadata..." "\n"
"[INFO] Searching for Favicon..." "\n"
"[INFO] Searching for main page..." "\n"
"[INFO] Verifying Articles' content..." "\n"
"[INFO] Searching for redundant articles..." "\n"
" Verifying Similar Articles for redundancies..." "\n"
"[INFO] Checking for redirect loops..." "\n"
"[ERROR] Empty articles:" "\n"
" Entry empty.html is empty" "\n"
"[ERROR] Metadata errors:" "\n"
" Missing mandatory metadata: Title" "\n"
" Missing mandatory metadata: Description" "\n"
" Missing mandatory metadata: Illustration_48x48@1" "\n"
" Language must contain at least 3 characters" "\n"
" Language doesn't match regex: ^\\w{3}(,\\w{3})*$" "\n"
"[ERROR] Favicon:" "\n"
" Favicon is missing" "\n"
"[ERROR] Missing mainpage:" "\n"
" Main Page Index stored in Archive Header: 4294967295" "\n"
"[WARNING] Redundant data found:" "\n"
" article1.html and redundant_article.html" "\n"
"[ERROR] Invalid internal links found:" "\n"
" The following links:" "\n"
"- A/non_existent.html" "\n"
"(A/non_existent.html) were not found in article dangling_link.html" "\n"
" ../../oops.html is out of bounds. Article: outofbounds_link.html" "\n"
"[ERROR] Invalid external links found:" "\n"
" http://a.io/pic.png is an external dependence in article external_image_http.html" "\n"
" https://a.io/pic.png is an external dependence in article external_image_https.html" "\n"
" //a.io/pic.png is an external dependence in article external_image_protocol_relative.html" "\n"
"[WARNING] Empty links found:" "\n"
" Found 1 empty links in article: empty_link.html" "\n"
"[ERROR] Redirect loop(s) exist:" "\n"
" Redirect loop exists from entry redirect_loop.html" "\n"
"" "\n"
" Redirect loop exists from entry redirect_loop2.html" "\n"
"" "\n"
" Redirect loop exists from entry redirect_loop3.html" "\n"
"" "\n"
"[INFO] Overall Test Status: Fail" "\n"
"[INFO] Total time taken by zimcheck: <3 seconds." "\n"
);
TEST(zimcheck, nooptions_poorzimfile)
{
CapturedStdout zimcheck_output;
ASSERT_EQ(1, zimcheck({"zimcheck", POOR_ZIMFILE}));
ASSERT_EQ(ALL_CHECKS_OUTPUT_ON_POORZIMFILE, std::string(zimcheck_output));
}
TEST(zimcheck, all_checks_poorzimfile)
{
test_zimcheck_single_option(
{"-A", "--all"},
POOR_ZIMFILE,
1,
ALL_CHECKS_OUTPUT_ON_POORZIMFILE,
EMPTY_STDERR
);
}
TEST(zimcheck, json_bad_checksum)
{
CapturedStdout zimcheck_output;
ASSERT_EQ(1, zimcheck({
"zimcheck",
"--json",
"-C",
"data/zimfiles/bad_checksum.zim"
}));
ASSERT_EQ(
"{" "\n"
" \"zimcheck_version\" : \"" VERSION "\"," "\n"
" \"checks\" : [" "\n"
" \"checksum\"" "\n"
" ]," "\n"
" \"file_name\" : \"data/zimfiles/bad_checksum.zim\"," "\n"
" \"file_uuid\" : \"00000000-0000-0000-0000-000000000000\"," "\n"
" \"status\" : false," "\n"
" \"logs\" : [" "\n"
" {" "\n"
" \"check\" : \"checksum\"," "\n"
" \"level\" : \"ERROR\"," "\n"
" \"message\" : \"ZIM Archive Checksum in archive: 00000000000000000000000000000000\\n\"," "\n"
" \"archive_checksum\" : \"00000000000000000000000000000000\"" "\n"
" }" "\n"
" ]" "\n"
"}" "\n"
, std::string(zimcheck_output)
);
}
TEST(zimcheck, json_poorzimfile)
{
CapturedStdout zimcheck_output;
ASSERT_EQ(1, zimcheck({"zimcheck", "--json", POOR_ZIMFILE}));
ASSERT_EQ(
"{" "\n"
" \"zimcheck_version\" : \"" VERSION "\"," "\n"
" \"checks\" : [" "\n"
" \"checksum\"," "\n"
" \"integrity\"," "\n"
" \"empty\"," "\n"
" \"metadata\"," "\n"
" \"favicon\"," "\n"
" \"main_page\"," "\n"
" \"redundant\"," "\n"
" \"url_internal\"," "\n"
" \"url_external\"," "\n"
" \"url_empty\"," "\n"
" \"redirect\"" "\n"
" ]," "\n"
" \"file_name\" : \"data/zimfiles/poor.zim\"," "\n"
" \"file_uuid\" : \"00000000-0000-0000-0000-000000000000\"," "\n"
" \"status\" : false," "\n"
" \"logs\" : [" "\n"
" {" "\n"
" \"check\" : \"empty\"," "\n"
" \"level\" : \"ERROR\"," "\n"
" \"message\" : \"Entry empty.html is empty\"," "\n"
" \"path\" : \"empty.html\"" "\n"
" }," "\n"
" {" "\n"
" \"check\" : \"metadata\"," "\n"
" \"level\" : \"ERROR\"," "\n"
" \"message\" : \"Missing mandatory metadata: Title\"," "\n"
" \"error\" : \"Missing mandatory metadata: Title\"" "\n"
" }," "\n"
" {" "\n"
" \"check\" : \"metadata\"," "\n"
" \"level\" : \"ERROR\"," "\n"
" \"message\" : \"Missing mandatory metadata: Description\"," "\n"
" \"error\" : \"Missing mandatory metadata: Description\"" "\n"
" }," "\n"
" {" "\n"
" \"check\" : \"metadata\"," "\n"
" \"level\" : \"ERROR\"," "\n"
" \"message\" : \"Missing mandatory metadata: Illustration_48x48@1\"," "\n"
" \"error\" : \"Missing mandatory metadata: Illustration_48x48@1\"" "\n"
" }," "\n"
" {" "\n"
" \"check\" : \"metadata\"," "\n"
" \"level\" : \"ERROR\"," "\n"
" \"message\" : \"Language must contain at least 3 characters\"," "\n"
" \"error\" : \"Language must contain at least 3 characters\"" "\n"
" }," "\n"
" {" "\n"
" \"check\" : \"metadata\"," "\n"
" \"level\" : \"ERROR\"," "\n"
" \"message\" : \"Language doesn't match regex: ^\\\\w{3}(,\\\\w{3})*$\"," "\n"
" \"error\" : \"Language doesn't match regex: ^\\\\w{3}(,\\\\w{3})*$\"" "\n"
" }," "\n"
" {" "\n"
" \"check\" : \"favicon\"," "\n"
" \"level\" : \"ERROR\"," "\n"
" \"message\" : \"Favicon is missing\"" "\n"
" }," "\n"
" {" "\n"
" \"check\" : \"main_page\"," "\n"
" \"level\" : \"ERROR\"," "\n"
" \"message\" : \"Main Page Index stored in Archive Header: 4294967295\"," "\n"
" \"main_page_index\" : \"4294967295\"" "\n"
" }," "\n"
" {" "\n"
" \"check\" : \"redundant\"," "\n"
" \"level\" : \"WARNING\"," "\n"
" \"message\" : \"article1.html and redundant_article.html\"," "\n"
" \"path1\" : \"article1.html\"," "\n"
" \"path2\" : \"redundant_article.html\"" "\n"
" }," "\n"
" {" "\n"
" \"check\" : \"url_internal\"," "\n"
" \"level\" : \"ERROR\"," "\n"
" \"message\" : \"The following links:\\n- A/non_existent.html\\n(A/non_existent.html) were not found in article dangling_link.html\"," "\n"
" \"links\" : [" "\n"
" \"A/non_existent.html\"" "\n"
" ]," "\n"
" \"normalized_link\" : \"A/non_existent.html\"," "\n"
" \"path\" : \"dangling_link.html\"" "\n"
" }," "\n"
" {" "\n"
" \"check\" : \"url_internal\"," "\n"
" \"level\" : \"ERROR\"," "\n"
" \"message\" : \"../../oops.html is out of bounds. Article: outofbounds_link.html\"," "\n"
" \"link\" : \"../../oops.html\"," "\n"
" \"path\" : \"outofbounds_link.html\"" "\n"
" }," "\n"
" {" "\n"
" \"check\" : \"url_external\"," "\n"
" \"level\" : \"ERROR\"," "\n"
" \"message\" : \"http://a.io/pic.png is an external dependence in article external_image_http.html\"," "\n"
" \"link\" : \"http://a.io/pic.png\"," "\n"
" \"path\" : \"external_image_http.html\"" "\n"
" }," "\n"
" {" "\n"
" \"check\" : \"url_external\"," "\n"
" \"level\" : \"ERROR\"," "\n"
" \"message\" : \"https://a.io/pic.png is an external dependence in article external_image_https.html\"," "\n"
" \"link\" : \"https://a.io/pic.png\"," "\n"
" \"path\" : \"external_image_https.html\"" "\n"
" }," "\n"
" {" "\n"
" \"check\" : \"url_external\"," "\n"
" \"level\" : \"ERROR\"," "\n"
" \"message\" : \"//a.io/pic.png is an external dependence in article external_image_protocol_relative.html\"," "\n"
" \"link\" : \"//a.io/pic.png\"," "\n"
" \"path\" : \"external_image_protocol_relative.html\"" "\n"
" }," "\n"
" {" "\n"
" \"check\" : \"url_empty\"," "\n"
" \"level\" : \"WARNING\"," "\n"
" \"message\" : \"Found 1 empty links in article: empty_link.html\"," "\n"
" \"count\" : \"1\"," "\n"
" \"path\" : \"empty_link.html\"" "\n"
" }," "\n"
" {" "\n"
" \"check\" : \"redirect\"," "\n"
" \"level\" : \"ERROR\"," "\n"
" \"message\" : \"Redirect loop exists from entry redirect_loop.html\\n\"," "\n"
" \"entry_path\" : \"redirect_loop.html\"" "\n"
" }," "\n"
" {" "\n"
" \"check\" : \"redirect\"," "\n"
" \"level\" : \"ERROR\"," "\n"
" \"message\" : \"Redirect loop exists from entry redirect_loop2.html\\n\"," "\n"
" \"entry_path\" : \"redirect_loop2.html\"" "\n"
" }," "\n"
" {" "\n"
" \"check\" : \"redirect\"," "\n"
" \"level\" : \"ERROR\"," "\n"
" \"message\" : \"Redirect loop exists from entry redirect_loop3.html\\n\"," "\n"
" \"entry_path\" : \"redirect_loop3.html\"" "\n"
" }" "\n"
" ]" "\n"
"}" "\n"
, std::string(zimcheck_output));
}
|