Skip to content

Commit 1ad078c

Browse files
authored
tests: move out of source tree (#20)
1 parent 77e6228 commit 1ad078c

File tree

7 files changed

+207
-221
lines changed

7 files changed

+207
-221
lines changed

CMakeLists.txt

Lines changed: 42 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -86,53 +86,6 @@ if(NOT HAS_INOTIFY AND inotify_FOUND)
8686
target_link_libraries(hyprtoolkit PUBLIC PkgConfig::inotify)
8787
endif()
8888

89-
if(NOT DISABLE_TESTS)
90-
enable_testing()
91-
92-
# test apps
93-
add_custom_target(tests)
94-
95-
add_executable(simpleWindow "tests/SimpleWindow.cpp")
96-
target_link_libraries(simpleWindow PRIVATE PkgConfig::deps hyprtoolkit)
97-
add_dependencies(tests simpleWindow)
98-
99-
add_executable(dialog "tests/Dialog.cpp")
100-
target_link_libraries(dialog PRIVATE PkgConfig::deps hyprtoolkit)
101-
add_dependencies(tests dialog)
102-
103-
add_executable(controls "tests/Controls.cpp")
104-
target_link_libraries(controls PRIVATE PkgConfig::deps hyprtoolkit)
105-
add_dependencies(tests controls)
106-
107-
add_executable(simpleSessionLock "tests/SimpleSessionLock.cpp")
108-
target_link_libraries(simpleSessionLock PRIVATE PkgConfig::deps hyprtoolkit)
109-
add_dependencies(tests simpleSessionLock)
110-
111-
112-
# GTest
113-
find_package(GTest CONFIG REQUIRED)
114-
include(GoogleTest)
115-
add_executable(hyprtoolkit_inline_tests ${SRCFILES})
116-
target_compile_definitions(hyprtoolkit_inline_tests PRIVATE HT_UNIT_TESTS=1)
117-
target_compile_options(hyprtoolkit_inline_tests PRIVATE --coverage)
118-
target_link_options(hyprtoolkit_inline_tests PRIVATE --coverage)
119-
target_include_directories(
120-
hyprtoolkit_inline_tests
121-
PUBLIC "./include"
122-
PRIVATE "./src" "./src/include" "./protocols" "${CMAKE_BINARY_DIR}")
123-
target_link_libraries(
124-
hyprtoolkit_inline_tests PRIVATE GTest::gtest_main OpenGL::EGL
125-
OpenGL::OpenGL PkgConfig::deps)
126-
127-
if(NOT HAS_TIMERFD AND epoll_FOUND)
128-
target_link_libraries(hyprtoolkit_inline_tests PUBLIC PkgConfig::epoll)
129-
endif()
130-
if(NOT HAS_INOTIFY AND inotify_FOUND)
131-
target_link_libraries(hyprtoolkit_inline_tests PUBLIC PkgConfig::inotify)
132-
endif()
133-
gtest_discover_tests(hyprtoolkit_inline_tests)
134-
endif()
135-
13689
# Protocols
13790
pkg_get_variable(WAYLAND_PROTOCOLS_DIR wayland-protocols pkgdatadir)
13891
message(STATUS "Found wayland-protocols at ${WAYLAND_PROTOCOLS_DIR}")
@@ -154,10 +107,6 @@ function(protocolNew protoPath protoName external)
154107
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
155108
target_sources(hyprtoolkit PRIVATE protocols/${protoName}.cpp
156109
protocols/${protoName}.hpp)
157-
if(NOT DISABLE_TESTS)
158-
target_sources(hyprtoolkit_inline_tests PRIVATE protocols/${protoName}.cpp
159-
protocols/${protoName}.hpp)
160-
endif()
161110
endfunction()
162111
function(protocolWayland)
163112
add_custom_command(
@@ -169,10 +118,6 @@ function(protocolWayland)
169118
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
170119
target_sources(hyprtoolkit PRIVATE protocols/wayland.cpp
171120
protocols/wayland.hpp)
172-
if(NOT DISABLE_TESTS)
173-
target_sources(hyprtoolkit_inline_tests PRIVATE protocols/wayland.cpp
174-
protocols/wayland.hpp)
175-
endif()
176121
endfunction()
177122

178123
protocolwayland()
@@ -188,6 +133,48 @@ protocolnew("unstable/text-input" "text-input-unstable-v3" false)
188133
protocolnew("staging/linux-drm-syncobj" "linux-drm-syncobj-v1" false)
189134
protocolnew("protocols" "wlr-layer-shell-unstable-v1" true)
190135

136+
# Tests
137+
if(NOT DISABLE_TESTS)
138+
enable_testing()
139+
140+
# test apps
141+
add_custom_target(tests)
142+
143+
add_executable(simpleWindow "tests/SimpleWindow.cpp")
144+
target_link_libraries(simpleWindow PRIVATE PkgConfig::deps hyprtoolkit)
145+
add_dependencies(tests simpleWindow)
146+
147+
add_executable(dialog "tests/Dialog.cpp")
148+
target_link_libraries(dialog PRIVATE PkgConfig::deps hyprtoolkit)
149+
add_dependencies(tests dialog)
150+
151+
add_executable(controls "tests/Controls.cpp")
152+
target_link_libraries(controls PRIVATE PkgConfig::deps hyprtoolkit)
153+
add_dependencies(tests controls)
154+
155+
add_executable(simpleSessionLock "tests/SimpleSessionLock.cpp")
156+
target_link_libraries(simpleSessionLock PRIVATE PkgConfig::deps hyprtoolkit)
157+
add_dependencies(tests simpleSessionLock)
158+
159+
160+
# GTest
161+
find_package(GTest CONFIG REQUIRED)
162+
include(GoogleTest)
163+
file(GLOB_RECURSE TESTFILES CONFIGURE_DEPENDS "tests/unit/*.cpp")
164+
add_executable(hyprtoolkit_tests ${TESTFILES})
165+
target_compile_options(hyprtoolkit_tests PRIVATE --coverage)
166+
target_link_options(hyprtoolkit_tests PRIVATE --coverage)
167+
target_include_directories(
168+
hyprtoolkit_tests
169+
PUBLIC "./include"
170+
PRIVATE "./src" "./src/include" "./protocols" "${CMAKE_BINARY_DIR}")
171+
target_link_libraries(
172+
hyprtoolkit_tests PRIVATE hyprtoolkit GTest::gtest_main OpenGL::EGL
173+
OpenGL::OpenGL PkgConfig::deps)
174+
175+
gtest_discover_tests(hyprtoolkit_tests)
176+
endif()
177+
191178
# Installation
192179
install(TARGETS hyprtoolkit)
193180
install(DIRECTORY "include/hyprtoolkit" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

src/helpers/Env.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,3 @@ bool Hyprtoolkit::Env::isTrace() {
2020
static bool TRACE = envEnabled("HT_TRACE");
2121
return TRACE;
2222
}
23-
24-
#ifdef HT_UNIT_TESTS
25-
26-
#include <gtest/gtest.h>
27-
28-
TEST(Env, enabled) {
29-
setenv("HT_INTERNAL_TEST1", "1", 1);
30-
setenv("HT_INTERNAL_TEST2", "SUS", 1);
31-
setenv("HT_INTERNAL_TEST3", "0", 1);
32-
setenv("HT_INTERNAL_TEST4", "", 1);
33-
34-
EXPECT_EQ(Env::envEnabled("HT_INTERNAL_TEST1"), true);
35-
EXPECT_EQ(Env::envEnabled("HT_INTERNAL_TEST2"), true);
36-
EXPECT_EQ(Env::envEnabled("HT_INTERNAL_TEST3"), false);
37-
EXPECT_EQ(Env::envEnabled("HT_INTERNAL_TEST4"), false);
38-
}
39-
40-
#endif

src/helpers/UTF8.cpp

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -101,41 +101,3 @@ std::string UTF8::substr(const std::string& s, size_t start, size_t length) {
101101

102102
return s.substr(byteStart, byteEnd - byteStart);
103103
}
104-
105-
#ifdef HT_UNIT_TESTS
106-
107-
#include <gtest/gtest.h>
108-
109-
TEST(UTF8, Length) {
110-
EXPECT_EQ(UTF8::length(""), 0);
111-
EXPECT_EQ(UTF8::length("Hello"), 5);
112-
EXPECT_EQ(UTF8::length("世界"), 2);
113-
EXPECT_EQ(UTF8::length("世界is酷薄"), 6);
114-
}
115-
116-
TEST(UTF8, Substr) {
117-
EXPECT_EQ(UTF8::substr("", 0, 0), "");
118-
EXPECT_EQ(UTF8::substr("", 1), "");
119-
EXPECT_EQ(UTF8::substr("", 0, 0), "");
120-
EXPECT_EQ(UTF8::substr("Hello", 0, 3), "Hel");
121-
EXPECT_EQ(UTF8::substr("世界", 1, 1), "");
122-
EXPECT_EQ(UTF8::substr("世界is酷薄", 1), "界is酷薄");
123-
EXPECT_EQ(UTF8::substr("ハイパーランド", 1, 2), "イパ");
124-
}
125-
126-
TEST(UTF8, UTF8ToOffset) {
127-
EXPECT_EQ(UTF8::utf8ToOffset("", 0), 0);
128-
EXPECT_EQ(UTF8::utf8ToOffset("Hello", 20000), 5);
129-
EXPECT_EQ(UTF8::utf8ToOffset("Hello", 3), 3);
130-
EXPECT_EQ(UTF8::utf8ToOffset("魑魅魍魎", 3), 9);
131-
EXPECT_EQ(UTF8::utf8ToOffset("a魑魅魍魎", 3), 7);
132-
}
133-
134-
TEST(UTF8, offsetToUTF8Len) {
135-
EXPECT_EQ(UTF8::offsetToUTF8Len("", 0), 0);
136-
EXPECT_EQ(UTF8::offsetToUTF8Len("Hello", 3), 3);
137-
EXPECT_EQ(UTF8::offsetToUTF8Len("魑魅魍魎", 3), 1);
138-
EXPECT_EQ(UTF8::offsetToUTF8Len("a魑魅魍魎", 4), 2);
139-
}
140-
141-
#endif

src/layout/Positioner.cpp

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -111,113 +111,3 @@ void CPositioner::initElementIfNeeded(SP<IElement> el) {
111111

112112
el->impl->positionerData = makeUnique<Hyprtoolkit::SPositionerData>();
113113
}
114-
115-
#ifdef HT_UNIT_TESTS
116-
117-
// FIXME: These tests aren't very comprehensive.
118-
119-
#include <gtest/gtest.h>
120-
121-
#include <hyprtoolkit/element/Null.hpp>
122-
#include <hyprtoolkit/element/RowLayout.hpp>
123-
#include <hyprtoolkit/element/ColumnLayout.hpp>
124-
125-
TEST(Positioner, main) {
126-
auto root = CNullBuilder::begin()->size({CDynamicSize::HT_SIZE_ABSOLUTE, CDynamicSize::HT_SIZE_ABSOLUTE, {1000, 1000}})->commence();
127-
root->setMargin(4);
128-
auto rowLayoutMain = CRowLayoutBuilder::begin()->size({CDynamicSize::HT_SIZE_PERCENT, CDynamicSize::HT_SIZE_PERCENT, {1, 1}})->gap(10)->commence();
129-
root->addChild(rowLayoutMain);
130-
131-
auto columnLayoutLeft = CColumnLayoutBuilder::begin()->size({CDynamicSize::HT_SIZE_AUTO, CDynamicSize::HT_SIZE_PERCENT, {1, 1}})->gap(10)->commence();
132-
auto childLeft = CNullBuilder::begin()->size({CDynamicSize::HT_SIZE_ABSOLUTE, CDynamicSize::HT_SIZE_ABSOLUTE, {100, 200}})->commence();
133-
134-
auto nullRight = CNullBuilder::begin()->size({CDynamicSize::HT_SIZE_AUTO, CDynamicSize::HT_SIZE_PERCENT, {1, 1}})->commence();
135-
nullRight->setGrow(true);
136-
137-
auto columnLayoutRight = CColumnLayoutBuilder::begin()->size({CDynamicSize::HT_SIZE_AUTO, CDynamicSize::HT_SIZE_AUTO, {1, 1}})->gap(10)->commence();
138-
auto childRight = CNullBuilder::begin()->size({CDynamicSize::HT_SIZE_ABSOLUTE, CDynamicSize::HT_SIZE_ABSOLUTE, {200, 300}})->commence();
139-
auto childRight2 = CNullBuilder::begin()->size({CDynamicSize::HT_SIZE_ABSOLUTE, CDynamicSize::HT_SIZE_ABSOLUTE, {200, 300}})->commence();
140-
141-
childRight->setPositionMode(IElement::HT_POSITION_ABSOLUTE);
142-
childRight2->setPositionMode(IElement::HT_POSITION_ABSOLUTE);
143-
columnLayoutRight->setPositionMode(IElement::HT_POSITION_ABSOLUTE);
144-
145-
nullRight->addChild(columnLayoutRight);
146-
rowLayoutMain->addChild(columnLayoutLeft);
147-
rowLayoutMain->addChild(nullRight);
148-
149-
columnLayoutLeft->addChild(childLeft);
150-
151-
columnLayoutRight->addChild(childRight);
152-
columnLayoutRight->addChild(childRight2);
153-
154-
g_positioner->position(root, {{}, {1000, 1000}});
155-
g_positioner->positionChildren(root);
156-
157-
EXPECT_EQ(root->impl->position, CBox(4, 4, 992, 992));
158-
EXPECT_EQ(rowLayoutMain->impl->position, CBox(4, 4, 992, 992));
159-
EXPECT_EQ(columnLayoutLeft->impl->position, CBox(4, 4, 100, 992));
160-
EXPECT_EQ(columnLayoutRight->impl->position, CBox(114, 4, 200, 610));
161-
EXPECT_EQ(childRight2->impl->position, CBox(114, 314, 200, 300));
162-
}
163-
164-
TEST(Positioner, align) {
165-
auto root = CNullBuilder::begin()->size({CDynamicSize::HT_SIZE_ABSOLUTE, CDynamicSize::HT_SIZE_ABSOLUTE, {1000, 1000}})->commence();
166-
auto child = CNullBuilder::begin()->size({CDynamicSize::HT_SIZE_ABSOLUTE, CDynamicSize::HT_SIZE_ABSOLUTE, {10, 10}})->commence();
167-
child->setPositionMode(IElement::HT_POSITION_ABSOLUTE);
168-
169-
root->addChild(child);
170-
171-
g_positioner->position(root, {{}, {1000, 1000}});
172-
g_positioner->positionChildren(root);
173-
174-
EXPECT_EQ(child->impl->position, CBox(0, 0, 10, 10));
175-
176-
child->setPositionFlag(IElement::HT_POSITION_FLAG_VCENTER, true);
177-
178-
g_positioner->position(root, {{}, {1000, 1000}});
179-
g_positioner->positionChildren(root);
180-
181-
EXPECT_EQ(child->impl->position, CBox(0, 495, 10, 10));
182-
183-
child->setPositionFlag(IElement::HT_POSITION_FLAG_HCENTER, true);
184-
185-
g_positioner->position(root, {{}, {1000, 1000}});
186-
g_positioner->positionChildren(root);
187-
188-
EXPECT_EQ(child->impl->position, CBox(495, 495, 10, 10));
189-
190-
child->setPositionFlag(IElement::HT_POSITION_FLAG_VCENTER, false);
191-
child->setPositionFlag(IElement::HT_POSITION_FLAG_TOP, true);
192-
193-
g_positioner->position(root, {{}, {1000, 1000}});
194-
g_positioner->positionChildren(root);
195-
196-
EXPECT_EQ(child->impl->position, CBox(495, 0, 10, 10));
197-
198-
child->setPositionFlag(IElement::HT_POSITION_FLAG_TOP, false);
199-
child->setPositionFlag(IElement::HT_POSITION_FLAG_BOTTOM, true);
200-
201-
g_positioner->position(root, {{}, {1000, 1000}});
202-
g_positioner->positionChildren(root);
203-
204-
EXPECT_EQ(child->impl->position, CBox(495, 990, 10, 10));
205-
206-
child->setPositionFlag(IElement::HT_POSITION_FLAG_HCENTER, false);
207-
child->setPositionFlag(IElement::HT_POSITION_FLAG_RIGHT, true);
208-
209-
g_positioner->position(root, {{}, {1000, 1000}});
210-
g_positioner->positionChildren(root);
211-
212-
EXPECT_EQ(child->impl->position, CBox(990, 990, 10, 10));
213-
214-
child->setPositionFlag(IElement::HT_POSITION_FLAG_RIGHT, false);
215-
child->setPositionFlag(IElement::HT_POSITION_FLAG_LEFT, true);
216-
217-
g_positioner->position(root, {{}, {1000, 1000}});
218-
g_positioner->positionChildren(root);
219-
220-
EXPECT_EQ(child->impl->position, CBox(0, 990, 10, 10));
221-
}
222-
223-
#endif

tests/unit/helpers/Env.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <gtest/gtest.h>
2+
3+
#include <helpers/Env.hpp>
4+
5+
using namespace Hyprtoolkit;
6+
7+
TEST(Env, enabled) {
8+
setenv("HT_INTERNAL_TEST1", "1", 1);
9+
setenv("HT_INTERNAL_TEST2", "SUS", 1);
10+
setenv("HT_INTERNAL_TEST3", "0", 1);
11+
setenv("HT_INTERNAL_TEST4", "", 1);
12+
13+
EXPECT_EQ(Env::envEnabled("HT_INTERNAL_TEST1"), true);
14+
EXPECT_EQ(Env::envEnabled("HT_INTERNAL_TEST2"), true);
15+
EXPECT_EQ(Env::envEnabled("HT_INTERNAL_TEST3"), false);
16+
EXPECT_EQ(Env::envEnabled("HT_INTERNAL_TEST4"), false);
17+
}

tests/unit/helpers/UTF8.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <helpers/UTF8.hpp>
2+
3+
#include <gtest/gtest.h>
4+
5+
using namespace Hyprtoolkit;
6+
7+
TEST(UTF8, Length) {
8+
EXPECT_EQ(UTF8::length(""), 0);
9+
EXPECT_EQ(UTF8::length("Hello"), 5);
10+
EXPECT_EQ(UTF8::length("世界"), 2);
11+
EXPECT_EQ(UTF8::length("世界is酷薄"), 6);
12+
}
13+
14+
TEST(UTF8, Substr) {
15+
EXPECT_EQ(UTF8::substr("", 0, 0), "");
16+
EXPECT_EQ(UTF8::substr("", 1), "");
17+
EXPECT_EQ(UTF8::substr("", 0, 0), "");
18+
EXPECT_EQ(UTF8::substr("Hello", 0, 3), "Hel");
19+
EXPECT_EQ(UTF8::substr("世界", 1, 1), "");
20+
EXPECT_EQ(UTF8::substr("世界is酷薄", 1), "界is酷薄");
21+
EXPECT_EQ(UTF8::substr("ハイパーランド", 1, 2), "イパ");
22+
}
23+
24+
TEST(UTF8, UTF8ToOffset) {
25+
EXPECT_EQ(UTF8::utf8ToOffset("", 0), 0);
26+
EXPECT_EQ(UTF8::utf8ToOffset("Hello", 20000), 5);
27+
EXPECT_EQ(UTF8::utf8ToOffset("Hello", 3), 3);
28+
EXPECT_EQ(UTF8::utf8ToOffset("魑魅魍魎", 3), 9);
29+
EXPECT_EQ(UTF8::utf8ToOffset("a魑魅魍魎", 3), 7);
30+
}
31+
32+
TEST(UTF8, offsetToUTF8Len) {
33+
EXPECT_EQ(UTF8::offsetToUTF8Len("", 0), 0);
34+
EXPECT_EQ(UTF8::offsetToUTF8Len("Hello", 3), 3);
35+
EXPECT_EQ(UTF8::offsetToUTF8Len("魑魅魍魎", 3), 1);
36+
EXPECT_EQ(UTF8::offsetToUTF8Len("a魑魅魍魎", 4), 2);
37+
}

0 commit comments

Comments
 (0)