Пересобранный и видоизмененный conky для ОСГОС
This commit is contained in:
commit
3a48cf8c86
738 changed files with 217718 additions and 0 deletions
55
tests/CMakeLists.txt
Normal file
55
tests/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
include(CTest)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/src)
|
||||
include_directories(${CMAKE_BINARY_DIR})
|
||||
include_directories(${conky_includes})
|
||||
|
||||
set(test_srcs "test-conky.cc")
|
||||
|
||||
if(OS_LINUX)
|
||||
set(test_srcs ${test_srcs} test-linux.cc)
|
||||
endif()
|
||||
|
||||
if(OS_DARWIN)
|
||||
set(test_srcs ${test_srcs} test-darwin.cc)
|
||||
endif()
|
||||
|
||||
set(test_srcs ${test_srcs} test-core.cc)
|
||||
set(test_srcs ${test_srcs} test-diskio.cc)
|
||||
set(test_srcs ${test_srcs} test-fs.cc)
|
||||
set(test_srcs ${test_srcs} test-gradient.cc)
|
||||
set(test_srcs ${test_srcs} test-graph.cc)
|
||||
set(test_srcs ${test_srcs} test-colours.cc)
|
||||
|
||||
add_executable(test-conky test-common.cc ${test_srcs})
|
||||
target_link_libraries(test-conky conky_core)
|
||||
catch_discover_tests(test-conky)
|
||||
|
||||
if(CODE_COVERAGE)
|
||||
set(COVERAGE_LCOV_EXCLUDES
|
||||
"*/include/c++/v1/*"
|
||||
"/usr/include/*"
|
||||
"/usr/lib/*"
|
||||
"/usr/local/Cellar/*"
|
||||
"/usr/local/include/*"
|
||||
"/usr/local/lib/*"
|
||||
"/usr/include/libkern/i386/*"
|
||||
"/usr/include/sys/_types/*"
|
||||
"/usr/local/opt/gettext/include/*"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/*"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/catch2/*"
|
||||
"${CMAKE_SOURCE_DIR}/3rdparty/*")
|
||||
|
||||
setup_target_for_coverage_lcov_html(NAME
|
||||
test-conky-coverage-html
|
||||
EXECUTABLE
|
||||
test-conky
|
||||
DEPENDENCIES
|
||||
test-conky)
|
||||
setup_target_for_coverage_lcov_txt(NAME
|
||||
test-conky-coverage-txt
|
||||
EXECUTABLE
|
||||
test-conky
|
||||
DEPENDENCIES
|
||||
test-conky)
|
||||
endif()
|
||||
17970
tests/catch2/catch.hpp
Normal file
17970
tests/catch2/catch.hpp
Normal file
File diff suppressed because it is too large
Load diff
24
tests/dockerfiles/Dockerfile.alpine-base
Normal file
24
tests/dockerfiles/Dockerfile.alpine-base
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
FROM alpine:latest
|
||||
|
||||
RUN apk add --no-cache \
|
||||
binutils \
|
||||
cmake \
|
||||
curl-dev \
|
||||
docbook2x \
|
||||
gettext-tiny-dev \
|
||||
git \
|
||||
icu-dev \
|
||||
imlib2-dev \
|
||||
iw \
|
||||
libmicrohttpd-dev \
|
||||
libpulse \
|
||||
libxdamage-dev \
|
||||
libxext-dev \
|
||||
libxft-dev \
|
||||
libxinerama-dev \
|
||||
linux-headers \
|
||||
lua5.3-dev \
|
||||
make \
|
||||
musl-dev \
|
||||
ncurses-dev \
|
||||
patch
|
||||
5
tests/dockerfiles/Dockerfile.alpine-clang
Normal file
5
tests/dockerfiles/Dockerfile.alpine-clang
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
ARG IMAGE=registry.gitlab.com/brndnmtthws-oss/conky
|
||||
FROM ${IMAGE}/builder/arch-base:latest
|
||||
|
||||
RUN apk add --no-cache \
|
||||
clang
|
||||
6
tests/dockerfiles/Dockerfile.alpine-gcc
Normal file
6
tests/dockerfiles/Dockerfile.alpine-gcc
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
ARG IMAGE=registry.gitlab.com/brndnmtthws-oss/conky
|
||||
FROM ${IMAGE}/builder/alpine-base:latest
|
||||
|
||||
RUN apk add --no-cache \
|
||||
g++ \
|
||||
gcc
|
||||
37
tests/dockerfiles/Dockerfile.archlinux-base
Normal file
37
tests/dockerfiles/Dockerfile.archlinux-base
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
FROM archlinux:base
|
||||
|
||||
# Fix from https://www.reddit.com/r/archlinux/comments/lek2ba/arch_linux_on_docker_ci_could_not_find_or_read/
|
||||
RUN patched_glibc=glibc-linux4-2.33-4-x86_64.pkg.tar.zst && \
|
||||
curl -LO "https://repo.archlinuxcn.org/x86_64/$patched_glibc" && \
|
||||
bsdtar -C / -xvf "$patched_glibc"
|
||||
|
||||
RUN pacman -Syu --noconfirm --needed \
|
||||
cairo \
|
||||
cmake \
|
||||
docbook2x \
|
||||
git \
|
||||
glib2 \
|
||||
imlib2 \
|
||||
iw \
|
||||
libical \
|
||||
libircclient \
|
||||
libmicrohttpd \
|
||||
libpulse \
|
||||
librsvg \
|
||||
libxdamage \
|
||||
libxext \
|
||||
libxft \
|
||||
libxinerama \
|
||||
libxnvctrl \
|
||||
lua \
|
||||
make \
|
||||
man-db \
|
||||
mariadb-libs \
|
||||
patch \
|
||||
pkg-config \
|
||||
wireless_tools \
|
||||
&& git clone https://github.com/linux-test-project/lcov.git \
|
||||
&& cd lcov \
|
||||
&& make install \
|
||||
&& cd .. \
|
||||
&& rm -rf lcov
|
||||
6
tests/dockerfiles/Dockerfile.archlinux-clang
Normal file
6
tests/dockerfiles/Dockerfile.archlinux-clang
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
ARG IMAGE=registry.gitlab.com/brndnmtthws-oss/conky
|
||||
FROM ${IMAGE}/builder/archlinux-base:latest
|
||||
|
||||
RUN pacman -Syu --noconfirm --needed \
|
||||
clang \
|
||||
libc++
|
||||
5
tests/dockerfiles/Dockerfile.archlinux-gcc
Normal file
5
tests/dockerfiles/Dockerfile.archlinux-gcc
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
ARG IMAGE=registry.gitlab.com/brndnmtthws-oss/conky
|
||||
FROM ${IMAGE}/builder/archlinux-base:latest
|
||||
|
||||
RUN pacman -Syu --noconfirm --needed \
|
||||
gcc
|
||||
36
tests/dockerfiles/Dockerfile.fedora-31-base
Normal file
36
tests/dockerfiles/Dockerfile.fedora-31-base
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
FROM fedora:31
|
||||
|
||||
RUN dnf update -y -q \
|
||||
&& dnf -y -q install \
|
||||
audacious-devel \
|
||||
cairo-devel \
|
||||
cmake \
|
||||
dbus-glib-devel \
|
||||
docbook2X \
|
||||
freetype-devel \
|
||||
git \
|
||||
imlib2-devel \
|
||||
lcov \
|
||||
libcurl-devel \
|
||||
libical-devel \
|
||||
libircclient-devel \
|
||||
libmicrohttpd-devel \
|
||||
librsvg2-devel \
|
||||
libX11-devel \
|
||||
libXdamage-devel \
|
||||
libXext-devel \
|
||||
libXft-devel \
|
||||
libXinerama-devel \
|
||||
libxml2-devel \
|
||||
libXNVCtrl-devel \
|
||||
lua-devel \
|
||||
make \
|
||||
man \
|
||||
mysql-devel \
|
||||
ncurses-devel \
|
||||
openssl-devel \
|
||||
patch \
|
||||
pulseaudio-libs-devel \
|
||||
readline-devel \
|
||||
systemd-devel \
|
||||
xmms2-devel
|
||||
11
tests/dockerfiles/Dockerfile.fedora-31-clang-8
Normal file
11
tests/dockerfiles/Dockerfile.fedora-31-clang-8
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
ARG IMAGE=registry.gitlab.com/brndnmtthws-oss/conky
|
||||
FROM ${IMAGE}/builder/fedora-31-base:latest
|
||||
|
||||
RUN dnf -y -q install \
|
||||
llvm \
|
||||
clang \
|
||||
libcxx-devel \
|
||||
libcxxabi-devel \
|
||||
npm \
|
||||
&& dnf clean all \
|
||||
&& npm cache clean --force
|
||||
36
tests/dockerfiles/Dockerfile.fedora-32-base
Normal file
36
tests/dockerfiles/Dockerfile.fedora-32-base
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
FROM fedora:32
|
||||
|
||||
RUN dnf update -y -q \
|
||||
&& dnf -y -q install \
|
||||
audacious-devel \
|
||||
cairo-devel \
|
||||
cmake \
|
||||
dbus-glib-devel \
|
||||
docbook2X \
|
||||
freetype-devel \
|
||||
git \
|
||||
imlib2-devel \
|
||||
lcov \
|
||||
libcurl-devel \
|
||||
libical-devel \
|
||||
libircclient-devel \
|
||||
libmicrohttpd-devel \
|
||||
librsvg2-devel \
|
||||
libX11-devel \
|
||||
libXdamage-devel \
|
||||
libXext-devel \
|
||||
libXft-devel \
|
||||
libXinerama-devel \
|
||||
libxml2-devel \
|
||||
libXNVCtrl-devel \
|
||||
lua-devel \
|
||||
make \
|
||||
man \
|
||||
mysql-devel \
|
||||
ncurses-devel \
|
||||
openssl-devel \
|
||||
patch \
|
||||
pulseaudio-libs-devel \
|
||||
readline-devel \
|
||||
systemd-devel \
|
||||
xmms2-devel
|
||||
11
tests/dockerfiles/Dockerfile.fedora-32-clang-10
Normal file
11
tests/dockerfiles/Dockerfile.fedora-32-clang-10
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
ARG IMAGE=registry.gitlab.com/brndnmtthws-oss/conky
|
||||
FROM ${IMAGE}/builder/fedora-32-base:latest
|
||||
|
||||
RUN dnf -y -q install \
|
||||
llvm \
|
||||
clang \
|
||||
libcxx-devel \
|
||||
libcxxabi-devel \
|
||||
npm \
|
||||
&& dnf clean all \
|
||||
&& npm cache clean --force
|
||||
36
tests/dockerfiles/Dockerfile.fedora-33-base
Normal file
36
tests/dockerfiles/Dockerfile.fedora-33-base
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
FROM fedora:33
|
||||
|
||||
RUN dnf update -y -q \
|
||||
&& dnf -y -q install \
|
||||
audacious-devel \
|
||||
cairo-devel \
|
||||
cmake \
|
||||
dbus-glib-devel \
|
||||
docbook2X \
|
||||
freetype-devel \
|
||||
git \
|
||||
imlib2-devel \
|
||||
lcov \
|
||||
libcurl-devel \
|
||||
libical-devel \
|
||||
libircclient-devel \
|
||||
libmicrohttpd-devel \
|
||||
librsvg2-devel \
|
||||
libX11-devel \
|
||||
libXdamage-devel \
|
||||
libXext-devel \
|
||||
libXft-devel \
|
||||
libXinerama-devel \
|
||||
libxml2-devel \
|
||||
libXNVCtrl-devel \
|
||||
lua-devel \
|
||||
make \
|
||||
man \
|
||||
mysql-devel \
|
||||
ncurses-devel \
|
||||
openssl-devel \
|
||||
patch \
|
||||
pulseaudio-libs-devel \
|
||||
readline-devel \
|
||||
systemd-devel \
|
||||
xmms2-devel
|
||||
13
tests/dockerfiles/Dockerfile.fedora-33-clang-11
Normal file
13
tests/dockerfiles/Dockerfile.fedora-33-clang-11
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
ARG IMAGE=registry.gitlab.com/brndnmtthws-oss/conky
|
||||
FROM ${IMAGE}/builder/fedora-33-base:latest
|
||||
|
||||
RUN dnf -y -q install \
|
||||
clang \
|
||||
gcovr \
|
||||
libcxx-devel \
|
||||
libcxxabi-devel \
|
||||
llvm \
|
||||
npm \
|
||||
&& dnf clean all \
|
||||
&& npm install -g lcov-summary \
|
||||
&& npm cache clean --force
|
||||
40
tests/dockerfiles/Dockerfile.ubuntu-base
Normal file
40
tests/dockerfiles/Dockerfile.ubuntu-base
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
FROM ubuntu:focal
|
||||
|
||||
RUN apt-get update \
|
||||
&& DEBIAN_FRONTEND=noninteractive \
|
||||
apt-get install -qy --no-install-recommends \
|
||||
audacious-dev \
|
||||
build-essential \
|
||||
cmake \
|
||||
docbook2x \
|
||||
git \
|
||||
gpg \
|
||||
gpg-agent \
|
||||
lcov \
|
||||
less \
|
||||
libaudclient-dev \
|
||||
libcairo2-dev \
|
||||
libcurl4-openssl-dev \
|
||||
libical-dev \
|
||||
libimlib2-dev \
|
||||
libircclient-dev \
|
||||
libiw-dev \
|
||||
liblua5.3-dev \
|
||||
libmicrohttpd-dev \
|
||||
libmysqlclient-dev \
|
||||
libpulse-dev \
|
||||
librsvg2-dev \
|
||||
libssl-dev \
|
||||
libsystemd-dev \
|
||||
libxdamage-dev \
|
||||
libxext-dev \
|
||||
libxft-dev \
|
||||
libxinerama-dev \
|
||||
libxml2-dev \
|
||||
libxmmsclient-dev \
|
||||
libxnvctrl-dev \
|
||||
man \
|
||||
ncurses-dev \
|
||||
software-properties-common \
|
||||
wget
|
||||
|
||||
18
tests/dockerfiles/Dockerfile.ubuntu-clang-10
Normal file
18
tests/dockerfiles/Dockerfile.ubuntu-clang-10
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
ARG IMAGE=registry.gitlab.com/brndnmtthws-oss/conky
|
||||
FROM ${IMAGE}/builder/ubuntu-base:latest
|
||||
|
||||
RUN wget -q https://apt.llvm.org/llvm-snapshot.gpg.key \
|
||||
&& apt-key add llvm-snapshot.gpg.key \
|
||||
&& add-apt-repository 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-10 main' \
|
||||
&& DEBIAN_FRONTEND=noninteractive \
|
||||
apt-get install -qy --no-install-recommends \
|
||||
clang-10 \
|
||||
lldb-10 \
|
||||
lld-10 \
|
||||
libc++-10-dev \
|
||||
libc++abi-10-dev \
|
||||
clang-tools-10 \
|
||||
clang-format-10 \
|
||||
clang-tidy-10 \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
24
tests/dockerfiles/Dockerfile.ubuntu-clang-11
Normal file
24
tests/dockerfiles/Dockerfile.ubuntu-clang-11
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
ARG IMAGE=registry.gitlab.com/brndnmtthws-oss/conky
|
||||
FROM ${IMAGE}/builder/ubuntu-base:latest
|
||||
|
||||
RUN wget -q https://apt.llvm.org/llvm-snapshot.gpg.key \
|
||||
&& apt-key add llvm-snapshot.gpg.key \
|
||||
&& add-apt-repository 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-11 main' \
|
||||
&& DEBIAN_FRONTEND=noninteractive \
|
||||
apt-get install -qy --no-install-recommends \
|
||||
clang-11 \
|
||||
clang-format-11 \
|
||||
clang-tidy-11 \
|
||||
clang-tools-11 \
|
||||
gcovr \
|
||||
libc++-11-dev \
|
||||
libc++abi-11-dev \
|
||||
lld-11 \
|
||||
lldb-11 \
|
||||
llvm-11 \
|
||||
nodejs \
|
||||
npm \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& npm install -g lcov-summary \
|
||||
&& npm cache clean --force
|
||||
18
tests/dockerfiles/Dockerfile.ubuntu-clang-9
Normal file
18
tests/dockerfiles/Dockerfile.ubuntu-clang-9
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
ARG IMAGE=registry.gitlab.com/brndnmtthws-oss/conky
|
||||
FROM ${IMAGE}/builder/ubuntu-base:latest
|
||||
|
||||
RUN wget -q https://apt.llvm.org/llvm-snapshot.gpg.key \
|
||||
&& apt-key add llvm-snapshot.gpg.key \
|
||||
&& add-apt-repository 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-9 main' \
|
||||
&& DEBIAN_FRONTEND=noninteractive \
|
||||
apt-get install -qy --no-install-recommends \
|
||||
clang-9 \
|
||||
lldb-9 \
|
||||
lld-9 \
|
||||
libc++-9-dev \
|
||||
libc++abi-9-dev \
|
||||
clang-tools-9 \
|
||||
clang-format-9 \
|
||||
clang-tidy-9 \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
11
tests/dockerfiles/Dockerfile.ubuntu-gcc-10
Normal file
11
tests/dockerfiles/Dockerfile.ubuntu-gcc-10
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
ARG IMAGE=registry.gitlab.com/brndnmtthws-oss/conky
|
||||
FROM ${IMAGE}/builder/ubuntu-base:latest
|
||||
|
||||
RUN wget -q https://apt.llvm.org/llvm-snapshot.gpg.key \
|
||||
&& apt-key add llvm-snapshot.gpg.key \
|
||||
&& add-apt-repository ppa:ubuntu-toolchain-r/test \
|
||||
&& DEBIAN_FRONTEND=noninteractive \
|
||||
apt-get install -qy --no-install-recommends \
|
||||
g++-10 \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
11
tests/dockerfiles/Dockerfile.ubuntu-gcc-7
Normal file
11
tests/dockerfiles/Dockerfile.ubuntu-gcc-7
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
ARG IMAGE=registry.gitlab.com/brndnmtthws-oss/conky
|
||||
FROM ${IMAGE}/builder/ubuntu-base:latest
|
||||
|
||||
RUN wget -q https://apt.llvm.org/llvm-snapshot.gpg.key \
|
||||
&& apt-key add llvm-snapshot.gpg.key \
|
||||
&& add-apt-repository ppa:ubuntu-toolchain-r/test \
|
||||
&& DEBIAN_FRONTEND=noninteractive \
|
||||
apt-get install -qy --no-install-recommends \
|
||||
g++-7 \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
11
tests/dockerfiles/Dockerfile.ubuntu-gcc-8
Normal file
11
tests/dockerfiles/Dockerfile.ubuntu-gcc-8
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
ARG IMAGE=registry.gitlab.com/brndnmtthws-oss/conky
|
||||
FROM ${IMAGE}/builder/ubuntu-base:latest
|
||||
|
||||
RUN wget -q https://apt.llvm.org/llvm-snapshot.gpg.key \
|
||||
&& apt-key add llvm-snapshot.gpg.key \
|
||||
&& add-apt-repository ppa:ubuntu-toolchain-r/test \
|
||||
&& DEBIAN_FRONTEND=noninteractive \
|
||||
apt-get install -qy --no-install-recommends \
|
||||
g++-8 \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
11
tests/dockerfiles/Dockerfile.ubuntu-gcc-9
Normal file
11
tests/dockerfiles/Dockerfile.ubuntu-gcc-9
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
ARG IMAGE=registry.gitlab.com/brndnmtthws-oss/conky
|
||||
FROM ${IMAGE}/builder/ubuntu-base:latest
|
||||
|
||||
RUN wget -q https://apt.llvm.org/llvm-snapshot.gpg.key \
|
||||
&& apt-key add llvm-snapshot.gpg.key \
|
||||
&& add-apt-repository ppa:ubuntu-toolchain-r/test \
|
||||
&& DEBIAN_FRONTEND=noninteractive \
|
||||
apt-get install -qy --no-install-recommends \
|
||||
g++-9 \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
29
tests/llvm-gcov.sh
Executable file
29
tests/llvm-gcov.sh
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
llvm_version_suffixes=(
|
||||
""
|
||||
-15
|
||||
150
|
||||
-14
|
||||
140
|
||||
-13
|
||||
130
|
||||
-12
|
||||
120
|
||||
-11
|
||||
110
|
||||
100
|
||||
-10
|
||||
90
|
||||
-9
|
||||
)
|
||||
|
||||
for suffix in "${llvm_version_suffixes[@]}"; do
|
||||
llvm_cov_test="llvm-cov${suffix}"
|
||||
if hash $llvm_cov_test 2>/dev/null; then
|
||||
llvm_cov=$llvm_cov_test
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
exec $llvm_cov gcov "$@"
|
||||
111
tests/test-colours.cc
Normal file
111
tests/test-colours.cc
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
#include "catch2/catch.hpp"
|
||||
|
||||
#include <colours.h>
|
||||
#include <config.h>
|
||||
|
||||
TEST_CASE("parse_color correctly parses colours", "[colours][parse_color]") {
|
||||
SECTION("parsing abbreviated hex color") {
|
||||
auto colour = parse_color("#abc");
|
||||
REQUIRE(colour.alpha == 255);
|
||||
REQUIRE(colour.red == 0xaa);
|
||||
REQUIRE(colour.green == 0xbb);
|
||||
REQUIRE(colour.blue == 0xcc);
|
||||
}
|
||||
|
||||
SECTION("parsing abbreviated hex color with alpha") {
|
||||
auto colour = parse_color("#4abc");
|
||||
REQUIRE(colour.alpha == 0x44);
|
||||
REQUIRE(colour.red == 0xaa);
|
||||
REQUIRE(colour.green == 0xbb);
|
||||
REQUIRE(colour.blue == 0xcc);
|
||||
}
|
||||
|
||||
SECTION("parsing hex red") {
|
||||
auto colour = parse_color("#ff0000");
|
||||
REQUIRE(colour.alpha == 255);
|
||||
REQUIRE(colour.red == 255);
|
||||
REQUIRE(colour.green == 0);
|
||||
REQUIRE(colour.blue == 0);
|
||||
}
|
||||
|
||||
SECTION("parsing hex green") {
|
||||
auto colour = parse_color("#00ff00");
|
||||
REQUIRE(colour.alpha == 255);
|
||||
REQUIRE(colour.red == 0);
|
||||
REQUIRE(colour.green == 255);
|
||||
REQUIRE(colour.blue == 0);
|
||||
}
|
||||
|
||||
SECTION("parsing hex blue") {
|
||||
auto colour = parse_color("#0000ff");
|
||||
REQUIRE(colour.alpha == 255);
|
||||
REQUIRE(colour.red == 0);
|
||||
REQUIRE(colour.green == 0);
|
||||
REQUIRE(colour.blue == 255);
|
||||
}
|
||||
|
||||
SECTION("parsing red") {
|
||||
auto colour = parse_color("ff0000");
|
||||
REQUIRE(colour.alpha == 255);
|
||||
REQUIRE(colour.red == 255);
|
||||
REQUIRE(colour.green == 0);
|
||||
REQUIRE(colour.blue == 0);
|
||||
}
|
||||
|
||||
SECTION("parsing green") {
|
||||
auto colour = parse_color("00ff00");
|
||||
REQUIRE(colour.alpha == 255);
|
||||
REQUIRE(colour.red == 0);
|
||||
REQUIRE(colour.green == 255);
|
||||
REQUIRE(colour.blue == 0);
|
||||
}
|
||||
|
||||
SECTION("parsing blue") {
|
||||
auto colour = parse_color("0000ff");
|
||||
REQUIRE(colour.alpha == 255);
|
||||
REQUIRE(colour.red == 0);
|
||||
REQUIRE(colour.green == 0);
|
||||
REQUIRE(colour.blue == 255);
|
||||
}
|
||||
|
||||
SECTION("argb values produce the expected result") {
|
||||
auto colour = Colour::from_argb32(0x11223344);
|
||||
REQUIRE(colour.alpha == 0x11);
|
||||
REQUIRE(colour.red == 0x22);
|
||||
REQUIRE(colour.green == 0x33);
|
||||
REQUIRE(colour.blue == 0x44);
|
||||
}
|
||||
|
||||
#ifdef BUILD_COLOUR_NAME_MAP
|
||||
SECTION("it parses the colour 'red'") {
|
||||
auto colour = parse_color("red");
|
||||
REQUIRE(colour.alpha == 255);
|
||||
REQUIRE(colour.red == 255);
|
||||
REQUIRE(colour.green == 0);
|
||||
REQUIRE(colour.blue == 0);
|
||||
}
|
||||
|
||||
SECTION("it parses the colour 'green'") {
|
||||
auto colour = parse_color("green");
|
||||
REQUIRE(colour.alpha == 255);
|
||||
REQUIRE(colour.red == 0);
|
||||
REQUIRE(colour.green == 255);
|
||||
REQUIRE(colour.blue == 0);
|
||||
}
|
||||
|
||||
SECTION("it parses the colour 'blue'") {
|
||||
auto colour = parse_color("blue");
|
||||
REQUIRE(colour.alpha == 255);
|
||||
REQUIRE(colour.red == 0);
|
||||
REQUIRE(colour.green == 0);
|
||||
REQUIRE(colour.blue == 255);
|
||||
}
|
||||
#endif /* BUILD_COLOUR_NAME_MAP */
|
||||
|
||||
SECTION("two identical colours should be equal") {
|
||||
auto c = GENERATE(take(100, random((uint32_t)0, (uint32_t)0xffffffff)));
|
||||
auto colour1 = Colour::from_argb32(c);
|
||||
auto colour2 = Colour::from_argb32(c);
|
||||
REQUIRE(colour1 == colour2);
|
||||
}
|
||||
}
|
||||
244
tests/test-common.cc
Normal file
244
tests/test-common.cc
Normal file
|
|
@ -0,0 +1,244 @@
|
|||
/*
|
||||
*
|
||||
* Conky, a system monitor, based on torsmo
|
||||
*
|
||||
* Any original torsmo code is licensed under the BSD license
|
||||
*
|
||||
* All code written since the fork of torsmo is licensed under the GPL
|
||||
*
|
||||
* Please see COPYING for details
|
||||
*
|
||||
* Copyright (c) 2005-2024 Brenden Matthews, Philip Kovacs, et. al.
|
||||
* (see AUTHORS)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do
|
||||
// this in one cpp file
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
|
||||
#include <common.h>
|
||||
#include <conky.h>
|
||||
|
||||
extern char **environ;
|
||||
|
||||
std::string get_valid_environment_variable_name() {
|
||||
if (getenv("HOME") != nullptr) { return "HOME"; }
|
||||
|
||||
// If HOME is not a valid environment variable name, try to get a valid one.
|
||||
char *env_var = *environ;
|
||||
|
||||
for (int i = 1; env_var; i++) {
|
||||
std::string variable_name(env_var);
|
||||
int variable_name_length = variable_name.find('=');
|
||||
variable_name = variable_name.substr(0, variable_name_length);
|
||||
|
||||
if (getenv(variable_name.c_str()) != nullptr) { return variable_name; }
|
||||
|
||||
env_var = *(environ + i);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string get_invalid_environment_variable_name() {
|
||||
std::string variable_name = "INVALIDVARIABLENAME";
|
||||
|
||||
while (getenv(variable_name.c_str()) != nullptr) {
|
||||
variable_name += std::to_string(variable_name.length());
|
||||
}
|
||||
|
||||
return variable_name;
|
||||
}
|
||||
|
||||
TEST_CASE("to_real_path becomes homedir", "[to_real_path]") {
|
||||
REQUIRE(to_real_path("~/test") == std::string(getenv("HOME")) + "/test");
|
||||
}
|
||||
|
||||
TEST_CASE("environment variables are substituted correctly",
|
||||
"[variable_substitute]") {
|
||||
std::string valid_name = get_valid_environment_variable_name();
|
||||
std::string valid_value = getenv(valid_name.c_str());
|
||||
std::string invalid_name = get_invalid_environment_variable_name();
|
||||
|
||||
SECTION("an empty string input returns an empty string") {
|
||||
REQUIRE(variable_substitute("") == "");
|
||||
}
|
||||
|
||||
SECTION("string in with no $ returns same string") {
|
||||
std::string string_alpha = "abcdefghijklmnopqrstuvwxyz";
|
||||
std::string string_numbers = "1234567890";
|
||||
std::string string_special = "`~!@#$%^&*()-=_+[]{}\\|;:'\",<.>/?";
|
||||
std::string string_valid_name = valid_name;
|
||||
|
||||
REQUIRE(variable_substitute(string_alpha) == string_alpha);
|
||||
REQUIRE(variable_substitute(string_numbers) == string_numbers);
|
||||
REQUIRE(variable_substitute(string_special) == string_special);
|
||||
REQUIRE(variable_substitute(string_valid_name) == string_valid_name);
|
||||
}
|
||||
|
||||
SECTION("invalid variables are removed from return string") {
|
||||
std::string string_in_1 = "a$" + invalid_name + " z";
|
||||
std::string string_in_2 = "a${" + invalid_name + "} z";
|
||||
std::string string_in_3 = "a${" + invalid_name + " " + valid_name + "} z";
|
||||
std::string string_in_4 = "a${ " + valid_name + "} z";
|
||||
std::string string_in_5 = "a${" + valid_name + " } z";
|
||||
std::string string_in_6 = "a$" + valid_name + "z z";
|
||||
std::string string_in_7 = "a$" + invalid_name + "# z";
|
||||
|
||||
REQUIRE(variable_substitute(string_in_1) == "a z");
|
||||
REQUIRE(variable_substitute(string_in_2) == "a z");
|
||||
REQUIRE(variable_substitute(string_in_3) == "a z");
|
||||
REQUIRE(variable_substitute(string_in_4) == "a z");
|
||||
REQUIRE(variable_substitute(string_in_5) == "a z");
|
||||
REQUIRE(variable_substitute(string_in_6) == "a z");
|
||||
REQUIRE(variable_substitute(string_in_7) == "a# z");
|
||||
}
|
||||
|
||||
SECTION("valid variable gets replaced in the return string") {
|
||||
std::string string_in_1 = "a$" + valid_name + " z";
|
||||
std::string string_in_2 = "a${" + valid_name + "} z";
|
||||
std::string string_in_3 = "a$" + valid_name + "# z";
|
||||
|
||||
std::string string_var_replaced_1 = "a" + valid_value + " z";
|
||||
std::string string_var_replaced_2 = "a" + valid_value + " z";
|
||||
std::string string_var_replaced_3 = "a" + valid_value + "# z";
|
||||
|
||||
REQUIRE(variable_substitute(string_in_1) == string_var_replaced_1);
|
||||
REQUIRE(variable_substitute(string_in_2) == string_var_replaced_2);
|
||||
REQUIRE(variable_substitute(string_in_3) == string_var_replaced_3);
|
||||
}
|
||||
|
||||
SECTION("$ without variable is ignored") {
|
||||
std::string string_in_1 = "a$#z";
|
||||
std::string string_in_2 = "a$2z";
|
||||
|
||||
REQUIRE(variable_substitute(string_in_1) == string_in_1);
|
||||
REQUIRE(variable_substitute(string_in_2) == string_in_2);
|
||||
}
|
||||
|
||||
SECTION("double $ gets converted to single $ and is passed over") {
|
||||
std::string string_in_1 = "a$$sz";
|
||||
std::string string_in_2 = "a$$" + valid_name + "z";
|
||||
std::string string_out_1 = "a$sz";
|
||||
std::string string_out_2 = "a$" + valid_name + "z";
|
||||
|
||||
REQUIRE(variable_substitute(string_in_1) == string_out_1);
|
||||
REQUIRE(variable_substitute(string_in_2) == string_out_2);
|
||||
}
|
||||
|
||||
SECTION("incomplete variable does not get replaced in return string") {
|
||||
std::string string_in = "a${" + valid_name + " z";
|
||||
|
||||
REQUIRE(variable_substitute(string_in) == string_in);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("cpu_percentage and cpu_barval return correct values") {
|
||||
struct text_object obj0;
|
||||
obj0.data.i = 0;
|
||||
struct text_object obj1;
|
||||
obj1.data.i = 1;
|
||||
// struct text_object obj2;
|
||||
// obj2.data.i = 2;
|
||||
info.cpu_count = 1;
|
||||
|
||||
// SECTION("for non-existent cpu") {
|
||||
// info.cpu_usage = new float[2];
|
||||
// info.cpu_usage[0] = 0.253;
|
||||
// info.cpu_usage[1] = 0.507;
|
||||
|
||||
// This does not exist in Catch2, but would be nice to have since that's
|
||||
// what happens in this case.
|
||||
// REQUIRE_EXIT(cpu_percentage(&obj2));
|
||||
// REQUIRE_EXIT(cpu_barval(&obj2));
|
||||
|
||||
// delete[] info.cpu_usage;
|
||||
// }
|
||||
|
||||
SECTION("for cpu_usage == nullptr") {
|
||||
info.cpu_usage = nullptr;
|
||||
|
||||
REQUIRE(cpu_percentage(&obj0) == 0);
|
||||
REQUIRE(cpu_barval(&obj0) == 0);
|
||||
REQUIRE(cpu_percentage(&obj1) == 0);
|
||||
REQUIRE(cpu_barval(&obj1) == 0);
|
||||
}
|
||||
|
||||
SECTION("for cpu_usage has data") {
|
||||
info.cpu_usage = new float[2];
|
||||
info.cpu_usage[0] = 0.253;
|
||||
info.cpu_usage[1] = 0.507;
|
||||
|
||||
REQUIRE(cpu_percentage(&obj0) == 25);
|
||||
REQUIRE(cpu_barval(&obj0) == Approx(0.253));
|
||||
REQUIRE(cpu_percentage(&obj1) == 51);
|
||||
REQUIRE(cpu_barval(&obj1) == Approx(0.507));
|
||||
|
||||
delete[] info.cpu_usage;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("mem_percentage and mem_barval return correct values") {
|
||||
info.mem = 6;
|
||||
|
||||
SECTION("for memmax == 0") {
|
||||
info.memmax = 0;
|
||||
|
||||
REQUIRE(mem_percentage(nullptr) == 0);
|
||||
REQUIRE(mem_barval(nullptr) == 0);
|
||||
}
|
||||
|
||||
SECTION("for memmax > 0") {
|
||||
info.memmax = 24;
|
||||
|
||||
REQUIRE(mem_percentage(nullptr) == 25);
|
||||
REQUIRE(mem_barval(nullptr) == Approx(0.25));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("mem_with_buffers_barval returns correct value") {
|
||||
info.memwithbuffers = 6;
|
||||
|
||||
SECTION("for memmax == 0") {
|
||||
info.memmax = 0;
|
||||
REQUIRE(mem_with_buffers_barval(nullptr) == 0);
|
||||
}
|
||||
|
||||
SECTION("for memmax > 0") {
|
||||
info.memmax = 24;
|
||||
REQUIRE(mem_with_buffers_barval(nullptr) == Approx(0.25));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("swap_percentage and swap_barval return correct values") {
|
||||
info.swap = 6;
|
||||
|
||||
SECTION("for swapmax == 0") {
|
||||
info.swapmax = 0;
|
||||
|
||||
REQUIRE(swap_percentage(nullptr) == 0);
|
||||
REQUIRE(swap_barval(nullptr) == 0);
|
||||
}
|
||||
|
||||
SECTION("for swapmax > 0") {
|
||||
info.swapmax = 24;
|
||||
|
||||
REQUIRE(swap_percentage(nullptr) == 25);
|
||||
REQUIRE(swap_barval(nullptr) == Approx(0.25));
|
||||
}
|
||||
}
|
||||
45
tests/test-conky.cc
Normal file
45
tests/test-conky.cc
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
*
|
||||
* Conky, a system monitor, based on torsmo
|
||||
*
|
||||
* Any original torsmo code is licensed under the BSD license
|
||||
*
|
||||
* All code written since the fork of torsmo is licensed under the GPL
|
||||
*
|
||||
* Please see COPYING for details
|
||||
*
|
||||
* Copyright (c) 2005-2024 Brenden Matthews, Philip Kovacs, et. al.
|
||||
* (see AUTHORS)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
#include "conky.h"
|
||||
#include "lua-config.hh"
|
||||
|
||||
TEST_CASE("Expressions can be evaluated", "[evaluate]") {
|
||||
state = std::make_unique<lua::state>();
|
||||
conky::export_symbols(*state);
|
||||
|
||||
SECTION("Simple expressions without substitutions can be evaluated") {
|
||||
constexpr int kMaxSize = 10;
|
||||
const char input[kMaxSize] = "text";
|
||||
char result[kMaxSize]{'\0'};
|
||||
|
||||
evaluate(input, result, kMaxSize);
|
||||
REQUIRE(strncmp(input, result, kMaxSize) == 0);
|
||||
}
|
||||
}
|
||||
68
tests/test-core.cc
Normal file
68
tests/test-core.cc
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
*
|
||||
* Conky, a system monitor, based on torsmo
|
||||
*
|
||||
* Any original torsmo code is licensed under the BSD license
|
||||
*
|
||||
* All code written since the fork of torsmo is licensed under the GPL
|
||||
*
|
||||
* Please see COPYING for details
|
||||
*
|
||||
* Copyright (c) 2005-2024 Brenden Matthews, Philip Kovacs, et. al.
|
||||
* (see AUTHORS)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
|
||||
#include <core.h>
|
||||
|
||||
TEST_CASE("remove_comments returns correct value") {
|
||||
SECTION("for no comments") {
|
||||
char text[] = "test text\n";
|
||||
|
||||
size_t removed_chars = remove_comments(text);
|
||||
|
||||
REQUIRE(removed_chars == 0);
|
||||
}
|
||||
|
||||
SECTION("for no comments but with backslashes") {
|
||||
char text[] = "te\\st t\\ext\n";
|
||||
|
||||
size_t removed_chars = remove_comments(text);
|
||||
|
||||
REQUIRE(removed_chars == 0);
|
||||
}
|
||||
|
||||
SECTION("for single line of comment") {
|
||||
char text_with_newline[] = "#test text\n";
|
||||
char text_no_newline[] = "#test text";
|
||||
|
||||
size_t removed_chars_with_newline = remove_comments(text_with_newline);
|
||||
size_t removed_chars_no_newline = remove_comments(text_no_newline);
|
||||
|
||||
REQUIRE(removed_chars_with_newline == 11);
|
||||
REQUIRE(removed_chars_no_newline == 10);
|
||||
}
|
||||
|
||||
SECTION("for comment starting in middle of line") {
|
||||
char text[] = "test #text\n";
|
||||
|
||||
size_t removed_chars = remove_comments(text);
|
||||
|
||||
REQUIRE(removed_chars == 6);
|
||||
}
|
||||
}
|
||||
36
tests/test-darwin.cc
Normal file
36
tests/test-darwin.cc
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
*
|
||||
* Conky, a system monitor, based on torsmo
|
||||
*
|
||||
* Any original torsmo code is licensed under the BSD license
|
||||
*
|
||||
* All code written since the fork of torsmo is licensed under the GPL
|
||||
*
|
||||
* Please see COPYING for details
|
||||
*
|
||||
* Copyright (c) 2005-2024 Brenden Matthews, Philip Kovacs, et. al.
|
||||
* (see AUTHORS)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
|
||||
#include <darwin.h>
|
||||
|
||||
TEST_CASE("get_entropy_avail returns 1", "[get_entropy_avail]") {
|
||||
unsigned int unused = 0;
|
||||
REQUIRE(get_entropy_avail(&unused) == 1);
|
||||
}
|
||||
50
tests/test-diskio.cc
Normal file
50
tests/test-diskio.cc
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
*
|
||||
* Conky, a system monitor, based on torsmo
|
||||
*
|
||||
* Any original torsmo code is licensed under the BSD license
|
||||
*
|
||||
* All code written since the fork of torsmo is licensed under the GPL
|
||||
*
|
||||
* Please see COPYING for details
|
||||
*
|
||||
* Copyright (c) 2005-2024 Brenden Matthews, Philip Kovacs, et. al.
|
||||
* (see AUTHORS)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
|
||||
#include <config.h>
|
||||
#include <conky.h>
|
||||
#include <diskio.h>
|
||||
|
||||
#if BUILD_X11
|
||||
TEST_CASE("diskiographval returns correct value") {
|
||||
struct text_object obj;
|
||||
|
||||
SECTION("for valid data") {
|
||||
diskio_stat *diskio = new diskio_stat;
|
||||
diskio->current = 2.5;
|
||||
|
||||
obj.data.opaque = diskio;
|
||||
|
||||
REQUIRE(diskiographval(&obj) == Approx(2.5));
|
||||
|
||||
delete diskio;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
61
tests/test-fs.cc
Normal file
61
tests/test-fs.cc
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
*
|
||||
* Conky, a system monitor, based on torsmo
|
||||
*
|
||||
* Any original torsmo code is licensed under the BSD license
|
||||
*
|
||||
* All code written since the fork of torsmo is licensed under the GPL
|
||||
*
|
||||
* Please see COPYING for details
|
||||
*
|
||||
* Copyright (c) 2005-2024 Brenden Matthews, Philip Kovacs, et. al.
|
||||
* (see AUTHORS)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
|
||||
#include <fs.h>
|
||||
|
||||
TEST_CASE("fs_free_percentage returns correct value") {
|
||||
struct text_object obj;
|
||||
|
||||
SECTION("for fs size == 0") {
|
||||
fs_stat *fs = new fs_stat;
|
||||
fs->size = 0;
|
||||
fs->avail = 17;
|
||||
fs->free = 97;
|
||||
|
||||
obj.data.opaque = fs;
|
||||
|
||||
REQUIRE(fs_free_percentage(&obj) == 0);
|
||||
|
||||
delete fs;
|
||||
}
|
||||
|
||||
SECTION("for valid data") {
|
||||
fs_stat *fs = new fs_stat;
|
||||
fs->size = 68;
|
||||
fs->avail = 17;
|
||||
fs->free = 97;
|
||||
|
||||
obj.data.opaque = fs;
|
||||
|
||||
REQUIRE(fs_free_percentage(&obj) == 25);
|
||||
|
||||
delete fs;
|
||||
}
|
||||
}
|
||||
139
tests/test-gradient.cc
Normal file
139
tests/test-gradient.cc
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
*
|
||||
* Conky, a system monitor, based on torsmo
|
||||
*
|
||||
* Any original torsmo code is licensed under the BSD license
|
||||
*
|
||||
* All code written since the fork of torsmo is licensed under the GPL
|
||||
*
|
||||
* Please see COPYING for details
|
||||
*
|
||||
* Copyright (c) 2005-2024 Brenden Matthews, Philip Kovacs, et. al.
|
||||
* (see AUTHORS)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
|
||||
#include <colours.h>
|
||||
#include <conky.h>
|
||||
#include <gradient.h>
|
||||
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
const int width = 4;
|
||||
const Colour colour = Colour::from_argb32(0xff996633); // brown
|
||||
const long expected_hue = 256;
|
||||
const long expected_value = 0x99; // max(0x99, 0x66, 0x33)
|
||||
const long expected_chroma = 0x66; // (0x99 - 0x33)
|
||||
const long expected_luma = 20712665L;
|
||||
const long expected_saturation = 122880L;
|
||||
const long expected_red = 0x99;
|
||||
const long expected_green = 0x66;
|
||||
const long expected_blue = 0x33;
|
||||
|
||||
const long full_scale = conky::gradient_factory::SCALE360;
|
||||
|
||||
std::ostream& operator<<(std::ostream& s, const Colour& c) {
|
||||
s << '#';
|
||||
s << std::setfill('0');
|
||||
s << std::setw(2);
|
||||
s << std::setbase(16);
|
||||
s << (int)c.alpha << (int)c.red << (int)c.green << (int)c.blue;
|
||||
return s;
|
||||
}
|
||||
|
||||
TEST_CASE("gradient_factory::convert_from_rgb returns correct value") {
|
||||
#ifdef BUILD_X11
|
||||
state = nullptr;
|
||||
#endif
|
||||
SECTION("rgb_gradient_factory") {
|
||||
auto factory = new conky::rgb_gradient_factory(width, colour, colour);
|
||||
long result[3];
|
||||
|
||||
factory->convert_from_rgb(colour, result);
|
||||
|
||||
SECTION("red") { REQUIRE(result[0] == expected_red * full_scale); }
|
||||
SECTION("green") { REQUIRE(result[1] == expected_green * full_scale); }
|
||||
SECTION("blue") { REQUIRE(result[2] == expected_blue * full_scale); }
|
||||
|
||||
delete factory;
|
||||
}
|
||||
|
||||
SECTION("hsv_gradient_factory") {
|
||||
auto factory = new conky::hsv_gradient_factory(width, colour, colour);
|
||||
long result[3];
|
||||
|
||||
factory->convert_from_rgb(colour, result);
|
||||
|
||||
SECTION("hue") { REQUIRE(result[0] == expected_hue * 60); }
|
||||
SECTION("saturation") { REQUIRE(result[1] == expected_saturation); }
|
||||
SECTION("value") { REQUIRE(result[2] == expected_value * full_scale); }
|
||||
|
||||
delete factory;
|
||||
}
|
||||
|
||||
SECTION("hcl_gradient_factory") {
|
||||
auto factory = new conky::hcl_gradient_factory(width, colour, colour);
|
||||
long result[3];
|
||||
|
||||
factory->convert_from_rgb(colour, result);
|
||||
|
||||
SECTION("hue") { REQUIRE(result[0] == expected_hue * 60); }
|
||||
SECTION("chroma") { REQUIRE(result[1] == expected_chroma * full_scale); }
|
||||
SECTION("luma") { REQUIRE(result[2] == expected_luma); }
|
||||
|
||||
delete factory;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(
|
||||
"gradient_factory should convert to and from rgb "
|
||||
"and get the initial value") {
|
||||
SECTION("rgb_gradient_factory") {
|
||||
long tmp[3];
|
||||
auto factory = new conky::rgb_gradient_factory(width, colour, colour);
|
||||
factory->convert_from_rgb(colour, tmp);
|
||||
auto result = factory->convert_to_rgb(tmp);
|
||||
|
||||
REQUIRE(result == colour);
|
||||
|
||||
delete factory;
|
||||
}
|
||||
|
||||
SECTION("hsv_gradient_factory") {
|
||||
long tmp[3];
|
||||
auto factory = new conky::hsv_gradient_factory(width, colour, colour);
|
||||
factory->convert_from_rgb(colour, tmp);
|
||||
auto result = factory->convert_to_rgb(tmp);
|
||||
|
||||
REQUIRE(result == colour);
|
||||
|
||||
delete factory;
|
||||
}
|
||||
|
||||
SECTION("hcl_gradient_factory") {
|
||||
long tmp[3];
|
||||
auto factory = new conky::hcl_gradient_factory(width, colour, colour);
|
||||
factory->convert_from_rgb(colour, tmp);
|
||||
auto result = factory->convert_to_rgb(tmp);
|
||||
|
||||
REQUIRE(result == colour);
|
||||
|
||||
delete factory;
|
||||
}
|
||||
}
|
||||
216
tests/test-graph.cc
Normal file
216
tests/test-graph.cc
Normal file
|
|
@ -0,0 +1,216 @@
|
|||
/*
|
||||
*
|
||||
* Conky, a system monitor, based on torsmo
|
||||
*
|
||||
* Any original torsmo code is licensed under the BSD license
|
||||
*
|
||||
* All code written since the fork of torsmo is licensed under the GPL
|
||||
*
|
||||
* Please see COPYING for details
|
||||
*
|
||||
* Copyright (c) 2005-2024 Brenden Matthews, Philip Kovacs, et. al.
|
||||
* (see AUTHORS)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <tuple>
|
||||
#include "catch2/catch.hpp"
|
||||
#include "conky.h"
|
||||
#include "lua-config.hh"
|
||||
#include "specials.h"
|
||||
|
||||
#ifdef BUILD_GUI
|
||||
|
||||
#define SF_SHOWLOG (1 << 1)
|
||||
|
||||
// Specific value doesn't matter, but we check if the same one comes back
|
||||
constexpr double default_scale = M_PI;
|
||||
|
||||
constexpr double default_width = 0;
|
||||
constexpr double default_height = 25;
|
||||
|
||||
struct graph {
|
||||
int id;
|
||||
char flags;
|
||||
int width, height;
|
||||
bool colours_set;
|
||||
Colour first_colour, last_colour;
|
||||
double scale;
|
||||
char tempgrad;
|
||||
};
|
||||
|
||||
static std::pair<struct graph, bool> test_parse(const char *s) {
|
||||
struct text_object obj;
|
||||
bool result = scan_graph(&obj, s, default_scale);
|
||||
auto g = static_cast<struct graph *>(obj.special_data);
|
||||
struct graph graph = *g;
|
||||
free(g);
|
||||
return {graph, result};
|
||||
}
|
||||
|
||||
std::string unquote(const std::string &s) {
|
||||
auto out = s;
|
||||
out.erase(remove(out.begin(), out.end(), '\"'), out.end());
|
||||
return out;
|
||||
}
|
||||
|
||||
TEST_CASE("scan_graph correctly parses input strings") {
|
||||
state = std::make_unique<lua::state>();
|
||||
conky::export_symbols(*state);
|
||||
|
||||
SECTION("Trivial parse") {
|
||||
auto [g, success] = test_parse("");
|
||||
|
||||
REQUIRE(g.width == default_width);
|
||||
REQUIRE(g.height == default_height);
|
||||
}
|
||||
|
||||
/* test parsing combinations of options */
|
||||
const char *size_options[][2] = {{"30", "500"}, {"80", ""}, {"", ""}};
|
||||
const char *color_options[][2] = {{"orange", "blue"},
|
||||
{"#deadff", "#392014"},
|
||||
{"000000", "000000"},
|
||||
{"", ""}};
|
||||
const char *scale_options[] = {"0.5", ""};
|
||||
|
||||
SECTION("subset of [height,width] [color1 color2] [scale] [-t] [-l]") {
|
||||
for (auto size : size_options) {
|
||||
for (auto colors : color_options) {
|
||||
for (auto scale : scale_options) {
|
||||
bool ends_at_first_size = false;
|
||||
|
||||
/* build an argument string by combining the selected options */
|
||||
std::string s;
|
||||
if (*size[0] != '\0') {
|
||||
s += size[0];
|
||||
s += ",";
|
||||
if (*size[1] == '\0') {
|
||||
/* if the size is just a height, it has to be the end of the
|
||||
* argument string */
|
||||
ends_at_first_size = true;
|
||||
} else {
|
||||
s += size[1];
|
||||
}
|
||||
s += " ";
|
||||
}
|
||||
if (!ends_at_first_size) {
|
||||
s += colors[0];
|
||||
s += " ";
|
||||
s += colors[1];
|
||||
s += " ";
|
||||
s += scale;
|
||||
}
|
||||
|
||||
/* parse the argument string */
|
||||
auto [g, success] = test_parse(s.c_str());
|
||||
|
||||
printf("command: %s\n", s.c_str());
|
||||
|
||||
/* validate parsing of each component */
|
||||
if (*size[0] == '\0') {
|
||||
REQUIRE(g.width == default_width);
|
||||
REQUIRE(g.height == default_height);
|
||||
} else {
|
||||
REQUIRE(g.height == atoi(size[0]));
|
||||
REQUIRE(g.width == atoi(size[1]));
|
||||
}
|
||||
|
||||
/* if second half of size is empty, no subsequent values should be
|
||||
* set
|
||||
*/
|
||||
if (ends_at_first_size) {
|
||||
REQUIRE(g.colours_set == false);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (*colors[0] == '\0') {
|
||||
REQUIRE(g.colours_set == false);
|
||||
} else {
|
||||
REQUIRE(g.colours_set == true);
|
||||
REQUIRE(g.first_colour == parse_color(colors[0]));
|
||||
REQUIRE(g.last_colour == parse_color(colors[1]));
|
||||
}
|
||||
|
||||
if (*scale == '\0') {
|
||||
REQUIRE(g.scale == default_scale);
|
||||
} else {
|
||||
REQUIRE(g.scale == 0.5);
|
||||
}
|
||||
|
||||
REQUIRE(g.flags == 0);
|
||||
REQUIRE(g.tempgrad == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("[height,width] [color1 color2] [scale] [-t] [-l]") {
|
||||
auto [g, success] = test_parse("21,340 orange blue 0.5 -t -l");
|
||||
|
||||
REQUIRE(success);
|
||||
REQUIRE(g.width == 340);
|
||||
REQUIRE(g.height == 21);
|
||||
REQUIRE(g.colours_set == true);
|
||||
REQUIRE(g.scale == 0.5);
|
||||
REQUIRE(g.flags == SF_SHOWLOG);
|
||||
REQUIRE(g.tempgrad == true);
|
||||
}
|
||||
|
||||
SECTION("-t location") {
|
||||
{
|
||||
auto [g, success] = test_parse("21,340 red blue 0.5");
|
||||
REQUIRE(g.tempgrad == false);
|
||||
}
|
||||
{
|
||||
auto [g, success] = test_parse("21,340 red blue 0.5");
|
||||
REQUIRE(g.tempgrad == false);
|
||||
}
|
||||
{
|
||||
auto [g, success] = test_parse("-t 21,340 red blue 0.5");
|
||||
REQUIRE(g.tempgrad == true);
|
||||
}
|
||||
{
|
||||
auto [g, success] = test_parse("21,340 -t red blue 0.5");
|
||||
REQUIRE(g.tempgrad == true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("scan_command correctly parses input strings") {
|
||||
SECTION("parse commands") {
|
||||
const char *command_options[][2] = {{"\"foo bar\"", "foo bar"},
|
||||
{"\"foo bar\"\tbaz", "foo bar"},
|
||||
{"\"foo bar\"\nbaz", "foo bar"},
|
||||
{"\"foo bar\" baz", "foo bar"},
|
||||
{"one two", "one"},
|
||||
{"\"ls -t\"", "ls -t"},
|
||||
{"\"ls -t\" 4309", "ls -t"},
|
||||
{"foo-test", "foo-test"},
|
||||
{"foo-test a b c", "foo-test"},
|
||||
{"", ""}};
|
||||
for (auto [command, expected_parsed] : command_options) {
|
||||
auto [parsed, len] = scan_command(command);
|
||||
REQUIRE(std::string(parsed) == expected_parsed);
|
||||
if (command[0] == '"') {
|
||||
REQUIRE(len == strlen(expected_parsed) + 2);
|
||||
} else {
|
||||
REQUIRE(len == strlen(expected_parsed));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* BUILD_GUI */
|
||||
36
tests/test-linux.cc
Normal file
36
tests/test-linux.cc
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
*
|
||||
* Conky, a system monitor, based on torsmo
|
||||
*
|
||||
* Any original torsmo code is licensed under the BSD license
|
||||
*
|
||||
* All code written since the fork of torsmo is licensed under the GPL
|
||||
*
|
||||
* Please see COPYING for details
|
||||
*
|
||||
* Copyright (c) 2005-2024 Brenden Matthews, Philip Kovacs, et. al.
|
||||
* (see AUTHORS)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
|
||||
#include <linux.h>
|
||||
|
||||
TEST_CASE("get_entropy_avail returns 0", "[get_entropy_avail]") {
|
||||
unsigned int unused = 0;
|
||||
REQUIRE(get_entropy_avail(&unused) == 0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue