Add test
This commit is contained in:
parent
7ed6742f51
commit
9d9f082b57
3
.github/workflows/build.yml
vendored
3
.github/workflows/build.yml
vendored
@ -75,6 +75,9 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: python ./share/ci/build.py
|
run: python ./share/ci/build.py
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: python ./share/ci/test.py
|
||||||
|
|
||||||
- name: Create AppImage
|
- name: Create AppImage
|
||||||
if: runner.os == 'Linux'
|
if: runner.os == 'Linux'
|
||||||
shell: bash
|
shell: bash
|
||||||
|
28
external/gtest/LICENSE
vendored
Normal file
28
external/gtest/LICENSE
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
Copyright 2008, Google Inc.
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are
|
||||||
|
met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above
|
||||||
|
copyright notice, this list of conditions and the following disclaimer
|
||||||
|
in the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Google Inc. nor the names of its
|
||||||
|
contributors may be used to endorse or promote products derived from
|
||||||
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
11824
external/gtest/gtest-all.cc
vendored
Normal file
11824
external/gtest/gtest-all.cc
vendored
Normal file
File diff suppressed because it is too large
Load Diff
14813
external/gtest/gtest.h
vendored
Normal file
14813
external/gtest/gtest.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -14,11 +14,13 @@ build_dir = path.abspath('build')
|
|||||||
dependencies_dir = path.abspath('deps')
|
dependencies_dir = path.abspath('deps')
|
||||||
pro_file = path.abspath(path.dirname(__file__) +
|
pro_file = path.abspath(path.dirname(__file__) +
|
||||||
'/../../screen-translator.pro')
|
'/../../screen-translator.pro')
|
||||||
|
test_pro_file = path.abspath(path.dirname(__file__) +
|
||||||
|
'/../../tests/tests.pro')
|
||||||
app_version = 'testing'
|
app_version = 'testing'
|
||||||
with open(pro_file, 'r') as f:
|
with open(pro_file, 'r') as f:
|
||||||
match = re.search(r'VER=(.*)', f.read())
|
match = re.search(r'VER=(.*)', f.read())
|
||||||
if match:
|
if match:
|
||||||
app_version = match.group(1)
|
app_version = match.group(1)
|
||||||
ts_files_dir = path.abspath(path.dirname(__file__) + '/../../translations')
|
ts_files_dir = path.abspath(path.dirname(__file__) + '/../../translations')
|
||||||
|
|
||||||
os_name = getenv('OS', 'linux')
|
os_name = getenv('OS', 'linux')
|
||||||
|
25
share/ci/test.py
Normal file
25
share/ci/test.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import common as c
|
||||||
|
from config import *
|
||||||
|
import os
|
||||||
|
import platform
|
||||||
|
import glob
|
||||||
|
|
||||||
|
c.print('>> Testing {} on {}'.format(app_name, os_name))
|
||||||
|
|
||||||
|
c.add_to_path(os.path.abspath(qt_dir + '/bin'))
|
||||||
|
|
||||||
|
if platform.system() == "Windows":
|
||||||
|
env_cmd = c.get_msvc_env_cmd(bitness=bitness, msvc_version=msvc_version)
|
||||||
|
c.apply_cmd_env(env_cmd)
|
||||||
|
|
||||||
|
c.recreate_dir(build_dir)
|
||||||
|
os.chdir(build_dir)
|
||||||
|
|
||||||
|
c.set_make_threaded()
|
||||||
|
c.run('qmake {} "{}"'.format(os.environ.get('QMAKE_FLAGS', ''), test_pro_file))
|
||||||
|
make_cmd = c.get_make_cmd()
|
||||||
|
c.run(make_cmd)
|
||||||
|
|
||||||
|
for file in glob.glob('./**/tests*', recursive=True):
|
||||||
|
print(file)
|
||||||
|
c.run(file, silent=False)
|
46
tests/geometryutils_test.cpp
Normal file
46
tests/geometryutils_test.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "geometryutils.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QRect>
|
||||||
|
|
||||||
|
using namespace service::geometry;
|
||||||
|
|
||||||
|
TEST(GeometryUtils, CornerAtPoint)
|
||||||
|
{
|
||||||
|
// outside
|
||||||
|
{
|
||||||
|
const auto testee = cornerAtPoint({0, 0}, {10, 10}, {10, 10, 50, 50});
|
||||||
|
EXPECT_EQ(QPoint(10, 10), testee);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const auto testee = cornerAtPoint({200, 200}, {10, 10}, {10, 10, 50, 50});
|
||||||
|
EXPECT_EQ(QPoint(50, 50), testee);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const auto testee = cornerAtPoint({200, 20}, {10, 10}, {10, 10, 50, 50});
|
||||||
|
EXPECT_EQ(QPoint(50, 20), testee);
|
||||||
|
}
|
||||||
|
|
||||||
|
// top left
|
||||||
|
{
|
||||||
|
const auto testee = cornerAtPoint({10, 10}, {10, 10}, {0, 0, 100, 100});
|
||||||
|
EXPECT_EQ(QPoint(10, 10), testee);
|
||||||
|
}
|
||||||
|
// top right
|
||||||
|
{
|
||||||
|
const auto testee = cornerAtPoint({95, 10}, {10, 10}, {0, 0, 100, 100});
|
||||||
|
EXPECT_EQ(QPoint(86, 10), testee);
|
||||||
|
}
|
||||||
|
// bottom left
|
||||||
|
{
|
||||||
|
const auto testee = cornerAtPoint({10, 95}, {10, 10}, {0, 0, 100, 100});
|
||||||
|
EXPECT_EQ(QPoint(10, 86), testee);
|
||||||
|
}
|
||||||
|
// bottom right
|
||||||
|
{
|
||||||
|
const auto testee = cornerAtPoint({95, 95}, {10, 10}, {0, 0, 100, 100});
|
||||||
|
EXPECT_EQ(QPoint(86, 86), testee);
|
||||||
|
}
|
||||||
|
}
|
10
tests/main.cpp
Normal file
10
tests/main.cpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QCoreApplication a(argc, argv);
|
||||||
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
|
return RUN_ALL_TESTS();
|
||||||
|
}
|
10
tests/tests.pro
Normal file
10
tests/tests.pro
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
CONFIG += c++17
|
||||||
|
CONFIG -= app_bundle
|
||||||
|
|
||||||
|
INCLUDEPATH += $$PWD/../external $$PWD/../src/service
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
../external/gtest/gtest-all.cc \
|
||||||
|
../src/service/geometryutils.cpp \
|
||||||
|
geometryutils_test.cpp \
|
||||||
|
main.cpp
|
Loading…
Reference in New Issue
Block a user