Initial unit tests implementation
parent
b9a4516534
commit
815c0e46a4
|
@ -70,10 +70,14 @@ build_script:
|
|||
|
||||
cd build
|
||||
|
||||
cmake -DCMAKE_PREFIX_PATH=%Qt5_DIR% -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake -DENABLE_SPICE=ON -DENABLE_TOOLS=ON -DENABLE_TTF=ON ..
|
||||
cmake -DCMAKE_PREFIX_PATH=%Qt5_DIR% -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake -DENABLE_SPICE=ON -DENABLE_TOOLS=ON -DENABLE_TTF=ON -DENABLE_TESTS=ON ..
|
||||
|
||||
cmake --build . --config Release -- /maxcpucount:4 /nologo
|
||||
|
||||
set CTEST_OUTPUT_ON_FAILURE=1
|
||||
|
||||
ctest -C Release
|
||||
|
||||
after_build:
|
||||
- cmd: >-
|
||||
cd c:\projects\celestia\build\src\celestia
|
||||
|
|
|
@ -35,8 +35,9 @@ before_script:
|
|||
- cd build
|
||||
|
||||
script:
|
||||
- cmake -DENABLE_SPICE=ON -DENABLE_TOOLS=ON -DENABLE_TTF=ON ..
|
||||
- cmake -DENABLE_SPICE=ON -DENABLE_TOOLS=ON -DENABLE_TTF=ON -DENABLE_TESTS=ON ..
|
||||
- make -j $(nproc || echo 4)
|
||||
- CTEST_OUTPUT_ON_FAILURE=1 ctest
|
||||
|
||||
addons:
|
||||
apt:
|
||||
|
|
|
@ -31,6 +31,7 @@ option(ENABLE_TOOLS "Build different tools? (Default: off)" OFF)
|
|||
option(NATIVE_OSX_APP "Support native OSX paths read data from (Default: off)" OFF)
|
||||
option(FAST_MATH "Build with unsafe fast-math compiller option (Default: off)" OFF)
|
||||
option(ENABLE_TTF "Use TrueType fonts instead of TXF (Default: off)" OFF)
|
||||
option(ENABLE_TESTS "Enable unit tests? (Default: off)" OFF)
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type." FORCE)
|
||||
|
@ -350,3 +351,8 @@ add_subdirectory(models)
|
|||
add_subdirectory(scripts)
|
||||
add_subdirectory(shaders)
|
||||
add_subdirectory(textures)
|
||||
|
||||
if(ENABLE_TESTS)
|
||||
enable_testing()
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
macro(test_case)
|
||||
set(trgt ${ARGV0})
|
||||
set(libs ${ARGV})
|
||||
list(REMOVE_AT libs 0 0)
|
||||
|
||||
add_executable(${trgt} "${trgt}_test.cpp")
|
||||
target_link_libraries(${trgt} PRIVATE ${libs})
|
||||
add_test(${trgt} ${trgt})
|
||||
set_target_properties(${trgt} PROPERTIES FOLDER test/unit)
|
||||
endmacro()
|
|
@ -3,9 +3,17 @@ Upstream-Name: Celestia
|
|||
Source: https://github.com/CelestiaProject/Celestia
|
||||
|
||||
Files: *
|
||||
Copyright: 2001-2019 Celestia Development Team
|
||||
Copyright: 2001-2020 Celestia Development Team
|
||||
License: GPL-2+
|
||||
|
||||
Files: src/celengine/curveplot.*
|
||||
Copyright: 2009-2010 Chris Laurel <claurel@gmail.com>
|
||||
License: LGPL-2+ or GPL-2+
|
||||
|
||||
Files: test/unit/catch.hpp
|
||||
Copyright: 2019 Two Blue Cubes Ltd
|
||||
License: Boost
|
||||
|
||||
Files: debian/*
|
||||
Copyright: 2001-2002 Marcelo E. Magallon <mmagallo@debian.org>
|
||||
2003 Mika Fischer <mf@debian.org>
|
||||
|
@ -35,3 +43,49 @@ License: GPL-2+
|
|||
On Debian systems, the full text of the GNU General Public
|
||||
License version 2 can be found in the file
|
||||
`/usr/share/common-licenses/GPL-2'.
|
||||
|
||||
License: LGPL-2+
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
.
|
||||
This library 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 Lesser General Public License for more details.
|
||||
.
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
.
|
||||
On Debian systems, the full text of the GNU Lesser General
|
||||
Public License version 2 can be found in the file
|
||||
`/usr/share/common-licenses/LGPL-2'.
|
||||
|
||||
License: Boost
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
.
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
.
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
file(GLOB SCRIPTS_SOURCES "*.cel" "*.celx")
|
||||
file(GLOB SCRIPTS_SOURCES "*.cel" "*.celx" "overlay/*.cel" "overlay/*.celx")
|
||||
|
||||
install(FILES ${SCRIPTS_SOURCES} DESTINATION "${DATADIR}/scripts")
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
add_subdirectory(unit)
|
|
@ -0,0 +1,7 @@
|
|||
include(TestCase)
|
||||
|
||||
test_case(hash celengine)
|
||||
test_case(fs celengine)
|
||||
if(WIN32)
|
||||
test_case(winutil celutil)
|
||||
endif()
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,56 @@
|
|||
#if 1
|
||||
#include <celcompat/fs.h>
|
||||
namespace fs = celestia::filesystem;
|
||||
#else
|
||||
#include <filesystem>
|
||||
namespace fs = std::filesystem;
|
||||
#endif
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("filesystem", "[filesystem]")
|
||||
{
|
||||
SECTION("fs::path::extension()")
|
||||
{
|
||||
REQUIRE(fs::path("/foo/bar.txt").extension() == ".txt");
|
||||
REQUIRE(fs::path("/foo/bar.").extension() == ".");
|
||||
REQUIRE(fs::path("/foo/bar").extension().empty() == true);
|
||||
REQUIRE(fs::path("/foo/bar.txt/bar.cc").extension() == ".cc");
|
||||
REQUIRE(fs::path("/foo/bar.txt/bar.").extension() == ".");
|
||||
REQUIRE(fs::path("/foo/bar.txt/bar").extension().empty() == true);
|
||||
REQUIRE(fs::path("/foo/.").extension().empty() == true);
|
||||
REQUIRE(fs::path("/foo/..").extension().empty() == true);
|
||||
REQUIRE(fs::path("/foo/.hidden").extension().empty() == true);
|
||||
REQUIRE(fs::path("/foo/..bar").extension() == ".bar");
|
||||
REQUIRE(fs::path("/foo/bar.txt").stem() == "bar");
|
||||
REQUIRE(fs::path("/foo/.bar").stem() == ".bar");
|
||||
}
|
||||
|
||||
SECTION("fs::path::stem()")
|
||||
{
|
||||
fs::path p = "foo.bar.baz.tar";
|
||||
REQUIRE(p.extension() == ".tar");
|
||||
p = p.stem();
|
||||
REQUIRE(p.extension() == ".baz");
|
||||
REQUIRE(p == "foo.bar.baz");
|
||||
p = p.stem();
|
||||
REQUIRE(p.extension() == ".bar");
|
||||
REQUIRE(p == "foo.bar");
|
||||
p = p.stem();
|
||||
REQUIRE(p.extension().empty() == true);
|
||||
REQUIRE(p == "foo");
|
||||
}
|
||||
|
||||
SECTION("path separators")
|
||||
{
|
||||
REQUIRE(fs::path("/foo/bar.txt") == "/foo/bar.txt");
|
||||
REQUIRE(fs::path("baz/foo/bar.txt") == "baz/foo/bar.txt");
|
||||
// These two fail on Unix/GCC both with C++11 fs and our own.
|
||||
// But they are successful with MinGW.
|
||||
#ifdef _WIN32
|
||||
REQUIRE(fs::path("c:\\foo\\bar.txt") == "c:/foo/bar.txt");
|
||||
REQUIRE(fs::path(L"c:\\foo\\bar.txt") == "c:/foo/bar.txt");
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
#include <celengine/hash.h>
|
||||
#include <celengine/value.h>
|
||||
#include <celutil/color.h>
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include <catch.hpp>
|
||||
|
||||
constexpr const double EPSILON = 1.0 / 255.0;
|
||||
|
||||
inline float C(float n)
|
||||
{
|
||||
return static_cast<float>(static_cast<unsigned char>(n * 255.99f)) / 255.0f;
|
||||
}
|
||||
|
||||
TEST_CASE("AssociativeArray", "[AssociativeArray]")
|
||||
{
|
||||
SECTION("Colors")
|
||||
{
|
||||
SECTION("Defined as Vector3")
|
||||
{
|
||||
AssociativeArray h;
|
||||
auto *ary = new ValueArray;
|
||||
ary->push_back(new Value(.23));
|
||||
ary->push_back(new Value(.34));
|
||||
ary->push_back(new Value(.45));
|
||||
auto *v = new Value(ary);
|
||||
h.addValue("color", *v);
|
||||
|
||||
auto val = h.getValue("color");
|
||||
REQUIRE(val->getType() == Value::ArrayType);
|
||||
|
||||
Eigen::Vector3d vec;
|
||||
auto v2 = h.getVector("color", vec);
|
||||
REQUIRE(vec.x() == .23);
|
||||
REQUIRE(vec.y() == .34);
|
||||
REQUIRE(vec.z() == .45);
|
||||
|
||||
Color c;
|
||||
h.getColor("color", c);
|
||||
REQUIRE(c.red() == Approx(C(.23)));
|
||||
REQUIRE(c.green() == Approx(C(.34)));
|
||||
REQUIRE(c.blue() == Approx(C(.45)));
|
||||
REQUIRE(c.alpha() == Approx(1.0));
|
||||
}
|
||||
|
||||
SECTION("Defined as Vector4")
|
||||
{
|
||||
AssociativeArray h;
|
||||
auto *ary = new ValueArray;
|
||||
ary->push_back(new Value(.23));
|
||||
ary->push_back(new Value(.34));
|
||||
ary->push_back(new Value(.45));
|
||||
ary->push_back(new Value(.56));
|
||||
auto *v = new Value(ary);
|
||||
h.addValue("color", *v);
|
||||
|
||||
auto val = h.getValue("color");
|
||||
REQUIRE(val->getType() == Value::ArrayType);
|
||||
|
||||
Eigen::Vector4d vec;
|
||||
auto v2 = h.getVector("color", vec);
|
||||
REQUIRE(vec.x() == .23);
|
||||
REQUIRE(vec.y() == .34);
|
||||
REQUIRE(vec.z() == .45);
|
||||
REQUIRE(vec.w() == .56);
|
||||
|
||||
Color c;
|
||||
h.getColor("color", c);
|
||||
REQUIRE(c.red() == Approx(C(.23)));
|
||||
REQUIRE(c.green() == Approx(C(.34)));
|
||||
REQUIRE(c.blue() == Approx(C(.45)));
|
||||
REQUIRE(c.alpha() == Approx(C(.56)));
|
||||
|
||||
}
|
||||
|
||||
SECTION("Defined as rrggbb string")
|
||||
{
|
||||
AssociativeArray h;
|
||||
auto *v = new Value("#123456");
|
||||
h.addValue("color", *v);
|
||||
|
||||
Color c;
|
||||
h.getColor("color", c);
|
||||
REQUIRE(c.red() == Approx(0x12 / 255.).epsilon(EPSILON));
|
||||
REQUIRE(c.green() == Approx(0x34 / 255.).epsilon(EPSILON));
|
||||
REQUIRE(c.blue() == Approx(0x56 / 255.).epsilon(EPSILON));
|
||||
REQUIRE(c.alpha() == Approx(1.0).epsilon(EPSILON));
|
||||
}
|
||||
|
||||
SECTION("Defined as rrggbbaa string")
|
||||
{
|
||||
AssociativeArray h;
|
||||
auto *v = new Value("#12345678");
|
||||
h.addValue("color", *v);
|
||||
|
||||
Color c;
|
||||
h.getColor("color", c);
|
||||
REQUIRE(c.red() == Approx(0x12 / 255.).epsilon(EPSILON));
|
||||
REQUIRE(c.green() == Approx(0x34 / 255.).epsilon(EPSILON));
|
||||
REQUIRE(c.blue() == Approx(0x56 / 255.).epsilon(EPSILON));
|
||||
REQUIRE(c.alpha() == Approx(0x78 / 255.).epsilon(EPSILON));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
#include <celutil/winutil.h>
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("CurrentCPToWide", "[CurrentCPToWide]")
|
||||
{
|
||||
REQUIRE(CurrentCPToWide("").empty() == true);
|
||||
REQUIRE(CurrentCPToWide("").length() == 0);
|
||||
REQUIRE(CurrentCPToWide("foo") == L"foo");
|
||||
REQUIRE(CurrentCPToWide("foo").length() == 3);
|
||||
}
|
||||
|
||||
TEST_CASE("WideToCurrentCP", "[WideToCurrentCP]")
|
||||
{
|
||||
REQUIRE(WideToCurrentCP(L"").empty() == true);
|
||||
REQUIRE(WideToCurrentCP(L"").length() == 0);
|
||||
REQUIRE(WideToCurrentCP(L"foo") == "foo");
|
||||
REQUIRE(WideToCurrentCP(L"foo").length() == 3);
|
||||
}
|
||||
|
||||
TEST_CASE("WideToUTF8","[WideToUTF8]")
|
||||
{
|
||||
REQUIRE(WideToUTF8(L"").empty() == true);
|
||||
REQUIRE(WideToUTF8(L"").length() == 0);
|
||||
REQUIRE(WideToUTF8(L"foo") == "foo");
|
||||
REQUIRE(WideToUTF8(L"foo").length() == 3);
|
||||
REQUIRE(WideToUTF8(L"\u0442\u044d\u0441\u0442") == "\321\202\321\215\321\201\321\202"); // тэст
|
||||
REQUIRE(WideToUTF8(L"\u0422\u044d\u0441\u0442").length() == 8);
|
||||
REQUIRE(WideToUTF8(L"\u2079") == "\342\201\271"); // superscript 9
|
||||
REQUIRE(WideToUTF8(L"\u2079").length() == 3);
|
||||
}
|
||||
|
||||
TEST_CASE("UTF8ToWide", "[UTF8ToWide]")
|
||||
{
|
||||
REQUIRE(UTF8ToWide("").empty() == true);
|
||||
REQUIRE(UTF8ToWide("").length() == 0);
|
||||
REQUIRE(UTF8ToWide("foo") == L"foo");
|
||||
REQUIRE(UTF8ToWide("foo").length() == 3);
|
||||
REQUIRE(UTF8ToWide("\321\202\321\215\321\201\321\202") == L"\u0442\u044d\u0441\u0442");
|
||||
REQUIRE(UTF8ToWide("\321\202\321\215\321\201\321\202").length() == 4);
|
||||
REQUIRE(UTF8ToWide("\342\201\271") == L"\u2079");
|
||||
REQUIRE(UTF8ToWide("\342\201\271").length() == 1);
|
||||
}
|
Loading…
Reference in New Issue