1 /*
2 * Copyright (C) 2009 Miguel Rocha
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
11 * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
12 * NON-INFRINGEMENT. See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 *
18 */
19
20 #include <zim/zim.h>
21 #include <zim/file.h>
22 #include <zim/error.h>
23 #include <zim/fileiterator.h>
24
25 #include "gtest/gtest.h"
26
27 namespace
28 {
29 // Not found cases
30
31 // ByTitle
TEST(FindTests,NotFoundByTitle)32 TEST(FindTests, NotFoundByTitle)
33 {
34 zim::File file ("./data/wikibooks_be_all_nopic_2017-02.zim");
35
36 auto article1 = file.findByTitle('U', "unkownTitle");
37 auto article2 = file.findByTitle('A', "unkownTitle");
38 ASSERT_EQ(article1->getIndex(), 0);
39 ASSERT_EQ(article2->getIndex(), 7);
40 }
41
42 // By URL
TEST(FindTests,NotFoundByURL)43 TEST(FindTests, NotFoundByURL)
44 {
45 zim::File file ("./data/wikibooks_be_all_nopic_2017-02.zim");
46
47 auto article1 = file.find('U', "unkwonUrl");
48 auto article2 = file.find('A', "unkwonUrl");
49 ASSERT_EQ(article1.getIndex(), file.getCountArticles());
50 ASSERT_EQ(article2->getIndex(), 7);
51 }
52
53 // By URL (no ns)
TEST(FindTests,NotFoundByURLDefaultNS)54 TEST(FindTests, NotFoundByURLDefaultNS)
55 {
56 zim::File file ("./data/wikibooks_be_all_nopic_2017-02.zim");
57
58 auto article0 = file.find("unkwonUrl");
59 auto article1 = file.find("U/unkwonUrl");
60 auto article2 = file.find("A/unkwonUrl");
61 ASSERT_EQ(article0->getIndex(), 0);
62 ASSERT_EQ(article1.getIndex(), file.getCountArticles());
63 ASSERT_EQ(article2->getIndex(), 7);
64 }
65
66 // Found cases
67
68 // ByTitle
TEST(FindTests,ByTitle)69 TEST(FindTests, ByTitle)
70 {
71 zim::File file ("./data/wikibooks_be_all_nopic_2017-02.zim");
72
73 auto article1 = file.findByTitle('-', "j/body.js");
74 auto article2 = file.findByTitle('A', "index.html");
75 ASSERT_EQ(article1.getIndex(), 1);
76 ASSERT_EQ(article2->getIndex(), 7);
77 }
78
79 // By URL
TEST(FindTests,ByURL)80 TEST(FindTests, ByURL)
81 {
82 zim::File file ("./data/wikibooks_be_all_nopic_2017-02.zim");
83
84 auto article1 = file.find('-', "j/body.js");
85 auto article2 = file.find('I', "m/115a35549794e50dcd03e60ef1a1ae24.png");
86 ASSERT_EQ(article1->getIndex(), 1);
87 ASSERT_EQ(article2->getIndex(), 76);
88 }
89
90 // By URL (no ns)
TEST(FindTests,ByURLDefaultNS)91 TEST(FindTests, ByURLDefaultNS)
92 {
93 zim::File file ("./data/wikibooks_be_all_nopic_2017-02.zim");
94
95 auto article0 = file.find("A/Main_Page.html");
96 auto article1 = file.find("I/s/ajax-loader.gif");
97 auto article2 = file.find("-/j/head.js");
98 ASSERT_EQ(article0->getIndex(), 5);
99 ASSERT_EQ(article1->getIndex(), 80);
100 ASSERT_EQ(article2->getIndex(), 2);
101 }
102
103 } // namespace
104