Skip to content

Commit

Permalink
Merge pull request #1113 from kiwix/ci_windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautierfr authored Aug 27, 2024
2 parents 27ad77c + 4812fb1 commit 199a10d
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 11 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,52 @@ jobs:
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

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:
strategy:
fail-fast: false
Expand Down
2 changes: 1 addition & 1 deletion scripts/kiwix-compile-resources
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Resource:
for base_dir in base_dirs:
try:
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
break
except FileNotFoundError:
Expand Down
2 changes: 1 addition & 1 deletion src/tools/stringTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
// valid escape code, just use the character and move on
if (it > value.end() - 3) {
if (value.end() - it < 3) {
os << *it;
continue;
}
Expand Down
14 changes: 11 additions & 3 deletions test/book.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@ struct XMLDoc : pugi::xml_document

} // 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)
{
const XMLDoc xml(R"(
<book id="zara"
path="./zara.zim"
path="zara.zim"
url="https://who.org/zara.zim"
title="Catch an infection in 24 hours"
description="Complete guide to contagious diseases"
Expand All @@ -40,9 +48,9 @@ TEST(BookTest, updateFromXMLTest)
)");

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.getTitle(), "Catch an infection in 24 hours");
EXPECT_EQ(book.getDescription(), "Complete guide to contagious diseases");
Expand Down
16 changes: 13 additions & 3 deletions test/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"(
<library version="1.0">
<book
id="raycharles"
path="./zimfile.zim"
path=")" ZIMFILE_PATH R"("
url="https://github.com/kiwix/libkiwix/raw/master/test/data/zimfile.zim"
title="Ray Charles"
description="Wikipedia articles about Ray Charles"
Expand All @@ -287,7 +297,7 @@ const char sampleLibraryXML[] = R"(
></book>
<book
id="example"
path="./example.zim"
path=")" EXAMPLE_PATH R"("
title="An example ZIM archive"
description="An eXaMpLe book added to the catalog via XML"
language="deu"
Expand Down Expand Up @@ -383,7 +393,7 @@ class LibraryTest : public ::testing::Test {
void SetUp() override {
kiwix::Manager manager(lib);
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="") {
Expand Down
18 changes: 15 additions & 3 deletions test/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,23 @@ TEST(ManagerTest, addBookFromPathAndGetIdTest)
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"(
<library version="1.0">
<book
id="0d0bcd57-d3f6-cb22-44cc-a723ccb4e1b2"
path="zimfiles/unittest.zim"
path=")" UNITTEST_ZIM_PATH R"("
url="https://example.com/zimfiles/unittest.zim"
title="Unit Test"
description="Wikipedia articles about unit testing"
Expand All @@ -51,9 +63,9 @@ TEST(ManagerTest, readXml)
auto lib = kiwix::Library::create();
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");
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("Unit Test", book.getTitle());
EXPECT_EQ("Wikipedia articles about unit testing", book.getDescription());
Expand Down
34 changes: 34 additions & 0 deletions test/name_mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@
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"(
<library version="1.0">
<book id="01" path="/data/zero_one.zim"> </book>
Expand All @@ -22,6 +39,7 @@ const char libraryXML[] = R"(
<book id="07-sub" path="/data/subdir/zero_seven.zim"></book>
</library>
)";
#endif

class NameMapperTest : public ::testing::Test {
public:
Expand Down Expand Up @@ -61,7 +79,22 @@ class CapturedStderr
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 =
"Path collision: '/data/zero_four_2021-10.zim' and"
" '/data/zero_four_2021-11.zim' can't share the same URL path 'zero_four'."
Expand All @@ -76,6 +109,7 @@ const std::string ZERO_SEVEN_NAME_CONFLICT_MSG =
"Path collision: '/data/subdir/zero_seven.zim' and"
" '/data/zero_seven.zim' can't share the same URL path 'zero_seven'."
" Therefore, only '/data/subdir/zero_seven.zim' will be served.\n";
#endif

// Name conflicts in the default mode (without the --nodatealiases is off
const std::string DEFAULT_NAME_CONFLICTS = ZERO_SIX_NAME_CONFLICT_MSG
Expand Down

0 comments on commit 199a10d

Please sign in to comment.