File: tests-backend-misc.cpp

package info (click to toggle)
appstream-generator 0.10.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,344 kB
  • sloc: cpp: 42,038; python: 292; xml: 259; sh: 223; makefile: 20
file content (94 lines) | stat: -rw-r--r-- 2,167 bytes parent folder | download
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
/*
 * Copyright (C) 2019-2025 Matthias Klumpp <matthias@tenstral.net>
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#define CATCH_CONFIG_MAIN
#include <catch2/catch_all.hpp>

#include <filesystem>
#include <algorithm>
#include <fstream>
#include <memory>
#include <string>
#include <unordered_map>
#include <string_view>

#include "logging.h"
#include "utils.h"

#include "backends/archlinux/listfile.h"
#include "backends/rpmmd/rpmpkgindex.h"

using namespace ASGenerator;

static struct TestSetup {
    TestSetup()
    {
        setVerbose(true);
    }
} testSetup;

TEST_CASE("ListFile parsing", "[backend][archlinux]")
{
    SECTION("Parse Arch Linux package format")
    {
        const std::string testData = R"(%FILENAME%
a2ps-4.14-6-x86_64.pkg.tar.xz

%NAME%
a2ps

%VERSION%
4.14-6

%DESC%
An Any to PostScript filter

%CSIZE%
629320

%MULTILINE%
Blah1
BLUBB2
EtcEtcEtc3

%SHA256SUM%
a629a0e0eca0d96a97eb3564f01be495772439df6350600c93120f5ac7f3a1b5)";

        ListFile lf;
        std::vector<std::uint8_t> testDataBytes(testData.begin(), testData.end());
        lf.loadData(testDataBytes);

        // Test single-line entries
        REQUIRE(lf.getEntry("FILENAME") == "a2ps-4.14-6-x86_64.pkg.tar.xz");
        REQUIRE(lf.getEntry("VERSION") == "4.14-6");
        REQUIRE(lf.getEntry("NAME") == "a2ps");
        REQUIRE(lf.getEntry("DESC") == "An Any to PostScript filter");
        REQUIRE(lf.getEntry("CSIZE") == "629320");

        // Test multiline entry
        REQUIRE(lf.getEntry("MULTILINE") == "Blah1\nBLUBB2\nEtcEtcEtc3");

        // Test SHA256SUM entry
        REQUIRE(lf.getEntry("SHA256SUM") == "a629a0e0eca0d96a97eb3564f01be495772439df6350600c93120f5ac7f3a1b5");

        // Test non-existent entry
        REQUIRE(lf.getEntry("NONEXISTENT").empty());
    }
}

TEST_CASE("RPMPackageIndex", "[backend][rpmmd]")
{
    SECTION("Load RPM packages from test repository")
    {
        auto samplesDir = Utils::getTestSamplesDir();
        auto rpmmdDir = samplesDir / "rpmmd";

        RPMPackageIndex pi(rpmmdDir.string());
        auto pkgs = pi.packagesFor("26", "Workstation", "x86_64");

        REQUIRE(pkgs.size() == 4);
    }
}