mirror of https://github.com/kiwix/libkiwix.git
Merge pull request #1113 from kiwix/ci_windows
This commit is contained in:
commit
199a10d093
|
@ -71,6 +71,52 @@ jobs:
|
||||||
LD_LIBRARY_PATH: ${{env.HOME}}/BUILD_${{matrix.arch_name}}/INSTALL/lib:${{env.HOME}}/BUILD_${{matrix.arch_name}}/INSTALL/lib64
|
LD_LIBRARY_PATH: ${{env.HOME}}/BUILD_${{matrix.arch_name}}/INSTALL/lib:${{env.HOME}}/BUILD_${{matrix.arch_name}}/INSTALL/lib64
|
||||||
run: meson test -C build --verbose
|
run: meson test -C build --verbose
|
||||||
|
|
||||||
|
Windows:
|
||||||
|
runs-on: windows-2022
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup python 3.10
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.10'
|
||||||
|
|
||||||
|
- name: Install packages
|
||||||
|
run:
|
||||||
|
choco install pkgconfiglite ninja
|
||||||
|
|
||||||
|
- name: Install python modules
|
||||||
|
run: pip3 install meson
|
||||||
|
|
||||||
|
- name: Setup MSVC compiler
|
||||||
|
uses: bus1/cabuild/action/msdevshell@v1
|
||||||
|
with:
|
||||||
|
architecture: x64
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
uses: kiwix/kiwix-build/actions/dl_deps_archive@main
|
||||||
|
with:
|
||||||
|
target_platform: win-x86_64-static
|
||||||
|
|
||||||
|
- name: Compile
|
||||||
|
shell: cmd
|
||||||
|
run: |
|
||||||
|
set PKG_CONFIG_PATH=%cd%\BUILD_win-amd64\INSTALL\lib\pkgconfig
|
||||||
|
set CPPFLAGS=-I%cd%\BUILD_win-amd64\INSTALL\include
|
||||||
|
meson.exe setup . build -Dwerror=false --default-library=static --buildtype=debug
|
||||||
|
cd build
|
||||||
|
ninja.exe
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
shell: cmd
|
||||||
|
run: |
|
||||||
|
cd build
|
||||||
|
meson.exe test --verbose
|
||||||
|
env:
|
||||||
|
WAIT_TIME_FACTOR_TEST: 10
|
||||||
|
|
||||||
Linux:
|
Linux:
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
|
|
|
@ -71,7 +71,7 @@ class Resource:
|
||||||
for base_dir in base_dirs:
|
for base_dir in base_dirs:
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(base_dir, filename), 'rb') as f:
|
with open(os.path.join(base_dir, filename), 'rb') as f:
|
||||||
self.data = f.read()
|
self.data = f.read().replace(b"\r\n", b"\n")
|
||||||
found = True
|
found = True
|
||||||
break
|
break
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
|
|
|
@ -257,7 +257,7 @@ std::string kiwix::urlDecode(const std::string& value, bool component)
|
||||||
|
|
||||||
// If there aren't enough characters left for this to be a
|
// If there aren't enough characters left for this to be a
|
||||||
// valid escape code, just use the character and move on
|
// valid escape code, just use the character and move on
|
||||||
if (it > value.end() - 3) {
|
if (value.end() - it < 3) {
|
||||||
os << *it;
|
os << *it;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,11 +15,19 @@ struct XMLDoc : pugi::xml_document
|
||||||
|
|
||||||
} // unnamed namespace
|
} // unnamed namespace
|
||||||
|
|
||||||
|
#if _WIN32
|
||||||
|
# define DATA_ABS_PATH "C:\\data\\zim"
|
||||||
|
# define ZARA_ABS_PATH "C:\\data\\zim\\zara.zim"
|
||||||
|
#else
|
||||||
|
# define DATA_ABS_PATH "/data/zim"
|
||||||
|
# define ZARA_ABS_PATH "/data/zim/zara.zim"
|
||||||
|
#endif
|
||||||
|
|
||||||
TEST(BookTest, updateFromXMLTest)
|
TEST(BookTest, updateFromXMLTest)
|
||||||
{
|
{
|
||||||
const XMLDoc xml(R"(
|
const XMLDoc xml(R"(
|
||||||
<book id="zara"
|
<book id="zara"
|
||||||
path="./zara.zim"
|
path="zara.zim"
|
||||||
url="https://who.org/zara.zim"
|
url="https://who.org/zara.zim"
|
||||||
title="Catch an infection in 24 hours"
|
title="Catch an infection in 24 hours"
|
||||||
description="Complete guide to contagious diseases"
|
description="Complete guide to contagious diseases"
|
||||||
|
@ -40,9 +48,9 @@ TEST(BookTest, updateFromXMLTest)
|
||||||
)");
|
)");
|
||||||
|
|
||||||
kiwix::Book book;
|
kiwix::Book book;
|
||||||
book.updateFromXml(xml.child("book"), "/data/zim");
|
book.updateFromXml(xml.child("book"), DATA_ABS_PATH);
|
||||||
|
|
||||||
EXPECT_EQ(book.getPath(), "/data/zim/zara.zim");
|
EXPECT_EQ(book.getPath(), ZARA_ABS_PATH);
|
||||||
EXPECT_EQ(book.getUrl(), "https://who.org/zara.zim");
|
EXPECT_EQ(book.getUrl(), "https://who.org/zara.zim");
|
||||||
EXPECT_EQ(book.getTitle(), "Catch an infection in 24 hours");
|
EXPECT_EQ(book.getTitle(), "Catch an infection in 24 hours");
|
||||||
EXPECT_EQ(book.getDescription(), "Complete guide to contagious diseases");
|
EXPECT_EQ(book.getDescription(), "Complete guide to contagious diseases");
|
||||||
|
|
|
@ -267,11 +267,21 @@ const char * sampleOpdsStream = R"(
|
||||||
|
|
||||||
)";
|
)";
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
# define ZIMFILE_PATH ".\\zimfile.zim"
|
||||||
|
# define EXAMPLE_PATH ".\\example.zim"
|
||||||
|
# define LIBRARY_PATH ".\\test\\library.xml"
|
||||||
|
#else
|
||||||
|
# define ZIMFILE_PATH "./zimfile.zim"
|
||||||
|
# define EXAMPLE_PATH "./example.zim"
|
||||||
|
# define LIBRARY_PATH "./test/library.xml"
|
||||||
|
#endif
|
||||||
|
|
||||||
const char sampleLibraryXML[] = R"(
|
const char sampleLibraryXML[] = R"(
|
||||||
<library version="1.0">
|
<library version="1.0">
|
||||||
<book
|
<book
|
||||||
id="raycharles"
|
id="raycharles"
|
||||||
path="./zimfile.zim"
|
path=")" ZIMFILE_PATH R"("
|
||||||
url="https://github.com/kiwix/libkiwix/raw/master/test/data/zimfile.zim"
|
url="https://github.com/kiwix/libkiwix/raw/master/test/data/zimfile.zim"
|
||||||
title="Ray Charles"
|
title="Ray Charles"
|
||||||
description="Wikipedia articles about Ray Charles"
|
description="Wikipedia articles about Ray Charles"
|
||||||
|
@ -287,7 +297,7 @@ const char sampleLibraryXML[] = R"(
|
||||||
></book>
|
></book>
|
||||||
<book
|
<book
|
||||||
id="example"
|
id="example"
|
||||||
path="./example.zim"
|
path=")" EXAMPLE_PATH R"("
|
||||||
title="An example ZIM archive"
|
title="An example ZIM archive"
|
||||||
description="An eXaMpLe book added to the catalog via XML"
|
description="An eXaMpLe book added to the catalog via XML"
|
||||||
language="deu"
|
language="deu"
|
||||||
|
@ -383,7 +393,7 @@ class LibraryTest : public ::testing::Test {
|
||||||
void SetUp() override {
|
void SetUp() override {
|
||||||
kiwix::Manager manager(lib);
|
kiwix::Manager manager(lib);
|
||||||
manager.readOpds(sampleOpdsStream, "foo.urlHost");
|
manager.readOpds(sampleOpdsStream, "foo.urlHost");
|
||||||
manager.readXml(sampleLibraryXML, false, "./test/library.xml", true);
|
manager.readXml(sampleLibraryXML, false, LIBRARY_PATH, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
kiwix::Bookmark createBookmark(const std::string &id, const std::string& url="", const std::string& title="") {
|
kiwix::Bookmark createBookmark(const std::string &id, const std::string& url="", const std::string& title="") {
|
||||||
|
|
|
@ -25,11 +25,23 @@ TEST(ManagerTest, addBookFromPathAndGetIdTest)
|
||||||
EXPECT_EQ(book.getUrl(), url);
|
EXPECT_EQ(book.getUrl(), url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if _WIN32
|
||||||
|
# define UNITTEST_ZIM_PATH "zimfiles\\unittest.zim"
|
||||||
|
# define LIB_ABS_PATH "C:\\data\\lib.xml"
|
||||||
|
# define ZIM_ABS_PATH "C:\\data\\zimfiles\\unittest.zim"
|
||||||
|
#else
|
||||||
|
# define UNITTEST_ZIM_PATH "zimfiles/unittest.zim"
|
||||||
|
# define LIB_ABS_PATH "/data/lib.xml"
|
||||||
|
# define ZIM_ABS_PATH "/data/zimfiles/unittest.zim"
|
||||||
|
#endif
|
||||||
|
|
||||||
const char sampleLibraryXML[] = R"(
|
const char sampleLibraryXML[] = R"(
|
||||||
<library version="1.0">
|
<library version="1.0">
|
||||||
<book
|
<book
|
||||||
id="0d0bcd57-d3f6-cb22-44cc-a723ccb4e1b2"
|
id="0d0bcd57-d3f6-cb22-44cc-a723ccb4e1b2"
|
||||||
path="zimfiles/unittest.zim"
|
path=")" UNITTEST_ZIM_PATH R"("
|
||||||
url="https://example.com/zimfiles/unittest.zim"
|
url="https://example.com/zimfiles/unittest.zim"
|
||||||
title="Unit Test"
|
title="Unit Test"
|
||||||
description="Wikipedia articles about unit testing"
|
description="Wikipedia articles about unit testing"
|
||||||
|
@ -51,9 +63,9 @@ TEST(ManagerTest, readXml)
|
||||||
auto lib = kiwix::Library::create();
|
auto lib = kiwix::Library::create();
|
||||||
kiwix::Manager manager = kiwix::Manager(lib);
|
kiwix::Manager manager = kiwix::Manager(lib);
|
||||||
|
|
||||||
EXPECT_EQ(true, manager.readXml(sampleLibraryXML, true, "/data/lib.xml", true));
|
EXPECT_EQ(true, manager.readXml(sampleLibraryXML, true, LIB_ABS_PATH, true));
|
||||||
kiwix::Book book = lib->getBookById("0d0bcd57-d3f6-cb22-44cc-a723ccb4e1b2");
|
kiwix::Book book = lib->getBookById("0d0bcd57-d3f6-cb22-44cc-a723ccb4e1b2");
|
||||||
EXPECT_EQ("/data/zimfiles/unittest.zim", book.getPath());
|
EXPECT_EQ(ZIM_ABS_PATH, book.getPath());
|
||||||
EXPECT_EQ("https://example.com/zimfiles/unittest.zim", book.getUrl());
|
EXPECT_EQ("https://example.com/zimfiles/unittest.zim", book.getUrl());
|
||||||
EXPECT_EQ("Unit Test", book.getTitle());
|
EXPECT_EQ("Unit Test", book.getTitle());
|
||||||
EXPECT_EQ("Wikipedia articles about unit testing", book.getDescription());
|
EXPECT_EQ("Wikipedia articles about unit testing", book.getDescription());
|
||||||
|
|
|
@ -7,6 +7,23 @@
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#if _WIN32
|
||||||
|
const char libraryXML[] = R"(
|
||||||
|
<library version="1.0">
|
||||||
|
<book id="01" path="C:\data\zero_one.zim"> </book>
|
||||||
|
<book id="02" path="C:\data\zero two.zim"> </book>
|
||||||
|
<book id="03" path="C:\data\ZERO thrêë.zim"> </book>
|
||||||
|
<book id="04-2021-10" path="C:\data\zero_four_2021-10.zim"></book>
|
||||||
|
<book id="04-2021-11" path="C:\data\zero_four_2021-11.zim"></book>
|
||||||
|
<book id="05-a" path="C:\data\zero_five-a.zim" name="zero_five"></book>
|
||||||
|
<book id="05-b" path="C:\data\zero_five-b.zim" name="zero_five"></book>
|
||||||
|
<book id="06+" path="C:\data\zërô + SIX.zim"></book>
|
||||||
|
<book id="06plus" path="C:\data\zero_plus_six.zim"></book>
|
||||||
|
<book id="07-super" path="C:\data\zero_seven.zim"></book>
|
||||||
|
<book id="07-sub" path="C:\data\subdir\zero_seven.zim"></book>
|
||||||
|
</library>
|
||||||
|
)";
|
||||||
|
#else
|
||||||
const char libraryXML[] = R"(
|
const char libraryXML[] = R"(
|
||||||
<library version="1.0">
|
<library version="1.0">
|
||||||
<book id="01" path="/data/zero_one.zim"> </book>
|
<book id="01" path="/data/zero_one.zim"> </book>
|
||||||
|
@ -22,6 +39,7 @@ const char libraryXML[] = R"(
|
||||||
<book id="07-sub" path="/data/subdir/zero_seven.zim"></book>
|
<book id="07-sub" path="/data/subdir/zero_seven.zim"></book>
|
||||||
</library>
|
</library>
|
||||||
)";
|
)";
|
||||||
|
#endif
|
||||||
|
|
||||||
class NameMapperTest : public ::testing::Test {
|
class NameMapperTest : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
|
@ -61,7 +79,22 @@ public:
|
||||||
operator std::string() const { return buffer.str(); }
|
operator std::string() const { return buffer.str(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if _WIN32
|
||||||
|
const std::string ZERO_FOUR_NAME_CONFLICT_MSG =
|
||||||
|
"Path collision: 'C:\\data\\zero_four_2021-10.zim' and"
|
||||||
|
" 'C:\\data\\zero_four_2021-11.zim' can't share the same URL path 'zero_four'."
|
||||||
|
" Therefore, only 'C:\\data\\zero_four_2021-10.zim' will be served.\n";
|
||||||
|
|
||||||
|
const std::string ZERO_SIX_NAME_CONFLICT_MSG =
|
||||||
|
"Path collision: 'C:\\data\\zërô + SIX.zim' and "
|
||||||
|
"'C:\\data\\zero_plus_six.zim' can't share the same URL path 'zero_plus_six'."
|
||||||
|
" Therefore, only 'C:\\data\\zërô + SIX.zim' will be served.\n";
|
||||||
|
|
||||||
|
const std::string ZERO_SEVEN_NAME_CONFLICT_MSG =
|
||||||
|
"Path collision: 'C:\\data\\subdir\\zero_seven.zim' and"
|
||||||
|
" 'C:\\data\\zero_seven.zim' can't share the same URL path 'zero_seven'."
|
||||||
|
" Therefore, only 'C:\\data\\subdir\\zero_seven.zim' will be served.\n";
|
||||||
|
#else
|
||||||
const std::string ZERO_FOUR_NAME_CONFLICT_MSG =
|
const std::string ZERO_FOUR_NAME_CONFLICT_MSG =
|
||||||
"Path collision: '/data/zero_four_2021-10.zim' and"
|
"Path collision: '/data/zero_four_2021-10.zim' and"
|
||||||
" '/data/zero_four_2021-11.zim' can't share the same URL path 'zero_four'."
|
" '/data/zero_four_2021-11.zim' can't share the same URL path 'zero_four'."
|
||||||
|
@ -76,6 +109,7 @@ const std::string ZERO_SEVEN_NAME_CONFLICT_MSG =
|
||||||
"Path collision: '/data/subdir/zero_seven.zim' and"
|
"Path collision: '/data/subdir/zero_seven.zim' and"
|
||||||
" '/data/zero_seven.zim' can't share the same URL path 'zero_seven'."
|
" '/data/zero_seven.zim' can't share the same URL path 'zero_seven'."
|
||||||
" Therefore, only '/data/subdir/zero_seven.zim' will be served.\n";
|
" Therefore, only '/data/subdir/zero_seven.zim' will be served.\n";
|
||||||
|
#endif
|
||||||
|
|
||||||
// Name conflicts in the default mode (without the --nodatealiases is off
|
// Name conflicts in the default mode (without the --nodatealiases is off
|
||||||
const std::string DEFAULT_NAME_CONFLICTS = ZERO_SIX_NAME_CONFLICT_MSG
|
const std::string DEFAULT_NAME_CONFLICTS = ZERO_SIX_NAME_CONFLICT_MSG
|
||||||
|
|
Loading…
Reference in New Issue