mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Added complete VizFwk
Added the complete VizFwk from the ResInsight branch in Perforce as of changelist 190.
This commit is contained in:
34
Fwk/VizFwk/Tests/CMakeLists.txt
Normal file
34
Fwk/VizFwk/Tests/CMakeLists.txt
Normal file
@@ -0,0 +1,34 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
# Builds all the unit tests
|
||||
|
||||
|
||||
# Just use the base compile flags for all unit tests
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CEE_BASE_CXX_FLAGS}")
|
||||
|
||||
# And then relax some of the warnings for the unit tests
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-variadic-macros -Wno-long-long -Wno-sign-compare")
|
||||
endif()
|
||||
|
||||
# Setup our platform dependent libraries here, assuming they'll be the same for all the tests
|
||||
if (UNIX AND NOT APPLE)
|
||||
set(CEE_PLATFORM_LIBS rt pthread)
|
||||
endif()
|
||||
|
||||
add_definitions(-DCVF_UTEST_DEFAULT_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/TestData/")
|
||||
|
||||
add_subdirectory(LibCore_UnitTests)
|
||||
add_subdirectory(LibIo_UnitTests)
|
||||
add_subdirectory(LibGeometry_UnitTests)
|
||||
add_subdirectory(LibRender_UnitTests)
|
||||
add_subdirectory(LibViewing_UnitTests)
|
||||
|
||||
add_subdirectory(LibRegGrid2D_UnitTests)
|
||||
add_subdirectory(LibStructGrid_UnitTests)
|
||||
|
||||
add_subdirectory(LibUtilities_UnitTests)
|
||||
|
||||
if (CEE_BUILD_GUI_QT)
|
||||
add_subdirectory(LibGuiQt_UnitTests)
|
||||
endif()
|
||||
50
Fwk/VizFwk/Tests/LibCore_UnitTests/CMakeLists.txt
Normal file
50
Fwk/VizFwk/Tests/LibCore_UnitTests/CMakeLists.txt
Normal file
@@ -0,0 +1,50 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(LibCore_UnitTests)
|
||||
|
||||
# Compile flags should already be setup by caller
|
||||
|
||||
|
||||
include_directories(${LibCore_SOURCE_DIR})
|
||||
include_directories(${VizFramework_SOURCE_DIR}/ThirdParty)
|
||||
|
||||
set(CEE_LIBS LibCore)
|
||||
|
||||
|
||||
set(CEE_SOURCE_FILES
|
||||
cvfArray-Test.cpp
|
||||
cvfBase-Test.cpp
|
||||
cvfBase64-Test.cpp
|
||||
cvfCharArray-Test.cpp
|
||||
cvfCodeLocation-Test.cpp
|
||||
cvfCollection-Test.cpp
|
||||
cvfColor3-Test.cpp
|
||||
cvfColor4-Test.cpp
|
||||
cvfDebugTimer-Test.cpp
|
||||
cvfFlags-Test.cpp
|
||||
cvfLogEvent-Test.cpp
|
||||
cvfLogger-Test.cpp
|
||||
cvfMath-Test.cpp
|
||||
cvfMatrix3-Test.cpp
|
||||
cvfMatrix4-Test.cpp
|
||||
cvfObject-Test.cpp
|
||||
cvfPlane-Test.cpp
|
||||
cvfPropertySet-Test.cpp
|
||||
cvfPropertySetCollection-Test.cpp
|
||||
cvfRect-Test.cpp
|
||||
cvfQuat-Test.cpp
|
||||
cvfString-Test.cpp
|
||||
cvfSystem-Test.cpp
|
||||
cvfTimer-Test.cpp
|
||||
cvfTrace-Test.cpp
|
||||
cvfVariant-Test.cpp
|
||||
cvfVector2-Test.cpp
|
||||
cvfVector3-Test.cpp
|
||||
cvfVector4-Test.cpp
|
||||
../../ThirdParty/gtest/gtest-all.cpp
|
||||
LibCore_UnitTests.cpp
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${CEE_SOURCE_FILES})
|
||||
target_link_libraries(${PROJECT_NAME} ${CEE_LIBS} ${CEE_PLATFORM_LIBS})
|
||||
|
||||
59
Fwk/VizFwk/Tests/LibCore_UnitTests/LibCore_UnitTests.cpp
Normal file
59
Fwk/VizFwk/Tests/LibCore_UnitTests/LibCore_UnitTests.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "cvfTrace.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
//printf("Running main() from LibCore_UnitTests.cpp\n");
|
||||
//printf("LibCore version: %s.%s-%s (%s) \n\n", CVF_MAJOR_VERSION, CVF_MINOR_VERSION, CVF_BUILD_NUMBER, CVF_SPECIAL_BUILD);
|
||||
|
||||
cvf::Assert::setReportMode(cvf::Assert::CONSOLE);
|
||||
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
308
Fwk/VizFwk/Tests/LibCore_UnitTests/LibCore_UnitTests.vcxproj
Normal file
308
Fwk/VizFwk/Tests/LibCore_UnitTests/LibCore_UnitTests.vcxproj
Normal file
@@ -0,0 +1,308 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug MD TBB|Win32">
|
||||
<Configuration>Debug MD TBB</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug MD TBB|x64">
|
||||
<Configuration>Debug MD TBB</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug MD|Win32">
|
||||
<Configuration>Debug MD</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug MD|x64">
|
||||
<Configuration>Debug MD</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD TBB|Win32">
|
||||
<Configuration>Release MD TBB</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD TBB|x64">
|
||||
<Configuration>Release MD TBB</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD|Win32">
|
||||
<Configuration>Release MD</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD|x64">
|
||||
<Configuration>Release MD</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{0E5E5956-5EFD-6D62-0ABE-AF60A0DEABA3}</ProjectGuid>
|
||||
<RootNamespace>LibCore_UnitTests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\ThirdParty\gtest\gtest-all.cpp" />
|
||||
<ClCompile Include="cvfArray-Test.cpp" />
|
||||
<ClCompile Include="cvfBase-Test.cpp" />
|
||||
<ClCompile Include="cvfBase64-Test.cpp" />
|
||||
<ClCompile Include="cvfCharArray-Test.cpp" />
|
||||
<ClCompile Include="cvfCodeLocation-Test.cpp" />
|
||||
<ClCompile Include="cvfCollection-Test.cpp" />
|
||||
<ClCompile Include="cvfColor3-Test.cpp" />
|
||||
<ClCompile Include="cvfColor4-Test.cpp" />
|
||||
<ClCompile Include="cvfDebugTimer-Test.cpp" />
|
||||
<ClCompile Include="cvfFlags-Test.cpp" />
|
||||
<ClCompile Include="cvfLogEvent-Test.cpp" />
|
||||
<ClCompile Include="cvfLogger-Test.cpp" />
|
||||
<ClCompile Include="cvfMath-Test.cpp" />
|
||||
<ClCompile Include="cvfMatrix3-Test.cpp" />
|
||||
<ClCompile Include="cvfMatrix4-Test.cpp" />
|
||||
<ClCompile Include="cvfObject-Test.cpp" />
|
||||
<ClCompile Include="cvfPlane-Test.cpp" />
|
||||
<ClCompile Include="cvfPropertySet-Test.cpp" />
|
||||
<ClCompile Include="cvfPropertySetCollection-Test.cpp" />
|
||||
<ClCompile Include="cvfQuat-Test.cpp" />
|
||||
<ClCompile Include="cvfRect-Test.cpp" />
|
||||
<ClCompile Include="cvfString-Test.cpp" />
|
||||
<ClCompile Include="cvfSystem-Test.cpp" />
|
||||
<ClCompile Include="cvfTimer-Test.cpp" />
|
||||
<ClCompile Include="cvfTrace-Test.cpp" />
|
||||
<ClCompile Include="cvfVariant-Test.cpp" />
|
||||
<ClCompile Include="cvfVector2-Test.cpp" />
|
||||
<ClCompile Include="cvfVector3-Test.cpp" />
|
||||
<ClCompile Include="cvfVector4-Test.cpp" />
|
||||
<ClCompile Include="LibCore_UnitTests.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="CMakeLists.txt" />
|
||||
<CustomBuild Include="TriggerTBBCopy.txt">
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb_debug.dll" + NUL "$(TargetDir)tbb_debug.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">$(TargetDir)tbb_debug.dll</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb.dll" + NUL "$(TargetDir)tbb.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">$(TargetDir)tbb.dll</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb_debug.dll" + NUL "$(TargetDir)tbb_debug.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">$(TargetDir)tbb_debug.dll</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb.dll" + NUL "$(TargetDir)tbb.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">$(TargetDir)tbb.dll</Outputs>
|
||||
</CustomBuild>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\LibCore\LibCore.vcxproj">
|
||||
<Project>{a9c7a239-b761-a892-bf34-5aeca0d9ee88}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="cvfArray-Test.cpp" />
|
||||
<ClCompile Include="cvfVector4-Test.cpp" />
|
||||
<ClCompile Include="cvfBase-Test.cpp" />
|
||||
<ClCompile Include="cvfCharArray-Test.cpp" />
|
||||
<ClCompile Include="cvfCollection-Test.cpp" />
|
||||
<ClCompile Include="cvfColor3-Test.cpp" />
|
||||
<ClCompile Include="cvfColor4-Test.cpp" />
|
||||
<ClCompile Include="cvfDebugTimer-Test.cpp" />
|
||||
<ClCompile Include="cvfFlags-Test.cpp" />
|
||||
<ClCompile Include="cvfMath-Test.cpp" />
|
||||
<ClCompile Include="cvfMatrix3-Test.cpp" />
|
||||
<ClCompile Include="cvfMatrix4-Test.cpp" />
|
||||
<ClCompile Include="cvfObject-Test.cpp" />
|
||||
<ClCompile Include="cvfPlane-Test.cpp" />
|
||||
<ClCompile Include="cvfQuat-Test.cpp" />
|
||||
<ClCompile Include="cvfRect-Test.cpp" />
|
||||
<ClCompile Include="cvfString-Test.cpp" />
|
||||
<ClCompile Include="cvfSystem-Test.cpp" />
|
||||
<ClCompile Include="cvfTimer-Test.cpp" />
|
||||
<ClCompile Include="cvfTrace-Test.cpp" />
|
||||
<ClCompile Include="cvfVector2-Test.cpp" />
|
||||
<ClCompile Include="cvfVector3-Test.cpp" />
|
||||
<ClCompile Include="LibCore_UnitTests.cpp" />
|
||||
<ClCompile Include="..\..\ThirdParty\gtest\gtest-all.cpp" />
|
||||
<ClCompile Include="cvfBase64-Test.cpp" />
|
||||
<ClCompile Include="cvfVariant-Test.cpp" />
|
||||
<ClCompile Include="cvfPropertySet-Test.cpp" />
|
||||
<ClCompile Include="cvfPropertySetCollection-Test.cpp" />
|
||||
<ClCompile Include="cvfLogger-Test.cpp" />
|
||||
<ClCompile Include="cvfLogEvent-Test.cpp" />
|
||||
<ClCompile Include="cvfCodeLocation-Test.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="CMakeLists.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="TriggerTBBCopy.txt" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
2
Fwk/VizFwk/Tests/LibCore_UnitTests/TriggerTBBCopy.txt
Normal file
2
Fwk/VizFwk/Tests/LibCore_UnitTests/TriggerTBBCopy.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
Sole purpose of this file is to have custom build rules to trigger copying of TBB DLLs
|
||||
1285
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfArray-Test.cpp
Normal file
1285
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfArray-Test.cpp
Normal file
File diff suppressed because it is too large
Load Diff
75
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfBase-Test.cpp
Normal file
75
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfBase-Test.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(BaseTest, MinMax)
|
||||
{
|
||||
int a = 1;
|
||||
int b = 2;
|
||||
int c = 3;
|
||||
|
||||
int min = CVF_MIN(a, b);
|
||||
ASSERT_EQ(1, min);
|
||||
|
||||
min = CVF_MIN(c, b);
|
||||
ASSERT_EQ(2, min);
|
||||
|
||||
int max = CVF_MAX(a, b);
|
||||
ASSERT_EQ(2, max);
|
||||
|
||||
max = CVF_MAX(c, b);
|
||||
ASSERT_EQ(3, max);
|
||||
|
||||
min = CVF_MIN(c, CVF_MIN(b, a));
|
||||
ASSERT_EQ(1, min);
|
||||
|
||||
min = CVF_MIN(b, CVF_MIN(c, a));
|
||||
ASSERT_EQ(1, min);
|
||||
|
||||
min = CVF_MIN(a, CVF_MIN(c, b));
|
||||
ASSERT_EQ(1, min);
|
||||
}
|
||||
81
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfBase64-Test.cpp
Normal file
81
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfBase64-Test.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfBase64.h"
|
||||
#include "cvfArray.h"
|
||||
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Base64Test, EncodeDecode)
|
||||
{
|
||||
// Create binary data buffer to be encoded
|
||||
static const size_t binaryDataSize = 4096;
|
||||
UByteArray binaryData;
|
||||
binaryData.resize(binaryDataSize);
|
||||
|
||||
// Populate the binary data buffer
|
||||
size_t i;
|
||||
for (i = 0; i < binaryDataSize; i++)
|
||||
{
|
||||
binaryData.set(i, static_cast<const ubyte>(i%256));
|
||||
}
|
||||
|
||||
// Encode binary data
|
||||
std::string encodedData = Base64::encode(binaryData);
|
||||
EXPECT_GT(encodedData.size(), binaryDataSize);
|
||||
|
||||
// Decode
|
||||
ref<UByteArray> decodedData = Base64::decode(encodedData);
|
||||
ASSERT_TRUE(decodedData.notNull());
|
||||
ASSERT_EQ(binaryDataSize, decodedData->size());
|
||||
|
||||
// Verify that decoded data is identical with the original binary data
|
||||
for (i = 0; i < binaryDataSize; i++)
|
||||
{
|
||||
const ubyte decodedByte = decodedData->get(i);
|
||||
ASSERT_EQ(binaryData[i], decodedByte);
|
||||
}
|
||||
}
|
||||
|
||||
238
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfCharArray-Test.cpp
Normal file
238
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfCharArray-Test.cpp
Normal file
@@ -0,0 +1,238 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfCharArray.h"
|
||||
#include "cvfSystem.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CharArrayTest, Construction)
|
||||
{
|
||||
CharArray ca0;
|
||||
ASSERT_EQ(0, ca0.size());
|
||||
|
||||
CharArray ca1(5, 'a');
|
||||
ASSERT_EQ(5, ca1.size());
|
||||
EXPECT_EQ('a', ca1[0]);
|
||||
EXPECT_EQ('a', ca1[4]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CharArrayTest, CopyConstruction)
|
||||
{
|
||||
CharArray ca0(5, 'a');
|
||||
ASSERT_EQ(5, ca0.size());
|
||||
EXPECT_EQ('a', ca0[0]);
|
||||
EXPECT_EQ('a', ca0[4]);
|
||||
|
||||
{
|
||||
CharArray ca(ca0);
|
||||
ASSERT_EQ(5, ca.size());
|
||||
EXPECT_EQ('a', ca[0]);
|
||||
EXPECT_EQ('a', ca[4]);
|
||||
|
||||
EXPECT_NE(ca0.ptr(), ca.ptr());
|
||||
|
||||
ca[0] = 'b';
|
||||
EXPECT_EQ('a', ca0[0]);
|
||||
EXPECT_EQ('b', ca[0]);
|
||||
}
|
||||
|
||||
{
|
||||
CharArray ca;
|
||||
ca = ca0;
|
||||
ASSERT_EQ(5, ca.size());
|
||||
EXPECT_EQ('a', ca[0]);
|
||||
EXPECT_EQ('a', ca[4]);
|
||||
|
||||
EXPECT_NE(ca0.ptr(), ca.ptr());
|
||||
|
||||
ca[0] = 'b';
|
||||
EXPECT_EQ('a', ca0[0]);
|
||||
EXPECT_EQ('b', ca[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CharArrayTest, ConstructFromCharPtr)
|
||||
{
|
||||
char myStr[] = "TestString";
|
||||
|
||||
CharArray ca(myStr);
|
||||
ASSERT_EQ(10, ca.size());
|
||||
|
||||
EXPECT_EQ('T', ca[0]);
|
||||
EXPECT_EQ('g', ca[9]);
|
||||
|
||||
myStr[0] = 'X';
|
||||
EXPECT_EQ('T', ca[0]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CharArrayTest, Resize)
|
||||
{
|
||||
CharArray ca;
|
||||
ASSERT_EQ(0, ca.size());
|
||||
|
||||
ca.resize(4);
|
||||
ASSERT_EQ(4, ca.size());
|
||||
|
||||
ca.resize(0);
|
||||
ASSERT_EQ(0, ca.size());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CharArrayTest, Accessors)
|
||||
{
|
||||
CharArray ca(4, 'a');
|
||||
|
||||
EXPECT_EQ('a', ca[0]);
|
||||
EXPECT_EQ('a', ca[3]);
|
||||
|
||||
ca[0] = '0';
|
||||
ca[1] = '1';
|
||||
ca[2] = '2';
|
||||
ca[3] = '3';
|
||||
|
||||
EXPECT_EQ('0', ca[0]);
|
||||
EXPECT_EQ('1', ca[1]);
|
||||
EXPECT_EQ('2', ca[2]);
|
||||
EXPECT_EQ('3', ca[3]);
|
||||
}
|
||||
|
||||
|
||||
#if CVF_ENABLE_TIGHT_ASSERTS == 1
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CharArrayDeathTest, IllegalAccessors)
|
||||
{
|
||||
CharArray ca;
|
||||
EXPECT_DEATH(ca[0], "Assertion");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CharArrayTest, GetCharPtr)
|
||||
{
|
||||
CharArray ca(4, 'a');
|
||||
EXPECT_EQ(4, ca.size());
|
||||
|
||||
const char* cptr = ca.ptr();
|
||||
EXPECT_EQ(4, System::strlen(cptr));
|
||||
|
||||
ca[2] = '\0';
|
||||
EXPECT_EQ(4, ca.size());
|
||||
EXPECT_EQ(2, System::strlen(cptr));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CharArrayTest, UnsignedVsSignedChar)
|
||||
{
|
||||
{
|
||||
char ch = '\xc6';
|
||||
unsigned char uch = (unsigned char)ch;
|
||||
|
||||
EXPECT_EQ(0, memcmp(&ch, &uch, 1));
|
||||
}
|
||||
|
||||
{
|
||||
CharArray a;
|
||||
unsigned char vUC = 0xc6; // '<27>'
|
||||
signed char vSC = (-256 + 0xc6);
|
||||
char vC = '\xc6';
|
||||
|
||||
a.push_back(vUC);
|
||||
a.push_back(vSC);
|
||||
a.push_back(vC);
|
||||
|
||||
EXPECT_EQ(a[0], a[1]);
|
||||
EXPECT_EQ(a[0], a[2]);
|
||||
}
|
||||
|
||||
{
|
||||
CharArray a;
|
||||
|
||||
unsigned int val = 198; // '<27>'
|
||||
|
||||
a.push_back(static_cast<unsigned char>(val));
|
||||
a.push_back(static_cast<char>(val));
|
||||
a.push_back(static_cast<signed char>(val));
|
||||
|
||||
EXPECT_EQ(a[0], a[1]);
|
||||
EXPECT_EQ(a[0], a[2]);
|
||||
}
|
||||
|
||||
{
|
||||
CharArray a;
|
||||
|
||||
unsigned int val = 198; // '<27>'
|
||||
|
||||
a.push_back((unsigned char)val);
|
||||
a.push_back((char)val);
|
||||
a.push_back((signed char)val);
|
||||
|
||||
EXPECT_EQ(a[0], a[1]);
|
||||
EXPECT_EQ(a[0], a[2]);
|
||||
}
|
||||
}
|
||||
132
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfCodeLocation-Test.cpp
Normal file
132
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfCodeLocation-Test.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfCodeLocation.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "cvfTrace.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CodeLocationTest, DefaultConstructor)
|
||||
{
|
||||
CodeLocation cl;
|
||||
|
||||
EXPECT_STREQ("", cl.fileName());
|
||||
EXPECT_STREQ("", cl.functionName());
|
||||
EXPECT_EQ(-1, cl.lineNumber());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CodeLocationTest, ConstructionAndQuery)
|
||||
{
|
||||
const char fileName[] = "c:/myDir/myFile.txt";
|
||||
const char funcName[] = "MyClass::myFunc";
|
||||
const int lineNumber = 123;
|
||||
|
||||
CodeLocation cl(fileName, funcName, lineNumber);
|
||||
EXPECT_STREQ(fileName, cl.fileName());
|
||||
EXPECT_STREQ(funcName, cl.functionName());
|
||||
EXPECT_EQ(lineNumber, cl.lineNumber());
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CodeLocationTest, ConstructionUsingMacro)
|
||||
{
|
||||
{
|
||||
CodeLocation cl = CVF_CODE_LOCATION;
|
||||
EXPECT_STRCASEEQ("cvfCodeLocation-Test.cpp", cl.shortFileName());
|
||||
// cvf::Trace::show("file: %s", cl.fileName());
|
||||
// cvf::Trace::show("func: %s", cl.functionName());
|
||||
// cvf::Trace::show("line: %d", cl.lineNumber());
|
||||
}
|
||||
|
||||
{
|
||||
CodeLocation cl(__FILE__, CVF_CODELOC_FUNCNAME, __LINE__);
|
||||
EXPECT_STRCASEEQ("cvfCodeLocation-Test.cpp", cl.shortFileName());
|
||||
// cvf::Trace::show("file: %s", cl.fileName());
|
||||
// cvf::Trace::show("func: %s", cl.functionName());
|
||||
// cvf::Trace::show("line: %d", cl.lineNumber());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CodeLocationTest, shortFileName)
|
||||
{
|
||||
{
|
||||
const char fileName[] = "c:/myDir/myFile.txt";
|
||||
CodeLocation cl(fileName, NULL, 0);
|
||||
EXPECT_STREQ("myFile.txt", cl.shortFileName());
|
||||
}
|
||||
|
||||
{
|
||||
const char fileName[] = "/myDir/myFile.txt";
|
||||
CodeLocation cl(fileName, NULL, 0);
|
||||
EXPECT_STREQ("myFile.txt", cl.shortFileName());
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
{
|
||||
const char fileName[] = "c:\\myDir\\myFile.txt";
|
||||
CodeLocation cl(fileName, NULL, 0);
|
||||
EXPECT_STREQ("myFile.txt", cl.shortFileName());
|
||||
}
|
||||
|
||||
{
|
||||
const char fileName[] = "c:\\myDir/myFile.txt";
|
||||
CodeLocation cl(fileName, NULL, 0);
|
||||
EXPECT_STREQ("myFile.txt", cl.shortFileName());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
506
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfCollection-Test.cpp
Normal file
506
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfCollection-Test.cpp
Normal file
@@ -0,0 +1,506 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfCollection.h"
|
||||
#include "cvfMath.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
|
||||
class MyObj : public Object
|
||||
{
|
||||
public:
|
||||
MyObj() { num_ = 0; }
|
||||
MyObj(int num) { num_ = num; }
|
||||
|
||||
int num() const { return num_; }
|
||||
void num(int num) { num_ = num; }
|
||||
|
||||
bool operator<(const MyObj& rhs)
|
||||
{
|
||||
return num_ < rhs.num_;
|
||||
}
|
||||
|
||||
private:
|
||||
int num_;
|
||||
};
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CollectionTest, DefaultConstructor)
|
||||
{
|
||||
Collection<MyObj> col;
|
||||
EXPECT_EQ(0, col.size());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CollectionTest, CopyConstructor)
|
||||
{
|
||||
Collection<MyObj> col1;
|
||||
col1.push_back(new MyObj(1));
|
||||
col1.push_back(new MyObj(2));
|
||||
ASSERT_EQ(2, col1.size());
|
||||
ASSERT_EQ(1, col1[0]->refCount());
|
||||
ASSERT_EQ(1, col1[1]->refCount());
|
||||
|
||||
Collection<MyObj> col2(col1);
|
||||
ASSERT_EQ(2, col2.size());
|
||||
ASSERT_EQ(2, col2[0]->refCount());
|
||||
ASSERT_EQ(2, col2[1]->refCount());
|
||||
|
||||
col2.push_back(new MyObj(99));
|
||||
ASSERT_EQ(2, col1.size());
|
||||
ASSERT_EQ(3, col2.size());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CollectionTest, ConstructFromStdVector)
|
||||
{
|
||||
std::vector< ref<MyObj> > native;
|
||||
native.push_back(new MyObj(10));
|
||||
native.push_back(new MyObj(11));
|
||||
|
||||
Collection<MyObj> col2(native);
|
||||
ASSERT_EQ(2u, col2.size());
|
||||
ASSERT_EQ(10, col2[0]->num());
|
||||
ASSERT_EQ(11, col2[1]->num());
|
||||
ASSERT_EQ(2, col2[0]->refCount());
|
||||
ASSERT_EQ(2, col2[1]->refCount());
|
||||
|
||||
Collection<MyObj> col3(col2);
|
||||
ASSERT_EQ(2u, col3.size());
|
||||
ASSERT_EQ(10, col3[0]->num());
|
||||
ASSERT_EQ(11, col3[1]->num());
|
||||
ASSERT_EQ(3, col3[0]->refCount());
|
||||
ASSERT_EQ(3, col3[1]->refCount());
|
||||
ASSERT_EQ(3, native[0]->refCount());
|
||||
ASSERT_EQ(3, native[1]->refCount());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CollectionTest, Assignment)
|
||||
{
|
||||
Collection<MyObj> col1;
|
||||
col1.push_back(new MyObj(1));
|
||||
col1.push_back(new MyObj(2));
|
||||
ASSERT_EQ(2, col1.size());
|
||||
ASSERT_EQ(1, col1[0]->refCount());
|
||||
ASSERT_EQ(1, col1[1]->refCount());
|
||||
|
||||
Collection<MyObj> col2;
|
||||
col2 = col1;
|
||||
ASSERT_EQ(2, col2.size());
|
||||
ASSERT_EQ(2, col2[0]->refCount());
|
||||
ASSERT_EQ(2, col2[1]->refCount());
|
||||
|
||||
col2.push_back(new MyObj(99));
|
||||
ASSERT_EQ(2, col1.size());
|
||||
ASSERT_EQ(3, col2.size());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CollectionTest, Resize)
|
||||
{
|
||||
Collection<MyObj> col3;
|
||||
col3.push_back(new MyObj(1));
|
||||
col3.push_back(new MyObj(2));
|
||||
|
||||
col3.resize(3);
|
||||
|
||||
ASSERT_TRUE(col3[2].isNull());
|
||||
|
||||
MyObj* o = new MyObj(99);
|
||||
col3[2] = o;
|
||||
|
||||
ASSERT_EQ(3u, col3.size());
|
||||
ASSERT_EQ(99, col3[2]->num());
|
||||
ASSERT_EQ(1, col3[2]->refCount());
|
||||
|
||||
o->addRef();
|
||||
ASSERT_EQ(2, o->refCount());
|
||||
|
||||
// Remove o from the collection (last element, check that it has been released)
|
||||
col3.resize(2);
|
||||
ASSERT_EQ(2u, col3.size());
|
||||
ASSERT_EQ(1, o->refCount());
|
||||
ASSERT_EQ(99, o->num());
|
||||
|
||||
col3.clear();
|
||||
ASSERT_EQ(0u, col3.size());
|
||||
|
||||
o->release();
|
||||
o = 0;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CollectionTest, ElementAccess)
|
||||
{
|
||||
Collection<MyObj> col;
|
||||
Collection<MyObj> col2;
|
||||
|
||||
col.push_back(new MyObj(1));
|
||||
col.push_back(new MyObj(2));
|
||||
col.push_back(new MyObj(3));
|
||||
|
||||
col2 = col;
|
||||
|
||||
ASSERT_EQ(1, col2[0]->num());
|
||||
ASSERT_EQ(2, col2[1]->num());
|
||||
ASSERT_EQ(3, col2[2]->num());
|
||||
ASSERT_EQ(2, col2[0]->refCount());
|
||||
ASSERT_EQ(2, col2[1]->refCount());
|
||||
ASSERT_EQ(2, col2[2]->refCount());
|
||||
|
||||
col.clear();
|
||||
|
||||
ASSERT_EQ(1, col2[0]->num());
|
||||
ASSERT_EQ(2, col2[1]->num());
|
||||
ASSERT_EQ(3, col2[2]->num());
|
||||
ASSERT_EQ(1, col2[0]->refCount());
|
||||
ASSERT_EQ(1, col2[1]->refCount());
|
||||
ASSERT_EQ(1, col2[2]->refCount());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CollectionTest, Push_back)
|
||||
{
|
||||
Collection<MyObj> col;
|
||||
|
||||
col.push_back(new MyObj(1));
|
||||
col.push_back(new MyObj(2));
|
||||
|
||||
ref<MyObj> o = new MyObj(3);
|
||||
col.push_back(o.p());
|
||||
|
||||
ASSERT_EQ(3u, col.size());
|
||||
EXPECT_EQ(1, col[0]->num());
|
||||
EXPECT_EQ(2, col[1]->num());
|
||||
EXPECT_EQ(3, col[2]->num());
|
||||
EXPECT_EQ(1, col[0]->refCount());
|
||||
EXPECT_EQ(1, col[1]->refCount());
|
||||
EXPECT_EQ(2, col[2]->refCount());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CollectionTest, Contains)
|
||||
{
|
||||
ref<MyObj> o1 = new MyObj;
|
||||
ref<MyObj> o2 = new MyObj;
|
||||
ref<MyObj> o3 = new MyObj;
|
||||
|
||||
Collection<MyObj> col;
|
||||
col.push_back(o1.p());
|
||||
col.push_back(o2.p());
|
||||
|
||||
ASSERT_TRUE(col.contains(o1.p()));
|
||||
ASSERT_TRUE(col.contains(o2.p()));
|
||||
ASSERT_FALSE(col.contains(o3.p()));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CollectionTest, IndexOf)
|
||||
{
|
||||
ref<MyObj> o1 = new MyObj;
|
||||
ref<MyObj> o2 = new MyObj;
|
||||
ref<MyObj> o3 = new MyObj;
|
||||
|
||||
Collection<MyObj> col;
|
||||
col.push_back(o1.p());
|
||||
col.push_back(o2.p());
|
||||
|
||||
EXPECT_EQ(0, col.indexOf(o1.p()));
|
||||
EXPECT_EQ(1, col.indexOf(o2.p()));
|
||||
|
||||
EXPECT_EQ(UNDEFINED_SIZE_T, col.indexOf(NULL));
|
||||
EXPECT_EQ(UNDEFINED_SIZE_T, col.indexOf(o3.p()));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CollectionTest, Erase)
|
||||
{
|
||||
ref<MyObj> o1 = new MyObj(1);
|
||||
ref<MyObj> o2 = new MyObj(2);
|
||||
ref<MyObj> o3 = new MyObj(3);
|
||||
ref<MyObj> o4 = new MyObj(4);
|
||||
|
||||
MyObj* po1 = o1.p();
|
||||
MyObj* po2 = o2.p();
|
||||
MyObj* po3 = o3.p();
|
||||
MyObj* po4 = o3.p();
|
||||
|
||||
Collection<MyObj> col;
|
||||
col.push_back(po1);
|
||||
col.push_back(po2);
|
||||
col.push_back(po3);
|
||||
col.push_back(po4);
|
||||
EXPECT_EQ(4, col.size());
|
||||
|
||||
col.erase(NULL);
|
||||
EXPECT_EQ(4, col.size());
|
||||
|
||||
col.erase(po2);
|
||||
EXPECT_EQ(3, col.size());
|
||||
|
||||
col.erase(NULL);
|
||||
EXPECT_EQ(3, col.size());
|
||||
|
||||
col.eraseAt(1);
|
||||
ASSERT_EQ(2, col.size());
|
||||
|
||||
EXPECT_EQ(po1, col[0].p());
|
||||
EXPECT_EQ(po4, col[1].p());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#ifdef _DEBUG
|
||||
TEST(CollectionDeathTest, IllegalEraseAt)
|
||||
{
|
||||
Collection<MyObj> col;
|
||||
EXPECT_DEATH(col.eraseAt(0), "Assertion");
|
||||
EXPECT_DEATH(col.eraseAt(1), "Assertion");
|
||||
|
||||
col.push_back(new MyObj(1));
|
||||
col.push_back(new MyObj(2));
|
||||
EXPECT_EQ(2, col.size());
|
||||
|
||||
EXPECT_DEATH(col.eraseAt(2), "Assertion");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CollectionTest, IteratorTest)
|
||||
{
|
||||
ref<MyObj> o1 = new MyObj(2);
|
||||
ref<MyObj> o2 = new MyObj(3);
|
||||
ref<MyObj> o3 = new MyObj(4);
|
||||
ref<MyObj> o4 = new MyObj(5);
|
||||
|
||||
MyObj* po1 = o1.p();
|
||||
MyObj* po2 = o2.p();
|
||||
MyObj* po3 = o3.p();
|
||||
MyObj* po4 = o4.p();
|
||||
|
||||
Collection<MyObj> col;
|
||||
col.push_back(po1);
|
||||
col.push_back(po2);
|
||||
col.push_back(po3);
|
||||
col.push_back(po4);
|
||||
EXPECT_EQ(4, col.size());
|
||||
|
||||
Collection<MyObj>::iterator it = col.begin();
|
||||
|
||||
int sum = 0;
|
||||
int count = 0;
|
||||
while (it != col.end())
|
||||
{
|
||||
MyObj* obj = it->p();
|
||||
ASSERT_TRUE(obj != NULL);
|
||||
sum += obj->num();
|
||||
count++;
|
||||
it++;
|
||||
}
|
||||
|
||||
ASSERT_EQ(4, count);
|
||||
ASSERT_EQ(14, sum);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CollectionTest, ConstIteratorTest)
|
||||
{
|
||||
ref<MyObj> o1 = new MyObj(2);
|
||||
ref<MyObj> o2 = new MyObj(3);
|
||||
ref<MyObj> o3 = new MyObj(4);
|
||||
ref<MyObj> o4 = new MyObj(5);
|
||||
|
||||
MyObj* po1 = o1.p();
|
||||
MyObj* po2 = o2.p();
|
||||
MyObj* po3 = o3.p();
|
||||
MyObj* po4 = o4.p();
|
||||
|
||||
Collection<MyObj> col;
|
||||
col.push_back(po1);
|
||||
col.push_back(po2);
|
||||
col.push_back(po3);
|
||||
col.push_back(po4);
|
||||
EXPECT_EQ(4, col.size());
|
||||
|
||||
Collection<MyObj>::const_iterator it = col.begin();
|
||||
|
||||
int sum = 0;
|
||||
int count = 0;
|
||||
while (it != col.end())
|
||||
{
|
||||
const MyObj* obj = it->p();
|
||||
ASSERT_TRUE(obj != NULL);
|
||||
sum += obj->num();
|
||||
count++;
|
||||
it++;
|
||||
}
|
||||
|
||||
ASSERT_EQ(4, count);
|
||||
ASSERT_EQ(14, sum);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool compFunc(ref<MyObj> i,ref<MyObj> j) { return (*i<*j); }
|
||||
TEST(CollectionTest, SortAndBinSearchTest)
|
||||
{
|
||||
ref<MyObj> o1 = new MyObj(5);
|
||||
ref<MyObj> o2 = new MyObj(2);
|
||||
ref<MyObj> o3 = new MyObj(1);
|
||||
ref<MyObj> o4 = new MyObj(4);
|
||||
|
||||
MyObj* po1 = o1.p();
|
||||
MyObj* po2 = o2.p();
|
||||
MyObj* po3 = o3.p();
|
||||
MyObj* po4 = o4.p();
|
||||
|
||||
Collection<MyObj> col;
|
||||
col.push_back(po1);
|
||||
col.push_back(po2);
|
||||
col.push_back(po3);
|
||||
col.push_back(po4);
|
||||
EXPECT_EQ(4, col.size());
|
||||
|
||||
// Using standard stl sort algorithm
|
||||
sort(col.begin(), col.end(), compFunc);
|
||||
|
||||
EXPECT_EQ(1, col[0]->num());
|
||||
EXPECT_EQ(2, col[1]->num());
|
||||
EXPECT_EQ(4, col[2]->num());
|
||||
EXPECT_EQ(5, col[3]->num());
|
||||
|
||||
ref<MyObj> valToFind = new MyObj(2);
|
||||
EXPECT_TRUE(binary_search(col.begin(), col.end(), valToFind, compFunc));
|
||||
|
||||
valToFind->num(5);
|
||||
EXPECT_TRUE(binary_search(col.begin(), col.end(), valToFind, compFunc));
|
||||
|
||||
valToFind->num(88);
|
||||
EXPECT_FALSE(binary_search(col.begin(), col.end(), valToFind, compFunc));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void testFunc(ref<MyObj> obj) { obj->num(obj->num()*2); }
|
||||
TEST(CollectionTest, ForEach)
|
||||
{
|
||||
Collection<MyObj> col;
|
||||
col.push_back(new MyObj(5));
|
||||
col.push_back(new MyObj(3));
|
||||
col.push_back(new MyObj(8));
|
||||
col.push_back(new MyObj(2));
|
||||
|
||||
for_each(col.begin(), col.end(), testFunc);
|
||||
|
||||
EXPECT_EQ(10, col[0]->num());
|
||||
EXPECT_EQ(6, col[1]->num());
|
||||
EXPECT_EQ(16, col[2]->num());
|
||||
EXPECT_EQ(4, col[3]->num());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CollectionTest, Reverse)
|
||||
{
|
||||
Collection<MyObj> col;
|
||||
col.push_back(new MyObj(5));
|
||||
col.push_back(new MyObj(3));
|
||||
col.push_back(new MyObj(8));
|
||||
col.push_back(new MyObj(2));
|
||||
|
||||
reverse(col.begin(), col.end());
|
||||
|
||||
EXPECT_EQ(2, col[0]->num());
|
||||
EXPECT_EQ(8, col[1]->num());
|
||||
EXPECT_EQ(3, col[2]->num());
|
||||
EXPECT_EQ(5, col[3]->num());
|
||||
}
|
||||
|
||||
|
||||
|
||||
571
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfColor3-Test.cpp
Normal file
571
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfColor3-Test.cpp
Normal file
@@ -0,0 +1,571 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfColor3.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color3fTest, Constructors)
|
||||
{
|
||||
// Default constructor
|
||||
Color3f c0;
|
||||
EXPECT_FLOAT_EQ(0.0f, c0.r());
|
||||
EXPECT_FLOAT_EQ(0.0f, c0.g());
|
||||
EXPECT_FLOAT_EQ(0.0f, c0.b());
|
||||
|
||||
// Constructor with component init
|
||||
Color3f c1(0.1f, 0.2f, 0.3f);
|
||||
EXPECT_FLOAT_EQ(0.1f, c1.r());
|
||||
EXPECT_FLOAT_EQ(0.2f, c1.g());
|
||||
EXPECT_FLOAT_EQ(0.3f, c1.b());
|
||||
|
||||
// Copy constructor
|
||||
Color3f c2(c1);
|
||||
EXPECT_FLOAT_EQ(0.1f, c2.r());
|
||||
EXPECT_FLOAT_EQ(0.2f, c2.g());
|
||||
EXPECT_FLOAT_EQ(0.3f, c2.b());
|
||||
|
||||
Color3f c3 = c1;
|
||||
EXPECT_FLOAT_EQ(0.1f, c3.r());
|
||||
EXPECT_FLOAT_EQ(0.2f, c3.g());
|
||||
EXPECT_FLOAT_EQ(0.3f, c3.b());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color3fTest, ConstructionFromColorIdent)
|
||||
{
|
||||
{
|
||||
Color3f c(Color3f::RED);
|
||||
EXPECT_FLOAT_EQ(1.0f, c.r());
|
||||
EXPECT_FLOAT_EQ(0.0f, c.g());
|
||||
EXPECT_FLOAT_EQ(0.0f, c.b());
|
||||
}
|
||||
|
||||
{
|
||||
Color3f c(Color3f::GREEN);
|
||||
EXPECT_FLOAT_EQ(0.0f, c.r());
|
||||
EXPECT_FLOAT_EQ(1.0f, c.g());
|
||||
EXPECT_FLOAT_EQ(0.0f, c.b());
|
||||
}
|
||||
|
||||
{
|
||||
Color3f c(Color3f::BLUE);
|
||||
EXPECT_FLOAT_EQ(0.0f, c.r());
|
||||
EXPECT_FLOAT_EQ(0.0f, c.g());
|
||||
EXPECT_FLOAT_EQ(1.0f, c.b());
|
||||
}
|
||||
|
||||
{
|
||||
Color3f c(Color3f::GRAY);
|
||||
EXPECT_NEAR(0.50196f, c.r(), 1e-5);
|
||||
EXPECT_NEAR(0.50196f, c.g(), 1e-5);
|
||||
EXPECT_NEAR(0.50196f, c.b(), 1e-5);
|
||||
}
|
||||
|
||||
{
|
||||
Color3f c(Color3f::ORANGE);
|
||||
EXPECT_NEAR(1.00000f, c.r(), 1e-5);
|
||||
EXPECT_NEAR(0.64706f, c.g(), 1e-5);
|
||||
EXPECT_NEAR(0.00000f, c.b(), 1e-5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color3fTest, ConstructionFromByteColor)
|
||||
{
|
||||
const Color3ub cub0(0, 0, 0);
|
||||
const Color3ub cub1(255, 255, 255);
|
||||
const Color3ub cub2(51, 102, 153);
|
||||
|
||||
{
|
||||
Color3f c(cub0);
|
||||
EXPECT_FLOAT_EQ(0.0f, c.r());
|
||||
EXPECT_FLOAT_EQ(0.0f, c.g());
|
||||
EXPECT_FLOAT_EQ(0.0f, c.b());
|
||||
}
|
||||
|
||||
{
|
||||
Color3f c(cub1);
|
||||
EXPECT_FLOAT_EQ(1.0f, c.r());
|
||||
EXPECT_FLOAT_EQ(1.0f, c.g());
|
||||
EXPECT_FLOAT_EQ(1.0f, c.b());
|
||||
}
|
||||
|
||||
{
|
||||
Color3f c(cub2);
|
||||
EXPECT_FLOAT_EQ(0.2f, c.r());
|
||||
EXPECT_FLOAT_EQ(0.4f, c.g());
|
||||
EXPECT_FLOAT_EQ(0.6f, c.b());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color3fTest, AssignmentOperator)
|
||||
{
|
||||
Color3f c0(0.1f, 0.2f, 0.3f);
|
||||
|
||||
Color3f c1;
|
||||
c1 = c0;
|
||||
EXPECT_FLOAT_EQ(0.1f, c1.r());
|
||||
EXPECT_FLOAT_EQ(0.2f, c1.g());
|
||||
EXPECT_FLOAT_EQ(0.3f, c1.b());
|
||||
|
||||
Color3f c;
|
||||
c = Color3f::RED;
|
||||
EXPECT_FLOAT_EQ(1.0f, c.r());
|
||||
EXPECT_FLOAT_EQ(0.0f, c.g());
|
||||
EXPECT_FLOAT_EQ(0.0f, c.b());
|
||||
|
||||
c = Color3f::GREEN;
|
||||
EXPECT_FLOAT_EQ(0.0f, c.r());
|
||||
EXPECT_FLOAT_EQ(1.0f, c.g());
|
||||
EXPECT_FLOAT_EQ(0.0f, c.b());
|
||||
|
||||
c = Color3f::BLUE;
|
||||
EXPECT_FLOAT_EQ(0.0f, c.r());
|
||||
EXPECT_FLOAT_EQ(0.0f, c.g());
|
||||
EXPECT_FLOAT_EQ(1.0f, c.b());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color3fTest, Comparison)
|
||||
{
|
||||
const Color3f c0(0.1f, 0.2f, 0.3f);
|
||||
const Color3f c1(0.5f, 0.6f, 0.7f);
|
||||
const Color3f c2(0.5f, 0.6f, 0.7f);
|
||||
|
||||
EXPECT_TRUE(c0 == c0);
|
||||
EXPECT_TRUE(c1 == c1);
|
||||
EXPECT_TRUE(c1 == c2);
|
||||
EXPECT_FALSE(c0 == c1);
|
||||
|
||||
EXPECT_FALSE(c0 != c0);
|
||||
EXPECT_FALSE(c1 != c1);
|
||||
EXPECT_FALSE(c1 != c2);
|
||||
EXPECT_TRUE(c0 != c1);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color3fTest, SettersAndGetters)
|
||||
{
|
||||
// Component getters
|
||||
{
|
||||
const Color3f c(0.1f, 0.2f, 0.3f);
|
||||
EXPECT_FLOAT_EQ(0.1f, c.r());
|
||||
EXPECT_FLOAT_EQ(0.2f, c.g());
|
||||
EXPECT_FLOAT_EQ(0.3f, c.b());
|
||||
}
|
||||
|
||||
// Component setters
|
||||
{
|
||||
Color3f c;
|
||||
c.r() = 0.5f;
|
||||
c.g() = 0.6f;
|
||||
c.b() = 0.7f;
|
||||
EXPECT_FLOAT_EQ(0.5f, c.r());
|
||||
EXPECT_FLOAT_EQ(0.6f, c.g());
|
||||
EXPECT_FLOAT_EQ(0.7f, c.b());
|
||||
}
|
||||
|
||||
{
|
||||
Color3f c;
|
||||
c.set(0.1f, 0.2f, 0.3f);
|
||||
EXPECT_FLOAT_EQ(0.1f, c.r());
|
||||
EXPECT_FLOAT_EQ(0.2f, c.g());
|
||||
EXPECT_FLOAT_EQ(0.3f, c.b());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color3fTest, GetNativePointer)
|
||||
{
|
||||
Color3f c(0.1f, 0.2f, 0.3f);
|
||||
EXPECT_FLOAT_EQ(0.1f, c.r());
|
||||
EXPECT_FLOAT_EQ(0.2f, c.g());
|
||||
EXPECT_FLOAT_EQ(0.3f, c.b());
|
||||
|
||||
const float* p = c.ptr();
|
||||
EXPECT_FLOAT_EQ(0.1f, p[0]);
|
||||
EXPECT_FLOAT_EQ(0.2f, p[1]);
|
||||
EXPECT_FLOAT_EQ(0.3f, p[2]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color3fTest, Validation)
|
||||
{
|
||||
EXPECT_TRUE(Color3f(0.0f, 0.0f, 0.0f).isValid());
|
||||
EXPECT_TRUE(Color3f(1.0f, 1.0f, 1.0f).isValid());
|
||||
EXPECT_TRUE(Color3f(0.5f, 0.5f, 0.5f).isValid());
|
||||
EXPECT_TRUE(Color3f(0.0f, 1.0f, 0.0f).isValid());
|
||||
EXPECT_TRUE(Color3f(0.1f, 0.2f, 0.3f).isValid());
|
||||
|
||||
EXPECT_FALSE(Color3f( 2.0f, 0.5f, 0.5f).isValid());
|
||||
EXPECT_FALSE(Color3f( 0.5f, 2.0f, 0.5f).isValid());
|
||||
EXPECT_FALSE(Color3f( 0.5f, 0.5f, 2.0f).isValid());
|
||||
EXPECT_FALSE(Color3f(-0.5f, 0.5f, 0.5f).isValid());
|
||||
EXPECT_FALSE(Color3f( 0.5f, -0.5f, 0.5f).isValid());
|
||||
EXPECT_FALSE(Color3f(00.5f, 0.5f, -0.5f).isValid());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color3fTest, CreateFromByteColor)
|
||||
{
|
||||
Color3f c = Color3f::fromByteColor(0, 0, 0);
|
||||
EXPECT_FLOAT_EQ(0.0f, c.r());
|
||||
EXPECT_FLOAT_EQ(0.0f, c.g());
|
||||
EXPECT_FLOAT_EQ(0.0f, c.b());
|
||||
|
||||
c = Color3f::fromByteColor(255, 255, 255);
|
||||
EXPECT_FLOAT_EQ(1.0f, c.r());
|
||||
EXPECT_FLOAT_EQ(1.0f, c.g());
|
||||
EXPECT_FLOAT_EQ(1.0f, c.b());
|
||||
|
||||
c = Color3f::fromByteColor(127, 127, 127);
|
||||
EXPECT_LT(c.r(), 0.5);
|
||||
EXPECT_LT(c.g(), 0.5);
|
||||
EXPECT_LT(c.b(), 0.5);
|
||||
|
||||
c = Color3f::fromByteColor(128, 128, 128);
|
||||
EXPECT_GT(c.r(), 0.5);
|
||||
EXPECT_GT(c.g(), 0.5);
|
||||
EXPECT_GT(c.b(), 0.5);
|
||||
|
||||
c = Color3f::fromByteColor(1, 1, 254);
|
||||
EXPECT_NEAR(c.r(), 0.004, 0.001);
|
||||
EXPECT_NEAR(c.g(), 0.004, 0.001);
|
||||
EXPECT_NEAR(c.b(), 0.996, 0.001);
|
||||
|
||||
c = Color3f::fromByteColor(254, 1, 1);
|
||||
EXPECT_NEAR(c.r(), 0.996, 0.001);
|
||||
EXPECT_NEAR(c.g(), 0.004, 0.001);
|
||||
EXPECT_NEAR(c.b(), 0.004, 0.001);
|
||||
|
||||
c = Color3f::fromByteColor(64, 128, 192);
|
||||
EXPECT_NEAR(c.r(), 0.2509, 0.001);
|
||||
EXPECT_NEAR(c.g(), 0.5020, 0.001);
|
||||
EXPECT_NEAR(c.b(), 0.7539, 0.001);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color3fTest, GetAsByteColorComponents)
|
||||
{
|
||||
Color3f c(0, 0, 0);
|
||||
EXPECT_EQ(0, c.rByte());
|
||||
EXPECT_EQ(0, c.gByte());
|
||||
EXPECT_EQ(0, c.bByte());
|
||||
|
||||
c.set(1.0f, 1.0f, 1.0f);
|
||||
EXPECT_EQ(255, c.rByte());
|
||||
EXPECT_EQ(255, c.gByte());
|
||||
EXPECT_EQ(255, c.bByte());
|
||||
|
||||
c.set(-1.0f, -2.0f, -3.0f);
|
||||
EXPECT_EQ(0, c.rByte());
|
||||
EXPECT_EQ(0, c.gByte());
|
||||
EXPECT_EQ(0, c.bByte());
|
||||
|
||||
c.set(1.0f, 2.0f, 2.0f);
|
||||
EXPECT_EQ(255, c.rByte());
|
||||
EXPECT_EQ(255, c.gByte());
|
||||
EXPECT_EQ(255, c.bByte());
|
||||
|
||||
|
||||
c = Color3f::fromByteColor(0, 1, 2);
|
||||
EXPECT_EQ(0, c.rByte());
|
||||
EXPECT_EQ(1, c.gByte());
|
||||
EXPECT_EQ(2, c.bByte());
|
||||
|
||||
c = Color3f::fromByteColor(253, 254, 255);
|
||||
EXPECT_EQ(253, c.rByte());
|
||||
EXPECT_EQ(254, c.gByte());
|
||||
EXPECT_EQ(255, c.bByte());
|
||||
|
||||
c = Color3f::fromByteColor(64, 128, 192);
|
||||
EXPECT_EQ(64, c.rByte());
|
||||
EXPECT_EQ(128, c.gByte());
|
||||
EXPECT_EQ(192, c.bByte());
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color3ubTest, Constructors)
|
||||
{
|
||||
// Default constructor
|
||||
const Color3ub clr0;
|
||||
EXPECT_EQ(0, clr0.r());
|
||||
EXPECT_EQ(0, clr0.g());
|
||||
EXPECT_EQ(0, clr0.b());
|
||||
|
||||
// Constructor with component init
|
||||
const Color3ub clr1(11, 12, 13);
|
||||
EXPECT_EQ(11, clr1.r());
|
||||
EXPECT_EQ(12, clr1.g());
|
||||
EXPECT_EQ(13, clr1.b());
|
||||
|
||||
const Color3ub clr2(10, 20, 30);
|
||||
EXPECT_EQ(10, clr2.r());
|
||||
EXPECT_EQ(20, clr2.g());
|
||||
EXPECT_EQ(30, clr2.b());
|
||||
|
||||
|
||||
// Copy constructor
|
||||
{
|
||||
Color3ub c1(clr1);
|
||||
EXPECT_EQ(11, c1.r());
|
||||
EXPECT_EQ(12, c1.g());
|
||||
EXPECT_EQ(13, c1.b());
|
||||
|
||||
Color3ub c2 = clr1;
|
||||
EXPECT_EQ(11, c2.r());
|
||||
EXPECT_EQ(12, c2.g());
|
||||
EXPECT_EQ(13, c2.b());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color3ubTest, ConstructionFromColorIdent)
|
||||
{
|
||||
{
|
||||
Color3ub c(Color3::RED);
|
||||
EXPECT_EQ(255, c.r());
|
||||
EXPECT_EQ(0, c.g());
|
||||
EXPECT_EQ(0, c.b());
|
||||
}
|
||||
|
||||
{
|
||||
Color3ub c(Color3::GREEN);
|
||||
EXPECT_EQ(0, c.r());
|
||||
EXPECT_EQ(255, c.g());
|
||||
EXPECT_EQ(0, c.b());
|
||||
}
|
||||
|
||||
{
|
||||
Color3ub c(Color3::BLUE);
|
||||
EXPECT_EQ(0, c.r());
|
||||
EXPECT_EQ(0, c.g());
|
||||
EXPECT_EQ(255, c.b());
|
||||
}
|
||||
|
||||
{
|
||||
Color3ub c(Color3::GRAY);
|
||||
EXPECT_EQ(128, c.r());
|
||||
EXPECT_EQ(128, c.g());
|
||||
EXPECT_EQ(128, c.b());
|
||||
}
|
||||
|
||||
{
|
||||
Color3ub c(Color3::ORANGE);
|
||||
EXPECT_EQ(255, c.r());
|
||||
EXPECT_EQ(165, c.g());
|
||||
EXPECT_EQ(0, c.b());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color3ubTest, AssignmentOperators)
|
||||
{
|
||||
Color3ub c0(10, 20, 30);
|
||||
|
||||
{
|
||||
Color3ub c;
|
||||
c = c0;
|
||||
EXPECT_EQ(10, c.r());
|
||||
EXPECT_EQ(20, c.g());
|
||||
EXPECT_EQ(30, c.b());
|
||||
}
|
||||
|
||||
{
|
||||
Color3ub c;
|
||||
c = Color3::RED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color3ubTest, Comparison)
|
||||
{
|
||||
const Color3ub c0(1, 2, 3);
|
||||
const Color3ub c1(5, 6, 7);
|
||||
const Color3ub c2(5, 6, 7);
|
||||
|
||||
EXPECT_TRUE(c0 == c0);
|
||||
EXPECT_TRUE(c1 == c1);
|
||||
EXPECT_TRUE(c1 == c2);
|
||||
EXPECT_FALSE(c0 == c1);
|
||||
|
||||
EXPECT_FALSE(c0 != c0);
|
||||
EXPECT_FALSE(c1 != c1);
|
||||
EXPECT_FALSE(c1 != c2);
|
||||
EXPECT_TRUE(c0 != c1);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color3ubTest, SettersAndGetters)
|
||||
{
|
||||
// Component getters
|
||||
{
|
||||
const Color3ub c(1, 2, 3);
|
||||
EXPECT_EQ(1, c.r());
|
||||
EXPECT_EQ(2, c.g());
|
||||
EXPECT_EQ(3, c.b());
|
||||
}
|
||||
|
||||
// Component setters
|
||||
{
|
||||
Color3ub c;
|
||||
c.r() = 5;
|
||||
c.g() = 6;
|
||||
c.b() = 7;
|
||||
EXPECT_EQ(5, c.r());
|
||||
EXPECT_EQ(6, c.g());
|
||||
EXPECT_EQ(7, c.b());
|
||||
}
|
||||
|
||||
{
|
||||
Color3ub c(0, 0, 0);
|
||||
c.set(1, 2, 3);
|
||||
EXPECT_EQ(1, c.r());
|
||||
EXPECT_EQ(2, c.g());
|
||||
EXPECT_EQ(3, c.b());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color3ubTest, ConstructionFromFloatColor)
|
||||
{
|
||||
const Color3f cf0(0, 0, 0);
|
||||
const Color3f cf1(1, 1, 1);
|
||||
const Color3f cf2(0.2f, 0.4f, 0.6f);
|
||||
|
||||
{
|
||||
Color3ub c(cf0);
|
||||
EXPECT_EQ(0, c.r());
|
||||
EXPECT_EQ(0, c.g());
|
||||
EXPECT_EQ(0, c.b());
|
||||
}
|
||||
|
||||
{
|
||||
Color3ub c(cf1);
|
||||
EXPECT_EQ(255, c.r());
|
||||
EXPECT_EQ(255, c.g());
|
||||
EXPECT_EQ(255, c.b());
|
||||
}
|
||||
|
||||
{
|
||||
Color3ub c(cf2);
|
||||
EXPECT_EQ(51, c.r());
|
||||
EXPECT_EQ(102, c.g());
|
||||
EXPECT_EQ(153, c.b());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color3ubTest, GetNativePointer)
|
||||
{
|
||||
Color3ub c(1, 2, 3);
|
||||
EXPECT_EQ(1, c.r());
|
||||
EXPECT_EQ(2, c.g());
|
||||
EXPECT_EQ(3, c.b());
|
||||
|
||||
const ubyte* p = c.ptr();
|
||||
EXPECT_EQ(1, p[0]);
|
||||
EXPECT_EQ(2, p[1]);
|
||||
EXPECT_EQ(3, p[2]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
576
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfColor4-Test.cpp
Normal file
576
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfColor4-Test.cpp
Normal file
@@ -0,0 +1,576 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfColor4.h"
|
||||
#include "cvfColor3.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
// Color4fTest
|
||||
//
|
||||
//==================================================================================================
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color4fTest, Constructors)
|
||||
{
|
||||
// Default constructor
|
||||
Color4f c0;
|
||||
EXPECT_FLOAT_EQ(0.0f, c0.r());
|
||||
EXPECT_FLOAT_EQ(0.0f, c0.g());
|
||||
EXPECT_FLOAT_EQ(0.0f, c0.b());
|
||||
EXPECT_FLOAT_EQ(1.0f, c0.a());
|
||||
|
||||
// Constructor with component init
|
||||
Color4f c1(0.1f, 0.2f, 0.3f, 0.4f);
|
||||
EXPECT_FLOAT_EQ(0.1f, c1.r());
|
||||
EXPECT_FLOAT_EQ(0.2f, c1.g());
|
||||
EXPECT_FLOAT_EQ(0.3f, c1.b());
|
||||
EXPECT_FLOAT_EQ(0.4f, c1.a());
|
||||
|
||||
// Copy constructor
|
||||
Color4f c2(c1);
|
||||
EXPECT_FLOAT_EQ(0.1f, c2.r());
|
||||
EXPECT_FLOAT_EQ(0.2f, c2.g());
|
||||
EXPECT_FLOAT_EQ(0.3f, c2.b());
|
||||
EXPECT_FLOAT_EQ(0.4f, c2.a());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color4fTest, ConstructionFromColor3)
|
||||
{
|
||||
const Color3f rgb(0.1f, 0.2f, 0.3f);
|
||||
|
||||
{
|
||||
Color4f c(rgb);
|
||||
EXPECT_FLOAT_EQ(0.1f, c.r());
|
||||
EXPECT_FLOAT_EQ(0.2f, c.g());
|
||||
EXPECT_FLOAT_EQ(0.3f, c.b());
|
||||
EXPECT_FLOAT_EQ(1.0f, c.a());
|
||||
}
|
||||
|
||||
{
|
||||
Color4f c(rgb, 0.5f);
|
||||
EXPECT_FLOAT_EQ(0.1f, c.r());
|
||||
EXPECT_FLOAT_EQ(0.2f, c.g());
|
||||
EXPECT_FLOAT_EQ(0.3f, c.b());
|
||||
EXPECT_FLOAT_EQ(0.5f, c.a());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color4fTest, ConstructionFromColorIdent)
|
||||
{
|
||||
{
|
||||
Color4f c(Color3::RED);
|
||||
EXPECT_FLOAT_EQ(1.0f, c.r());
|
||||
EXPECT_FLOAT_EQ(0.0f, c.g());
|
||||
EXPECT_FLOAT_EQ(0.0f, c.b());
|
||||
EXPECT_FLOAT_EQ(1.0f, c.a());
|
||||
}
|
||||
|
||||
{
|
||||
Color4f c(Color3f::ORANGE);
|
||||
EXPECT_NEAR(1.00000f, c.r(), 1e-5);
|
||||
EXPECT_NEAR(0.64706f, c.g(), 1e-5);
|
||||
EXPECT_NEAR(0.00000f, c.b(), 1e-5);
|
||||
EXPECT_FLOAT_EQ(1.0f, c.a());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color4fTest, ConstructionFromByteColor)
|
||||
{
|
||||
const Color4ub cub0(0, 0, 0, 0);
|
||||
const Color4ub cub1(255, 255, 255, 255);
|
||||
const Color4ub cub2(51, 102, 153, 204);
|
||||
|
||||
{
|
||||
Color4f c(cub0);
|
||||
EXPECT_FLOAT_EQ(0.0f, c.r());
|
||||
EXPECT_FLOAT_EQ(0.0f, c.g());
|
||||
EXPECT_FLOAT_EQ(0.0f, c.b());
|
||||
EXPECT_FLOAT_EQ(0.0f, c.a());
|
||||
}
|
||||
|
||||
{
|
||||
Color4f c(cub1);
|
||||
EXPECT_FLOAT_EQ(1.0f, c.r());
|
||||
EXPECT_FLOAT_EQ(1.0f, c.g());
|
||||
EXPECT_FLOAT_EQ(1.0f, c.b());
|
||||
EXPECT_FLOAT_EQ(1.0f, c.a());
|
||||
}
|
||||
|
||||
{
|
||||
Color4f c(cub2);
|
||||
EXPECT_FLOAT_EQ(0.2f, c.r());
|
||||
EXPECT_FLOAT_EQ(0.4f, c.g());
|
||||
EXPECT_FLOAT_EQ(0.6f, c.b());
|
||||
EXPECT_FLOAT_EQ(0.8f, c.a());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color4fTest, Assignment)
|
||||
{
|
||||
Color4f c0(0.1f, 0.2f, 0.3f, 0.4f);
|
||||
|
||||
Color4f c1;
|
||||
c1 = c0;
|
||||
EXPECT_FLOAT_EQ(0.1f, c1.r());
|
||||
EXPECT_FLOAT_EQ(0.2f, c1.g());
|
||||
EXPECT_FLOAT_EQ(0.3f, c1.b());
|
||||
EXPECT_FLOAT_EQ(0.4f, c1.a());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color4fTest, Comparison)
|
||||
{
|
||||
const Color4f c0(0.1f, 0.2f, 0.3f, 0.4f);
|
||||
const Color4f c1(0.5f, 0.6f, 0.7f, 0.8f);
|
||||
const Color4f c2(0.5f, 0.6f, 0.7f, 0.8f);
|
||||
|
||||
EXPECT_TRUE(c0 == c0);
|
||||
EXPECT_TRUE(c1 == c1);
|
||||
EXPECT_TRUE(c1 == c2);
|
||||
EXPECT_FALSE(c0 == c1);
|
||||
|
||||
EXPECT_FALSE(c0 != c0);
|
||||
EXPECT_FALSE(c1 != c1);
|
||||
EXPECT_FALSE(c1 != c2);
|
||||
EXPECT_TRUE(c0 != c1);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color4fTest, SettersAndGetters)
|
||||
{
|
||||
// Component getters
|
||||
{
|
||||
const Color4f c(0.1f, 0.2f, 0.3f, 0.4f);
|
||||
EXPECT_FLOAT_EQ(0.1f, c.r());
|
||||
EXPECT_FLOAT_EQ(0.2f, c.g());
|
||||
EXPECT_FLOAT_EQ(0.3f, c.b());
|
||||
EXPECT_FLOAT_EQ(0.4f, c.a());
|
||||
}
|
||||
|
||||
// Component setters
|
||||
{
|
||||
Color4f c;
|
||||
c.r() = 0.5f;
|
||||
c.g() = 0.6f;
|
||||
c.b() = 0.7f;
|
||||
c.a() = 0.8f;
|
||||
EXPECT_FLOAT_EQ(0.5f, c.r());
|
||||
EXPECT_FLOAT_EQ(0.6f, c.g());
|
||||
EXPECT_FLOAT_EQ(0.7f, c.b());
|
||||
EXPECT_FLOAT_EQ(0.8f, c.a());
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
Color4f c;
|
||||
c.set(0.1f, 0.2f, 0.3f, 0.4f);
|
||||
EXPECT_FLOAT_EQ(0.1f, c.r());
|
||||
EXPECT_FLOAT_EQ(0.2f, c.g());
|
||||
EXPECT_FLOAT_EQ(0.3f, c.b());
|
||||
EXPECT_FLOAT_EQ(0.4f, c.a());
|
||||
}
|
||||
|
||||
{
|
||||
const Color3f rgb1(1.0f, 2.0f, 3.0f);
|
||||
Color4f c;
|
||||
c.set(rgb1, 4.0f);
|
||||
EXPECT_FLOAT_EQ(1.0f, c.r());
|
||||
EXPECT_FLOAT_EQ(2.0f, c.g());
|
||||
EXPECT_FLOAT_EQ(3.0f, c.b());
|
||||
EXPECT_FLOAT_EQ(4.0f, c.a());
|
||||
}
|
||||
|
||||
{
|
||||
const Color3f rgb2(4.0f, 5.0f, 6.0f);
|
||||
Color4f c;
|
||||
c.set(rgb2);
|
||||
EXPECT_FLOAT_EQ(4.0f, c.r());
|
||||
EXPECT_FLOAT_EQ(5.0f, c.g());
|
||||
EXPECT_FLOAT_EQ(6.0f, c.b());
|
||||
EXPECT_FLOAT_EQ(1.0f, c.a());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color4fTest, GetNativePointer)
|
||||
{
|
||||
Color4f c(0.1f, 0.2f, 0.3f, 0.4f);
|
||||
EXPECT_FLOAT_EQ(0.1f, c.r());
|
||||
EXPECT_FLOAT_EQ(0.2f, c.g());
|
||||
EXPECT_FLOAT_EQ(0.3f, c.b());
|
||||
EXPECT_FLOAT_EQ(0.4f, c.a());
|
||||
|
||||
const float* p = c.ptr();
|
||||
EXPECT_FLOAT_EQ(0.1f, p[0]);
|
||||
EXPECT_FLOAT_EQ(0.2f, p[1]);
|
||||
EXPECT_FLOAT_EQ(0.3f, p[2]);
|
||||
EXPECT_FLOAT_EQ(0.4f, p[3]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color4fTest, Validation)
|
||||
{
|
||||
EXPECT_TRUE(Color4f(0.0f, 0.0f, 0.0f, 0.0f).isValid());
|
||||
EXPECT_TRUE(Color4f(1.0f, 1.0f, 1.0f, 1.0f).isValid());
|
||||
EXPECT_TRUE(Color4f(0.5f, 0.5f, 0.5f, 0.5f).isValid());
|
||||
EXPECT_TRUE(Color4f(0.0f, 1.0f, 0.0f, 1.0f).isValid());
|
||||
EXPECT_TRUE(Color4f(0.1f, 0.2f, 0.3f, 0.4f).isValid());
|
||||
|
||||
EXPECT_FALSE(Color4f( 2.0f, 0.5f, 0.5f, 0.5f).isValid());
|
||||
EXPECT_FALSE(Color4f( 0.5f, 2.0f, 0.5f, 0.5f).isValid());
|
||||
EXPECT_FALSE(Color4f( 0.5f, 0.5f, 2.0f, 0.5f).isValid());
|
||||
EXPECT_FALSE(Color4f( 0.5f, 0.5f, 0.5f, 2.0f).isValid());
|
||||
EXPECT_FALSE(Color4f(-0.5f, 0.5f, 0.5f, 0.5f).isValid());
|
||||
EXPECT_FALSE(Color4f( 0.5f, -0.5f, 0.5f, 0.5f).isValid());
|
||||
EXPECT_FALSE(Color4f(00.5f, 0.5f, -0.5f, 0.5f).isValid());
|
||||
EXPECT_FALSE(Color4f(00.5f, 0.5f, 0.5f, -0.5f).isValid());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color4fTest, ConvertToColor3f)
|
||||
{
|
||||
const Color4f c(0.1f, 0.2f, 0.3f, 0.4f);
|
||||
|
||||
Color3f rgb = c.toColor3f();
|
||||
EXPECT_FLOAT_EQ(0.1f, rgb.r());
|
||||
EXPECT_FLOAT_EQ(0.2f, rgb.g());
|
||||
EXPECT_FLOAT_EQ(0.3f, rgb.b());
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
// Color4ubTest
|
||||
//
|
||||
//==================================================================================================
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color4ubTest, Constructors)
|
||||
{
|
||||
// Default constructor
|
||||
const Color4ub clr0;
|
||||
EXPECT_EQ(0, clr0.r());
|
||||
EXPECT_EQ(0, clr0.g());
|
||||
EXPECT_EQ(0, clr0.b());
|
||||
EXPECT_EQ(255, clr0.a());
|
||||
|
||||
// Constructor with component init
|
||||
const Color4ub clr1(11, 12, 13, 14);
|
||||
EXPECT_EQ(11, clr1.r());
|
||||
EXPECT_EQ(12, clr1.g());
|
||||
EXPECT_EQ(13, clr1.b());
|
||||
EXPECT_EQ(14, clr1.a());
|
||||
|
||||
const Color4ub clr2(10, 20, 30, 40);
|
||||
EXPECT_EQ(10, clr2.r());
|
||||
EXPECT_EQ(20, clr2.g());
|
||||
EXPECT_EQ(30, clr2.b());
|
||||
EXPECT_EQ(40, clr2.a());
|
||||
|
||||
// Copy constructor
|
||||
{
|
||||
Color4ub c1(clr1);
|
||||
EXPECT_EQ(11, c1.r());
|
||||
EXPECT_EQ(12, c1.g());
|
||||
EXPECT_EQ(13, c1.b());
|
||||
EXPECT_EQ(14, c1.a());
|
||||
|
||||
Color4ub c2 = clr1;
|
||||
EXPECT_EQ(11, c2.r());
|
||||
EXPECT_EQ(12, c2.g());
|
||||
EXPECT_EQ(13, c2.b());
|
||||
EXPECT_EQ(14, c2.a());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color4ubTest, ConstructionFromColor3)
|
||||
{
|
||||
Color3ub rgb(1, 2, 3);
|
||||
|
||||
{
|
||||
Color4ub c(rgb);
|
||||
EXPECT_EQ(1, c.r());
|
||||
EXPECT_EQ(2, c.g());
|
||||
EXPECT_EQ(3, c.b());
|
||||
EXPECT_EQ(255, c.a());
|
||||
}
|
||||
|
||||
{
|
||||
Color4ub c(rgb, 100);
|
||||
EXPECT_EQ(1, c.r());
|
||||
EXPECT_EQ(2, c.g());
|
||||
EXPECT_EQ(3, c.b());
|
||||
EXPECT_EQ(100, c.a());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color4ubTest, ConstructionFromColorIdent)
|
||||
{
|
||||
{
|
||||
Color4ub c(Color3::RED);
|
||||
EXPECT_EQ(255, c.r());
|
||||
EXPECT_EQ(0, c.g());
|
||||
EXPECT_EQ(0, c.b());
|
||||
EXPECT_EQ(255, c.a());
|
||||
}
|
||||
|
||||
{
|
||||
Color4ub c(Color3::GREEN);
|
||||
EXPECT_EQ(0, c.r());
|
||||
EXPECT_EQ(255, c.g());
|
||||
EXPECT_EQ(0, c.b());
|
||||
EXPECT_EQ(255, c.a());
|
||||
}
|
||||
|
||||
{
|
||||
Color4ub c(Color3::BLUE);
|
||||
EXPECT_EQ(0, c.r());
|
||||
EXPECT_EQ(0, c.g());
|
||||
EXPECT_EQ(255, c.b());
|
||||
EXPECT_EQ(255, c.a());
|
||||
}
|
||||
|
||||
{
|
||||
Color4ub c(Color3::GRAY);
|
||||
EXPECT_EQ(128, c.r());
|
||||
EXPECT_EQ(128, c.g());
|
||||
EXPECT_EQ(128, c.b());
|
||||
EXPECT_EQ(255, c.a());
|
||||
}
|
||||
|
||||
{
|
||||
Color4ub c(Color3::ORANGE);
|
||||
EXPECT_EQ(255, c.r());
|
||||
EXPECT_EQ(165, c.g());
|
||||
EXPECT_EQ(0, c.b());
|
||||
EXPECT_EQ(255, c.a());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color4ubTest, AssignmentOperators)
|
||||
{
|
||||
Color4ub c0(10, 20, 30, 40);
|
||||
|
||||
{
|
||||
Color4ub c;
|
||||
c = c0;
|
||||
EXPECT_EQ(10, c.r());
|
||||
EXPECT_EQ(20, c.g());
|
||||
EXPECT_EQ(30, c.b());
|
||||
EXPECT_EQ(40, c.a());
|
||||
}
|
||||
|
||||
{
|
||||
Color4ub c;
|
||||
c = Color4ub(Color3::RED);
|
||||
|
||||
EXPECT_EQ(255, c.r());
|
||||
EXPECT_EQ(0, c.g());
|
||||
EXPECT_EQ(0, c.b());
|
||||
EXPECT_EQ(255, c.a());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color4ubTest, Comparison)
|
||||
{
|
||||
const Color4ub c0(1, 2, 3, 4);
|
||||
const Color4ub c1(5, 6, 7, 8);
|
||||
const Color4ub c2(5, 6, 7, 8);
|
||||
|
||||
EXPECT_TRUE(c0 == c0);
|
||||
EXPECT_TRUE(c1 == c1);
|
||||
EXPECT_TRUE(c1 == c2);
|
||||
EXPECT_FALSE(c0 == c1);
|
||||
|
||||
EXPECT_FALSE(c0 != c0);
|
||||
EXPECT_FALSE(c1 != c1);
|
||||
EXPECT_FALSE(c1 != c2);
|
||||
EXPECT_TRUE(c0 != c1);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color4ubTest, SettersAndGetters)
|
||||
{
|
||||
// Component getters
|
||||
{
|
||||
const Color4ub c(1, 2, 3, 4);
|
||||
EXPECT_EQ(1, c.r());
|
||||
EXPECT_EQ(2, c.g());
|
||||
EXPECT_EQ(3, c.b());
|
||||
EXPECT_EQ(4, c.a());
|
||||
}
|
||||
|
||||
// Component setters
|
||||
{
|
||||
Color4ub c;
|
||||
c.r() = 5;
|
||||
c.g() = 6;
|
||||
c.b() = 7;
|
||||
c.a() = 8;
|
||||
EXPECT_EQ(5, c.r());
|
||||
EXPECT_EQ(6, c.g());
|
||||
EXPECT_EQ(7, c.b());
|
||||
EXPECT_EQ(8, c.a());
|
||||
}
|
||||
|
||||
{
|
||||
Color4ub c(0, 0, 0, 0);
|
||||
c.set(1, 2, 3, 4);
|
||||
EXPECT_EQ(1, c.r());
|
||||
EXPECT_EQ(2, c.g());
|
||||
EXPECT_EQ(3, c.b());
|
||||
EXPECT_EQ(4, c.a());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color4ubTest, ConstructionFromFloatColor)
|
||||
{
|
||||
const Color4f cf0(0, 0, 0, 0);
|
||||
const Color4f cf1(1, 1, 1, 1);
|
||||
const Color4f cf2(0.2f, 0.4f, 0.6f, 0.8f);
|
||||
|
||||
{
|
||||
Color4ub c(cf0);
|
||||
EXPECT_EQ(0, c.r());
|
||||
EXPECT_EQ(0, c.g());
|
||||
EXPECT_EQ(0, c.b());
|
||||
EXPECT_EQ(0, c.a());
|
||||
}
|
||||
|
||||
{
|
||||
Color4ub c(cf1);
|
||||
EXPECT_EQ(255, c.r());
|
||||
EXPECT_EQ(255, c.g());
|
||||
EXPECT_EQ(255, c.b());
|
||||
EXPECT_EQ(255, c.a());
|
||||
}
|
||||
|
||||
{
|
||||
Color4ub c(cf2);
|
||||
EXPECT_EQ(51, c.r());
|
||||
EXPECT_EQ(102, c.g());
|
||||
EXPECT_EQ(153, c.b());
|
||||
EXPECT_EQ(204, c.a());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Color4ubTest, GetNativePointer)
|
||||
{
|
||||
Color4ub c(1, 2, 3, 4);
|
||||
EXPECT_EQ(1, c.r());
|
||||
EXPECT_EQ(2, c.g());
|
||||
EXPECT_EQ(3, c.b());
|
||||
EXPECT_EQ(4, c.a());
|
||||
|
||||
const ubyte* p = c.ptr();
|
||||
EXPECT_EQ(1, p[0]);
|
||||
EXPECT_EQ(2, p[1]);
|
||||
EXPECT_EQ(3, p[2]);
|
||||
EXPECT_EQ(4, p[3]);
|
||||
}
|
||||
|
||||
68
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfDebugTimer-Test.cpp
Normal file
68
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfDebugTimer-Test.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfDebugTimer.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(DebugTimerTest, CoverageTest)
|
||||
{
|
||||
DebugTimer dt("MyPrefix", DebugTimer::DISABLED);
|
||||
|
||||
// Just calling all methods
|
||||
dt.restart();
|
||||
dt.echoMessage("MyEchoMessage");
|
||||
dt.reportTime();
|
||||
dt.reportTime("reportTime");
|
||||
dt.reportTimeMS();
|
||||
dt.reportTimeMS("reportTimeMS");
|
||||
dt.reportLapTimeMS();
|
||||
dt.reportLapTimeMS("reportLapTimeMS");
|
||||
dt.echoMessage("MySecondEchoMessage");
|
||||
}
|
||||
|
||||
|
||||
209
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfFlags-Test.cpp
Normal file
209
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfFlags-Test.cpp
Normal file
@@ -0,0 +1,209 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfFlags.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
enum MyColor
|
||||
{
|
||||
MyNoColor = 0x0000,
|
||||
MyRed = 0x0001,
|
||||
MyBlue = 0x0002,
|
||||
MyGreen = 0x004
|
||||
};
|
||||
|
||||
typedef Flags<MyColor> MyColors;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(FlagsTest, Constructors)
|
||||
{
|
||||
// Default ctor
|
||||
MyColors clrs0;
|
||||
EXPECT_TRUE(clrs0 == MyNoColor);
|
||||
|
||||
// Constructor with initialization
|
||||
MyColors clrs1(MyRed);
|
||||
EXPECT_TRUE(clrs1 == MyRed);
|
||||
|
||||
// Copy constructor
|
||||
MyColors clrs2(clrs1);
|
||||
EXPECT_TRUE(clrs2 == MyRed);
|
||||
|
||||
MyColors clrs3 = clrs1;
|
||||
EXPECT_TRUE(clrs3 == MyRed);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(FlagsTest, AssignmentOperators)
|
||||
{
|
||||
// Assignment from enum
|
||||
MyColors clrs1;
|
||||
clrs1 = MyRed;
|
||||
EXPECT_TRUE(clrs1 == MyRed);
|
||||
|
||||
// Assignment from other object
|
||||
MyColors clrs2;
|
||||
clrs2 = clrs1;
|
||||
EXPECT_TRUE(clrs1 == MyRed);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(FlagsTest, Comparison)
|
||||
{
|
||||
MyColors clrs1(MyRed);
|
||||
MyColors clrs2(MyRed);
|
||||
MyColors clrs3(MyBlue);
|
||||
MyColors clrs4(MyBlue);
|
||||
|
||||
EXPECT_TRUE(clrs1 == MyRed);
|
||||
EXPECT_TRUE(clrs1 != MyBlue);
|
||||
EXPECT_TRUE(clrs1 == clrs2);
|
||||
|
||||
EXPECT_TRUE(clrs3 == MyBlue);
|
||||
EXPECT_TRUE(clrs3 != MyRed);
|
||||
EXPECT_TRUE(clrs3 == clrs4);
|
||||
|
||||
EXPECT_TRUE(clrs1 != clrs3);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(FlagsTest, TestForFlag)
|
||||
{
|
||||
MyColors clrs1(MyRed);
|
||||
EXPECT_TRUE(clrs1.testFlag(MyRed));
|
||||
EXPECT_FALSE(clrs1.testFlag(MyBlue));
|
||||
|
||||
MyColors clrs2(MyBlue);
|
||||
EXPECT_TRUE(clrs2.testFlag(MyBlue));
|
||||
EXPECT_FALSE(clrs2.testFlag(MyGreen));
|
||||
|
||||
MyColors clrs3;
|
||||
clrs3 |= MyRed;
|
||||
clrs3 |= MyGreen;
|
||||
EXPECT_TRUE(clrs3.testFlag(MyRed));
|
||||
EXPECT_TRUE(clrs3.testFlag(MyGreen));
|
||||
EXPECT_FALSE(clrs3.testFlag(MyBlue));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(FlagsTest, BitwiseOrAssigment)
|
||||
{
|
||||
MyColors clrs1;
|
||||
EXPECT_TRUE(clrs1 == MyNoColor);
|
||||
|
||||
clrs1 |= MyRed;
|
||||
EXPECT_TRUE(clrs1 == MyRed);
|
||||
|
||||
clrs1 |= MyBlue;
|
||||
EXPECT_TRUE(clrs1 == (MyRed | MyBlue));
|
||||
|
||||
clrs1 |= MyNoColor;
|
||||
EXPECT_TRUE(clrs1 == (MyRed | MyBlue));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(FlagsTest, BitwiseOr)
|
||||
{
|
||||
MyColors clrs1(MyRed);
|
||||
MyColors clrs2(MyBlue);
|
||||
|
||||
MyColors clrs3 = clrs1 | clrs2;
|
||||
EXPECT_TRUE(clrs3 == (MyRed | MyBlue));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(FlagsTest, BitwiseAndAssigment)
|
||||
{
|
||||
MyColors clrs1(MyRed);
|
||||
clrs1 |= MyBlue;
|
||||
EXPECT_TRUE(clrs1 == (MyRed | MyBlue));
|
||||
|
||||
clrs1 &= MyRed;
|
||||
EXPECT_TRUE(clrs1 == MyRed);
|
||||
|
||||
clrs1 &= MyNoColor;
|
||||
EXPECT_TRUE(clrs1 == MyNoColor);
|
||||
EXPECT_TRUE(clrs1 == 0);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(FlagsTest, BitwiseAnd)
|
||||
{
|
||||
MyColors clrs1(MyRed);
|
||||
MyColors clrs2(MyBlue);
|
||||
|
||||
MyColors clrs3 = clrs1 | clrs2;
|
||||
EXPECT_TRUE(clrs3 == (MyRed | MyBlue));
|
||||
|
||||
clrs3 = clrs3 & MyRed;
|
||||
EXPECT_TRUE(clrs3 == MyRed);
|
||||
|
||||
clrs3 = clrs3 & MyBlue;
|
||||
EXPECT_TRUE(clrs3 == 0);
|
||||
}
|
||||
|
||||
|
||||
124
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfLogEvent-Test.cpp
Normal file
124
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfLogEvent-Test.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfLogEvent.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(LogEventTest, DefaultConstruction)
|
||||
{
|
||||
LogEvent le;
|
||||
|
||||
EXPECT_STREQ(L"", le.source().c_str());
|
||||
EXPECT_STREQ(L"", le.message().c_str());
|
||||
EXPECT_EQ(Logger::LL_ERROR, le.level());
|
||||
|
||||
EXPECT_STREQ("", le.location().fileName());
|
||||
EXPECT_STREQ("", le.location().functionName());
|
||||
EXPECT_EQ(-1, le.location().lineNumber());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(LogEventTest, NormalConstruction)
|
||||
{
|
||||
const wchar_t* src = L"mySourceLogger";
|
||||
const wchar_t* msg = L"myMessage";
|
||||
const Logger::Level level = Logger::LL_WARNING;
|
||||
const char* file = "theFile.cpp";
|
||||
const char* func = "theClass::theFunction()";
|
||||
const int line = 123;
|
||||
|
||||
LogEvent le(src, msg, level, CodeLocation(file, func, line));
|
||||
|
||||
EXPECT_STREQ(src, le.source().c_str());
|
||||
EXPECT_STREQ(msg, le.message().c_str());
|
||||
EXPECT_EQ(level, le.level());
|
||||
EXPECT_STREQ(file, le.location().fileName());
|
||||
EXPECT_STREQ(func, le.location().functionName());
|
||||
EXPECT_EQ(line, le.location().lineNumber());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(LogEventTest, CopyConstructionAndAssignment)
|
||||
{
|
||||
const wchar_t* src = L"mySourceLogger";
|
||||
const wchar_t* msg = L"myMessage";
|
||||
const Logger::Level level = Logger::LL_WARNING;
|
||||
const char* file = "theFile.cpp";
|
||||
const char* func = "theClass::theFunction()";
|
||||
const int line = 123;
|
||||
|
||||
LogEvent le0(src, msg, level, CodeLocation(file, func, line));
|
||||
|
||||
{
|
||||
LogEvent le(le0);
|
||||
|
||||
EXPECT_STREQ(src, le.source().c_str());
|
||||
EXPECT_STREQ(msg, le.message().c_str());
|
||||
EXPECT_EQ(level, le.level());
|
||||
EXPECT_STREQ(file, le.location().fileName());
|
||||
EXPECT_STREQ(func, le.location().functionName());
|
||||
EXPECT_EQ(line, le.location().lineNumber());
|
||||
}
|
||||
|
||||
{
|
||||
LogEvent le;
|
||||
le = le0;
|
||||
|
||||
EXPECT_STREQ(src, le.source().c_str());
|
||||
EXPECT_STREQ(msg, le.message().c_str());
|
||||
EXPECT_EQ(level, le.level());
|
||||
EXPECT_STREQ(file, le.location().fileName());
|
||||
EXPECT_STREQ(func, le.location().functionName());
|
||||
EXPECT_EQ(line, le.location().lineNumber());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
435
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfLogger-Test.cpp
Normal file
435
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfLogger-Test.cpp
Normal file
@@ -0,0 +1,435 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfLogger.h"
|
||||
#include "cvfLogManager.h"
|
||||
#include "cvfLogEvent.h"
|
||||
#include "cvfLogDestinationConsole.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
class MyLogDestination : public LogDestination
|
||||
{
|
||||
public:
|
||||
MyLogDestination(LogDestination* aRealDestination)
|
||||
: m_aRealDestination(aRealDestination)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void log(const LogEvent& logEvent)
|
||||
{
|
||||
m_lastLogEvent = logEvent;
|
||||
if (m_aRealDestination.notNull())
|
||||
{
|
||||
m_aRealDestination->log(logEvent);
|
||||
}
|
||||
}
|
||||
|
||||
LogEvent getLastAndClear()
|
||||
{
|
||||
LogEvent le = m_lastLogEvent;
|
||||
m_lastLogEvent = LogEvent();
|
||||
return le;
|
||||
}
|
||||
|
||||
private:
|
||||
LogEvent m_lastLogEvent;
|
||||
ref<LogDestination> m_aRealDestination;
|
||||
};
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(LoggerTest, BasicConstruction)
|
||||
{
|
||||
Logger l("myLogger", Logger::LL_WARNING, NULL);
|
||||
|
||||
EXPECT_STREQ(L"myLogger", l.name().c_str());
|
||||
EXPECT_EQ(Logger::LL_WARNING, l.level());
|
||||
EXPECT_TRUE(l.destination() == NULL);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(LoggerTest, SetAndQueryLogLevel)
|
||||
{
|
||||
ref<Logger> l = new Logger("myLogger", 0, NULL);
|
||||
|
||||
EXPECT_EQ(0, l->level());
|
||||
EXPECT_FALSE(l->isErrorEnabled());
|
||||
EXPECT_FALSE(l->isWarningEnabled());
|
||||
EXPECT_FALSE(l->isInfoEnabled());
|
||||
EXPECT_FALSE(l->isDebugEnabled());
|
||||
|
||||
l->setLevel(99);
|
||||
EXPECT_EQ(99, l->level());
|
||||
EXPECT_TRUE(l->isErrorEnabled());
|
||||
EXPECT_TRUE(l->isWarningEnabled());
|
||||
EXPECT_TRUE(l->isInfoEnabled());
|
||||
EXPECT_TRUE(l->isDebugEnabled());
|
||||
|
||||
l->setLevel(Logger::LL_ERROR);
|
||||
EXPECT_EQ(Logger::LL_ERROR, l->level());
|
||||
EXPECT_TRUE(l->isErrorEnabled());
|
||||
EXPECT_FALSE(l->isWarningEnabled());
|
||||
EXPECT_FALSE(l->isInfoEnabled());
|
||||
EXPECT_FALSE(l->isDebugEnabled());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(LoggerTest, FullLoggingAtDifferentLevels)
|
||||
{
|
||||
ref<MyLogDestination> dest = new MyLogDestination(NULL);
|
||||
ref<Logger> l = new Logger("myLogger", Logger::LL_DEBUG, dest.p());
|
||||
|
||||
{
|
||||
l->error("err1");
|
||||
LogEvent le = dest->getLastAndClear();
|
||||
EXPECT_EQ(Logger::LL_ERROR, le.level());
|
||||
EXPECT_STREQ(L"err1", le.message().c_str());
|
||||
}
|
||||
{
|
||||
l->warning("warn1");
|
||||
LogEvent le = dest->getLastAndClear();
|
||||
EXPECT_EQ(Logger::LL_WARNING, le.level());
|
||||
EXPECT_STREQ(L"warn1", le.message().c_str());
|
||||
}
|
||||
{
|
||||
l->info("info1");
|
||||
LogEvent le = dest->getLastAndClear();
|
||||
EXPECT_EQ(Logger::LL_INFO, le.level());
|
||||
EXPECT_STREQ(L"info1", le.message().c_str());
|
||||
}
|
||||
{
|
||||
l->debug("dbg1", CodeLocation());
|
||||
LogEvent le = dest->getLastAndClear();
|
||||
EXPECT_EQ(Logger::LL_DEBUG, le.level());
|
||||
EXPECT_STREQ(L"dbg1", le.message().c_str());
|
||||
}
|
||||
|
||||
// Log the same messages after setting log level to errors only
|
||||
l->setLevel(Logger::LL_ERROR);
|
||||
|
||||
{
|
||||
l->error("err1");
|
||||
LogEvent le = dest->getLastAndClear();
|
||||
EXPECT_EQ(Logger::LL_ERROR, le.level());
|
||||
EXPECT_STREQ(L"err1", le.message().c_str());
|
||||
}
|
||||
{
|
||||
l->warning("warn1");
|
||||
LogEvent le = dest->getLastAndClear();
|
||||
EXPECT_EQ(Logger::LL_ERROR, le.level());
|
||||
EXPECT_STREQ(L"", le.message().c_str());
|
||||
}
|
||||
{
|
||||
l->info("info1");
|
||||
LogEvent le = dest->getLastAndClear();
|
||||
EXPECT_EQ(Logger::LL_ERROR, le.level());
|
||||
EXPECT_STREQ(L"", le.message().c_str());
|
||||
}
|
||||
{
|
||||
l->debug("dbg1", CodeLocation());
|
||||
LogEvent le = dest->getLastAndClear();
|
||||
EXPECT_EQ(Logger::LL_ERROR, le.level());
|
||||
EXPECT_STREQ(L"", le.message().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(LoggerTest, TestLoggingMacros)
|
||||
{
|
||||
//ref<MyLogDestination> dest = new MyLogDestination(new LogDestinationConsole);
|
||||
ref<MyLogDestination> dest = new MyLogDestination(NULL);
|
||||
ref<Logger> l = new Logger("myLogger", Logger::LL_DEBUG, dest.p());
|
||||
|
||||
{
|
||||
CVF_LOG_ERROR(l, "err1");
|
||||
LogEvent le = dest->getLastAndClear();
|
||||
EXPECT_EQ(Logger::LL_ERROR, le.level());
|
||||
EXPECT_STREQ(L"err1", le.message().c_str());
|
||||
}
|
||||
{
|
||||
CVF_LOG_WARNING(l, "warn1");
|
||||
LogEvent le = dest->getLastAndClear();
|
||||
EXPECT_EQ(Logger::LL_WARNING, le.level());
|
||||
EXPECT_STREQ(L"warn1", le.message().c_str());
|
||||
}
|
||||
{
|
||||
CVF_LOG_INFO(l, "info1");
|
||||
LogEvent le = dest->getLastAndClear();
|
||||
EXPECT_EQ(Logger::LL_INFO, le.level());
|
||||
EXPECT_STREQ(L"info1", le.message().c_str());
|
||||
}
|
||||
{
|
||||
CVF_LOG_DEBUG(l, "dbg1");
|
||||
LogEvent le = dest->getLastAndClear();
|
||||
EXPECT_EQ(Logger::LL_DEBUG, le.level());
|
||||
EXPECT_STREQ(L"dbg1", le.message().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(LoggerTest, CreatingNamedLoggers)
|
||||
{
|
||||
ref<LogManager> myLogManager = new LogManager;
|
||||
ref<Logger> root = myLogManager->rootLogger();
|
||||
ASSERT_STREQ(L"", root->name().c_str());
|
||||
|
||||
const int rootLevel = root->level();
|
||||
ref<LogDestination> rootDestination = root->destination();
|
||||
|
||||
ref<Logger> l_moduleA_classA = myLogManager->logger("moduleA.classA");
|
||||
EXPECT_STREQ(L"moduleA.classA", l_moduleA_classA->name().c_str());
|
||||
EXPECT_EQ(rootLevel, l_moduleA_classA->level());
|
||||
EXPECT_EQ(rootDestination, l_moduleA_classA->destination());
|
||||
{
|
||||
// Get it again and make sure we get same pointer
|
||||
ref<Logger> l_moduleA_classA_2 = myLogManager->logger("moduleA.classA");
|
||||
EXPECT_EQ(l_moduleA_classA, l_moduleA_classA_2);
|
||||
}
|
||||
|
||||
ref<Logger> l_moduleA_classB = myLogManager->logger("moduleA.classB");
|
||||
EXPECT_STREQ(L"moduleA.classB", l_moduleA_classB->name().c_str());
|
||||
EXPECT_EQ(rootLevel, l_moduleA_classB->level());
|
||||
EXPECT_EQ(rootDestination, l_moduleA_classB->destination());
|
||||
|
||||
ref<Logger> l_moduleA = myLogManager->logger("moduleA");
|
||||
EXPECT_STREQ(L"moduleA", l_moduleA->name().c_str());
|
||||
EXPECT_EQ(rootLevel, l_moduleA->level());
|
||||
EXPECT_EQ(rootDestination, l_moduleA->destination());
|
||||
|
||||
// Now set another destination and level for ModuleA and create a new child logger
|
||||
const int moduleA_level = Logger::LL_DEBUG;
|
||||
ref<LogDestinationConsole> moduleA_destination = new LogDestinationConsole;
|
||||
l_moduleA->setLevel(moduleA_level);
|
||||
l_moduleA->setDestination(moduleA_destination.p());
|
||||
|
||||
ref<Logger> l_moduleA_classC = myLogManager->logger("moduleA.classC");
|
||||
EXPECT_STREQ(L"moduleA.classC", l_moduleA_classC->name().c_str());
|
||||
EXPECT_EQ(moduleA_level, l_moduleA_classC->level());
|
||||
EXPECT_EQ(moduleA_destination, l_moduleA_classC->destination());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(LoggerTest, SettingLevelRecursive)
|
||||
{
|
||||
ref<LogManager> myLogManager = new LogManager;
|
||||
|
||||
ref<Logger> mA = myLogManager->logger("moduleA");
|
||||
ref<Logger> mA_cX = myLogManager->logger("moduleA.classX");
|
||||
ref<Logger> mA_cX_f1 = myLogManager->logger("moduleA.classX.func1");
|
||||
ref<Logger> mA_cY = myLogManager->logger("moduleA.classY");
|
||||
ref<Logger> mB_cX = myLogManager->logger("moduleB.classX");
|
||||
ref<Logger> mB_cY_f2 = myLogManager->logger("moduleB.classY.func2");
|
||||
EXPECT_EQ(Logger::LL_WARNING, mA ->level());
|
||||
EXPECT_EQ(Logger::LL_WARNING, mA_cX ->level());
|
||||
EXPECT_EQ(Logger::LL_WARNING, mA_cX_f1 ->level());
|
||||
EXPECT_EQ(Logger::LL_WARNING, mA_cY ->level());
|
||||
EXPECT_EQ(Logger::LL_WARNING, mB_cX ->level());
|
||||
EXPECT_EQ(Logger::LL_WARNING, mB_cY_f2 ->level());
|
||||
|
||||
myLogManager->setLevelRecursive("", Logger::LL_DEBUG);
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA_cX ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA_cX_f1 ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA_cY ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mB_cX ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mB_cY_f2 ->level());
|
||||
|
||||
myLogManager->setLevelRecursive("", Logger::LL_DEBUG);
|
||||
myLogManager->setLevelRecursive("moduleA", Logger::LL_ERROR);
|
||||
EXPECT_EQ(Logger::LL_ERROR, mA ->level());
|
||||
EXPECT_EQ(Logger::LL_ERROR, mA_cX ->level());
|
||||
EXPECT_EQ(Logger::LL_ERROR, mA_cX_f1 ->level());
|
||||
EXPECT_EQ(Logger::LL_ERROR, mA_cY ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mB_cX ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mB_cY_f2 ->level());
|
||||
|
||||
myLogManager->setLevelRecursive("", Logger::LL_DEBUG);
|
||||
myLogManager->setLevelRecursive("moduleA.classX", Logger::LL_ERROR);
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA ->level());
|
||||
EXPECT_EQ(Logger::LL_ERROR, mA_cX ->level());
|
||||
EXPECT_EQ(Logger::LL_ERROR, mA_cX_f1 ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA_cY ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mB_cX ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mB_cY_f2 ->level());
|
||||
|
||||
myLogManager->setLevelRecursive("", Logger::LL_DEBUG);
|
||||
myLogManager->setLevelRecursive("moduleB.classY.func2", Logger::LL_ERROR);
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA_cX ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA_cX_f1 ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA_cY ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mB_cX ->level());
|
||||
EXPECT_EQ(Logger::LL_ERROR, mB_cY_f2 ->level());
|
||||
|
||||
|
||||
// The following should give no change
|
||||
myLogManager->setLevelRecursive("", Logger::LL_DEBUG);
|
||||
myLogManager->setLevelRecursive("module", Logger::LL_ERROR);
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA_cX ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA_cX_f1 ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA_cY ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mB_cX ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mB_cY_f2 ->level());
|
||||
|
||||
myLogManager->setLevelRecursive("classX", Logger::LL_ERROR);
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA_cX ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA_cX_f1 ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA_cY ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mB_cX ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mB_cY_f2 ->level());
|
||||
|
||||
myLogManager->setLevelRecursive("func1", Logger::LL_ERROR);
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA_cX ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA_cX_f1 ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mA_cY ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mB_cX ->level());
|
||||
EXPECT_EQ(Logger::LL_DEBUG, mB_cY_f2 ->level());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(LoggerTest, SettingDestinationRecursive)
|
||||
{
|
||||
ref<LogManager> myLogManager = new LogManager;
|
||||
|
||||
ref<LogDestination> root = myLogManager->rootLogger()->destination();
|
||||
ref<LogDestinationConsole> dest0 = new LogDestinationConsole;
|
||||
ref<LogDestinationConsole> dest1 = new LogDestinationConsole;
|
||||
|
||||
ref<Logger> mA = myLogManager->logger("moduleA");
|
||||
ref<Logger> mA_cX = myLogManager->logger("moduleA.classX");
|
||||
ref<Logger> mA_cX_f1 = myLogManager->logger("moduleA.classX.func1");
|
||||
ref<Logger> mA_cY = myLogManager->logger("moduleA.classY");
|
||||
ref<Logger> mB_cX = myLogManager->logger("moduleB.classX");
|
||||
ref<Logger> mB_cY_f2 = myLogManager->logger("moduleB.classY.func2");
|
||||
EXPECT_EQ(root, mA ->destination());
|
||||
EXPECT_EQ(root, mA_cX ->destination());
|
||||
EXPECT_EQ(root, mA_cX_f1 ->destination());
|
||||
EXPECT_EQ(root, mA_cY ->destination());
|
||||
EXPECT_EQ(root, mB_cX ->destination());
|
||||
EXPECT_EQ(root, mB_cY_f2 ->destination());
|
||||
|
||||
myLogManager->setDestinationRecursive("", dest0.p());
|
||||
EXPECT_EQ(dest0, mA ->destination());
|
||||
EXPECT_EQ(dest0, mA_cX ->destination());
|
||||
EXPECT_EQ(dest0, mA_cX_f1 ->destination());
|
||||
EXPECT_EQ(dest0, mA_cY ->destination());
|
||||
EXPECT_EQ(dest0, mB_cX ->destination());
|
||||
EXPECT_EQ(dest0, mB_cY_f2 ->destination());
|
||||
|
||||
myLogManager->setDestinationRecursive("", dest0.p());
|
||||
myLogManager->setDestinationRecursive("moduleA", dest1.p());
|
||||
EXPECT_EQ(dest1, mA ->destination());
|
||||
EXPECT_EQ(dest1, mA_cX ->destination());
|
||||
EXPECT_EQ(dest1, mA_cX_f1 ->destination());
|
||||
EXPECT_EQ(dest1, mA_cY ->destination());
|
||||
EXPECT_EQ(dest0, mB_cX ->destination());
|
||||
EXPECT_EQ(dest0, mB_cY_f2 ->destination());
|
||||
|
||||
myLogManager->setDestinationRecursive("", dest0.p());
|
||||
myLogManager->setDestinationRecursive("moduleA.classX", dest1.p());
|
||||
EXPECT_EQ(dest0, mA ->destination());
|
||||
EXPECT_EQ(dest1, mA_cX ->destination());
|
||||
EXPECT_EQ(dest1, mA_cX_f1 ->destination());
|
||||
EXPECT_EQ(dest0, mA_cY ->destination());
|
||||
EXPECT_EQ(dest0, mB_cX ->destination());
|
||||
EXPECT_EQ(dest0, mB_cY_f2 ->destination());
|
||||
|
||||
myLogManager->setDestinationRecursive("", dest0.p());
|
||||
myLogManager->setDestinationRecursive("moduleB.classY.func2", dest1.p());
|
||||
EXPECT_EQ(dest0, mA ->destination());
|
||||
EXPECT_EQ(dest0, mA_cX ->destination());
|
||||
EXPECT_EQ(dest0, mA_cX_f1 ->destination());
|
||||
EXPECT_EQ(dest0, mA_cY ->destination());
|
||||
EXPECT_EQ(dest0, mB_cX ->destination());
|
||||
EXPECT_EQ(dest1, mB_cY_f2 ->destination());
|
||||
|
||||
|
||||
// The following should give no change
|
||||
myLogManager->setDestinationRecursive("", dest0.p());
|
||||
myLogManager->setDestinationRecursive("module", dest1.p());
|
||||
EXPECT_EQ(dest0, mA ->destination());
|
||||
EXPECT_EQ(dest0, mA_cX ->destination());
|
||||
EXPECT_EQ(dest0, mA_cX_f1 ->destination());
|
||||
EXPECT_EQ(dest0, mA_cY ->destination());
|
||||
EXPECT_EQ(dest0, mB_cX ->destination());
|
||||
EXPECT_EQ(dest0, mB_cY_f2 ->destination());
|
||||
|
||||
myLogManager->setDestinationRecursive("classX", dest1.p());
|
||||
EXPECT_EQ(dest0, mA ->destination());
|
||||
EXPECT_EQ(dest0, mA_cX ->destination());
|
||||
EXPECT_EQ(dest0, mA_cX_f1 ->destination());
|
||||
EXPECT_EQ(dest0, mA_cY ->destination());
|
||||
EXPECT_EQ(dest0, mB_cX ->destination());
|
||||
EXPECT_EQ(dest0, mB_cY_f2 ->destination());
|
||||
|
||||
myLogManager->setDestinationRecursive("func1", dest1.p());
|
||||
EXPECT_EQ(dest0, mA ->destination());
|
||||
EXPECT_EQ(dest0, mA_cX ->destination());
|
||||
EXPECT_EQ(dest0, mA_cX_f1 ->destination());
|
||||
EXPECT_EQ(dest0, mA_cY ->destination());
|
||||
EXPECT_EQ(dest0, mB_cX ->destination());
|
||||
EXPECT_EQ(dest0, mB_cY_f2 ->destination());
|
||||
}
|
||||
|
||||
502
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfMath-Test.cpp
Normal file
502
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfMath-Test.cpp
Normal file
@@ -0,0 +1,502 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
// Brings in the math constants from math.h (via cmath include)
|
||||
// May not work on other platforms!
|
||||
#define _USE_MATH_DEFINES
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfMath.h"
|
||||
#include "cvfSystem.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
#ifdef WIN32
|
||||
// We intentionally divide by 0 so nuke the warning
|
||||
#pragma warning (disable: 4723)
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MathTest, MathAssumptions)
|
||||
{
|
||||
double dZero = 0.0;
|
||||
double dNaN = sqrt(-1.0);
|
||||
double dPosInf = 1.0/dZero;
|
||||
double dNegInf = -1.0/dZero;
|
||||
|
||||
EXPECT_NE(dNaN, dNaN);
|
||||
EXPECT_FALSE(dNaN == dNaN);
|
||||
EXPECT_TRUE(dNaN != dNaN);
|
||||
EXPECT_FALSE(1 > dNaN);
|
||||
EXPECT_FALSE(1 < dNaN);
|
||||
EXPECT_TRUE(!(1 > dNaN));
|
||||
EXPECT_TRUE(!(1 < dNaN));
|
||||
|
||||
EXPECT_EQ(dPosInf, dPosInf);
|
||||
EXPECT_TRUE(dPosInf == dPosInf);
|
||||
EXPECT_GT(dPosInf, 100);
|
||||
|
||||
EXPECT_EQ(dNegInf, dNegInf);
|
||||
EXPECT_TRUE(dNegInf == dNegInf);
|
||||
EXPECT_GT(-100, dNegInf);
|
||||
|
||||
EXPECT_GT(dPosInf, dNegInf);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MathTest, DegreesRadiansConversion)
|
||||
{
|
||||
ASSERT_DOUBLE_EQ(0, Math::toRadians(0.0));
|
||||
ASSERT_DOUBLE_EQ(M_PI, Math::toRadians(180.0));
|
||||
ASSERT_DOUBLE_EQ(M_PI_2, Math::toRadians(90.0));
|
||||
ASSERT_DOUBLE_EQ(M_PI_4, Math::toRadians(45.0));
|
||||
ASSERT_DOUBLE_EQ(-M_PI_4, Math::toRadians(-45.0));
|
||||
|
||||
ASSERT_DOUBLE_EQ(0.0, Math::toDegrees(0.0));
|
||||
ASSERT_DOUBLE_EQ(180.0, Math::toDegrees(M_PI));
|
||||
ASSERT_DOUBLE_EQ(90, Math::toDegrees(M_PI_2));
|
||||
ASSERT_DOUBLE_EQ(45.0, Math::toDegrees(M_PI_4));
|
||||
ASSERT_DOUBLE_EQ(-45.0, Math::toDegrees(-M_PI_4));
|
||||
|
||||
ASSERT_FLOAT_EQ(0.0f, Math::toRadians(0.0f));
|
||||
ASSERT_FLOAT_EQ(static_cast<float>(M_PI_4), Math::toRadians(45.0f));
|
||||
ASSERT_FLOAT_EQ(static_cast<float>(-M_PI_4),Math::toRadians(-45.0f));
|
||||
|
||||
ASSERT_DOUBLE_EQ(0.0f, Math::toDegrees(0.0f));
|
||||
ASSERT_FLOAT_EQ(45.0f, Math::toDegrees(static_cast<float>(M_PI_4)));
|
||||
ASSERT_FLOAT_EQ(-45.0f, Math::toDegrees(static_cast<float>(-M_PI_4)));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MathTest, CosAcos)
|
||||
{
|
||||
EXPECT_EQ(cos(2.5), Math::cos(2.5));
|
||||
EXPECT_EQ(cosf(1.5f), Math::cos(1.5f));
|
||||
|
||||
EXPECT_EQ(acos(-0.5), Math::acos(-0.5));
|
||||
EXPECT_EQ(acosf(0.5f), Math::acos(0.5f));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MathTest, SinAsin)
|
||||
{
|
||||
EXPECT_EQ(sin(2.5), Math::sin(2.5));
|
||||
EXPECT_EQ(sinf(1.5f), Math::sin(1.5f));
|
||||
|
||||
EXPECT_EQ(asin(-0.5), Math::asin(-0.5));
|
||||
EXPECT_EQ(asinf(0.5f), Math::asin(0.5f));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MathTest, TanAtan)
|
||||
{
|
||||
EXPECT_EQ(tan(2.5), Math::tan(2.5));
|
||||
EXPECT_EQ(tanf(1.5f), Math::tan(1.5f));
|
||||
|
||||
EXPECT_EQ(atan(-0.5), Math::atan(-0.5));
|
||||
EXPECT_EQ(atanf(0.5f), Math::atan(0.5f));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MathTest, Sqrt)
|
||||
{
|
||||
EXPECT_EQ(sqrt(9.0), Math::sqrt(9.0));
|
||||
EXPECT_EQ(sqrtf(16.0f), Math::sqrt(16.0f));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MathTest, Floor)
|
||||
{
|
||||
EXPECT_DOUBLE_EQ(1.0, Math::floor(1.5));
|
||||
EXPECT_EQ(floor(1.5), Math::floor(1.5));
|
||||
|
||||
EXPECT_FLOAT_EQ(2.0f, Math::floor(2.5f));
|
||||
EXPECT_EQ(floorf(2.5), Math::floor(2.5f));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MathTest, Ceil)
|
||||
{
|
||||
EXPECT_DOUBLE_EQ(2.0, Math::ceil(1.5));
|
||||
EXPECT_EQ(ceil(1.5), Math::ceil(1.5));
|
||||
|
||||
EXPECT_FLOAT_EQ(3.0f, Math::ceil(2.5f));
|
||||
EXPECT_EQ(ceilf(2.5), Math::ceil(2.5f));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MathTest, Fmod)
|
||||
{
|
||||
EXPECT_DOUBLE_EQ(1.0, Math::fmod(3.0, 2.0));
|
||||
EXPECT_EQ(fmod(7.0, 5.0), Math::fmod(7.0, 5.0));
|
||||
|
||||
EXPECT_FLOAT_EQ(1.0f, Math::fmod(5.0f, 2.0f));
|
||||
EXPECT_EQ(fmodf(9.0f, 5.0f), Math::fmod(9.0f, 5.0f));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MathTest, IsPow2)
|
||||
{
|
||||
EXPECT_TRUE(Math::isPow2(1));
|
||||
EXPECT_TRUE(Math::isPow2(2));
|
||||
EXPECT_TRUE(Math::isPow2(1024));
|
||||
EXPECT_TRUE(Math::isPow2(2147483648));
|
||||
|
||||
EXPECT_FALSE(Math::isPow2(0));
|
||||
EXPECT_FALSE(Math::isPow2(3));
|
||||
EXPECT_FALSE(Math::isPow2(1023));
|
||||
EXPECT_FALSE(Math::isPow2(2147483648 - 1));
|
||||
EXPECT_FALSE(Math::isPow2(2147483648 + 1));
|
||||
EXPECT_FALSE(Math::isPow2(4294967295));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MathTest, RoundUpPow2)
|
||||
{
|
||||
EXPECT_EQ(1, Math::roundUpPow2(0));
|
||||
EXPECT_EQ(1, Math::roundUpPow2(1));
|
||||
EXPECT_EQ(2, Math::roundUpPow2(2));
|
||||
EXPECT_EQ(4, Math::roundUpPow2(3));
|
||||
|
||||
EXPECT_EQ( 64, Math::roundUpPow2(63));
|
||||
EXPECT_EQ( 64, Math::roundUpPow2(64));
|
||||
EXPECT_EQ(128, Math::roundUpPow2(65));
|
||||
|
||||
EXPECT_EQ(2147483648, Math::roundUpPow2(2147483648 - 1));
|
||||
EXPECT_EQ(2147483648, Math::roundUpPow2(2147483648));
|
||||
|
||||
EXPECT_EQ(0, Math::roundUpPow2(2147483648 + 1));
|
||||
EXPECT_EQ(0, Math::roundUpPow2(4294967295));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MathTest, ValueInRange)
|
||||
{
|
||||
EXPECT_TRUE(Math::valueInRange((int) 0, 0, 0));
|
||||
EXPECT_TRUE(Math::valueInRange((int) 5, 5, 5));
|
||||
EXPECT_TRUE(Math::valueInRange((int) 5, -9, 9));
|
||||
EXPECT_TRUE(Math::valueInRange((int)-5, -9, 9));
|
||||
EXPECT_FALSE(Math::valueInRange((int)0, 1, 2));
|
||||
EXPECT_FALSE(Math::valueInRange((int)5, 3, 4));
|
||||
|
||||
EXPECT_TRUE(Math::valueInRange( 0.0f, 0.0f, 0.0f));
|
||||
EXPECT_TRUE(Math::valueInRange( 5.0f, 5.0f, 5.0f));
|
||||
EXPECT_TRUE(Math::valueInRange( 5.0f, -9.0f, 9.0f));
|
||||
EXPECT_TRUE(Math::valueInRange(-5.0f, -9.0f, 9.0f));
|
||||
EXPECT_FALSE(Math::valueInRange(0.0f, 1.0f, 2.0f));
|
||||
EXPECT_FALSE(Math::valueInRange(5.0f, 3.0f, 4.0f));
|
||||
|
||||
EXPECT_TRUE(Math::valueInRange( 0.0, 0.0, 0.0));
|
||||
EXPECT_TRUE(Math::valueInRange( 5.0, 5.0, 5.0));
|
||||
EXPECT_TRUE(Math::valueInRange( 5.0, -9.0, 9.0));
|
||||
EXPECT_TRUE(Math::valueInRange(-5.0, -9.0, 9.0));
|
||||
EXPECT_FALSE(Math::valueInRange(0.0, 1.0, 2.0));
|
||||
EXPECT_FALSE(Math::valueInRange(5.0, 3.0, 4.0));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MathTest, ValueInRange_InfNaN)
|
||||
{
|
||||
double dZero = 0.0;
|
||||
double dNaN = sqrt(-1.0);
|
||||
double dPosInf = 1.0/dZero;
|
||||
double dNegInf = -1.0/dZero;
|
||||
|
||||
EXPECT_FALSE(Math::valueInRange(dNaN, -99.0, 99.0));
|
||||
|
||||
EXPECT_FALSE(Math::valueInRange(dPosInf, -99.0, 99.0));
|
||||
EXPECT_FALSE(Math::valueInRange(dNegInf, -99.0, 99.0));
|
||||
|
||||
EXPECT_TRUE(Math::valueInRange( 0.0, dNegInf, dPosInf));
|
||||
EXPECT_TRUE(Math::valueInRange( 99.0, dNegInf, dPosInf));
|
||||
EXPECT_TRUE(Math::valueInRange(-99.0, dNegInf, dPosInf));
|
||||
|
||||
EXPECT_TRUE(Math::valueInRange(std::numeric_limits<double>::min(), dNegInf, dPosInf));
|
||||
EXPECT_TRUE(Math::valueInRange(std::numeric_limits<double>::max(), dNegInf, dPosInf));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MathTest, Clamp)
|
||||
{
|
||||
EXPECT_DOUBLE_EQ(0.0, Math::clamp( 1.0, 0.0, 0.0));
|
||||
EXPECT_DOUBLE_EQ(0.0, Math::clamp(-1.0, 0.0, 0.0));
|
||||
|
||||
EXPECT_DOUBLE_EQ( 5.0, Math::clamp( 5.0, 5.0, 6.0));
|
||||
EXPECT_DOUBLE_EQ( 6.0, Math::clamp( 6.0, 5.0, 6.0));
|
||||
EXPECT_DOUBLE_EQ(-6.0, Math::clamp(-6.0, -6.0, -5.0));
|
||||
EXPECT_DOUBLE_EQ(-5.0, Math::clamp(-5.0, -6.0, -5.0));
|
||||
|
||||
EXPECT_DOUBLE_EQ(2.0, Math::clamp( 3.0, 1.0, 2.0));
|
||||
EXPECT_DOUBLE_EQ(1.0, Math::clamp( 1.0, 1.0, 2.0));
|
||||
EXPECT_DOUBLE_EQ(1.0, Math::clamp(-1.0, 1.0, 2.0));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MathTest, Clamp_InfNan)
|
||||
{
|
||||
double dZero = 0.0;
|
||||
double dNaN = sqrt(-1.0);
|
||||
double dPosInf = 1.0/dZero;
|
||||
double dNegInf = -1.0/dZero;
|
||||
|
||||
EXPECT_DOUBLE_EQ( 0.0, Math::clamp( 0.0, dNegInf, dPosInf));
|
||||
EXPECT_DOUBLE_EQ( 1.0, Math::clamp( 1.0, dNegInf, dPosInf));
|
||||
EXPECT_DOUBLE_EQ(-1.0, Math::clamp(-1.0, dNegInf, dPosInf));
|
||||
|
||||
EXPECT_DOUBLE_EQ(-5.0, Math::clamp(dNegInf, -5.0, 5.0));
|
||||
EXPECT_DOUBLE_EQ( 5.0, Math::clamp(dPosInf, -5.0, 5.0));
|
||||
|
||||
EXPECT_DOUBLE_EQ(-5.0, Math::clamp(dNaN, -5.0, 5.0));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MathTest, IsUndefined)
|
||||
{
|
||||
{
|
||||
double val = UNDEFINED_DOUBLE;
|
||||
EXPECT_TRUE(Math::isUndefined(val));
|
||||
|
||||
val = 123.0;
|
||||
EXPECT_FALSE(Math::isUndefined(val));
|
||||
|
||||
val = -123.0;
|
||||
EXPECT_FALSE(Math::isUndefined(val));
|
||||
}
|
||||
|
||||
{
|
||||
float val = UNDEFINED_FLOAT;
|
||||
EXPECT_TRUE(Math::isUndefined(val));
|
||||
|
||||
val = 123.0f;
|
||||
EXPECT_FALSE(Math::isUndefined(val));
|
||||
|
||||
val = -123.0f;
|
||||
EXPECT_FALSE(Math::isUndefined(val));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MathTest, UndefinedUint)
|
||||
{
|
||||
cvf::uint ui = UNDEFINED_UINT;
|
||||
ASSERT_EQ(UNDEFINED_UINT, ui);
|
||||
ASSERT_EQ(-1, ui);
|
||||
ASSERT_EQ(4294967295u, ui);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MathTest, UndefinedSize_t)
|
||||
{
|
||||
size_t st = UNDEFINED_SIZE_T;
|
||||
ASSERT_EQ(UNDEFINED_SIZE_T, st);
|
||||
ASSERT_EQ(-1, st);
|
||||
|
||||
if (System::is64Bit())
|
||||
{
|
||||
ASSERT_EQ(18446744073709551615u, st);
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT_EQ(4294967295u, st);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MathTest, Abs)
|
||||
{
|
||||
{
|
||||
int i = 134;
|
||||
int j = -134;
|
||||
|
||||
EXPECT_EQ(134, Math::abs(i));
|
||||
EXPECT_EQ(134, Math::abs(j));
|
||||
EXPECT_EQ(134, Math::abs(j*2 + i));
|
||||
}
|
||||
|
||||
{
|
||||
float i = 134.0f;
|
||||
float j = -134.0f;
|
||||
|
||||
EXPECT_EQ(134.0f, Math::abs(i));
|
||||
EXPECT_EQ(134.0f, Math::abs(j));
|
||||
EXPECT_EQ(134.0f, Math::abs(j*2 + i));
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
double i = 134.0;
|
||||
double j = -134.0;
|
||||
|
||||
EXPECT_EQ(134.0, Math::abs(i));
|
||||
EXPECT_EQ(134.0, Math::abs(j));
|
||||
EXPECT_EQ(134.0, Math::abs(j*2 + i));
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MathTest, Sign)
|
||||
{
|
||||
{
|
||||
double val = UNDEFINED_DOUBLE;
|
||||
|
||||
val = 10.0;
|
||||
EXPECT_EQ(1, Math::sign(val));
|
||||
|
||||
val = 0.0001;
|
||||
EXPECT_EQ(1, Math::sign(val));
|
||||
|
||||
val = 0.0;
|
||||
EXPECT_EQ(1, Math::sign(val));
|
||||
|
||||
val = -0.0;
|
||||
EXPECT_EQ(1, Math::sign(val));
|
||||
|
||||
val = -0.0001;
|
||||
EXPECT_EQ(-1, Math::sign(val));
|
||||
|
||||
val = -10.0;
|
||||
EXPECT_EQ(-1, Math::sign(val));
|
||||
}
|
||||
|
||||
{
|
||||
float val = UNDEFINED_FLOAT;
|
||||
|
||||
val = 10.0f;
|
||||
EXPECT_EQ(1, Math::sign(val));
|
||||
|
||||
val = 0.0001f;
|
||||
EXPECT_EQ(1, Math::sign(val));
|
||||
|
||||
val = 0.0f;
|
||||
EXPECT_EQ(1, Math::sign(val));
|
||||
|
||||
val = -0.0f;
|
||||
EXPECT_EQ(1, Math::sign(val));
|
||||
|
||||
val = -0.0001f;
|
||||
EXPECT_EQ(-1, Math::sign(val));
|
||||
|
||||
val = -10.0f;
|
||||
EXPECT_EQ(-1, Math::sign(val));
|
||||
}
|
||||
|
||||
{
|
||||
int val = UNDEFINED_INT;
|
||||
|
||||
val = 10;
|
||||
EXPECT_EQ(1, Math::sign(val));
|
||||
|
||||
val = 1;
|
||||
EXPECT_EQ(1, Math::sign(val));
|
||||
|
||||
val = 0;
|
||||
EXPECT_EQ(1, Math::sign(val));
|
||||
|
||||
val = -0;
|
||||
EXPECT_EQ(1, Math::sign(val));
|
||||
|
||||
val = -1;
|
||||
EXPECT_EQ(-1, Math::sign(val));
|
||||
|
||||
val = -10;
|
||||
EXPECT_EQ(-1, Math::sign(val));
|
||||
}
|
||||
|
||||
}
|
||||
1157
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfMatrix3-Test.cpp
Normal file
1157
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfMatrix3-Test.cpp
Normal file
File diff suppressed because it is too large
Load Diff
2029
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfMatrix4-Test.cpp
Normal file
2029
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfMatrix4-Test.cpp
Normal file
File diff suppressed because it is too large
Load Diff
900
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfObject-Test.cpp
Normal file
900
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfObject-Test.cpp
Normal file
@@ -0,0 +1,900 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfObject.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
class ClassA : public Object
|
||||
{
|
||||
public:
|
||||
ClassA() { data = 1; }
|
||||
ClassA(int val) { data = val; }
|
||||
int data;
|
||||
};
|
||||
|
||||
class ClassB : public Object
|
||||
{
|
||||
public:
|
||||
ClassB() { data = 2; }
|
||||
int data;
|
||||
};
|
||||
|
||||
class DerivedClass : public ClassA
|
||||
{
|
||||
public:
|
||||
DerivedClass() { data = -1; D = 0; }
|
||||
int D;
|
||||
};
|
||||
|
||||
static ref<ClassA> createClassAInstance(int val)
|
||||
{
|
||||
return new ClassA(val);
|
||||
}
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
// ObjectTest
|
||||
//
|
||||
//==================================================================================================
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(ObjectTest, MinimalLifeCycle)
|
||||
{
|
||||
Object* obj = new ClassA;
|
||||
EXPECT_EQ(0, obj->refCount());
|
||||
|
||||
delete obj;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(ObjectTest, AddRefAndRelease)
|
||||
{
|
||||
Object* obj = new ClassA;
|
||||
EXPECT_EQ(0, obj->refCount());
|
||||
|
||||
EXPECT_EQ(1, obj->addRef());
|
||||
EXPECT_EQ(1, obj->refCount());
|
||||
|
||||
EXPECT_EQ(2, obj->addRef());
|
||||
EXPECT_EQ(2, obj->refCount());
|
||||
|
||||
EXPECT_EQ(1, obj->release());
|
||||
EXPECT_EQ(1, obj->refCount());
|
||||
|
||||
EXPECT_EQ(0, obj->release());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#if CVF_ENABLE_TIGHT_ASSERTS == 1
|
||||
TEST(ObjectDeathTest, AddRefAndReleaseBehaviorOnNullPointer)
|
||||
{
|
||||
Object* obj = NULL;
|
||||
|
||||
EXPECT_DEATH(obj->addRef(), "Assertion");
|
||||
EXPECT_DEATH(obj->refCount(), "Assertion");
|
||||
|
||||
// Release is OK on NULL pointer
|
||||
EXPECT_EQ(0, obj->release());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#if CVF_ENABLE_ASSERTS == 1
|
||||
TEST(ObjectDeathTest, DeleteAnObjectWithAReference)
|
||||
{
|
||||
Object* obj = new ClassA;
|
||||
obj->addRef();
|
||||
|
||||
EXPECT_DEATH(delete obj, "Assertion");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
// RefTest - tests for ref class
|
||||
//
|
||||
//==================================================================================================
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RefTest, ConstructWithNullPointer)
|
||||
{
|
||||
ref<ClassA> r;
|
||||
EXPECT_EQ(NULL, r.p());
|
||||
|
||||
const ref<ClassA> cr;
|
||||
EXPECT_EQ(NULL, cr.p());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RefTest, ConstructFromNakedPointer)
|
||||
{
|
||||
ClassA* pa = new ClassA;
|
||||
DerivedClass* pd = new DerivedClass;
|
||||
|
||||
{
|
||||
ref<ClassA> r(pa);
|
||||
EXPECT_EQ(pa, r.p());
|
||||
EXPECT_EQ(1, pa->refCount());
|
||||
}
|
||||
|
||||
{
|
||||
ref<ClassA> r(pd);
|
||||
EXPECT_EQ(pd, r.p());
|
||||
EXPECT_EQ(1, pd->refCount());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RefTest, CopyConstructor)
|
||||
{
|
||||
ClassA* pa = new ClassA;
|
||||
ref<ClassA> ra(pa);
|
||||
ASSERT_EQ(pa, ra.p());
|
||||
ASSERT_EQ(1, pa->refCount());
|
||||
|
||||
{
|
||||
ref<ClassA> r(ra);
|
||||
ASSERT_EQ(pa, r.p());
|
||||
EXPECT_EQ(2, pa->refCount());
|
||||
}
|
||||
|
||||
{
|
||||
ref<ClassA> r = ra;
|
||||
ASSERT_EQ(pa, r.p());
|
||||
EXPECT_EQ(2, pa->refCount());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RefTest, CopyConstructorFromTemporary)
|
||||
{
|
||||
ref<ClassA> r = createClassAInstance(99);
|
||||
EXPECT_EQ(1, r->refCount());
|
||||
EXPECT_EQ(99, r->data);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RefTest, ConstructFromRelatedRef)
|
||||
{
|
||||
DerivedClass* pd = new DerivedClass;
|
||||
ASSERT_EQ(-1, pd->data);
|
||||
|
||||
ref<DerivedClass> rd(pd);
|
||||
ASSERT_EQ(1, pd->refCount());
|
||||
ASSERT_EQ(-1, rd->data);
|
||||
|
||||
// Trigger construction from related (in this case derived)
|
||||
ref<ClassA> r(rd);
|
||||
EXPECT_EQ(pd, r.p());
|
||||
EXPECT_EQ(2, pd->refCount());
|
||||
EXPECT_EQ(-1, r->data);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RefTest, BasicLifeCycle)
|
||||
{
|
||||
ref<ClassA> smartPtr = new ClassA;
|
||||
ASSERT_EQ(1, smartPtr->refCount());
|
||||
{
|
||||
ref<ClassA> smartPtr2 = smartPtr;
|
||||
ASSERT_EQ(2, smartPtr->refCount());
|
||||
ASSERT_EQ(true, smartPtr == smartPtr2);
|
||||
|
||||
smartPtr->data = 3;
|
||||
ASSERT_EQ(3, smartPtr2->data);
|
||||
}
|
||||
|
||||
ASSERT_EQ(1, smartPtr->refCount());
|
||||
ASSERT_EQ(3, smartPtr->data);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RefTest, NullPointerTest)
|
||||
{
|
||||
ref<ClassA> smartPtr;
|
||||
ASSERT_TRUE(smartPtr.isNull());
|
||||
ASSERT_FALSE(smartPtr.notNull());
|
||||
|
||||
smartPtr = new ClassA;
|
||||
ASSERT_TRUE(smartPtr.notNull());
|
||||
ASSERT_FALSE(smartPtr.isNull());
|
||||
|
||||
smartPtr = NULL;
|
||||
ASSERT_TRUE(smartPtr.isNull());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RefTest, AssignmentFromNakedPointer)
|
||||
{
|
||||
ClassA* pNaked = new ClassA(99);
|
||||
ASSERT_EQ(0, pNaked->refCount());
|
||||
|
||||
ref<ClassA> r;
|
||||
r = pNaked;
|
||||
EXPECT_EQ(pNaked, r.p());
|
||||
EXPECT_EQ(99, r->data);
|
||||
EXPECT_EQ(1, pNaked->refCount());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RefTest, AssignmentFromNakedPointerDerivedClass)
|
||||
{
|
||||
DerivedClass* pNaked = new DerivedClass;
|
||||
ASSERT_EQ(0, pNaked->refCount());
|
||||
ASSERT_EQ(-1, pNaked->data);
|
||||
|
||||
ref<ClassA> r;
|
||||
r = pNaked;
|
||||
EXPECT_EQ(pNaked, r.p());
|
||||
EXPECT_EQ(-1, r->data);
|
||||
EXPECT_EQ(1, pNaked->refCount());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RefTest, AssignmentFromRef)
|
||||
{
|
||||
ClassA* p1 = new ClassA(10);
|
||||
ClassA* p2 = new ClassA(20);
|
||||
ASSERT_EQ(10, p1->data);
|
||||
ASSERT_EQ(20, p2->data);
|
||||
|
||||
ref<ClassA> r1(p1);
|
||||
ref<ClassA> r2(p2);
|
||||
ASSERT_EQ(p1, r1.p());
|
||||
ASSERT_EQ(p2, r2.p());
|
||||
ASSERT_EQ(1, p1->refCount());
|
||||
ASSERT_EQ(1, p2->refCount());
|
||||
|
||||
ref<ClassA> r;
|
||||
r = r1;
|
||||
EXPECT_EQ(p1, r.p());
|
||||
EXPECT_EQ(10, r->data);
|
||||
EXPECT_EQ(2, p1->refCount());
|
||||
EXPECT_EQ(1, p2->refCount());
|
||||
|
||||
r = r2;
|
||||
EXPECT_EQ(p2, r.p());
|
||||
EXPECT_EQ(20, r->data);
|
||||
EXPECT_EQ(1, p1->refCount());
|
||||
EXPECT_EQ(2, p2->refCount());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RefTest, AssignmentFromRefDerivedClasses)
|
||||
{
|
||||
ClassA* pa = new ClassA;
|
||||
DerivedClass* pd = new DerivedClass;
|
||||
|
||||
ref<ClassA> ra(pa);
|
||||
ref<DerivedClass> rd(pd);
|
||||
|
||||
{
|
||||
ref<Object> r;
|
||||
|
||||
r = ra;
|
||||
EXPECT_EQ(pa, r.p());
|
||||
EXPECT_EQ(2, pa->refCount());
|
||||
EXPECT_EQ(1, pd->refCount());
|
||||
|
||||
r = rd;
|
||||
EXPECT_EQ(pd, r.p());
|
||||
EXPECT_EQ(1, pa->refCount());
|
||||
EXPECT_EQ(2, pd->refCount());
|
||||
}
|
||||
|
||||
{
|
||||
ref<ClassA> r;
|
||||
|
||||
r = rd;
|
||||
EXPECT_EQ(pd, r.p());
|
||||
EXPECT_EQ(-1, r->data);
|
||||
EXPECT_EQ(1, pa->refCount());
|
||||
EXPECT_EQ(2, pd->refCount());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RefTest, CompareLessThan)
|
||||
{
|
||||
ref<ClassA> r1 = new ClassA(22);
|
||||
ref<ClassA> r2 = new ClassA(33);
|
||||
|
||||
if (r1.p() > r2.p())
|
||||
{
|
||||
EXPECT_TRUE(r2 < r1);
|
||||
EXPECT_FALSE(r1 < r2);
|
||||
}
|
||||
else
|
||||
{
|
||||
EXPECT_TRUE(r1 < r2);
|
||||
EXPECT_FALSE(r2 < r1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RefTest, Swap)
|
||||
{
|
||||
ClassA* p1 = new ClassA;
|
||||
ClassA* p2 = new ClassA;
|
||||
|
||||
ref<ClassA> r1 = p1;
|
||||
ref<ClassA> r2 = p2;
|
||||
|
||||
p1->data = 1;
|
||||
p2->data = 2;
|
||||
|
||||
r1.swap(r2);
|
||||
|
||||
EXPECT_EQ(p1, r2.p());
|
||||
EXPECT_EQ(p2, r1.p());
|
||||
EXPECT_EQ(2, r1->data);
|
||||
EXPECT_EQ(1, r2->data);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RefTest, GlobalSwap)
|
||||
{
|
||||
ClassA* p1 = new ClassA;
|
||||
ClassA* p2 = new ClassA;
|
||||
|
||||
ref<ClassA> r1 = p1;
|
||||
ref<ClassA> r2 = p2;
|
||||
|
||||
p1->data = 1;
|
||||
p2->data = 2;
|
||||
|
||||
swap(r1, r2);
|
||||
|
||||
EXPECT_EQ(p1, r2.p());
|
||||
EXPECT_EQ(p2, r1.p());
|
||||
EXPECT_EQ(2, r1->data);
|
||||
EXPECT_EQ(1, r2->data);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RefTest, ComparisonWithNakedPointer)
|
||||
{
|
||||
ref<ClassA> r1 = new ClassA(10);
|
||||
|
||||
ClassA* pNaked1 = r1.p();
|
||||
ASSERT_EQ(10, pNaked1->data);
|
||||
|
||||
EXPECT_TRUE((pNaked1 == r1));
|
||||
EXPECT_TRUE((r1 == pNaked1));
|
||||
EXPECT_FALSE((pNaked1 != r1));
|
||||
EXPECT_FALSE((r1 != pNaked1));
|
||||
|
||||
ClassA* pNaked2 = new ClassA(20);
|
||||
ASSERT_EQ(20, pNaked2->data);
|
||||
|
||||
EXPECT_FALSE((pNaked2 == r1));
|
||||
EXPECT_FALSE((r1 == pNaked2));
|
||||
EXPECT_TRUE((pNaked2 != r1));
|
||||
EXPECT_TRUE((r1 != pNaked2));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RefTest, ComparisonWithNakedPointerDerivedClass)
|
||||
{
|
||||
ref<ClassA> ra = new ClassA;
|
||||
ClassA* pNakedD = new DerivedClass;
|
||||
ASSERT_EQ(1, ra->data);
|
||||
ASSERT_EQ(-1, pNakedD->data);
|
||||
|
||||
EXPECT_FALSE((pNakedD == ra));
|
||||
EXPECT_FALSE((ra == pNakedD));
|
||||
EXPECT_TRUE((pNakedD != ra));
|
||||
EXPECT_TRUE((ra != pNakedD));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RefTest, RefObjectsInStdSet)
|
||||
{
|
||||
// This test relies on the less-than operator in cvf::ref
|
||||
// The test ensures that no other overload gets used instead when ordering the elements of the set
|
||||
ref<ClassA> r1 = new ClassA;
|
||||
ref<ClassA> r2 = new ClassA;
|
||||
ref<ClassA> r3 = new ClassA;
|
||||
r1->data = 1;
|
||||
r2->data = 2;
|
||||
r3->data = 3;
|
||||
EXPECT_EQ(1, r1->data);
|
||||
EXPECT_EQ(2, r2->data);
|
||||
EXPECT_EQ(3, r3->data);
|
||||
EXPECT_EQ(1, r1->refCount());
|
||||
EXPECT_EQ(1, r2->refCount());
|
||||
EXPECT_EQ(1, r3->refCount());
|
||||
|
||||
ClassA* p1 = r1.p();
|
||||
ClassA* p2 = r2.p();
|
||||
ClassA* p3 = r3.p();
|
||||
|
||||
std::set<ref<ClassA> > mySet;
|
||||
|
||||
mySet.insert(p1);
|
||||
EXPECT_EQ(2, r1->refCount());
|
||||
EXPECT_EQ(1, mySet.size());
|
||||
|
||||
mySet.insert(p1);
|
||||
EXPECT_EQ(2, r1->refCount());
|
||||
EXPECT_EQ(1, mySet.size());
|
||||
|
||||
mySet.insert(p2);
|
||||
EXPECT_EQ(2, r2->refCount());
|
||||
EXPECT_EQ(2, mySet.size());
|
||||
|
||||
mySet.insert(p3);
|
||||
EXPECT_EQ(2, r3->refCount());
|
||||
EXPECT_EQ(3, mySet.size());
|
||||
|
||||
mySet.erase(p2);
|
||||
EXPECT_EQ(1, r2->refCount());
|
||||
EXPECT_EQ(2, mySet.size());
|
||||
|
||||
EXPECT_TRUE(mySet.find(p1) != mySet.end());
|
||||
EXPECT_TRUE(mySet.find(p3) != mySet.end());
|
||||
EXPECT_TRUE(mySet.find(p2) == mySet.end());
|
||||
|
||||
mySet.clear();
|
||||
EXPECT_EQ(1, r1->refCount());
|
||||
EXPECT_EQ(1, r2->refCount());
|
||||
EXPECT_EQ(1, r3->refCount());
|
||||
EXPECT_EQ(0, mySet.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
// ConstRefTest - tests for cref class
|
||||
//
|
||||
//==================================================================================================
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(ConstRefTest, ConstructWithNullPointer)
|
||||
{
|
||||
cref<ClassA> r;
|
||||
EXPECT_EQ(NULL, r.p());
|
||||
|
||||
const cref<ClassA> cr;
|
||||
EXPECT_EQ(NULL, cr.p());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(ConstRefTest, ConstructFromNakedPointer)
|
||||
{
|
||||
ClassA* pa1 = new ClassA;
|
||||
const ClassA* pa2 = new ClassA;
|
||||
DerivedClass* pd = new DerivedClass;
|
||||
|
||||
{
|
||||
cref<ClassA> r(pa1);
|
||||
EXPECT_EQ(pa1, r.p());
|
||||
EXPECT_EQ(1, pa1->refCount());
|
||||
}
|
||||
|
||||
{
|
||||
cref<ClassA> r(pa2);
|
||||
EXPECT_EQ(pa2, r.p());
|
||||
EXPECT_EQ(1, pa2->refCount());
|
||||
}
|
||||
|
||||
{
|
||||
cref<ClassA> r(pd);
|
||||
EXPECT_EQ(pd, r.p());
|
||||
EXPECT_EQ(1, pd->refCount());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(ConstRefTest, CopyConstructor)
|
||||
{
|
||||
ClassA* pa = new ClassA;
|
||||
cref<ClassA> ra(pa);
|
||||
ASSERT_EQ(pa, ra.p());
|
||||
ASSERT_EQ(1, pa->refCount());
|
||||
|
||||
{
|
||||
cref<ClassA> r(ra);
|
||||
ASSERT_EQ(pa, r.p());
|
||||
EXPECT_EQ(2, pa->refCount());
|
||||
}
|
||||
|
||||
{
|
||||
cref<ClassA> r = ra;
|
||||
ASSERT_EQ(pa, r.p());
|
||||
EXPECT_EQ(2, pa->refCount());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(ConstRefTest, ConstructFromRelatedRef)
|
||||
{
|
||||
DerivedClass* pd = new DerivedClass;
|
||||
ASSERT_EQ(-1, pd->data);
|
||||
|
||||
cref<DerivedClass> rd(pd);
|
||||
ASSERT_EQ(1, pd->refCount());
|
||||
ASSERT_EQ(-1, rd->data);
|
||||
|
||||
// Trigger construction from related (in this case derived)
|
||||
cref<ClassA> r(rd);
|
||||
EXPECT_EQ(pd, r.p());
|
||||
EXPECT_EQ(2, pd->refCount());
|
||||
EXPECT_EQ(-1, r->data);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(ConstRefTest, NullPointerTest)
|
||||
{
|
||||
cref<ClassA> smartPtr;
|
||||
ASSERT_TRUE(smartPtr.isNull());
|
||||
ASSERT_FALSE(smartPtr.notNull());
|
||||
|
||||
smartPtr = new ClassA;
|
||||
ASSERT_TRUE(smartPtr.notNull());
|
||||
ASSERT_FALSE(smartPtr.isNull());
|
||||
|
||||
smartPtr = NULL;
|
||||
ASSERT_TRUE(smartPtr.isNull());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(ConstRefTest, AssignmentFromNakedPointer)
|
||||
{
|
||||
const ClassA* pNaked = new ClassA(99);
|
||||
ASSERT_EQ(0, pNaked->refCount());
|
||||
|
||||
cref<ClassA> r;
|
||||
r = pNaked;
|
||||
EXPECT_EQ(pNaked, r.p());
|
||||
EXPECT_EQ(99, r->data);
|
||||
EXPECT_EQ(1, pNaked->refCount());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(ConstRefTest, AssignmentFromNakedPointerDerivedClass)
|
||||
{
|
||||
const DerivedClass* pNaked = new DerivedClass;
|
||||
ASSERT_EQ(0, pNaked->refCount());
|
||||
ASSERT_EQ(-1, pNaked->data);
|
||||
|
||||
cref<ClassA> r;
|
||||
r = pNaked;
|
||||
EXPECT_EQ(pNaked, r.p());
|
||||
EXPECT_EQ(-1, r->data);
|
||||
EXPECT_EQ(1, pNaked->refCount());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(ConstRefTest, AssignmentFromRef)
|
||||
{
|
||||
const ClassA* p1 = new ClassA(10);
|
||||
const ClassA* p2 = new ClassA(20);
|
||||
ASSERT_EQ(10, p1->data);
|
||||
ASSERT_EQ(20, p2->data);
|
||||
|
||||
cref<ClassA> r1(p1);
|
||||
cref<ClassA> r2(p2);
|
||||
ASSERT_EQ(p1, r1.p());
|
||||
ASSERT_EQ(p2, r2.p());
|
||||
ASSERT_EQ(1, p1->refCount());
|
||||
ASSERT_EQ(1, p2->refCount());
|
||||
|
||||
cref<ClassA> r;
|
||||
r = r1;
|
||||
EXPECT_EQ(p1, r.p());
|
||||
EXPECT_EQ(10, r->data);
|
||||
EXPECT_EQ(2, p1->refCount());
|
||||
EXPECT_EQ(1, p2->refCount());
|
||||
|
||||
r = r2;
|
||||
EXPECT_EQ(p2, r.p());
|
||||
EXPECT_EQ(20, r->data);
|
||||
EXPECT_EQ(1, p1->refCount());
|
||||
EXPECT_EQ(2, p2->refCount());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(ConstRefTest, AssignmentFromRefDerivedClasses)
|
||||
{
|
||||
const ClassA* pa = new ClassA;
|
||||
const DerivedClass* pd = new DerivedClass;
|
||||
|
||||
cref<ClassA> ra(pa);
|
||||
cref<DerivedClass> rd(pd);
|
||||
|
||||
{
|
||||
cref<Object> r;
|
||||
|
||||
r = ra;
|
||||
EXPECT_EQ(pa, r.p());
|
||||
EXPECT_EQ(2, pa->refCount());
|
||||
EXPECT_EQ(1, pd->refCount());
|
||||
|
||||
r = rd;
|
||||
EXPECT_EQ(pd, r.p());
|
||||
EXPECT_EQ(1, pa->refCount());
|
||||
EXPECT_EQ(2, pd->refCount());
|
||||
}
|
||||
|
||||
{
|
||||
cref<ClassA> r;
|
||||
|
||||
r = rd;
|
||||
EXPECT_EQ(pd, r.p());
|
||||
EXPECT_EQ(-1, r->data);
|
||||
EXPECT_EQ(1, pa->refCount());
|
||||
EXPECT_EQ(2, pd->refCount());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(ConstRefTest, CompareLessThan)
|
||||
{
|
||||
cref<ClassA> r1 = new ClassA(22);
|
||||
cref<ClassA> r2 = new ClassA(33);
|
||||
|
||||
if (r1.p() > r2.p())
|
||||
{
|
||||
EXPECT_TRUE(r2 < r1);
|
||||
EXPECT_FALSE(r1 < r2);
|
||||
}
|
||||
else
|
||||
{
|
||||
EXPECT_TRUE(r1 < r2);
|
||||
EXPECT_FALSE(r2 < r1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(ConstRefTest, Swap)
|
||||
{
|
||||
const ClassA* p1 = new ClassA(1);
|
||||
const ClassA* p2 = new ClassA(2);
|
||||
|
||||
cref<ClassA> r1 = p1;
|
||||
cref<ClassA> r2 = p2;
|
||||
|
||||
r1.swap(r2);
|
||||
|
||||
EXPECT_EQ(p1, r2.p());
|
||||
EXPECT_EQ(p2, r1.p());
|
||||
EXPECT_EQ(2, r1->data);
|
||||
EXPECT_EQ(1, r2->data);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(ConstRefTest, ComparisonWithNakedPointer)
|
||||
{
|
||||
cref<ClassA> r1 = new ClassA(10);
|
||||
|
||||
const ClassA* pNaked1 = r1.p();
|
||||
ASSERT_EQ(10, pNaked1->data);
|
||||
|
||||
EXPECT_TRUE((pNaked1 == r1));
|
||||
EXPECT_TRUE((r1 == pNaked1));
|
||||
EXPECT_FALSE((pNaked1 != r1));
|
||||
EXPECT_FALSE((r1 != pNaked1));
|
||||
|
||||
const ClassA* pNaked2 = new ClassA(20);
|
||||
ASSERT_EQ(20, pNaked2->data);
|
||||
|
||||
EXPECT_FALSE((pNaked2 == r1));
|
||||
EXPECT_FALSE((r1 == pNaked2));
|
||||
EXPECT_TRUE((pNaked2 != r1));
|
||||
EXPECT_TRUE((r1 != pNaked2));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(ConstRefTest, ComparisonWithNakedPointerDerivedClass)
|
||||
{
|
||||
cref<ClassA> ra = new ClassA;
|
||||
const ClassA* pNakedD = new DerivedClass;
|
||||
ASSERT_EQ(1, ra->data);
|
||||
ASSERT_EQ(-1, pNakedD->data);
|
||||
|
||||
EXPECT_FALSE((pNakedD == ra));
|
||||
EXPECT_FALSE((ra == pNakedD));
|
||||
EXPECT_TRUE((pNakedD != ra));
|
||||
EXPECT_TRUE((ra != pNakedD));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(ConstRefTest, RefObjectsInStdSet)
|
||||
{
|
||||
// This test relies on the less-than operator in cvf::cref
|
||||
// The test ensures that no other overload gets used instead when ordering the elements of the set
|
||||
cref<ClassA> r1 = new ClassA(1);
|
||||
cref<ClassA> r2 = new ClassA(2);
|
||||
cref<ClassA> r3 = new ClassA(3);
|
||||
EXPECT_EQ(1, r1->data);
|
||||
EXPECT_EQ(2, r2->data);
|
||||
EXPECT_EQ(3, r3->data);
|
||||
EXPECT_EQ(1, r1->refCount());
|
||||
EXPECT_EQ(1, r2->refCount());
|
||||
EXPECT_EQ(1, r3->refCount());
|
||||
|
||||
const ClassA* p1 = r1.p();
|
||||
const ClassA* p2 = r2.p();
|
||||
const ClassA* p3 = r3.p();
|
||||
|
||||
std::set<cref<ClassA> > mySet;
|
||||
|
||||
mySet.insert(p1);
|
||||
EXPECT_EQ(2, r1->refCount());
|
||||
EXPECT_EQ(1, mySet.size());
|
||||
|
||||
mySet.insert(p1);
|
||||
EXPECT_EQ(2, r1->refCount());
|
||||
EXPECT_EQ(1, mySet.size());
|
||||
|
||||
mySet.insert(p2);
|
||||
EXPECT_EQ(2, r2->refCount());
|
||||
EXPECT_EQ(2, mySet.size());
|
||||
|
||||
mySet.insert(p3);
|
||||
EXPECT_EQ(2, r3->refCount());
|
||||
EXPECT_EQ(3, mySet.size());
|
||||
|
||||
mySet.erase(p2);
|
||||
EXPECT_EQ(1, r2->refCount());
|
||||
EXPECT_EQ(2, mySet.size());
|
||||
|
||||
EXPECT_TRUE(mySet.find(p1) != mySet.end());
|
||||
EXPECT_TRUE(mySet.find(p3) != mySet.end());
|
||||
EXPECT_TRUE(mySet.find(p2) == mySet.end());
|
||||
|
||||
mySet.clear();
|
||||
EXPECT_EQ(1, r1->refCount());
|
||||
EXPECT_EQ(1, r2->refCount());
|
||||
EXPECT_EQ(1, r3->refCount());
|
||||
EXPECT_EQ(0, mySet.size());
|
||||
}
|
||||
|
||||
535
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfPlane-Test.cpp
Normal file
535
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfPlane-Test.cpp
Normal file
@@ -0,0 +1,535 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfPlane.h"
|
||||
#include "cvfMath.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PlaneTest, BasicConstruction)
|
||||
{
|
||||
Plane plane1;
|
||||
EXPECT_FALSE(plane1.isValid());
|
||||
|
||||
Plane plane2(1.0, 2.0, 3.0, 4.0);
|
||||
EXPECT_TRUE(plane2.isValid());
|
||||
|
||||
Plane plane3(plane2);
|
||||
EXPECT_TRUE(plane3.isValid());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PlaneTest, Operators)
|
||||
{
|
||||
Plane plane1;
|
||||
Plane plane2(1.0, 2.0, 3.0, 4.0);
|
||||
Plane plane3(plane2);
|
||||
Plane plane4 = plane3; // Assignment operator
|
||||
|
||||
|
||||
// == operator
|
||||
// --------------------------------------
|
||||
|
||||
// Test plane1
|
||||
EXPECT_FALSE(plane1==plane2);
|
||||
EXPECT_FALSE(plane1==plane3);
|
||||
EXPECT_FALSE(plane1==plane4);
|
||||
|
||||
// Test plane2
|
||||
EXPECT_FALSE(plane2==plane1);
|
||||
EXPECT_TRUE( plane2==plane3);
|
||||
EXPECT_TRUE( plane2==plane4);
|
||||
|
||||
// Test plane3
|
||||
EXPECT_FALSE(plane3==plane1);
|
||||
EXPECT_TRUE( plane3==plane2);
|
||||
EXPECT_TRUE( plane3==plane4);
|
||||
|
||||
// Test plane4
|
||||
EXPECT_FALSE(plane4==plane1);
|
||||
EXPECT_TRUE( plane4==plane2);
|
||||
EXPECT_TRUE( plane4==plane3);
|
||||
|
||||
|
||||
// != operator
|
||||
// --------------------------------------
|
||||
|
||||
// Test plane1
|
||||
EXPECT_TRUE( plane1!=plane2);
|
||||
EXPECT_TRUE( plane1!=plane3);
|
||||
EXPECT_TRUE( plane1!=plane4);
|
||||
|
||||
// Test plane2
|
||||
EXPECT_TRUE( plane2!=plane1);
|
||||
EXPECT_FALSE(plane2!=plane3);
|
||||
EXPECT_FALSE(plane2!=plane4);
|
||||
|
||||
// Test plane3
|
||||
EXPECT_TRUE( plane3!=plane1);
|
||||
EXPECT_FALSE(plane3!=plane2);
|
||||
EXPECT_FALSE(plane3!=plane4);
|
||||
|
||||
// Test plane4
|
||||
EXPECT_TRUE( plane4!=plane1);
|
||||
EXPECT_FALSE(plane4!=plane2);
|
||||
EXPECT_FALSE(plane4!=plane3);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PlaneTest, IsValid)
|
||||
{
|
||||
Plane plane1;
|
||||
EXPECT_FALSE(plane1.isValid());
|
||||
|
||||
Plane plane2(0.0, 0.0, 0.0, 0.0);
|
||||
EXPECT_FALSE(plane2.isValid());
|
||||
|
||||
Plane plane3(1.0, 2.0, 3.0, 4.0);
|
||||
EXPECT_TRUE(plane3.isValid());
|
||||
|
||||
plane2 = plane3;
|
||||
EXPECT_TRUE(plane2.isValid());
|
||||
|
||||
plane2 = plane1;
|
||||
EXPECT_FALSE(plane2.isValid());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PlaneTest, Set)
|
||||
{
|
||||
Plane plane;
|
||||
plane.set(7.0, -5.0, -3.0, -4.0);
|
||||
|
||||
// Points which should be located in the plane
|
||||
Vec3d p1(1.0, 0.0, 1.0);
|
||||
Vec3d p2(2.0, 2.0, 0.0);
|
||||
Vec3d p3(3.0, 1.0, 4.0);
|
||||
|
||||
EXPECT_DOUBLE_EQ(0.0, plane.distance(p1));
|
||||
EXPECT_DOUBLE_EQ(0.0, plane.distance(p2));
|
||||
EXPECT_DOUBLE_EQ(0.0, plane.distance(p3));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#ifdef _DEBUG
|
||||
TEST(PlaneDeathTest, Set)
|
||||
{
|
||||
Plane plane;
|
||||
EXPECT_DEATH(plane.set(0.0, 0.0, 0.0, 0.0), "Assertion");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PlaneTest, SetFromPointAndNormal)
|
||||
{
|
||||
Vec3d point(1.0, 2.0, 3.0);
|
||||
Vec3d normal(1.0, 8.0, 6.0);
|
||||
|
||||
// Define a plane by point and normal
|
||||
Plane plane;
|
||||
EXPECT_TRUE(plane.setFromPointAndNormal(point, normal));
|
||||
|
||||
// Project a point we know is on the plane down on the plane itself.
|
||||
// This projected point should be the same as the unprojected point
|
||||
Vec3d projectedPoint = plane.projectPoint(point);
|
||||
EXPECT_DOUBLE_EQ(point.x(), projectedPoint.x());
|
||||
EXPECT_DOUBLE_EQ(point.y(), projectedPoint.y());
|
||||
EXPECT_DOUBLE_EQ(point.z(), projectedPoint.z());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PlaneTest, SetFromPoints)
|
||||
{
|
||||
Vec3d p1(1.0, 2.0, 3.0);
|
||||
Vec3d p2(4.0, 5.0, 6.0);
|
||||
Vec3d p3(7.0, 8.0, 9.0);
|
||||
Vec3d p4(1.0, 1.1, 2.42);
|
||||
Vec3d p5(3.0, 5.1, 1.22);
|
||||
Vec3d normal(1.0, 2.0, 3.0);
|
||||
Plane plane;
|
||||
|
||||
// Define a plane from three points on a line, which should fail
|
||||
EXPECT_FALSE(plane.setFromPoints(p1, p2, p3));
|
||||
|
||||
// Define a plane by 3 points not aligned on a line
|
||||
EXPECT_TRUE(plane.setFromPoints(p1, p4, p5));
|
||||
|
||||
// Project a point we know is on the plane down on the plane itself.
|
||||
// This projected point should be the same as the unprojected point
|
||||
Vec3d pointInPlane = (p1+p4+p5)/3.0;
|
||||
Vec3d projectedPoint = plane.projectPoint(pointInPlane);
|
||||
EXPECT_DOUBLE_EQ(pointInPlane.x(), projectedPoint.x());
|
||||
EXPECT_DOUBLE_EQ(pointInPlane.y(), projectedPoint.y());
|
||||
EXPECT_DOUBLE_EQ(pointInPlane.z(), projectedPoint.z());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PlaneTest, Normal)
|
||||
{
|
||||
Vec3d point(1.0, 2.0, 3.0);
|
||||
Vec3d normal(1.0, 8.0, 6.0);
|
||||
Plane plane;
|
||||
|
||||
EXPECT_TRUE(plane.setFromPointAndNormal(point, normal));
|
||||
|
||||
Vec3d planeNormal = plane.normal();
|
||||
|
||||
EXPECT_DOUBLE_EQ(normal.x(), planeNormal.x());
|
||||
EXPECT_DOUBLE_EQ(normal.y(), planeNormal.y());
|
||||
EXPECT_DOUBLE_EQ(normal.z(), planeNormal.z());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PlaneTest, PointInPlane)
|
||||
{
|
||||
Vec3d p1(1.0, 0.0, 1.0);
|
||||
Vec3d p2(2.0, 2.0, 0.0);
|
||||
Vec3d p3(3.0, 1.0, 4.0);
|
||||
Plane plane;
|
||||
plane.setFromPoints(p1, p2, p3);
|
||||
|
||||
// Get a point somewhere on the plane
|
||||
Vec3d pip = plane.pointInPlane();
|
||||
|
||||
// Project the point we already know is on the plane, down onto the plane
|
||||
// These two points should be the same
|
||||
Vec3d projectedPoint = plane.projectPoint(pip);
|
||||
EXPECT_DOUBLE_EQ(pip.x(), projectedPoint.x());
|
||||
EXPECT_DOUBLE_EQ(pip.y(), projectedPoint.y());
|
||||
EXPECT_DOUBLE_EQ(pip.z(), projectedPoint.z());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PlaneTest, Flip)
|
||||
{
|
||||
Vec3d point(1.0, 2.0, 3.0);
|
||||
Vec3d normal(1.0, 0.0, 0.0);
|
||||
Plane plane1;
|
||||
plane1.setFromPointAndNormal(point, normal);
|
||||
Plane plane2 = plane1;
|
||||
|
||||
plane2.flip();
|
||||
EXPECT_FALSE(plane1.normal() == plane2.normal());
|
||||
EXPECT_TRUE(plane1.normal() == -plane2.normal());
|
||||
|
||||
plane2.flip();
|
||||
EXPECT_TRUE(plane1.normal() == plane2.normal());
|
||||
EXPECT_FALSE(plane1.normal() == -plane2.normal());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PlaneTest, Transform)
|
||||
{
|
||||
// Todo: Add test
|
||||
// void transform(const Mat4d& mat);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PlaneTest, Distance)
|
||||
{
|
||||
Vec3d p1(1.0, 0.0, 1.0);
|
||||
Vec3d p2(2.0, 2.0, 0.0);
|
||||
Vec3d p3(3.0, 1.0, 4.0);
|
||||
Plane plane;
|
||||
plane.setFromPoints(p1, p2, p3);
|
||||
Vec3d pip = plane.pointInPlane();
|
||||
|
||||
|
||||
// Test distance(..) by pulling a point on the plane in
|
||||
// the direction of the normal
|
||||
// ------------------------------------------------------
|
||||
EXPECT_DOUBLE_EQ(5.0, plane.distance(pip + plane.normal().getNormalized()*5.0));
|
||||
EXPECT_DOUBLE_EQ(-6.0, plane.distance(pip + plane.normal().getNormalized()*(-6.0)));
|
||||
|
||||
|
||||
// Test distanceSquared by checking the sign
|
||||
// -> which side the point is on
|
||||
// ------------------------------------------------------
|
||||
double distanceSquaredPos = plane.distanceSquared(pip + plane.normal()*5.0);
|
||||
double distanceSquaredNeg = plane.distanceSquared(pip + plane.normal()*(-5.0));
|
||||
EXPECT_TRUE(distanceSquaredPos > 0.0);
|
||||
EXPECT_TRUE(distanceSquaredNeg < 0.0);
|
||||
|
||||
|
||||
// Test distanceSquared() against distance()
|
||||
// ------------------------------------------------------
|
||||
double factor = sqrt(plane.A()*plane.A() + plane.B()*plane.B() + plane.C()*plane.C());
|
||||
|
||||
EXPECT_DOUBLE_EQ(distanceSquaredPos/factor, plane.distance(pip + plane.normal()*5.0));
|
||||
EXPECT_DOUBLE_EQ(distanceSquaredNeg/factor, plane.distance(pip + plane.normal()*(-5.0)));
|
||||
|
||||
|
||||
// Test distanceToOrigin();
|
||||
// ------------------------------------
|
||||
Vec3d p4(1.234, 0.0, 0.0);
|
||||
plane.setFromPointAndNormal(p4, p4.getNormalized());
|
||||
EXPECT_DOUBLE_EQ(1.234, plane.distanceToOrigin());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PlaneTest, ProjectPointAndVector)
|
||||
{
|
||||
Vec3d point(1.0, 2.0, 3.0);
|
||||
Vec3d normal(1.0, 8.0, 6.0);
|
||||
Plane plane;
|
||||
plane.setFromPointAndNormal(point, normal);
|
||||
|
||||
// Get a point somewhere on the plane
|
||||
Vec3d pip = plane.pointInPlane();
|
||||
|
||||
// Project the point we already know is on the plane, down onto the plane
|
||||
// These two points should be the same
|
||||
Vec3d projectedPoint = plane.projectPoint(pip);
|
||||
EXPECT_DOUBLE_EQ(pip.x(), projectedPoint.x());
|
||||
EXPECT_DOUBLE_EQ(pip.y(), projectedPoint.y());
|
||||
EXPECT_DOUBLE_EQ(pip.z(), projectedPoint.z());
|
||||
|
||||
// projectVector(..) is used directly by projectPoint(..) and is as such automatically tested above
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PlaneTest, PlaneAndPlaneIntersect)
|
||||
{
|
||||
Plane plane1;
|
||||
plane1.setFromPointAndNormal(Vec3d::X_AXIS, Vec3d::X_AXIS);
|
||||
Plane plane2;
|
||||
plane2.setFromPointAndNormal(Vec3d::Y_AXIS, Vec3d::Y_AXIS);
|
||||
|
||||
Vec3d point, normal;
|
||||
EXPECT_TRUE(plane1.intersect(plane2, &point, &normal));
|
||||
EXPECT_TRUE(normal == Vec3d::Z_AXIS);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PlaneTest, PlaneAndLineIntersect)
|
||||
{
|
||||
// a above, b below
|
||||
{
|
||||
Plane plane;
|
||||
plane.setFromPointAndNormal(Vec3d::ZERO, Vec3d::Z_AXIS);
|
||||
|
||||
cvf::Vec3d a(10.0, 10.0, 10.0);
|
||||
cvf::Vec3d b(10.0, 10.0, -10.0);
|
||||
|
||||
cvf::Vec3d intersection;
|
||||
|
||||
EXPECT_TRUE(plane.intersect(a, b, &intersection));
|
||||
EXPECT_TRUE(intersection == Vec3d(10.0, 10.0, 0.0));
|
||||
}
|
||||
|
||||
// a below, b above
|
||||
{
|
||||
Plane plane;
|
||||
plane.setFromPointAndNormal(Vec3d::ZERO, Vec3d::Z_AXIS);
|
||||
|
||||
cvf::Vec3d a(10.0, 10.0, -10.0);
|
||||
cvf::Vec3d b(10.0, 10.0, 10.0);
|
||||
|
||||
cvf::Vec3d intersection;
|
||||
|
||||
EXPECT_TRUE(plane.intersect(a, b, &intersection));
|
||||
EXPECT_TRUE(intersection == Vec3d(10.0, 10.0, 0.0));
|
||||
}
|
||||
|
||||
// b on plane
|
||||
{
|
||||
Plane plane;
|
||||
plane.setFromPointAndNormal(Vec3d::ZERO, Vec3d::Z_AXIS);
|
||||
|
||||
cvf::Vec3d a(10.0, 10.0, 10.0);
|
||||
cvf::Vec3d b(10.0, 10.0, 0.0);
|
||||
|
||||
cvf::Vec3d intersection;
|
||||
|
||||
EXPECT_TRUE(plane.intersect(a, b, &intersection));
|
||||
EXPECT_TRUE(intersection == Vec3d(10.0, 10.0, 0.0));
|
||||
}
|
||||
|
||||
// a and b above plane
|
||||
{
|
||||
Plane plane;
|
||||
plane.setFromPointAndNormal(Vec3d::ZERO, Vec3d::Z_AXIS);
|
||||
|
||||
cvf::Vec3d a(10.0, 10.0, 10.0);
|
||||
cvf::Vec3d b(10.0, 10.0, 1.0);
|
||||
|
||||
cvf::Vec3d intersection;
|
||||
|
||||
EXPECT_FALSE(plane.intersect(a, b, &intersection));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PlaneTest, SideForPoint)
|
||||
{
|
||||
Plane plane;
|
||||
plane.setFromPointAndNormal(Vec3d::ZERO, Vec3d::Z_AXIS);
|
||||
|
||||
// Front
|
||||
{
|
||||
cvf::Vec3d a = Vec3d::Z_AXIS;
|
||||
EXPECT_TRUE(Plane::FRONT == plane.side(a));
|
||||
}
|
||||
|
||||
// On
|
||||
{
|
||||
cvf::Vec3d a = Vec3d::ZERO;
|
||||
EXPECT_TRUE(Plane::ON == plane.side(a));
|
||||
}
|
||||
|
||||
// Back
|
||||
{
|
||||
cvf::Vec3d a = -Vec3d::Z_AXIS;
|
||||
EXPECT_TRUE(Plane::BACK == plane.side(a));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PlaneTest, SideForPoints)
|
||||
{
|
||||
Plane plane;
|
||||
plane.setFromPointAndNormal(Vec3d::ZERO, Vec3d::Z_AXIS);
|
||||
|
||||
cvf::Vec3d pointFront(Vec3d::Z_AXIS);
|
||||
cvf::Vec3d pointOn(Vec3d::ZERO);
|
||||
cvf::Vec3d pointBack(-Vec3d::Z_AXIS);
|
||||
|
||||
// All front
|
||||
{
|
||||
cvf::Vec3dArray a;
|
||||
a.reserve(10);
|
||||
|
||||
a.add(pointFront);
|
||||
EXPECT_TRUE(Plane::FRONT == plane.side(a));
|
||||
|
||||
a.add(pointOn);
|
||||
EXPECT_TRUE(Plane::FRONT == plane.side(a));
|
||||
}
|
||||
|
||||
// All on
|
||||
{
|
||||
cvf::Vec3dArray a;
|
||||
a.reserve(10);
|
||||
|
||||
a.add(pointOn);
|
||||
a.add(pointOn);
|
||||
EXPECT_TRUE(Plane::ON == plane.side(a));
|
||||
}
|
||||
|
||||
// All back
|
||||
{
|
||||
cvf::Vec3dArray a;
|
||||
a.reserve(10);
|
||||
|
||||
a.add(pointBack);
|
||||
EXPECT_TRUE(Plane::BACK == plane.side(a));
|
||||
|
||||
a.add(pointOn);
|
||||
EXPECT_TRUE(Plane::BACK == plane.side(a));
|
||||
}
|
||||
|
||||
// Both sides
|
||||
{
|
||||
cvf::Vec3dArray a;
|
||||
a.reserve(10);
|
||||
|
||||
a.add(pointFront);
|
||||
a.add(pointBack);
|
||||
EXPECT_TRUE(Plane::BOTH == plane.side(a));
|
||||
|
||||
a.add(pointOn);
|
||||
EXPECT_TRUE(Plane::BOTH == plane.side(a));
|
||||
}
|
||||
}
|
||||
245
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfPropertySet-Test.cpp
Normal file
245
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfPropertySet-Test.cpp
Normal file
@@ -0,0 +1,245 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfPropertySet.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PropertySetTest, Constructor)
|
||||
{
|
||||
PropertySet ps("mySet");
|
||||
ASSERT_TRUE(ps.classType() == "mySet");
|
||||
ASSERT_TRUE(ps.isEmpty());
|
||||
ASSERT_FALSE(ps.contains("dummy"));
|
||||
|
||||
Variant v = ps.value("dummy2");
|
||||
ASSERT_EQ(Variant::INVALID, v.type());
|
||||
ASSERT_FALSE(v.isValid());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PropertySetTest, SimpleSet)
|
||||
{
|
||||
PropertySet ps("mySet");
|
||||
ASSERT_TRUE(ps.isEmpty());
|
||||
|
||||
ps.setValue("key_int", Variant(static_cast<int>(123)));
|
||||
ps.setValue("key_double", Variant(1.234));
|
||||
ps.setValue("key_string", Variant("myString"));
|
||||
|
||||
EXPECT_FALSE(ps.isEmpty());
|
||||
EXPECT_TRUE(ps.contains("key_int"));
|
||||
EXPECT_TRUE(ps.contains("key_double"));
|
||||
EXPECT_TRUE(ps.contains("key_string"));
|
||||
|
||||
{
|
||||
Variant v = ps.value("key_int");
|
||||
ASSERT_EQ(Variant::INT, v.type());
|
||||
ASSERT_EQ(123, v.getInt());
|
||||
}
|
||||
{
|
||||
Variant v = ps.value("key_double");
|
||||
ASSERT_EQ(Variant::DOUBLE, v.type());
|
||||
ASSERT_EQ(1.234, v.getDouble());
|
||||
}
|
||||
{
|
||||
Variant v = ps.value("key_string");
|
||||
ASSERT_EQ(Variant::STRING, v.type());
|
||||
ASSERT_TRUE(v.getString() == "myString");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PropertySetTest, EqualsOperator)
|
||||
{
|
||||
ref<PropertySet> ps0 = new PropertySet("propSet");
|
||||
ps0->setValue("myInt", 123);
|
||||
ps0->setValue("myDouble", 1.234);
|
||||
ASSERT_TRUE(*ps0 == *ps0);
|
||||
|
||||
{
|
||||
ref<PropertySet> ps = new PropertySet("propSet");
|
||||
ps->setValue("myDouble", 1.234);
|
||||
ps->setValue("myInt", 123);
|
||||
ASSERT_TRUE(*ps == *ps0);
|
||||
}
|
||||
{
|
||||
ref<PropertySet> ps = new PropertySet("propSet");
|
||||
ps->setValue("myInt", 999);
|
||||
ps->setValue("myDouble", 1.234);
|
||||
ASSERT_FALSE(*ps == *ps0);
|
||||
}
|
||||
{
|
||||
ref<PropertySet> ps = new PropertySet("propSet");
|
||||
ps->setValue("myIntXX", 123);
|
||||
ps->setValue("myDouble", 1.234);
|
||||
ASSERT_FALSE(*ps == *ps0);
|
||||
}
|
||||
{
|
||||
ref<PropertySet> ps = new PropertySet("propSet");
|
||||
ps->setValue("myInt", 123);
|
||||
ps->setValue("myInt_2", 456);
|
||||
ps->setValue("myDouble", 1.234);
|
||||
ASSERT_FALSE(*ps == *ps0);
|
||||
}
|
||||
{
|
||||
ref<PropertySet> ps = new PropertySet("ABC");
|
||||
ps->setValue("myInt", 123);
|
||||
ps->setValue("myDouble", 1.234);
|
||||
ASSERT_FALSE(*ps == *ps0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PropertySetTest, ReplaceKey)
|
||||
{
|
||||
PropertySet ps("mySet");
|
||||
ASSERT_TRUE(ps.isEmpty());
|
||||
|
||||
ps.setValue("key1", Variant(1234));
|
||||
ps.setValue("key2", Variant(1.234));
|
||||
|
||||
{
|
||||
Variant v1 = ps.value("key1");
|
||||
Variant v2 = ps.value("key2");
|
||||
Variant v3 = ps.value("key3");
|
||||
ASSERT_EQ(Variant::INT, v1.type());
|
||||
ASSERT_EQ(Variant::DOUBLE, v2.type());
|
||||
ASSERT_EQ(Variant::INVALID, v3.type());
|
||||
ASSERT_EQ(1234, v1.getInt());
|
||||
ASSERT_EQ(1.234, v2.getDouble());
|
||||
}
|
||||
|
||||
ps.setValue("key3", Variant("myString"));
|
||||
ps.setValue("key2", Variant(true));
|
||||
|
||||
{
|
||||
Variant v1 = ps.value("key1");
|
||||
Variant v2 = ps.value("key2");
|
||||
Variant v3 = ps.value("key3");
|
||||
ASSERT_EQ(Variant::INT, v1.type());
|
||||
ASSERT_EQ(Variant::BOOL, v2.type());
|
||||
ASSERT_EQ(Variant::STRING, v3.type());
|
||||
ASSERT_EQ(1234, v1.getInt());
|
||||
ASSERT_EQ(true, v2.getBool());
|
||||
ASSERT_TRUE(v3.getString() == "myString");
|
||||
}
|
||||
|
||||
ps.setValue("key1", Variant());
|
||||
|
||||
{
|
||||
Variant v1 = ps.value("key1");
|
||||
Variant v2 = ps.value("key2");
|
||||
Variant v3 = ps.value("key3");
|
||||
ASSERT_EQ(Variant::INVALID, v1.type());
|
||||
ASSERT_EQ(Variant::BOOL, v2.type());
|
||||
ASSERT_EQ(Variant::STRING, v3.type());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PropertySetTest, AllKeysAndAllValues)
|
||||
{
|
||||
PropertySet ps("mySet");
|
||||
ps.setValue("key1", Variant(1234));
|
||||
ps.setValue("key2", Variant(1.234));
|
||||
ps.setValue("key3", Variant(true));
|
||||
|
||||
std::vector<String> allKeys = ps.allKeys();
|
||||
std::vector<Variant> allValues = ps.allValues();
|
||||
|
||||
ASSERT_EQ(3, allKeys.size());
|
||||
ASSERT_EQ(3, allValues.size());
|
||||
|
||||
bool saw1 = false;
|
||||
bool saw2 = false;
|
||||
bool saw3 = false;
|
||||
for (size_t i = 0; i < 3; i++)
|
||||
{
|
||||
const String& s = allKeys[i];
|
||||
const Variant& v = allValues[i];
|
||||
|
||||
if (s == "key1")
|
||||
{
|
||||
EXPECT_EQ(1234, v.getInt());
|
||||
saw1 = true;
|
||||
}
|
||||
else if (s == "key2")
|
||||
{
|
||||
EXPECT_EQ(1.234, v.getDouble());
|
||||
saw2 = true;
|
||||
}
|
||||
else if (s == "key3")
|
||||
{
|
||||
EXPECT_EQ(true, v.getBool());
|
||||
saw3 = true;
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(saw1);
|
||||
EXPECT_TRUE(saw2);
|
||||
EXPECT_TRUE(saw3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfPropertySetCollection.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PropertySetCollectionTest, Constructor)
|
||||
{
|
||||
ref<PropertySetCollection> psc = new PropertySetCollection;
|
||||
ASSERT_EQ(0, psc->count());
|
||||
ASSERT_EQ(0, psc->countOfType("dummy"));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PropertySetCollectionTest, AddAndRetrieve)
|
||||
{
|
||||
ref<PropertySetCollection> psc = new PropertySetCollection;
|
||||
|
||||
psc->addPropertySet(new PropertySet("ctA"));
|
||||
psc->addPropertySet(new PropertySet("ctB"));
|
||||
ASSERT_EQ(2, psc->count());
|
||||
|
||||
PropertySet* ps1 = psc->propertySet(0);
|
||||
PropertySet* ps2 = psc->propertySet(1);
|
||||
EXPECT_TRUE(ps1->classType() == "ctA");
|
||||
EXPECT_TRUE(ps2->classType() == "ctB");
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PropertySetCollectionTest, GetPropertySetOfSpecificClass)
|
||||
{
|
||||
ref<PropertySetCollection> psc = new PropertySetCollection;
|
||||
|
||||
{
|
||||
PropertySet* ps1 = new PropertySet("ctA");
|
||||
PropertySet* ps2 = new PropertySet("ctB");
|
||||
PropertySet* ps3 = new PropertySet("ctA");
|
||||
ps1->setValue("name", "ps1");
|
||||
ps2->setValue("name", "ps2");
|
||||
ps3->setValue("name", "ps3");
|
||||
psc->addPropertySet(ps1);
|
||||
psc->addPropertySet(ps2);
|
||||
psc->addPropertySet(ps3);
|
||||
}
|
||||
|
||||
ASSERT_EQ(3, psc->count());
|
||||
ASSERT_EQ(2, psc->countOfType("ctA"));
|
||||
ASSERT_EQ(1, psc->countOfType("ctB"));
|
||||
|
||||
const PropertySet* ps1 = psc->propertySetOfType("ctA", 0);
|
||||
const PropertySet* ps2 = psc->propertySetOfType("ctB", 0);
|
||||
const PropertySet* ps3 = psc->propertySetOfType("ctA", 1);
|
||||
EXPECT_TRUE(ps1->value("name").getString() == "ps1");
|
||||
EXPECT_TRUE(ps2->value("name").getString() == "ps2");
|
||||
EXPECT_TRUE(ps3->value("name").getString() == "ps3");
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PropertySetCollectionTest, FirstPropertySetOfType)
|
||||
{
|
||||
ref<PropertySetCollection> psc = new PropertySetCollection;
|
||||
|
||||
cvf::ref<PropertySet> ps1 = new PropertySet("ctA");
|
||||
cvf::ref<PropertySet> ps2 = new PropertySet("ctB");
|
||||
cvf::ref<PropertySet> ps3 = new PropertySet("ctA");
|
||||
psc->addPropertySet(ps1.p());
|
||||
psc->addPropertySet(ps2.p());
|
||||
psc->addPropertySet(ps3.p());
|
||||
ASSERT_EQ(3, psc->count());
|
||||
|
||||
const PropertySet* psA = psc->firstPropertySetOfType("ctA");
|
||||
const PropertySet* psB = psc->firstPropertySetOfType("ctB");
|
||||
const PropertySet* psZ = psc->firstPropertySetOfType("ctZ");
|
||||
EXPECT_EQ(psA, ps1.p());
|
||||
EXPECT_EQ(psB, ps2.p());
|
||||
EXPECT_TRUE(psZ == NULL);
|
||||
}
|
||||
|
||||
|
||||
880
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfQuat-Test.cpp
Normal file
880
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfQuat-Test.cpp
Normal file
@@ -0,0 +1,880 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfQuat.h"
|
||||
#include "cvfMatrix4.h"
|
||||
#include "cvfMath.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <cmath>
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(QuatTest, ConstructionAndAssigmentOperator)
|
||||
{
|
||||
{
|
||||
Quat<double> q1;
|
||||
ASSERT_DOUBLE_EQ(0, q1.x());
|
||||
ASSERT_DOUBLE_EQ(0, q1.y());
|
||||
ASSERT_DOUBLE_EQ(0, q1.z());
|
||||
ASSERT_DOUBLE_EQ(0, q1.w());
|
||||
|
||||
Quat<double> q2(1, 2, 3, 4);
|
||||
ASSERT_DOUBLE_EQ(1, q2.x());
|
||||
ASSERT_DOUBLE_EQ(2, q2.y());
|
||||
ASSERT_DOUBLE_EQ(3, q2.z());
|
||||
ASSERT_DOUBLE_EQ(4, q2.w());
|
||||
|
||||
Quat<double> q3(q2);
|
||||
ASSERT_DOUBLE_EQ(1, q3.x());
|
||||
ASSERT_DOUBLE_EQ(2, q3.y());
|
||||
ASSERT_DOUBLE_EQ(3, q3.z());
|
||||
ASSERT_DOUBLE_EQ(4, q3.w());
|
||||
|
||||
Quat<double> q4(-1, -2, -3, -4);
|
||||
ASSERT_DOUBLE_EQ(-1, q4.x());
|
||||
ASSERT_DOUBLE_EQ(-2, q4.y());
|
||||
ASSERT_DOUBLE_EQ(-3, q4.z());
|
||||
ASSERT_DOUBLE_EQ(-4, q4.w());
|
||||
|
||||
q4 = q3;
|
||||
ASSERT_DOUBLE_EQ(1, q4.x());
|
||||
ASSERT_DOUBLE_EQ(2, q4.y());
|
||||
ASSERT_DOUBLE_EQ(3, q4.z());
|
||||
ASSERT_DOUBLE_EQ(4, q4.w());
|
||||
}
|
||||
|
||||
{
|
||||
Quat<float> q1;
|
||||
ASSERT_FLOAT_EQ(0, q1.x());
|
||||
ASSERT_FLOAT_EQ(0, q1.y());
|
||||
ASSERT_FLOAT_EQ(0, q1.z());
|
||||
ASSERT_FLOAT_EQ(0, q1.w());
|
||||
|
||||
Quat<float> q2(1, 2, 3, 4);
|
||||
ASSERT_FLOAT_EQ(1, q2.x());
|
||||
ASSERT_FLOAT_EQ(2, q2.y());
|
||||
ASSERT_FLOAT_EQ(3, q2.z());
|
||||
ASSERT_FLOAT_EQ(4, q2.w());
|
||||
|
||||
Quat<float> q3(q2);
|
||||
ASSERT_FLOAT_EQ(1, q3.x());
|
||||
ASSERT_FLOAT_EQ(2, q3.y());
|
||||
ASSERT_FLOAT_EQ(3, q3.z());
|
||||
ASSERT_FLOAT_EQ(4, q3.w());
|
||||
|
||||
Quat<float> q4(-1, -2, -3, -4);
|
||||
ASSERT_FLOAT_EQ(-1, q4.x());
|
||||
ASSERT_FLOAT_EQ(-2, q4.y());
|
||||
ASSERT_FLOAT_EQ(-3, q4.z());
|
||||
ASSERT_FLOAT_EQ(-4, q4.w());
|
||||
|
||||
q4 = q3;
|
||||
ASSERT_FLOAT_EQ(1, q4.x());
|
||||
ASSERT_FLOAT_EQ(2, q4.y());
|
||||
ASSERT_FLOAT_EQ(3, q4.z());
|
||||
ASSERT_FLOAT_EQ(4, q4.w());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(QuatTest, Comparison)
|
||||
{
|
||||
{
|
||||
Quat<double> q0;
|
||||
Quat<double> q1(1, 2, 3, 4);
|
||||
|
||||
ASSERT_TRUE(q0 == q0);
|
||||
ASSERT_TRUE(q1 == q1);
|
||||
ASSERT_TRUE(q1 != q0);
|
||||
|
||||
Quat<double> q2(q1);
|
||||
ASSERT_TRUE(q1 == q2);
|
||||
|
||||
q2.x() = 99;
|
||||
ASSERT_FALSE(q1 == q2);
|
||||
ASSERT_TRUE(q1 != q2);
|
||||
|
||||
Quat<double> qA(0, 2, 3, 4);
|
||||
Quat<double> qB(1, 0, 3, 4);
|
||||
Quat<double> qC(1, 2, 0, 4);
|
||||
Quat<double> qD(1, 2, 3, 0);
|
||||
ASSERT_FALSE(q1 == qA);
|
||||
ASSERT_FALSE(q1 == qB);
|
||||
ASSERT_FALSE(q1 == qC);
|
||||
ASSERT_FALSE(q1 == qD);
|
||||
ASSERT_TRUE(q1 != qA);
|
||||
ASSERT_TRUE(q1 != qB);
|
||||
ASSERT_TRUE(q1 != qC);
|
||||
ASSERT_TRUE(q1 != qD);
|
||||
}
|
||||
|
||||
{
|
||||
Quat<float> q0;
|
||||
Quat<float> q1(1, 2, 3, 4);
|
||||
|
||||
ASSERT_TRUE(q0 == q0);
|
||||
ASSERT_TRUE(q1 == q1);
|
||||
ASSERT_TRUE(q1 != q0);
|
||||
|
||||
Quat<float> q2(q1);
|
||||
ASSERT_TRUE(q1 == q2);
|
||||
|
||||
q2.x() = 99;
|
||||
ASSERT_FALSE(q1 == q2);
|
||||
ASSERT_TRUE(q1 != q2);
|
||||
|
||||
Quat<float> qA(0, 2, 3, 4);
|
||||
Quat<float> qB(1, 0, 3, 4);
|
||||
Quat<float> qC(1, 2, 0, 4);
|
||||
Quat<float> qD(1, 2, 3, 0);
|
||||
ASSERT_FALSE(q1 == qA);
|
||||
ASSERT_FALSE(q1 == qB);
|
||||
ASSERT_FALSE(q1 == qC);
|
||||
ASSERT_FALSE(q1 == qD);
|
||||
ASSERT_TRUE(q1 != qA);
|
||||
ASSERT_TRUE(q1 != qB);
|
||||
ASSERT_TRUE(q1 != qC);
|
||||
ASSERT_TRUE(q1 != qD);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(QuatTest, GettersAndSetters)
|
||||
{
|
||||
{
|
||||
Quat<double> q(1, 2, 3, 4);
|
||||
ASSERT_DOUBLE_EQ(1, q.x());
|
||||
ASSERT_DOUBLE_EQ(2, q.y());
|
||||
ASSERT_DOUBLE_EQ(3, q.z());
|
||||
ASSERT_DOUBLE_EQ(4, q.w());
|
||||
|
||||
q.x() = 100;
|
||||
q.y() = 200;
|
||||
q.z() = 300;
|
||||
q.w() = 400;
|
||||
ASSERT_DOUBLE_EQ(100, q.x());
|
||||
ASSERT_DOUBLE_EQ(200, q.y());
|
||||
ASSERT_DOUBLE_EQ(300, q.z());
|
||||
ASSERT_DOUBLE_EQ(400, q.w());
|
||||
|
||||
q.set(10, 20, 30, 40);
|
||||
ASSERT_DOUBLE_EQ(10, q.x());
|
||||
ASSERT_DOUBLE_EQ(20, q.y());
|
||||
ASSERT_DOUBLE_EQ(30, q.z());
|
||||
ASSERT_DOUBLE_EQ(40, q.w());
|
||||
}
|
||||
|
||||
{
|
||||
Quat<float> q(1, 2, 3, 4);
|
||||
ASSERT_DOUBLE_EQ(1, q.x());
|
||||
ASSERT_DOUBLE_EQ(2, q.y());
|
||||
ASSERT_DOUBLE_EQ(3, q.z());
|
||||
ASSERT_DOUBLE_EQ(4, q.w());
|
||||
|
||||
q.x() = 100;
|
||||
q.y() = 200;
|
||||
q.z() = 300;
|
||||
q.w() = 400;
|
||||
ASSERT_DOUBLE_EQ(100, q.x());
|
||||
ASSERT_DOUBLE_EQ(200, q.y());
|
||||
ASSERT_DOUBLE_EQ(300, q.z());
|
||||
ASSERT_DOUBLE_EQ(400, q.w());
|
||||
|
||||
q.set(10, 20, 30, 40);
|
||||
ASSERT_DOUBLE_EQ(10, q.x());
|
||||
ASSERT_DOUBLE_EQ(20, q.y());
|
||||
ASSERT_DOUBLE_EQ(30, q.z());
|
||||
ASSERT_DOUBLE_EQ(40, q.w());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(QuatTest, Normalize)
|
||||
{
|
||||
{
|
||||
const double absErr = 0.0001;
|
||||
|
||||
Quat<double> q;
|
||||
Quat<double> e;
|
||||
|
||||
q.set(1, 0, 0, 0);
|
||||
e.set(1, 0, 0, 0);
|
||||
ASSERT_TRUE(q.normalize());
|
||||
ASSERT_TRUE(e == q);
|
||||
|
||||
q.set(0, 1, 0, 0);
|
||||
e.set(0, 1, 0, 0);
|
||||
ASSERT_TRUE(q.normalize());
|
||||
ASSERT_TRUE(e == q);
|
||||
|
||||
q.set(0, 0, 1, 0);
|
||||
e.set(0, 0, 1, 0);
|
||||
ASSERT_TRUE(q.normalize());
|
||||
ASSERT_TRUE(e == q);
|
||||
|
||||
q.set(0, 0, 0, 0);
|
||||
e.set(0, 0, 0, 0);
|
||||
ASSERT_FALSE(q.normalize());
|
||||
ASSERT_TRUE(e == q);
|
||||
|
||||
q.set(1, 1, 1, 1);
|
||||
e.set(0.5, 0.5, 0.5, 0.5);
|
||||
ASSERT_TRUE(q.normalize());
|
||||
ASSERT_TRUE(e == q);
|
||||
|
||||
q.set(1, 2, 3, 4);
|
||||
ASSERT_TRUE(q.normalize());
|
||||
ASSERT_NEAR(0.1825, q.x(), absErr);
|
||||
ASSERT_NEAR(0.3651, q.y(), absErr);
|
||||
ASSERT_NEAR(0.5477, q.z(), absErr);
|
||||
ASSERT_NEAR(0.7302, q.w(), absErr);
|
||||
}
|
||||
|
||||
{
|
||||
const double absErr = 0.0001;
|
||||
|
||||
Quat<float> q;
|
||||
Quat<float> e;
|
||||
|
||||
q.set(1, 0, 0, 0);
|
||||
e.set(1, 0, 0, 0);
|
||||
ASSERT_TRUE(q.normalize());
|
||||
ASSERT_TRUE(e == q);
|
||||
|
||||
q.set(0, 1, 0, 0);
|
||||
e.set(0, 1, 0, 0);
|
||||
ASSERT_TRUE(q.normalize());
|
||||
ASSERT_TRUE(e == q);
|
||||
|
||||
q.set(0, 0, 1, 0);
|
||||
e.set(0, 0, 1, 0);
|
||||
ASSERT_TRUE(q.normalize());
|
||||
ASSERT_TRUE(e == q);
|
||||
|
||||
q.set(0, 0, 0, 0);
|
||||
e.set(0, 0, 0, 0);
|
||||
ASSERT_FALSE(q.normalize());
|
||||
ASSERT_TRUE(e == q);
|
||||
|
||||
q.set(1, 1, 1, 1);
|
||||
e.set(0.5, 0.5, 0.5, 0.5);
|
||||
ASSERT_TRUE(q.normalize());
|
||||
ASSERT_TRUE(e == q);
|
||||
|
||||
q.set(1, 2, 3, 4);
|
||||
ASSERT_TRUE(q.normalize());
|
||||
ASSERT_NEAR(0.1825, q.x(), absErr);
|
||||
ASSERT_NEAR(0.3651, q.y(), absErr);
|
||||
ASSERT_NEAR(0.5477, q.z(), absErr);
|
||||
ASSERT_NEAR(0.7302, q.w(), absErr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(QuatTest, AxisAngleToQuatSpecialCases)
|
||||
{
|
||||
{
|
||||
Quat<double> q;
|
||||
Quat<double> e;
|
||||
|
||||
q.setFromAxisAngle(Vec3d(1, 0, 0), 0);
|
||||
e.set(0, 0, 0, 1);
|
||||
ASSERT_TRUE(e == q);
|
||||
|
||||
q.setFromAxisAngle(Vec3d(1, 1, 1), 0);
|
||||
e.set(0, 0, 0, 1);
|
||||
ASSERT_TRUE(e == q);
|
||||
}
|
||||
|
||||
{
|
||||
Quat<float> q;
|
||||
Quat<float> e;
|
||||
|
||||
q.setFromAxisAngle(Vec3f(1, 0, 0), 0);
|
||||
e.set(0, 0, 0, 1);
|
||||
ASSERT_TRUE(e == q);
|
||||
|
||||
q.setFromAxisAngle(Vec3f(1, 1, 1), 0);
|
||||
e.set(0, 0, 0, 1);
|
||||
ASSERT_TRUE(e == q);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(QuatTest, FromAndtoMatrix4)
|
||||
{
|
||||
const double absErr = 0.00001;
|
||||
const double absErrDeg = 0.001;
|
||||
|
||||
// Input matrices and axis angles borrowed from Matrix4Test::FromRotation
|
||||
|
||||
|
||||
// --------------------
|
||||
{
|
||||
const double expAngleDeg = 45;
|
||||
const Vector3<double> expAxisNorm = Vector3<double>(1, 1, 1).getNormalized();
|
||||
const Matrix4<double> mi( 0.80474, -0.31062, 0.50588, 0,
|
||||
0.50588, 0.80474, -0.31062, 0,
|
||||
-0.31062, 0.50588, 0.80474, 0,
|
||||
0, 0, 0, 1);
|
||||
|
||||
const Quat<double> qi = Quat<double>::fromAxisAngle(expAxisNorm, Math::toRadians(expAngleDeg));
|
||||
|
||||
|
||||
{
|
||||
const Quat<double> q = Quat<double>::fromRotationMatrix(mi);
|
||||
double angle= 0;
|
||||
Vector3<double> axis(0, 0, 0);
|
||||
q.toAxisAngle(&axis, &angle);
|
||||
ASSERT_NEAR(expAxisNorm.x(), axis.x(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.y(), axis.y(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.z(), axis.z(), absErr);
|
||||
ASSERT_NEAR(expAngleDeg, Math::toDegrees(angle), absErrDeg);
|
||||
|
||||
const Matrix4<double> m = qi.toMatrix4();
|
||||
ASSERT_NEAR(mi.rowCol(0, 0), m.rowCol(0, 0), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(0, 1), m.rowCol(0, 1), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(0, 2), m.rowCol(0, 2), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(1, 0), m.rowCol(1, 0), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(1, 1), m.rowCol(1, 1), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(1, 2), m.rowCol(1, 2), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(2, 0), m.rowCol(2, 0), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(2, 1), m.rowCol(2, 1), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(2, 2), m.rowCol(2, 2), absErr);
|
||||
}
|
||||
|
||||
{
|
||||
const Matrix4<float> mif(mi);
|
||||
const Quat<float> q = Quat<float>::fromRotationMatrix(mif);
|
||||
float angle= 0;
|
||||
Vector3<float> axis(0, 0, 0);
|
||||
q.toAxisAngle(&axis, &angle);
|
||||
ASSERT_NEAR(expAxisNorm.x(), axis.x(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.y(), axis.y(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.z(), axis.z(), absErr);
|
||||
ASSERT_NEAR(expAngleDeg, Math::toDegrees(angle), absErrDeg);
|
||||
|
||||
const Quat<float> qif(qi);
|
||||
const Matrix4<float> m = qif.toMatrix4();
|
||||
ASSERT_NEAR(mif.rowCol(0, 0), m.rowCol(0, 0), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(0, 1), m.rowCol(0, 1), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(0, 2), m.rowCol(0, 2), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(1, 0), m.rowCol(1, 0), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(1, 1), m.rowCol(1, 1), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(1, 2), m.rowCol(1, 2), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(2, 0), m.rowCol(2, 0), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(2, 1), m.rowCol(2, 1), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(2, 2), m.rowCol(2, 2), absErr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// --------------------
|
||||
{
|
||||
const double expAngleDeg = 200;
|
||||
const Vector3<double> expAxisNorm = Vector3<double>(1, 1, 1).getNormalized();
|
||||
const Matrix4<double> mi(-0.29313, 0.84403, 0.44910, 0,
|
||||
0.44910, -0.29313, 0.84403, 0,
|
||||
0.84403, 0.44910, -0.29313, 0,
|
||||
0, 0, 0, 1);
|
||||
|
||||
const Quat<double> qi = Quat<double>::fromAxisAngle(expAxisNorm, Math::toRadians(expAngleDeg));
|
||||
|
||||
|
||||
{
|
||||
const Quat<double> q = Quat<double>::fromRotationMatrix(mi);
|
||||
double angle= 0;
|
||||
Vector3<double> axis(0, 0, 0);
|
||||
q.toAxisAngle(&axis, &angle);
|
||||
ASSERT_NEAR(expAxisNorm.x(), axis.x(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.y(), axis.y(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.z(), axis.z(), absErr);
|
||||
ASSERT_NEAR(expAngleDeg, Math::toDegrees(angle), absErrDeg);
|
||||
|
||||
const Matrix4<double> m = qi.toMatrix4();
|
||||
ASSERT_NEAR(mi.rowCol(0, 0), m.rowCol(0, 0), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(0, 1), m.rowCol(0, 1), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(0, 2), m.rowCol(0, 2), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(1, 0), m.rowCol(1, 0), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(1, 1), m.rowCol(1, 1), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(1, 2), m.rowCol(1, 2), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(2, 0), m.rowCol(2, 0), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(2, 1), m.rowCol(2, 1), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(2, 2), m.rowCol(2, 2), absErr);
|
||||
}
|
||||
|
||||
{
|
||||
const Matrix4<float> mif(mi);
|
||||
const Quat<float> q = Quat<float>::fromRotationMatrix(mif);
|
||||
float angle= 0;
|
||||
Vector3<float> axis(0, 0, 0);
|
||||
q.toAxisAngle(&axis, &angle);
|
||||
ASSERT_NEAR(expAxisNorm.x(), axis.x(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.y(), axis.y(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.z(), axis.z(), absErr);
|
||||
ASSERT_NEAR(expAngleDeg, Math::toDegrees(angle), absErrDeg);
|
||||
|
||||
const Quat<float> qif(qi);
|
||||
const Matrix4<float> m = qif.toMatrix4();
|
||||
ASSERT_NEAR(mif.rowCol(0, 0), m.rowCol(0, 0), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(0, 1), m.rowCol(0, 1), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(0, 2), m.rowCol(0, 2), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(1, 0), m.rowCol(1, 0), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(1, 1), m.rowCol(1, 1), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(1, 2), m.rowCol(1, 2), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(2, 0), m.rowCol(2, 0), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(2, 1), m.rowCol(2, 1), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(2, 2), m.rowCol(2, 2), absErr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// --------------------
|
||||
{
|
||||
const double expAngleDeg = 150;
|
||||
const Vector3<double> expAxisNorm = Vector3<double>(1, 2, 3).getNormalized();
|
||||
const Matrix4<double> mi(-0.73274, -0.13432, 0.66712, 0,
|
||||
0.66747, -0.33288, 0.66609, 0,
|
||||
0.13260, 0.93336, 0.33356, 0,
|
||||
0, 0, 0, 1);
|
||||
|
||||
const Quat<double> qi = Quat<double>::fromAxisAngle(expAxisNorm, Math::toRadians(expAngleDeg));
|
||||
|
||||
|
||||
{
|
||||
const Quat<double> q = Quat<double>::fromRotationMatrix(mi);
|
||||
double angle= 0;
|
||||
Vector3<double> axis(0, 0, 0);
|
||||
q.toAxisAngle(&axis, &angle);
|
||||
ASSERT_NEAR(expAxisNorm.x(), axis.x(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.y(), axis.y(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.z(), axis.z(), absErr);
|
||||
ASSERT_NEAR(expAngleDeg, Math::toDegrees(angle), absErrDeg);
|
||||
|
||||
const Matrix4<double> m = qi.toMatrix4();
|
||||
ASSERT_NEAR(mi.rowCol(0, 0), m.rowCol(0, 0), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(0, 1), m.rowCol(0, 1), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(0, 2), m.rowCol(0, 2), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(1, 0), m.rowCol(1, 0), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(1, 1), m.rowCol(1, 1), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(1, 2), m.rowCol(1, 2), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(2, 0), m.rowCol(2, 0), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(2, 1), m.rowCol(2, 1), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(2, 2), m.rowCol(2, 2), absErr);
|
||||
}
|
||||
|
||||
{
|
||||
const Matrix4<float> mif(mi);
|
||||
const Quat<float> q = Quat<float>::fromRotationMatrix(mif);
|
||||
float angle= 0;
|
||||
Vector3<float> axis(0, 0, 0);
|
||||
q.toAxisAngle(&axis, &angle);
|
||||
ASSERT_NEAR(expAxisNorm.x(), axis.x(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.y(), axis.y(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.z(), axis.z(), absErr);
|
||||
ASSERT_NEAR(expAngleDeg, Math::toDegrees(angle), absErrDeg);
|
||||
|
||||
const Quat<float> qif(qi);
|
||||
const Matrix4<float> m = qif.toMatrix4();
|
||||
ASSERT_NEAR(mif.rowCol(0, 0), m.rowCol(0, 0), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(0, 1), m.rowCol(0, 1), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(0, 2), m.rowCol(0, 2), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(1, 0), m.rowCol(1, 0), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(1, 1), m.rowCol(1, 1), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(1, 2), m.rowCol(1, 2), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(2, 0), m.rowCol(2, 0), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(2, 1), m.rowCol(2, 1), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(2, 2), m.rowCol(2, 2), absErr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// --------------------
|
||||
{
|
||||
const double expAngleDeg = 160;
|
||||
const Vector3<double> expAxisNorm = Vector3<double>(1, 0.1, 0.2).getNormalized();
|
||||
const Matrix4<double> mi( 0.90763, 0.11798, 0.40284, 0,
|
||||
0.25149, -0.92122, -0.29683, 0,
|
||||
0.33609, 0.37072, -0.86580, 0,
|
||||
0, 0, 0, 1);
|
||||
|
||||
const Quat<double> qi = Quat<double>::fromAxisAngle(expAxisNorm, Math::toRadians(expAngleDeg));
|
||||
|
||||
|
||||
{
|
||||
const Quat<double> q = Quat<double>::fromRotationMatrix(mi);
|
||||
double angle= 0;
|
||||
Vector3<double> axis(0, 0, 0);
|
||||
q.toAxisAngle(&axis, &angle);
|
||||
ASSERT_NEAR(expAxisNorm.x(), axis.x(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.y(), axis.y(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.z(), axis.z(), absErr);
|
||||
ASSERT_NEAR(expAngleDeg, Math::toDegrees(angle), absErrDeg);
|
||||
|
||||
const Matrix4<double> m = qi.toMatrix4();
|
||||
ASSERT_NEAR(mi.rowCol(0, 0), m.rowCol(0, 0), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(0, 1), m.rowCol(0, 1), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(0, 2), m.rowCol(0, 2), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(1, 0), m.rowCol(1, 0), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(1, 1), m.rowCol(1, 1), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(1, 2), m.rowCol(1, 2), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(2, 0), m.rowCol(2, 0), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(2, 1), m.rowCol(2, 1), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(2, 2), m.rowCol(2, 2), absErr);
|
||||
}
|
||||
|
||||
{
|
||||
const Matrix4<float> mif(mi);
|
||||
const Quat<float> q = Quat<float>::fromRotationMatrix(mif);
|
||||
float angle= 0;
|
||||
Vector3<float> axis(0, 0, 0);
|
||||
q.toAxisAngle(&axis, &angle);
|
||||
ASSERT_NEAR(expAxisNorm.x(), axis.x(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.y(), axis.y(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.z(), axis.z(), absErr);
|
||||
ASSERT_NEAR(expAngleDeg, Math::toDegrees(angle), absErrDeg);
|
||||
|
||||
const Quat<float> qif(qi);
|
||||
const Matrix4<float> m = qif.toMatrix4();
|
||||
ASSERT_NEAR(mif.rowCol(0, 0), m.rowCol(0, 0), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(0, 1), m.rowCol(0, 1), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(0, 2), m.rowCol(0, 2), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(1, 0), m.rowCol(1, 0), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(1, 1), m.rowCol(1, 1), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(1, 2), m.rowCol(1, 2), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(2, 0), m.rowCol(2, 0), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(2, 1), m.rowCol(2, 1), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(2, 2), m.rowCol(2, 2), absErr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// --------------------
|
||||
{
|
||||
const double expAngleDeg = 170;
|
||||
const Vector3<double> expAxisNorm = Vector3<double>(0.2, 1, 0.1).getNormalized();
|
||||
const Matrix4<double> mi(-0.90920, 0.36111, 0.20727, 0,
|
||||
0.39500, 0.90549, 0.15514, 0,
|
||||
-0.13166, 0.22292, -0.96590, 0,
|
||||
0, 0, 0, 1);
|
||||
|
||||
const Quat<double> qi = Quat<double>::fromAxisAngle(expAxisNorm, Math::toRadians(expAngleDeg));
|
||||
|
||||
|
||||
{
|
||||
const Quat<double> q = Quat<double>::fromRotationMatrix(mi);
|
||||
double angle= 0;
|
||||
Vector3<double> axis(0, 0, 0);
|
||||
q.toAxisAngle(&axis, &angle);
|
||||
ASSERT_NEAR(expAxisNorm.x(), axis.x(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.y(), axis.y(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.z(), axis.z(), absErr);
|
||||
ASSERT_NEAR(expAngleDeg, Math::toDegrees(angle), absErrDeg);
|
||||
|
||||
const Matrix4<double> m = qi.toMatrix4();
|
||||
ASSERT_NEAR(mi.rowCol(0, 0), m.rowCol(0, 0), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(0, 1), m.rowCol(0, 1), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(0, 2), m.rowCol(0, 2), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(1, 0), m.rowCol(1, 0), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(1, 1), m.rowCol(1, 1), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(1, 2), m.rowCol(1, 2), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(2, 0), m.rowCol(2, 0), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(2, 1), m.rowCol(2, 1), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(2, 2), m.rowCol(2, 2), absErr);
|
||||
}
|
||||
|
||||
{
|
||||
const Matrix4<float> mif(mi);
|
||||
const Quat<float> q = Quat<float>::fromRotationMatrix(mif);
|
||||
float angle= 0;
|
||||
Vector3<float> axis(0, 0, 0);
|
||||
q.toAxisAngle(&axis, &angle);
|
||||
ASSERT_NEAR(expAxisNorm.x(), axis.x(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.y(), axis.y(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.z(), axis.z(), absErr);
|
||||
ASSERT_NEAR(expAngleDeg, Math::toDegrees(angle), absErrDeg);
|
||||
|
||||
const Quat<float> qif(qi);
|
||||
const Matrix4<float> m = qif.toMatrix4();
|
||||
ASSERT_NEAR(mif.rowCol(0, 0), m.rowCol(0, 0), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(0, 1), m.rowCol(0, 1), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(0, 2), m.rowCol(0, 2), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(1, 0), m.rowCol(1, 0), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(1, 1), m.rowCol(1, 1), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(1, 2), m.rowCol(1, 2), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(2, 0), m.rowCol(2, 0), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(2, 1), m.rowCol(2, 1), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(2, 2), m.rowCol(2, 2), absErr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// --------------------
|
||||
{
|
||||
const double expAngleDeg = 150;
|
||||
const Vector3<double> expAxisNorm = Vector3<double>(0.1, 0.2, 1).getNormalized();
|
||||
const Matrix4<double> mi(-0.848250, -0.45241, 0.27531, 0,
|
||||
0.523490, -0.79494, 0.30664, 0,
|
||||
0.080127, 0.40423, 0.91114, 0,
|
||||
0, 0, 0, 1);
|
||||
|
||||
const Quat<double> qi = Quat<double>::fromAxisAngle(expAxisNorm, Math::toRadians(expAngleDeg));
|
||||
|
||||
|
||||
{
|
||||
const Quat<double> q = Quat<double>::fromRotationMatrix(mi);
|
||||
double angle= 0;
|
||||
Vector3<double> axis(0, 0, 0);
|
||||
q.toAxisAngle(&axis, &angle);
|
||||
ASSERT_NEAR(expAxisNorm.x(), axis.x(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.y(), axis.y(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.z(), axis.z(), absErr);
|
||||
ASSERT_NEAR(expAngleDeg, Math::toDegrees(angle), absErrDeg);
|
||||
|
||||
const Matrix4<double> m = qi.toMatrix4();
|
||||
ASSERT_NEAR(mi.rowCol(0, 0), m.rowCol(0, 0), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(0, 1), m.rowCol(0, 1), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(0, 2), m.rowCol(0, 2), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(1, 0), m.rowCol(1, 0), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(1, 1), m.rowCol(1, 1), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(1, 2), m.rowCol(1, 2), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(2, 0), m.rowCol(2, 0), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(2, 1), m.rowCol(2, 1), absErr);
|
||||
ASSERT_NEAR(mi.rowCol(2, 2), m.rowCol(2, 2), absErr);
|
||||
}
|
||||
|
||||
{
|
||||
const Matrix4<float> mif(mi);
|
||||
const Quat<float> q = Quat<float>::fromRotationMatrix(mif);
|
||||
float angle= 0;
|
||||
Vector3<float> axis(0, 0, 0);
|
||||
q.toAxisAngle(&axis, &angle);
|
||||
ASSERT_NEAR(expAxisNorm.x(), axis.x(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.y(), axis.y(), absErr);
|
||||
ASSERT_NEAR(expAxisNorm.z(), axis.z(), absErr);
|
||||
ASSERT_NEAR(expAngleDeg, Math::toDegrees(angle), absErrDeg);
|
||||
|
||||
const Quat<float> qif(qi);
|
||||
const Matrix4<float> m = qif.toMatrix4();
|
||||
ASSERT_NEAR(mif.rowCol(0, 0), m.rowCol(0, 0), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(0, 1), m.rowCol(0, 1), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(0, 2), m.rowCol(0, 2), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(1, 0), m.rowCol(1, 0), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(1, 1), m.rowCol(1, 1), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(1, 2), m.rowCol(1, 2), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(2, 0), m.rowCol(2, 0), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(2, 1), m.rowCol(2, 1), absErr);
|
||||
ASSERT_NEAR(mif.rowCol(2, 2), m.rowCol(2, 2), absErr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
// Parametrized test for AxisAngle to/from Quat
|
||||
//
|
||||
//==================================================================================================
|
||||
|
||||
struct AxisAngleQuat
|
||||
{
|
||||
Vec3d axis;
|
||||
double angleDeg;
|
||||
Quat<double> quat;
|
||||
};
|
||||
|
||||
class QuatTestAxisAngle : public ::testing::TestWithParam<AxisAngleQuat>
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST_P(QuatTestAxisAngle, ParameterizedSetFromAxisAngle)
|
||||
{
|
||||
const double absErr = 0.0001;
|
||||
|
||||
const AxisAngleQuat& aaq = GetParam();
|
||||
const Quat<double>& expected = aaq.quat;
|
||||
|
||||
{
|
||||
const Quat<double> q = Quat<double>::fromAxisAngle(aaq.axis, Math::toRadians(aaq.angleDeg));
|
||||
ASSERT_NEAR(expected.x(), q.x(), absErr);
|
||||
ASSERT_NEAR(expected.y(), q.y(), absErr);
|
||||
ASSERT_NEAR(expected.z(), q.z(), absErr);
|
||||
ASSERT_NEAR(expected.w(), q.w(), absErr);
|
||||
|
||||
Quat<double> q2;
|
||||
q2.setFromAxisAngle(aaq.axis, Math::toRadians(aaq.angleDeg));
|
||||
ASSERT_TRUE(q == q2);
|
||||
}
|
||||
|
||||
{
|
||||
const Quat<float> q = Quat<float>::fromAxisAngle(Vec3f(aaq.axis), (float)Math::toRadians(aaq.angleDeg));
|
||||
ASSERT_NEAR(expected.x(), q.x(), absErr);
|
||||
ASSERT_NEAR(expected.y(), q.y(), absErr);
|
||||
ASSERT_NEAR(expected.z(), q.z(), absErr);
|
||||
ASSERT_NEAR(expected.w(), q.w(), absErr);
|
||||
|
||||
Quat<float> q2;
|
||||
q2.setFromAxisAngle(Vec3f(aaq.axis), (float)Math::toRadians(aaq.angleDeg));
|
||||
ASSERT_TRUE(q == q2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST_P(QuatTestAxisAngle, ParameterizedtoAxisAngle)
|
||||
{
|
||||
const double absErr = 0.0001;
|
||||
const double absErrDeg = 0.01;
|
||||
|
||||
const AxisAngleQuat& aaq = GetParam();
|
||||
|
||||
double expectedAngleDeg = aaq.angleDeg;
|
||||
Vec3d expectedAxis = aaq.axis;
|
||||
|
||||
// We'll never get negative values back so just flip sign of angle
|
||||
// and direction of axis vector
|
||||
if (expectedAngleDeg < 0)
|
||||
{
|
||||
expectedAngleDeg *= -1;
|
||||
expectedAxis *= -1;
|
||||
}
|
||||
|
||||
expectedAxis.normalize();
|
||||
|
||||
|
||||
{
|
||||
Vec3d axis(0, 0, 0);
|
||||
double angle = 0;
|
||||
aaq.quat.toAxisAngle(&axis, &angle);
|
||||
|
||||
ASSERT_NEAR(expectedAxis.x(), axis.x(), absErr);
|
||||
ASSERT_NEAR(expectedAxis.y(), axis.y(), absErr);
|
||||
ASSERT_NEAR(expectedAxis.z(), axis.z(), absErr);
|
||||
ASSERT_NEAR(expectedAngleDeg, Math::toDegrees(angle), absErrDeg);
|
||||
}
|
||||
|
||||
{
|
||||
Vec3f axis(0, 0, 0);
|
||||
float angle = 0;
|
||||
|
||||
const Quat<float> quatf(aaq.quat);
|
||||
quatf.toAxisAngle(&axis, &angle);
|
||||
|
||||
ASSERT_NEAR(expectedAxis.x(), axis.x(), absErr);
|
||||
ASSERT_NEAR(expectedAxis.y(), axis.y(), absErr);
|
||||
ASSERT_NEAR(expectedAxis.z(), axis.z(), absErr);
|
||||
ASSERT_NEAR(expectedAngleDeg, (float)Math::toDegrees(angle), absErrDeg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// C# function to generate data
|
||||
//
|
||||
// static void PrintAxisAngleToQuat(Vector3D axis, double angle)
|
||||
// {
|
||||
// CultureInfo ci = new CultureInfo("en-us");
|
||||
//
|
||||
// Quaternion q = new Quaternion(axis, angle);
|
||||
// String frm = "Vec3d({0:f1}, {1:f1}, {2:f1}), \t{3:f1}, \tQuat<double>({4:f4}, {5:f4}, {6:f4}, {7:f4})";
|
||||
// Debug.WriteLine(String.Format(ci, frm, axis.X, axis.Y, axis.Z, angle, q.X, q.Y, q.Z, q.W));
|
||||
// }
|
||||
AxisAngleQuat AAQ_ARRAY[] =
|
||||
{
|
||||
// Axis Angle Quat
|
||||
{ Vec3d(1.0, 0.0, 0.0), 45.0, Quat<double>( 0.3827, 0.0000, 0.0000, 0.9239) },
|
||||
{ Vec3d(1.0, 0.0, 0.0), -45.0, Quat<double>(-0.3827, 0.0000, 0.0000, 0.9239) },
|
||||
{ Vec3d(1.0, 0.0, 0.0), 90.0, Quat<double>( 0.7071, 0.0000, 0.0000, 0.7071) },
|
||||
{ Vec3d(1.0, 0.0, 0.0), -90.0, Quat<double>(-0.7071, 0.0000, 0.0000, 0.7071) },
|
||||
{ Vec3d(1.0, 0.0, 0.0), 180.0, Quat<double>( 1.0000, 0.0000, 0.0000, 0.0000) },
|
||||
|
||||
{ Vec3d(0.0, 1.0, 0.0), 45.0, Quat<double>( 0.0000, 0.3827, 0.0000, 0.9239) },
|
||||
{ Vec3d(0.0, 1.0, 0.0), 90.0, Quat<double>( 0.0000, 0.7071, 0.0000, 0.7071) },
|
||||
|
||||
{ Vec3d(0.0, 0.0, 1.0), 45.0, Quat<double>( 0.0000, 0.0000, 0.3827, 0.9239) },
|
||||
{ Vec3d(0.0, 0.0, 1.0), 90.0, Quat<double>( 0.0000, 0.0000, 0.7071, 0.7071) },
|
||||
|
||||
{ Vec3d(1.0, 1.0, 1.0), 45.0, Quat<double>( 0.2209, 0.2209, 0.2209, 0.9239) },
|
||||
{ Vec3d(1.0, 1.0, 1.0), -45.0, Quat<double>(-0.2209, -0.2209, -0.2209, 0.9239) },
|
||||
{ Vec3d(1.0, 1.0, 1.0), 90.0, Quat<double>( 0.4082, 0.4082, 0.4082, 0.7071) },
|
||||
{ Vec3d(1.0, 1.0, 1.0), -90.0, Quat<double>(-0.4082, -0.4082, -0.4082, 0.7071) },
|
||||
{ Vec3d(1.0, 1.0, 1.0), 180.0, Quat<double>( 0.5774, 0.5774, 0.5774, 0.0000) },
|
||||
|
||||
{ Vec3d(1.0, 0.0, 1.0), 45.0, Quat<double>( 0.2706, 0.0000, 0.2706, 0.9239) },
|
||||
{ Vec3d(1.0, 0.0, 1.0), 90.0, Quat<double>( 0.5000, 0.0000, 0.5000, 0.7071) },
|
||||
|
||||
{ Vec3d(1.0, 1.0, 1.0), 200.0, Quat<double>( 0.5686, 0.5686, 0.5686, -0.1736) },
|
||||
{ Vec3d(1.0, 2.0, 3.0), 150.0, Quat<double>( 0.2582, 0.5163, 0.7745, 0.2588) },
|
||||
{ Vec3d(1.0, 0.1, 0.2), 160.0, Quat<double>( 0.9611, 0.0961, 0.1922, 0.1736) },
|
||||
{ Vec3d(0.2, 1.0, 0.1), 170.0, Quat<double>( 0.1944, 0.9722, 0.0972, 0.0872) },
|
||||
{ Vec3d(0.1, 0.2, 1.0), 150.0, Quat<double>( 0.0943, 0.1885, 0.9426, 0.2588) }
|
||||
};
|
||||
|
||||
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ParamInst, QuatTestAxisAngle, ::testing::ValuesIn(AAQ_ARRAY));
|
||||
|
||||
|
||||
651
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfRect-Test.cpp
Normal file
651
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfRect-Test.cpp
Normal file
@@ -0,0 +1,651 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfRect.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RectTest, Construction)
|
||||
{
|
||||
{
|
||||
Rectd rect;
|
||||
EXPECT_DOUBLE_EQ(0.0, rect.min().x());
|
||||
EXPECT_DOUBLE_EQ(0.0, rect.min().y());
|
||||
EXPECT_DOUBLE_EQ(0.0, rect.width());
|
||||
EXPECT_DOUBLE_EQ(0.0, rect.height());
|
||||
|
||||
EXPECT_FALSE(rect.isValid());
|
||||
}
|
||||
|
||||
{
|
||||
Rectd rect(-1, -2, 5, 10);
|
||||
EXPECT_DOUBLE_EQ(-1, rect.min().x());
|
||||
EXPECT_DOUBLE_EQ(-2, rect.min().y());
|
||||
EXPECT_DOUBLE_EQ(5, rect.width());
|
||||
EXPECT_DOUBLE_EQ(10, rect.height());
|
||||
|
||||
EXPECT_TRUE(rect.isValid());
|
||||
}
|
||||
|
||||
{
|
||||
Vec2d min(-2, -3);
|
||||
Rectd rect(min, 5, 10);
|
||||
EXPECT_DOUBLE_EQ(min.x(), rect.min().x());
|
||||
EXPECT_DOUBLE_EQ(min.y(), rect.min().y());
|
||||
EXPECT_DOUBLE_EQ(5, rect.width());
|
||||
EXPECT_DOUBLE_EQ(10, rect.height());
|
||||
|
||||
EXPECT_TRUE(rect.isValid());
|
||||
}
|
||||
|
||||
{
|
||||
Vec2d min(-2, -3);
|
||||
Rectd rect(min, 5, 10);
|
||||
EXPECT_DOUBLE_EQ(min.x(), rect.min().x());
|
||||
EXPECT_DOUBLE_EQ(min.y(), rect.min().y());
|
||||
EXPECT_DOUBLE_EQ(5, rect.width());
|
||||
EXPECT_DOUBLE_EQ(10, rect.height());
|
||||
|
||||
EXPECT_TRUE(rect.isValid());
|
||||
|
||||
Rectd otherRect(rect);
|
||||
EXPECT_DOUBLE_EQ(rect.min().x(), otherRect.min().x());
|
||||
EXPECT_DOUBLE_EQ(rect.min().y(), otherRect.min().y());
|
||||
EXPECT_DOUBLE_EQ(rect.width(), otherRect.width());
|
||||
EXPECT_DOUBLE_EQ(rect.height(), otherRect.height());
|
||||
|
||||
EXPECT_TRUE(otherRect.isValid());
|
||||
}
|
||||
|
||||
{
|
||||
Vec2d min(-2, -3);
|
||||
Vec2d max(5, 6);
|
||||
Rectd rect = Rectd::fromMinMax(min, max);
|
||||
|
||||
EXPECT_TRUE(rect.isValid());
|
||||
EXPECT_DOUBLE_EQ(min.x(), rect.min().x());
|
||||
EXPECT_DOUBLE_EQ(min.y(), rect.min().y());
|
||||
EXPECT_DOUBLE_EQ(7, rect.width());
|
||||
EXPECT_DOUBLE_EQ(9, rect.height());
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
Vec2d min(-2, -3);
|
||||
Rectd rectOriginal(min, 5, 10);
|
||||
Rectd rect;
|
||||
EXPECT_FALSE(rect.isValid());
|
||||
|
||||
rect = rectOriginal;
|
||||
|
||||
EXPECT_TRUE(rect.isValid());
|
||||
EXPECT_DOUBLE_EQ(-2, rect.min().x());
|
||||
EXPECT_DOUBLE_EQ(-3, rect.min().y());
|
||||
EXPECT_DOUBLE_EQ(3, rect.max().x());
|
||||
EXPECT_DOUBLE_EQ(7, rect.max().y());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RectTest, RectTypes)
|
||||
{
|
||||
// Rectf
|
||||
{
|
||||
Rectf rect;
|
||||
EXPECT_FLOAT_EQ(0.0f, rect.min().x());
|
||||
EXPECT_FLOAT_EQ(0.0f, rect.min().y());
|
||||
EXPECT_FLOAT_EQ(0.0f, rect.width());
|
||||
EXPECT_FLOAT_EQ(0.0f, rect.height());
|
||||
|
||||
EXPECT_FALSE(rect.isValid());
|
||||
}
|
||||
|
||||
{
|
||||
Rectf rect(-1.0f, -2.0f, 5.0f, 10.0f);
|
||||
EXPECT_FLOAT_EQ(-1.0f, rect.min().x());
|
||||
EXPECT_FLOAT_EQ(-2.0f, rect.min().y());
|
||||
EXPECT_FLOAT_EQ(5.0f, rect.width());
|
||||
EXPECT_FLOAT_EQ(10.0f, rect.height());
|
||||
|
||||
EXPECT_TRUE(rect.isValid());
|
||||
}
|
||||
|
||||
// Recti
|
||||
{
|
||||
Recti rect;
|
||||
EXPECT_EQ(0, rect.min().x());
|
||||
EXPECT_EQ(0, rect.min().y());
|
||||
EXPECT_EQ(0, rect.width());
|
||||
EXPECT_EQ(0, rect.height());
|
||||
|
||||
EXPECT_FALSE(rect.isValid());
|
||||
}
|
||||
|
||||
{
|
||||
Recti rect(-1, -2, 5, 10);
|
||||
EXPECT_EQ(-1, rect.min().x());
|
||||
EXPECT_EQ(-2, rect.min().y());
|
||||
EXPECT_EQ(5, rect.width());
|
||||
EXPECT_EQ(10, rect.height());
|
||||
|
||||
EXPECT_TRUE(rect.isValid());
|
||||
}
|
||||
|
||||
// Rectui
|
||||
{
|
||||
Rectui rect;
|
||||
EXPECT_EQ(0, rect.min().x());
|
||||
EXPECT_EQ(0, rect.min().y());
|
||||
EXPECT_EQ(0, rect.width());
|
||||
EXPECT_EQ(0, rect.height());
|
||||
|
||||
EXPECT_FALSE(rect.isValid());
|
||||
}
|
||||
|
||||
{
|
||||
Rectui rect(1, 2, 5, 10);
|
||||
EXPECT_EQ(1, rect.min().x());
|
||||
EXPECT_EQ(2, rect.min().y());
|
||||
EXPECT_EQ(5, rect.width());
|
||||
EXPECT_EQ(10, rect.height());
|
||||
|
||||
EXPECT_TRUE(rect.isValid());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RectTest, CenterAndSetters)
|
||||
{
|
||||
Rectd rect(0, 0, 5, 10);
|
||||
EXPECT_DOUBLE_EQ(2.5, rect.center().x());
|
||||
EXPECT_DOUBLE_EQ(5, rect.center().y());
|
||||
|
||||
Vec2d otherMin(-2, -4);
|
||||
rect.setMin(otherMin);
|
||||
EXPECT_DOUBLE_EQ(0.5, rect.center().x());
|
||||
EXPECT_DOUBLE_EQ(1, rect.center().y());
|
||||
|
||||
rect.setWidth(20);
|
||||
EXPECT_DOUBLE_EQ(8, rect.center().x());
|
||||
EXPECT_DOUBLE_EQ(1, rect.center().y());
|
||||
|
||||
rect.setHeight(30);
|
||||
EXPECT_DOUBLE_EQ(8, rect.center().x());
|
||||
EXPECT_DOUBLE_EQ(11, rect.center().y());
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RectTest, Normalize)
|
||||
{
|
||||
{
|
||||
Rectd r(0, 0, -5, 10);
|
||||
EXPECT_FALSE(r.isValid());
|
||||
EXPECT_DOUBLE_EQ(-5, r.width());
|
||||
|
||||
r.normalize();
|
||||
EXPECT_TRUE(r.isValid());
|
||||
EXPECT_DOUBLE_EQ(-5, r.min().x());
|
||||
EXPECT_DOUBLE_EQ(5, r.width());
|
||||
}
|
||||
|
||||
{
|
||||
Recti r(0, 0, -5, 10);
|
||||
EXPECT_FALSE(r.isValid());
|
||||
EXPECT_DOUBLE_EQ(-5, r.width());
|
||||
|
||||
r.normalize();
|
||||
EXPECT_TRUE(r.isValid());
|
||||
EXPECT_DOUBLE_EQ(-5, r.min().x());
|
||||
EXPECT_DOUBLE_EQ(5, r.width());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RectTest, Include)
|
||||
{
|
||||
{
|
||||
Rectd rect;
|
||||
Vec2d pt1(10, 20);
|
||||
rect.include(pt1);
|
||||
|
||||
EXPECT_DOUBLE_EQ(0.0, rect.min().x());
|
||||
EXPECT_DOUBLE_EQ(0.0, rect.min().y());
|
||||
EXPECT_DOUBLE_EQ(10, rect.width());
|
||||
EXPECT_DOUBLE_EQ(20, rect.height());
|
||||
|
||||
Vec2d pt2(20, 30);
|
||||
rect.include(pt2);
|
||||
|
||||
EXPECT_DOUBLE_EQ(0, rect.min().x());
|
||||
EXPECT_DOUBLE_EQ(0, rect.min().y());
|
||||
EXPECT_DOUBLE_EQ(20, rect.width());
|
||||
EXPECT_DOUBLE_EQ(30, rect.height());
|
||||
}
|
||||
|
||||
{
|
||||
Rectd rect;
|
||||
Vec2d pt1(10, 20);
|
||||
rect.setMin(pt1);
|
||||
|
||||
EXPECT_DOUBLE_EQ(10, rect.min().x());
|
||||
EXPECT_DOUBLE_EQ(20, rect.min().y());
|
||||
EXPECT_DOUBLE_EQ(0, rect.width());
|
||||
EXPECT_DOUBLE_EQ(0, rect.height());
|
||||
|
||||
Vec2d pt2(20, 30);
|
||||
rect.include(pt2);
|
||||
|
||||
EXPECT_DOUBLE_EQ(10, rect.min().x());
|
||||
EXPECT_DOUBLE_EQ(20, rect.min().y());
|
||||
EXPECT_DOUBLE_EQ(10, rect.width());
|
||||
EXPECT_DOUBLE_EQ(10, rect.height());
|
||||
|
||||
Vec2d pt3(-20, -30);
|
||||
rect.include(pt3);
|
||||
|
||||
EXPECT_DOUBLE_EQ(-20, rect.min().x());
|
||||
EXPECT_DOUBLE_EQ(-30, rect.min().y());
|
||||
EXPECT_DOUBLE_EQ(40, rect.width());
|
||||
EXPECT_DOUBLE_EQ(60, rect.height());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RectTest, IncludeRect)
|
||||
{
|
||||
Rectd rect;
|
||||
{
|
||||
Rectd otherRect(10, 20, 5, 15);
|
||||
rect.include(otherRect);
|
||||
|
||||
EXPECT_DOUBLE_EQ(0.0, rect.min().x());
|
||||
EXPECT_DOUBLE_EQ(0.0, rect.min().y());
|
||||
EXPECT_DOUBLE_EQ(15, rect.width());
|
||||
EXPECT_DOUBLE_EQ(35, rect.height());
|
||||
}
|
||||
|
||||
{
|
||||
Rectd otherRect(-10, -20, 5, 5);
|
||||
rect.include(otherRect);
|
||||
|
||||
EXPECT_DOUBLE_EQ(-10, rect.min().x());
|
||||
EXPECT_DOUBLE_EQ(-20, rect.min().y());
|
||||
EXPECT_DOUBLE_EQ(25, rect.width());
|
||||
EXPECT_DOUBLE_EQ(55, rect.height());
|
||||
}
|
||||
|
||||
{
|
||||
Rectd otherRect(-100, -200, 200, 300);
|
||||
rect.include(otherRect);
|
||||
|
||||
EXPECT_DOUBLE_EQ(-100, rect.min().x());
|
||||
EXPECT_DOUBLE_EQ(-200, rect.min().y());
|
||||
EXPECT_DOUBLE_EQ(200, rect.width());
|
||||
EXPECT_DOUBLE_EQ(300, rect.height());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RectTest, Contains_Rectd)
|
||||
{
|
||||
Rectd rect;
|
||||
|
||||
{
|
||||
const Vec2d pt(10, 20);
|
||||
EXPECT_FALSE(rect.contains(pt));
|
||||
|
||||
rect.setWidth(10);
|
||||
EXPECT_FALSE(rect.contains(pt));
|
||||
|
||||
rect.setHeight(10);
|
||||
EXPECT_FALSE(rect.contains(pt));
|
||||
|
||||
rect.setHeight(20);
|
||||
EXPECT_TRUE(rect.contains(pt));
|
||||
}
|
||||
|
||||
{
|
||||
const Vec2d pt(0, 0);
|
||||
EXPECT_TRUE(rect.contains(pt));
|
||||
}
|
||||
|
||||
{
|
||||
const Vec2d pt(-0.5, 0);
|
||||
EXPECT_FALSE(rect.contains(pt));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RectTest, Contains_Rectui)
|
||||
{
|
||||
// minx, miny, width, height
|
||||
Rectui rect(10, 20, 5, 10);
|
||||
|
||||
// Points inside
|
||||
EXPECT_TRUE(rect.contains(Vec2ui(11, 21)));
|
||||
EXPECT_TRUE(rect.contains(Vec2ui(14, 29)));
|
||||
|
||||
// Points on the edge
|
||||
EXPECT_TRUE(rect.contains(Vec2ui(10, 20)));
|
||||
EXPECT_TRUE(rect.contains(Vec2ui(10, 21)));
|
||||
EXPECT_TRUE(rect.contains(Vec2ui(15, 30)));
|
||||
EXPECT_TRUE(rect.contains(Vec2ui(15, 29)));
|
||||
|
||||
// Points outside
|
||||
EXPECT_FALSE(rect.contains(Vec2ui(0, 0)));
|
||||
EXPECT_FALSE(rect.contains(Vec2ui(26, 31)));
|
||||
EXPECT_FALSE(rect.contains(Vec2ui(9, 21)));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RectTest, Intersects)
|
||||
{
|
||||
{
|
||||
Rectd rect;
|
||||
Rectd otherRect(10, 20, 5, 15);
|
||||
|
||||
EXPECT_FALSE(rect.intersects(otherRect));
|
||||
}
|
||||
|
||||
{
|
||||
Rectd rect(5, 0, 10, 20);
|
||||
Rectd otherRect(0, 2, 10, 2);
|
||||
|
||||
EXPECT_TRUE(rect.intersects(otherRect));
|
||||
}
|
||||
|
||||
{
|
||||
Rectd rect;
|
||||
|
||||
Rectd otherRect(10, 20, 5, 15);
|
||||
EXPECT_FALSE(rect.intersects(otherRect));
|
||||
|
||||
rect.setWidth(5);
|
||||
EXPECT_FALSE(rect.intersects(otherRect));
|
||||
|
||||
rect.setHeight(5);
|
||||
EXPECT_FALSE(rect.intersects(otherRect));
|
||||
|
||||
rect.setWidth(10);
|
||||
rect.setHeight(20);
|
||||
EXPECT_FALSE(rect.intersects(otherRect));
|
||||
|
||||
rect.setWidth(10.1);
|
||||
rect.setHeight(20.1);
|
||||
EXPECT_TRUE(rect.intersects(otherRect));
|
||||
}
|
||||
|
||||
{
|
||||
Rectd rect(10, 20, 5, 15);
|
||||
Rectd otherRect(0, 0, 11, 21);
|
||||
|
||||
EXPECT_TRUE(rect.intersects(otherRect));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RectTest, Translate)
|
||||
{
|
||||
{
|
||||
Rectd rect(0, 5, 2, 2);
|
||||
|
||||
rect.translate(Vec2d(10, 10));
|
||||
EXPECT_DOUBLE_EQ(10, rect.min().x());
|
||||
EXPECT_DOUBLE_EQ(15, rect.min().y());
|
||||
|
||||
rect.translate(Vec2d(-20, -20));
|
||||
EXPECT_DOUBLE_EQ(-10, rect.min().x());
|
||||
EXPECT_DOUBLE_EQ(-5, rect.min().y());
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RectTest, FromMinMax)
|
||||
{
|
||||
{
|
||||
Rectd rect = Rectd::fromMinMax(Vec2d(-1, 2), Vec2d(10, 12));
|
||||
EXPECT_TRUE(rect.isValid());
|
||||
EXPECT_DOUBLE_EQ(-1, rect.min().x());
|
||||
EXPECT_DOUBLE_EQ(2, rect.min().y());
|
||||
EXPECT_DOUBLE_EQ(10, rect.max().x());
|
||||
EXPECT_DOUBLE_EQ(12, rect.max().y());
|
||||
EXPECT_DOUBLE_EQ(11, rect.width());
|
||||
EXPECT_DOUBLE_EQ(10, rect.height());
|
||||
}
|
||||
|
||||
{
|
||||
Recti rect = Recti::fromMinMax(Vec2i(-1, 2), Vec2i(10, 12));
|
||||
EXPECT_TRUE(rect.isValid());
|
||||
EXPECT_EQ(-1, rect.min().x());
|
||||
EXPECT_EQ( 2, rect.min().y());
|
||||
EXPECT_EQ(10, rect.max().x());
|
||||
EXPECT_EQ(12, rect.max().y());
|
||||
EXPECT_EQ(11, rect.width());
|
||||
EXPECT_EQ(10, rect.height());
|
||||
}
|
||||
|
||||
{
|
||||
Rectui rect = Rectui::fromMinMax(Vec2ui(1, 2), Vec2ui(11, 22));
|
||||
EXPECT_TRUE(rect.isValid());
|
||||
EXPECT_EQ( 1, rect.min().x());
|
||||
EXPECT_EQ( 2, rect.min().y());
|
||||
EXPECT_EQ(11, rect.max().x());
|
||||
EXPECT_EQ(22, rect.max().y());
|
||||
EXPECT_EQ(10, rect.width());
|
||||
EXPECT_EQ(20, rect.height());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RectTest, LineSegmentIntersect)
|
||||
{
|
||||
// p1 outside, p2 inside
|
||||
{
|
||||
Rectd rect = Rectd::fromMinMax(Vec2d(5, 7), Vec2d(10, 20));
|
||||
|
||||
Vec2d p1(3, 15);
|
||||
Vec2d p2(13, 15);
|
||||
Vec2d intersect1;
|
||||
Vec2d intersect2;
|
||||
EXPECT_TRUE(rect.segmentIntersect(p1, p2, &intersect1, &intersect2));
|
||||
EXPECT_DOUBLE_EQ(5, intersect1.x());
|
||||
EXPECT_DOUBLE_EQ(15, intersect1.y());
|
||||
EXPECT_DOUBLE_EQ(10, intersect2.x());
|
||||
EXPECT_DOUBLE_EQ(15, intersect2.y());
|
||||
}
|
||||
|
||||
// p1 inside, p2 outside
|
||||
{
|
||||
Rectd rect = Rectd::fromMinMax(Vec2d(5, 7), Vec2d(10, 20));
|
||||
|
||||
Vec2d p1(7, 15);
|
||||
Vec2d p2(13, 15);
|
||||
Vec2d intersect1;
|
||||
Vec2d intersect2;
|
||||
EXPECT_TRUE(rect.segmentIntersect(p1, p2, &intersect1, &intersect2));
|
||||
EXPECT_DOUBLE_EQ(7, intersect1.x());
|
||||
EXPECT_DOUBLE_EQ(15, intersect1.y());
|
||||
EXPECT_DOUBLE_EQ(10, intersect2.x());
|
||||
EXPECT_DOUBLE_EQ(15, intersect2.y());
|
||||
}
|
||||
|
||||
// p1 inside, p2 inside
|
||||
{
|
||||
Rectd rect = Rectd::fromMinMax(Vec2d(5, 7), Vec2d(10, 20));
|
||||
|
||||
Vec2d p1(7, 15);
|
||||
Vec2d p2(8, 15);
|
||||
Vec2d intersect1;
|
||||
Vec2d intersect2;
|
||||
EXPECT_TRUE(rect.segmentIntersect(p1, p2, &intersect1, &intersect2));
|
||||
EXPECT_DOUBLE_EQ(7, intersect1.x());
|
||||
EXPECT_DOUBLE_EQ(15, intersect1.y());
|
||||
EXPECT_DOUBLE_EQ(8, intersect2.x());
|
||||
EXPECT_DOUBLE_EQ(15, intersect2.y());
|
||||
}
|
||||
|
||||
// p1 inside, p2 outside
|
||||
{
|
||||
Rectd rect = Rectd::fromMinMax(Vec2d(5, 7), Vec2d(10, 20));
|
||||
|
||||
Vec2d p1(7, 15);
|
||||
Vec2d p2(13, 15);
|
||||
Vec2d intersect1;
|
||||
Vec2d intersect2;
|
||||
EXPECT_TRUE(rect.segmentIntersect(p1, p2, &intersect1, &intersect2));
|
||||
EXPECT_DOUBLE_EQ(7, intersect1.x());
|
||||
EXPECT_DOUBLE_EQ(15, intersect1.y());
|
||||
EXPECT_DOUBLE_EQ(10, intersect2.x());
|
||||
EXPECT_DOUBLE_EQ(15, intersect2.y());
|
||||
}
|
||||
|
||||
// p1 inside, p2 outside
|
||||
{
|
||||
Rectd rect = Rectd::fromMinMax(Vec2d(5, 7), Vec2d(10, 20));
|
||||
|
||||
Vec2d p1(7, 15);
|
||||
Vec2d p2(7, 25);
|
||||
Vec2d intersect1;
|
||||
Vec2d intersect2;
|
||||
EXPECT_TRUE(rect.segmentIntersect(p1, p2, &intersect1, &intersect2));
|
||||
EXPECT_DOUBLE_EQ(7, intersect1.x());
|
||||
EXPECT_DOUBLE_EQ(15, intersect1.y());
|
||||
EXPECT_DOUBLE_EQ(7, intersect2.x());
|
||||
EXPECT_DOUBLE_EQ(20, intersect2.y());
|
||||
}
|
||||
|
||||
{
|
||||
Rectd rect = Rectd::fromMinMax(Vec2d(5, 7), Vec2d(10, 20));
|
||||
|
||||
Vec2d p1(3, 15);
|
||||
Vec2d p2(10, 25);
|
||||
Vec2d intersect1;
|
||||
Vec2d intersect2;
|
||||
EXPECT_TRUE(rect.segmentIntersect(p1, p2, &intersect1, &intersect2));
|
||||
EXPECT_DOUBLE_EQ(5, intersect1.x());
|
||||
EXPECT_NEAR(17.85, intersect1.y(), 0.1);
|
||||
EXPECT_DOUBLE_EQ(6.5, intersect2.x());
|
||||
EXPECT_DOUBLE_EQ(20, intersect2.y());
|
||||
}
|
||||
|
||||
|
||||
// No intersection
|
||||
{
|
||||
Rectd rect = Rectd::fromMinMax(Vec2d(5, 7), Vec2d(10, 20));
|
||||
|
||||
Vec2d p1(3, 15);
|
||||
Vec2d p2(4, 15);
|
||||
Vec2d intersect1 = Vec2d::UNDEFINED;
|
||||
Vec2d intersect2 = Vec2d::UNDEFINED;
|
||||
EXPECT_FALSE(rect.segmentIntersect(p1, p2, &intersect1, &intersect2));
|
||||
EXPECT_TRUE(intersect1.isUndefined());
|
||||
EXPECT_TRUE(intersect2.isUndefined());
|
||||
}
|
||||
|
||||
// Invalid rect
|
||||
{
|
||||
Rectd rect(Vec2d(5, 7), -10, -20);
|
||||
|
||||
Vec2d p1(3, 15);
|
||||
Vec2d p2(4, 15);
|
||||
Vec2d intersect1 = Vec2d::UNDEFINED;
|
||||
Vec2d intersect2 = Vec2d::UNDEFINED;
|
||||
EXPECT_FALSE(rect.segmentIntersect(p1, p2, &intersect1, &intersect2));
|
||||
EXPECT_TRUE(intersect1.isUndefined());
|
||||
EXPECT_TRUE(intersect2.isUndefined());
|
||||
}
|
||||
|
||||
// p1 and p2 equal
|
||||
{
|
||||
Rectd rect = Rectd::fromMinMax(Vec2d(5, 7), Vec2d(10, 20));
|
||||
|
||||
Vec2d p1(7, 15);
|
||||
Vec2d p2(7, 15);
|
||||
Vec2d intersect1;
|
||||
Vec2d intersect2;
|
||||
EXPECT_TRUE(rect.segmentIntersect(p1, p2, &intersect1, &intersect2));
|
||||
EXPECT_DOUBLE_EQ(7, intersect1.x());
|
||||
EXPECT_DOUBLE_EQ(15, intersect1.y());
|
||||
EXPECT_DOUBLE_EQ(7, intersect2.x());
|
||||
EXPECT_DOUBLE_EQ(15, intersect2.y());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
1486
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfString-Test.cpp
Normal file
1486
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfString-Test.cpp
Normal file
File diff suppressed because it is too large
Load Diff
258
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfSystem-Test.cpp
Normal file
258
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfSystem-Test.cpp
Normal file
@@ -0,0 +1,258 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfSystem.h"
|
||||
#include "cvfString.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(SystemTest, memcpy)
|
||||
{
|
||||
const char src[] = "Test123";
|
||||
|
||||
{
|
||||
char dst[10];
|
||||
memset(dst, 'X', 10);
|
||||
ASSERT_EQ('X', dst[0]);
|
||||
ASSERT_EQ('X', dst[9]);
|
||||
|
||||
// SHould be OK to copy 0 bytes
|
||||
EXPECT_TRUE(System::memcpy(dst, 10, src, 0));
|
||||
|
||||
EXPECT_TRUE(System::memcpy(dst, 10, src, 8));
|
||||
EXPECT_STREQ("Test123", dst);
|
||||
EXPECT_EQ(0, dst[7]);
|
||||
EXPECT_EQ('X', dst[8]);
|
||||
EXPECT_EQ('X', dst[9]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(SystemTest, strcpy)
|
||||
{
|
||||
const char src[] = "Test123";
|
||||
|
||||
{
|
||||
char dst[10];
|
||||
memset(dst, 'X', 10);
|
||||
|
||||
EXPECT_TRUE(System::strcpy(dst, 10, src));
|
||||
EXPECT_STREQ("Test123", dst);
|
||||
EXPECT_EQ(0, dst[7]);
|
||||
}
|
||||
|
||||
{
|
||||
char dst[8];
|
||||
memset(dst, 'X', 8);
|
||||
|
||||
EXPECT_TRUE(System::strcpy(dst, 8, src));
|
||||
EXPECT_STREQ("Test123", dst);
|
||||
EXPECT_EQ(0, dst[7]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(SystemTest, strcat)
|
||||
{
|
||||
const char str1[] = "Test1";
|
||||
const char str2[] = "Str2";
|
||||
|
||||
{
|
||||
char str[6];
|
||||
str[0] = '\0';
|
||||
ASSERT_TRUE(System::strcat(str, sizeof(str), str1));
|
||||
ASSERT_STREQ("Test1", str);
|
||||
}
|
||||
|
||||
{
|
||||
char str[20];
|
||||
str[0] = '\0';
|
||||
ASSERT_TRUE(System::strcat(str, sizeof(str), str1));
|
||||
ASSERT_TRUE(System::strcat(str, sizeof(str), str2));
|
||||
ASSERT_STREQ("Test1Str2", str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(SystemTest, sprintf)
|
||||
{
|
||||
{
|
||||
char buf[100];
|
||||
int numWritten = System::sprintf(buf, 100, "%d %s %.2f", 999, "ABC", 1.23f);
|
||||
EXPECT_EQ(12, numWritten);
|
||||
EXPECT_STREQ("999 ABC 1.23", buf);
|
||||
}
|
||||
|
||||
{
|
||||
char buf[5];
|
||||
int numWritten = System::sprintf(buf, 5, "%s", "ABCD");
|
||||
EXPECT_EQ(4, numWritten);
|
||||
EXPECT_STREQ("ABCD", buf);
|
||||
}
|
||||
|
||||
{
|
||||
char buf[5];
|
||||
memset(buf, 'X', 5);
|
||||
|
||||
int numWritten = System::sprintf(buf, 4, "%s", "ABC");
|
||||
EXPECT_EQ(3, numWritten);
|
||||
EXPECT_EQ('C', buf[2]);
|
||||
EXPECT_EQ('\0', buf[3]);
|
||||
EXPECT_EQ('X', buf[4]);
|
||||
}
|
||||
|
||||
{
|
||||
char buf[4];
|
||||
int numWritten = System::sprintf(buf, 4, "%s", "ABCD");
|
||||
EXPECT_EQ(-1, numWritten);
|
||||
EXPECT_STREQ("ABC", buf);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(SystemTest, swprintf)
|
||||
{
|
||||
{
|
||||
wchar_t buf[100];
|
||||
int numWritten = System::swprintf(buf, 100, L"%d %ls %.2f", 999, L"ABC", 1.23f);
|
||||
EXPECT_EQ(12, numWritten);
|
||||
|
||||
/// Expected string "999 ABC 1.23"
|
||||
EXPECT_EQ(L'9', buf[0]);
|
||||
EXPECT_EQ(L'A', buf[4]);
|
||||
EXPECT_EQ(L'.', buf[9]);
|
||||
EXPECT_EQ(L'3', buf[11]);
|
||||
EXPECT_EQ(L'\0', buf[12]);
|
||||
}
|
||||
|
||||
{
|
||||
wchar_t buf[5];
|
||||
int numWritten = System::swprintf(buf, 5, L"%ls", L"ABCD");
|
||||
EXPECT_EQ(4, numWritten);
|
||||
EXPECT_EQ(L'A', buf[0]);
|
||||
EXPECT_EQ(L'B', buf[1]);
|
||||
EXPECT_EQ(L'C', buf[2]);
|
||||
EXPECT_EQ(L'D', buf[3]);
|
||||
EXPECT_EQ(L'\0', buf[4]);
|
||||
}
|
||||
|
||||
{
|
||||
wchar_t buf[5];
|
||||
buf[0] = L'X';
|
||||
buf[1] = L'X';
|
||||
buf[2] = L'X';
|
||||
buf[3] = L'X';
|
||||
buf[4] = L'X';
|
||||
|
||||
int numWritten = System::swprintf(buf, 4, L"%ls", L"ABC");
|
||||
EXPECT_EQ(3, numWritten);
|
||||
EXPECT_EQ(L'C', buf[2]);
|
||||
EXPECT_EQ(L'\0', buf[3]);
|
||||
EXPECT_EQ(L'X', buf[4]);
|
||||
}
|
||||
|
||||
{
|
||||
wchar_t buf[4];
|
||||
int numWritten = System::swprintf(buf, 4, L"%ls", L"ABCD");
|
||||
EXPECT_EQ(-1, numWritten);
|
||||
EXPECT_EQ(L'A', buf[0]);
|
||||
EXPECT_EQ(L'B', buf[1]);
|
||||
EXPECT_EQ(L'C', buf[2]);
|
||||
EXPECT_EQ(L'\0', buf[3]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(SystemTest, strlen)
|
||||
{
|
||||
char str0[] = "";
|
||||
char str1[] = "Test123";
|
||||
|
||||
EXPECT_EQ(0, System::strlen(str0));
|
||||
EXPECT_EQ(7, System::strlen(str1));
|
||||
|
||||
EXPECT_EQ(0, System::strlen(NULL));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(SystemTest, strcmp)
|
||||
{
|
||||
char str0[] = "";
|
||||
char str1[] = "Test1";
|
||||
char str2[] = "Test2";
|
||||
|
||||
EXPECT_EQ(0, System::strcmp(str0, ""));
|
||||
EXPECT_EQ(0, System::strcmp(str0, str0));
|
||||
EXPECT_EQ(0, System::strcmp(str1, "Test1"));
|
||||
EXPECT_EQ(0, System::strcmp(str1, str1));
|
||||
EXPECT_EQ(0, System::strcmp(NULL, NULL));
|
||||
|
||||
EXPECT_GT(System::strcmp(str1, str0), 0);
|
||||
EXPECT_LT(System::strcmp(str1, str2), 0);
|
||||
EXPECT_GT(System::strcmp(str0, NULL), 0);
|
||||
EXPECT_GT(System::strcmp(str1, NULL), 0);
|
||||
EXPECT_GT(System::strcmp(str2, NULL), 0);
|
||||
}
|
||||
|
||||
|
||||
63
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfTimer-Test.cpp
Normal file
63
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfTimer-Test.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfTimer.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(TimerTest, BasicConstruction)
|
||||
{
|
||||
Timer timer;
|
||||
|
||||
double time = timer.time();
|
||||
ASSERT_TRUE(time >= 0.0);
|
||||
|
||||
double lapTime = timer.lapTime();
|
||||
ASSERT_TRUE(lapTime >= 0.0);
|
||||
|
||||
timer.restart();
|
||||
}
|
||||
|
||||
53
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfTrace-Test.cpp
Normal file
53
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfTrace-Test.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfTrace.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(TraceTest, BasicConstruction)
|
||||
{
|
||||
Trace::show(" cvf::Trace test output: My output!!");
|
||||
Trace::show(" cvf::Trace test output: Txt: %s %d %f", "Hello", 123, 123.456f);
|
||||
}
|
||||
501
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfVariant-Test.cpp
Normal file
501
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfVariant-Test.cpp
Normal file
@@ -0,0 +1,501 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfVariant.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VariantTest, DefaultConstructor)
|
||||
{
|
||||
Variant var;
|
||||
ASSERT_EQ(Variant::INVALID, var.type());
|
||||
ASSERT_FALSE(var.isValid());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VariantTest, CopyConstructor)
|
||||
{
|
||||
{
|
||||
const Variant var(-1234);
|
||||
ASSERT_TRUE(var.isValid());
|
||||
ASSERT_EQ(Variant::INT, var.type());
|
||||
|
||||
Variant var2(var);
|
||||
ASSERT_TRUE(var2.isValid());
|
||||
ASSERT_EQ(Variant::INT, var2.type());
|
||||
ASSERT_EQ(-1234, var2.getInt());
|
||||
|
||||
Variant var3 = var;
|
||||
ASSERT_TRUE(var3.isValid());
|
||||
ASSERT_EQ(Variant::INT, var3.type());
|
||||
ASSERT_EQ(-1234, var3.getInt());
|
||||
}
|
||||
|
||||
{
|
||||
const String theString("MyStr");
|
||||
const Variant var(theString);
|
||||
ASSERT_TRUE(var.isValid());
|
||||
ASSERT_EQ(Variant::STRING, var.type());
|
||||
|
||||
Variant var2(var);
|
||||
ASSERT_TRUE(var2.isValid());
|
||||
ASSERT_EQ(Variant::STRING, var2.type());
|
||||
ASSERT_TRUE(var2.getString() == theString);
|
||||
|
||||
Variant var3 = var;
|
||||
ASSERT_TRUE(var3.isValid());
|
||||
ASSERT_EQ(Variant::STRING, var3.type());
|
||||
ASSERT_TRUE(var3.getString() == theString);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VariantTest, AssignmentOperator)
|
||||
{
|
||||
{
|
||||
const Variant var(-1234);
|
||||
ASSERT_TRUE(var.isValid());
|
||||
ASSERT_EQ(Variant::INT, var.type());
|
||||
|
||||
Variant var2;
|
||||
var2 = var;
|
||||
ASSERT_TRUE(var2.isValid());
|
||||
ASSERT_EQ(Variant::INT, var2.type());
|
||||
ASSERT_EQ(-1234, var2.getInt());
|
||||
}
|
||||
|
||||
{
|
||||
const String theString("MyStr");
|
||||
const Variant var(theString);
|
||||
ASSERT_TRUE(var.isValid());
|
||||
ASSERT_EQ(Variant::STRING, var.type());
|
||||
|
||||
Variant var2;
|
||||
var2 = var;
|
||||
ASSERT_TRUE(var2.isValid());
|
||||
ASSERT_EQ(Variant::STRING, var2.type());
|
||||
ASSERT_TRUE(var2.getString() == theString);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VariantTest, ComparisonOperatorAtomicVariants)
|
||||
{
|
||||
const Variant v;
|
||||
const Variant vi(-1234);
|
||||
const Variant vui(5678u);
|
||||
const Variant vd(1.234);
|
||||
const Variant vf(2.234f);
|
||||
const Variant vb(true);
|
||||
const Variant vv3d(Vec3d(1, 2, 3));
|
||||
const Variant vc3f(Color3f(0.1f, 0.2f, 0.3f));
|
||||
const Variant vs("myString");
|
||||
|
||||
ASSERT_TRUE(v == Variant());
|
||||
ASSERT_FALSE(v == Variant(1));
|
||||
|
||||
ASSERT_TRUE(vi == Variant(-1234));
|
||||
ASSERT_FALSE(vi == Variant(-12345));
|
||||
|
||||
ASSERT_TRUE(vui == Variant(5678u));
|
||||
ASSERT_FALSE(vui == Variant(56789u));
|
||||
ASSERT_FALSE(vui == Variant(5678));
|
||||
|
||||
ASSERT_TRUE(vd == Variant(1.234));
|
||||
ASSERT_FALSE(vd == Variant(1.2345));
|
||||
|
||||
ASSERT_TRUE(vf == Variant(2.234f));
|
||||
ASSERT_FALSE(vf == Variant(2.2345f));
|
||||
|
||||
ASSERT_TRUE(vb == Variant(true));
|
||||
ASSERT_FALSE(vb == Variant(false));
|
||||
|
||||
ASSERT_TRUE(vv3d == Variant(Vec3d(1, 2, 3)));
|
||||
ASSERT_FALSE(vv3d == Variant(Vec3d(1, 2, 4)));
|
||||
|
||||
ASSERT_TRUE(vc3f == Variant(Color3f(0.1f, 0.2f, 0.3f)));
|
||||
ASSERT_FALSE(vc3f == Variant(Color3f(0.1f, 0.2f, 0.4f)));
|
||||
|
||||
ASSERT_TRUE(vs == Variant("myString"));
|
||||
ASSERT_FALSE(vs == Variant("notMyString"));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VariantTest, ComparisonOperatorArrayVariant)
|
||||
{
|
||||
std::vector<Variant> arr1;
|
||||
arr1.push_back(Variant(123));
|
||||
arr1.push_back(Variant("myString"));
|
||||
|
||||
std::vector<Variant> arr2;
|
||||
arr2.push_back(Variant(123));
|
||||
arr2.push_back(Variant("myString"));
|
||||
|
||||
Variant v1(arr1);
|
||||
Variant v2(arr2);
|
||||
|
||||
ASSERT_TRUE(arr1 == arr2);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VariantTest, TypeInt)
|
||||
{
|
||||
const int val = -123;
|
||||
Variant var(val);
|
||||
ASSERT_EQ(Variant::INT, var.type());
|
||||
ASSERT_TRUE(var.isValid());
|
||||
|
||||
int v = var.getInt();
|
||||
EXPECT_EQ(val, v);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VariantTest, TypeUInt)
|
||||
{
|
||||
const cvf::uint val = 123;
|
||||
Variant var(val);
|
||||
ASSERT_EQ(Variant::UINT, var.type());
|
||||
ASSERT_TRUE(var.isValid());
|
||||
|
||||
cvf::uint v = var.getUInt();
|
||||
EXPECT_EQ(val, v);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VariantTest, TypeDouble)
|
||||
{
|
||||
const double val = 123.1234567;
|
||||
Variant var(val);
|
||||
ASSERT_EQ(Variant::DOUBLE, var.type());
|
||||
ASSERT_TRUE(var.isValid());
|
||||
|
||||
double v = var.getDouble();
|
||||
EXPECT_EQ(val, v);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VariantTest, TypeFloat)
|
||||
{
|
||||
const float val = 123.1234567f;
|
||||
Variant var(val);
|
||||
ASSERT_EQ(Variant::FLOAT, var.type());
|
||||
ASSERT_TRUE(var.isValid());
|
||||
|
||||
float v = var.getFloat();
|
||||
EXPECT_EQ(val, v);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VariantTest, TypeBool)
|
||||
{
|
||||
{
|
||||
const bool val = true;
|
||||
Variant var(val);
|
||||
ASSERT_EQ(Variant::BOOL, var.type());
|
||||
ASSERT_TRUE(var.isValid());
|
||||
|
||||
bool v = var.getBool();
|
||||
EXPECT_EQ(val, v);
|
||||
}
|
||||
|
||||
{
|
||||
const bool val = false;
|
||||
Variant var(val);
|
||||
ASSERT_EQ(Variant::BOOL, var.type());
|
||||
ASSERT_TRUE(var.isValid());
|
||||
|
||||
bool v = var.getBool();
|
||||
EXPECT_EQ(val, v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VariantTest, TypeVec3d)
|
||||
{
|
||||
const Vec3d val(1.0, -2000.1234, 3000.6789);
|
||||
Variant var(val);
|
||||
ASSERT_EQ(Variant::VEC3D, var.type());
|
||||
ASSERT_TRUE(var.isValid());
|
||||
|
||||
Vec3d v = var.getVec3d();
|
||||
ASSERT_EQ(val.x(), v.x());
|
||||
ASSERT_EQ(val.y(), v.y());
|
||||
ASSERT_EQ(val.z(), v.z());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VariantTest, TypeColor3f)
|
||||
{
|
||||
const Color3f val(0.2f, 0.2f, 0.3f);
|
||||
Variant var(val);
|
||||
ASSERT_EQ(Variant::COLOR3F, var.type());
|
||||
ASSERT_TRUE(var.isValid());
|
||||
|
||||
Color3f v = var.getColor3f();
|
||||
ASSERT_EQ(val.r(), v.r());
|
||||
ASSERT_EQ(val.g(), v.g());
|
||||
ASSERT_EQ(val.b(), v.b());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VariantTest, TypeString)
|
||||
{
|
||||
{
|
||||
const String val("ABC");
|
||||
Variant var(val);
|
||||
ASSERT_EQ(Variant::STRING, var.type());
|
||||
ASSERT_TRUE(var.isValid());
|
||||
|
||||
String v = var.getString();
|
||||
ASSERT_EQ(3, v.size());
|
||||
ASSERT_EQ(L'A', v[0]);
|
||||
ASSERT_EQ(L'B', v[1]);
|
||||
ASSERT_EQ(L'C', v[2]);
|
||||
}
|
||||
{
|
||||
const String val("");
|
||||
Variant var(val);
|
||||
ASSERT_EQ(Variant::STRING, var.type());
|
||||
ASSERT_TRUE(var.isValid());
|
||||
|
||||
String v = var.getString();
|
||||
ASSERT_EQ(0, v.size());
|
||||
ASSERT_TRUE(v == "");
|
||||
}
|
||||
{
|
||||
// Wil use the const char* constructor
|
||||
Variant var("abc");
|
||||
ASSERT_EQ(Variant::STRING, var.type());
|
||||
ASSERT_TRUE(var.isValid());
|
||||
|
||||
String v = var.getString();
|
||||
ASSERT_TRUE(v == "abc");
|
||||
}
|
||||
{
|
||||
const String val(static_cast<wchar_t*>(NULL));
|
||||
Variant var(val);
|
||||
ASSERT_EQ(Variant::STRING, var.type());
|
||||
ASSERT_TRUE(var.isValid());
|
||||
|
||||
String v = var.getString();
|
||||
ASSERT_EQ(0, v.size());
|
||||
ASSERT_TRUE(v == "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VariantTest, ArrayPopulatedWithVariants)
|
||||
{
|
||||
std::vector<Variant> arr;
|
||||
arr.push_back(Variant(1));
|
||||
arr.push_back(Variant(1.2));
|
||||
arr.push_back(Variant(Vec3d(1,2,3)));
|
||||
ASSERT_EQ(3, arr.size());
|
||||
|
||||
{
|
||||
Variant var = arr[0];
|
||||
ASSERT_EQ(Variant::INT, var.type());
|
||||
ASSERT_EQ(1, var.getInt());
|
||||
}
|
||||
|
||||
{
|
||||
Variant var = arr[1];
|
||||
ASSERT_EQ(Variant::DOUBLE, var.type());
|
||||
ASSERT_EQ(1.2, var.getDouble());
|
||||
}
|
||||
|
||||
{
|
||||
Variant var = arr[2];
|
||||
ASSERT_EQ(Variant::VEC3D, var.type());
|
||||
ASSERT_TRUE(var.getVec3d() == Vec3d(1,2,3));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VariantTest, VariantContainingAnArray)
|
||||
{
|
||||
std::vector<Variant> orgArr;
|
||||
orgArr.push_back(Variant(1));
|
||||
orgArr.push_back(Variant(1.2));
|
||||
orgArr.push_back(Variant(Vec3d(1,2,3)));
|
||||
ASSERT_EQ(3, orgArr.size());
|
||||
|
||||
Variant varContainingArray(orgArr);
|
||||
ASSERT_EQ(Variant::ARRAY, varContainingArray.type());
|
||||
|
||||
std::vector<Variant> arr = varContainingArray.getArray();
|
||||
ASSERT_EQ(3, arr.size());
|
||||
EXPECT_EQ(1, arr[0].getInt());
|
||||
EXPECT_EQ(1.2, arr[1].getDouble());
|
||||
EXPECT_TRUE(arr[2].getVec3d() == Vec3d(1,2,3));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VariantTest, VariantContainingEmptyArray)
|
||||
{
|
||||
std::vector<Variant> orgArr;
|
||||
|
||||
Variant varContainingArray(orgArr);
|
||||
ASSERT_EQ(Variant::ARRAY, varContainingArray.type());
|
||||
|
||||
std::vector<Variant> arr = varContainingArray.getArray();
|
||||
ASSERT_EQ(0, arr.size());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VariantTest, NestedVariantArrays)
|
||||
{
|
||||
std::vector<Variant> orgArr;
|
||||
|
||||
{
|
||||
std::vector<Variant> orgSubArr;
|
||||
orgSubArr.push_back(Variant(1));
|
||||
orgSubArr.push_back(Variant(1.9));
|
||||
ASSERT_EQ(2, orgSubArr.size());
|
||||
|
||||
Variant varWithArray(orgSubArr);
|
||||
orgArr.push_back(varWithArray);
|
||||
}
|
||||
|
||||
orgArr.push_back(99);
|
||||
|
||||
{
|
||||
std::vector<Variant> orgSubArr;
|
||||
orgSubArr.push_back(Variant(2));
|
||||
orgSubArr.push_back(Variant(2.9));
|
||||
ASSERT_EQ(2, orgSubArr.size());
|
||||
|
||||
orgArr.push_back(orgSubArr);
|
||||
}
|
||||
|
||||
orgArr.push_back(99.99);
|
||||
|
||||
Variant variantContainingArray(orgArr);
|
||||
ASSERT_EQ(Variant::ARRAY, variantContainingArray.type());
|
||||
|
||||
std::vector<Variant> arrayOfVariants = variantContainingArray.getArray();
|
||||
ASSERT_EQ(4, arrayOfVariants.size());
|
||||
ASSERT_EQ(cvf::Variant::ARRAY, arrayOfVariants[0].type());
|
||||
ASSERT_EQ(cvf::Variant::INT, arrayOfVariants[1].type());
|
||||
ASSERT_EQ(cvf::Variant::ARRAY, arrayOfVariants[2].type());
|
||||
ASSERT_EQ(cvf::Variant::DOUBLE, arrayOfVariants[3].type());
|
||||
|
||||
{
|
||||
Variant var = arrayOfVariants[0];
|
||||
std::vector<Variant> arr = var.getArray();
|
||||
ASSERT_EQ(2, arr.size());
|
||||
EXPECT_EQ(1, arr[0].getInt());
|
||||
EXPECT_EQ(1.9, arr[1].getDouble());
|
||||
}
|
||||
|
||||
{
|
||||
Variant var = arrayOfVariants[1];
|
||||
EXPECT_EQ(99, var.getInt());
|
||||
}
|
||||
|
||||
{
|
||||
Variant var = arrayOfVariants[2];
|
||||
std::vector<Variant> arr = var.getArray();
|
||||
ASSERT_EQ(2, arr.size());
|
||||
EXPECT_EQ(2, arr[0].getInt());
|
||||
EXPECT_EQ(2.9, arr[1].getDouble());
|
||||
}
|
||||
|
||||
{
|
||||
Variant var = arrayOfVariants[3];
|
||||
EXPECT_EQ(99.99, var.getDouble());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
736
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfVector2-Test.cpp
Normal file
736
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfVector2-Test.cpp
Normal file
@@ -0,0 +1,736 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfVector2.h"
|
||||
#include "cvfMatrix4.h"
|
||||
#include "cvfString.h" // Used for String vector
|
||||
#include "cvfMath.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, Constants)
|
||||
{
|
||||
EXPECT_FLOAT_EQ(1.0f, Vec2f::X_AXIS.x());
|
||||
EXPECT_FLOAT_EQ(0.0f, Vec2f::X_AXIS.y());
|
||||
|
||||
EXPECT_FLOAT_EQ(0.0f, Vec2f::Y_AXIS.x());
|
||||
EXPECT_FLOAT_EQ(1.0f, Vec2f::Y_AXIS.y());
|
||||
|
||||
EXPECT_FLOAT_EQ(0.0f, Vec2f::ZERO.x());
|
||||
EXPECT_FLOAT_EQ(0.0f, Vec2f::ZERO.y());
|
||||
|
||||
|
||||
EXPECT_DOUBLE_EQ(1.0, Vec2d::X_AXIS.x());
|
||||
EXPECT_DOUBLE_EQ(0.0, Vec2d::X_AXIS.y());
|
||||
|
||||
EXPECT_DOUBLE_EQ(0.0, Vec2d::Y_AXIS.x());
|
||||
EXPECT_DOUBLE_EQ(1.0, Vec2d::Y_AXIS.y());
|
||||
|
||||
EXPECT_DOUBLE_EQ(0.0, Vec2d::ZERO.x());
|
||||
EXPECT_DOUBLE_EQ(0.0, Vec2d::ZERO.y());
|
||||
|
||||
EXPECT_DOUBLE_EQ(UNDEFINED_DOUBLE, Vec2d::UNDEFINED.x());
|
||||
EXPECT_DOUBLE_EQ(UNDEFINED_DOUBLE, Vec2d::UNDEFINED.y());
|
||||
|
||||
EXPECT_FLOAT_EQ(UNDEFINED_FLOAT, Vec2f::UNDEFINED.x());
|
||||
EXPECT_FLOAT_EQ(UNDEFINED_FLOAT, Vec2f::UNDEFINED.y());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, BasicConstruction)
|
||||
{
|
||||
// float
|
||||
Vec2f v;
|
||||
v.set(1.0f, 2.5f);
|
||||
|
||||
ASSERT_FLOAT_EQ(1.0f, v.x());
|
||||
ASSERT_FLOAT_EQ(2.5f, v.y());
|
||||
|
||||
Vec2f v2;
|
||||
v2.setZero();
|
||||
|
||||
ASSERT_FLOAT_EQ(0.0f, v2.x());
|
||||
ASSERT_FLOAT_EQ(0.0f, v2.y());
|
||||
|
||||
ASSERT_TRUE(v2.isZero());
|
||||
ASSERT_FALSE(v.isZero());
|
||||
|
||||
// double
|
||||
Vec2d d;
|
||||
d.set(1.0, 2.5);
|
||||
|
||||
ASSERT_DOUBLE_EQ(1.0, d.x());
|
||||
ASSERT_DOUBLE_EQ(2.5, d.y());
|
||||
|
||||
Vec2f d2;
|
||||
d2.setZero();
|
||||
|
||||
ASSERT_DOUBLE_EQ(0.0, d2.x());
|
||||
ASSERT_DOUBLE_EQ(0.0, d2.y());
|
||||
|
||||
ASSERT_TRUE(d2.isZero());
|
||||
ASSERT_FALSE(d.isZero());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, ConstructionFromScalars)
|
||||
{
|
||||
float data[] = {1.0f, 2.2f};
|
||||
|
||||
Vec2f vf = Vec2f(data[0], data[1]);
|
||||
|
||||
EXPECT_EQ(1.0f, vf[0]);
|
||||
EXPECT_EQ(2.2f, vf[1]);
|
||||
|
||||
double datad[] = {1.0, 2.2};
|
||||
|
||||
Vec2d vd = Vec2d(datad[0], datad[1]);
|
||||
|
||||
EXPECT_EQ(1.0, vd[0]);
|
||||
EXPECT_EQ(2.2, vd[1]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, CopyConstructor)
|
||||
{
|
||||
// float
|
||||
Vec2f v1(1.0f, 2.5f);
|
||||
Vec2f v2(v1);
|
||||
Vec2f v3 = v1;
|
||||
Vec2f v4;
|
||||
v4 = v1;
|
||||
|
||||
ASSERT_FLOAT_EQ(1.0f, v1.x());
|
||||
ASSERT_FLOAT_EQ(2.5f, v1.y());
|
||||
ASSERT_FLOAT_EQ(1.0f, v2.x());
|
||||
ASSERT_FLOAT_EQ(2.5f, v2.y());
|
||||
ASSERT_FLOAT_EQ(1.0f, v3.x());
|
||||
ASSERT_FLOAT_EQ(2.5f, v3.y());
|
||||
ASSERT_FLOAT_EQ(1.0f, v4.x());
|
||||
ASSERT_FLOAT_EQ(2.5f, v4.y());
|
||||
|
||||
// double
|
||||
Vec2d d1(1.0, 2.5);
|
||||
Vec2d d2(d1);
|
||||
Vec2d d3 = d1;
|
||||
Vec2d d4;
|
||||
d4 = d1;
|
||||
|
||||
ASSERT_DOUBLE_EQ(1.0, d1.x());
|
||||
ASSERT_DOUBLE_EQ(2.5, d1.y());
|
||||
ASSERT_DOUBLE_EQ(1.0, d2.x());
|
||||
ASSERT_DOUBLE_EQ(2.5, d2.y());
|
||||
ASSERT_DOUBLE_EQ(1.0, d3.x());
|
||||
ASSERT_DOUBLE_EQ(2.5, d3.y());
|
||||
ASSERT_DOUBLE_EQ(1.0, d4.x());
|
||||
ASSERT_DOUBLE_EQ(2.5, d4.y());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, AssignMemebers)
|
||||
{
|
||||
// float
|
||||
Vec2f vf;
|
||||
|
||||
vf.x() = 1.0f + 2.5f*3.0f;
|
||||
vf.y() = 2.0f - 2.5f*3.0f;
|
||||
|
||||
ASSERT_FLOAT_EQ(8.5f, vf.x());
|
||||
ASSERT_FLOAT_EQ(-5.5f, vf.y());
|
||||
|
||||
vf.x() = 0.0f;
|
||||
vf.y() = 0.0f;
|
||||
ASSERT_TRUE(vf.isZero());
|
||||
|
||||
vf.y() = 0.1f;
|
||||
ASSERT_FALSE(vf.isZero());
|
||||
|
||||
// double
|
||||
Vec2d vd;
|
||||
|
||||
vd.x() = 1.0 + 2.5*3.0;
|
||||
vd.y() = 2.0 - 2.5*3.0;
|
||||
|
||||
ASSERT_DOUBLE_EQ(8.5, vd.x());
|
||||
ASSERT_DOUBLE_EQ(-5.5, vd.y());
|
||||
|
||||
vd.x() = 0.0;
|
||||
vd.y() = 0.0;
|
||||
ASSERT_TRUE(vd.isZero());
|
||||
|
||||
vd.y() = 0.1;
|
||||
ASSERT_FALSE(vd.isZero());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, IndexOperator)
|
||||
{
|
||||
Vec2d v;
|
||||
v[0] = 1.0;
|
||||
v[1] = 2.0;
|
||||
EXPECT_EQ(1.0, v[0]);
|
||||
EXPECT_EQ(2.0, v[1]);
|
||||
|
||||
Vec2f vf;
|
||||
vf[0] = 1.0f;
|
||||
vf[1] = 2.0f;
|
||||
EXPECT_EQ(1.0f, vf[0]);
|
||||
EXPECT_EQ(2.0f, vf[1]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#ifdef _DEBUG
|
||||
TEST(Vector2DeathTest, IndexOperator)
|
||||
{
|
||||
Vec2d v;
|
||||
|
||||
EXPECT_DEATH(v[-1], "Assertion");
|
||||
EXPECT_DEATH(v[2], "Assertion");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, Conversion)
|
||||
{
|
||||
Vec2f vf1(1.0f, 2.0f);
|
||||
Vec2d vd1(vf1);
|
||||
Vec2f vf2(4.0f, 5.0f);
|
||||
Vec2d vd2;
|
||||
vd2.set(vf2);
|
||||
|
||||
ASSERT_FLOAT_EQ(1.0, vf1.x());
|
||||
ASSERT_FLOAT_EQ(2.0, vf1.y());
|
||||
ASSERT_DOUBLE_EQ(1.0, vd1.x());
|
||||
ASSERT_DOUBLE_EQ(2.0, vd1.y());
|
||||
|
||||
ASSERT_FLOAT_EQ(4.0, vf2.x());
|
||||
ASSERT_FLOAT_EQ(5.0, vf2.y());
|
||||
ASSERT_DOUBLE_EQ(4.0, vd2.x());
|
||||
ASSERT_DOUBLE_EQ(5.0, vd2.y());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, DataAccess)
|
||||
{
|
||||
Vec2f vf(1.0f, 2.5f);
|
||||
Vec2d vd(4, 5.5);
|
||||
|
||||
float* pfData = vf.ptr();
|
||||
double* pdData = vd.ptr();
|
||||
|
||||
ASSERT_EQ(1.0f, pfData[0]);
|
||||
ASSERT_EQ(2.5f, pfData[1]);
|
||||
ASSERT_EQ(vf.x(), pfData[0]);
|
||||
ASSERT_EQ(vf.y(), pfData[1]);
|
||||
|
||||
ASSERT_EQ(4.0, pdData[0]);
|
||||
ASSERT_EQ(5.5, pdData[1]);
|
||||
ASSERT_EQ(vf.x(), pfData[0]);
|
||||
ASSERT_EQ(vf.y(), pfData[1]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, Length)
|
||||
{
|
||||
Vec2f vf(1.0f, 2.0f);
|
||||
Vec2d vd(4, 5);
|
||||
Vec2d vzero(0, 0);
|
||||
|
||||
ASSERT_FLOAT_EQ(2.23606798f, vf.length());
|
||||
ASSERT_DOUBLE_EQ(6.4031242374328485, vd.length());
|
||||
ASSERT_DOUBLE_EQ(0.0, vzero.length());
|
||||
|
||||
ASSERT_FLOAT_EQ(5.0f, vf.lengthSquared());
|
||||
ASSERT_DOUBLE_EQ(41.0, vd.lengthSquared());
|
||||
ASSERT_DOUBLE_EQ(0.0, vzero.lengthSquared());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, LengthOfConstants)
|
||||
{
|
||||
const Vec2d vx = Vec2d::X_AXIS;
|
||||
const Vec2d vy = Vec2d::Y_AXIS;
|
||||
ASSERT_DOUBLE_EQ(1, vx.length());
|
||||
ASSERT_DOUBLE_EQ(1, vy.length());
|
||||
|
||||
const Vec2d vxneg = -vx;
|
||||
const Vec2d vyneg = -vy;
|
||||
ASSERT_DOUBLE_EQ(1, vxneg.length());
|
||||
ASSERT_DOUBLE_EQ(1, vyneg.length());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, SetLength)
|
||||
{
|
||||
Vec2d vx = Vec2d::X_AXIS;
|
||||
vx.setLength(10);
|
||||
ASSERT_DOUBLE_EQ(10, vx.length());
|
||||
|
||||
Vec2d vy = Vec2d::Y_AXIS;
|
||||
vy.setLength(20);
|
||||
ASSERT_DOUBLE_EQ(20, vy.length());
|
||||
|
||||
|
||||
Vec2d v0(0, 0);
|
||||
ASSERT_FALSE(v0.setLength(2));
|
||||
ASSERT_DOUBLE_EQ(0, v0.length());
|
||||
|
||||
Vec2d v1(1, 1);
|
||||
ASSERT_TRUE(v1.setLength(0));
|
||||
ASSERT_DOUBLE_EQ(0, v1.length());
|
||||
|
||||
Vec2d v2(1, 1);
|
||||
ASSERT_TRUE(v2.setLength(12));
|
||||
ASSERT_DOUBLE_EQ(12, v2.length());
|
||||
|
||||
Vec2d v3(4, -5);
|
||||
ASSERT_TRUE(v3.setLength(33));
|
||||
ASSERT_DOUBLE_EQ(33, v3.length());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, Addition)
|
||||
{
|
||||
Vec2f f1(1.0f, 2.6f);
|
||||
Vec2f f2(4.0f, 5.2f);
|
||||
Vec2f fa = f1 + f2;
|
||||
|
||||
ASSERT_FLOAT_EQ(5.0f, fa.x());
|
||||
ASSERT_FLOAT_EQ(7.8f, fa.y());
|
||||
|
||||
fa += f1;
|
||||
|
||||
ASSERT_FLOAT_EQ(6.0f, fa.x());
|
||||
ASSERT_FLOAT_EQ(10.4f, fa.y());
|
||||
|
||||
fa.add(f2);
|
||||
|
||||
ASSERT_FLOAT_EQ(10.0f, fa.x());
|
||||
ASSERT_FLOAT_EQ(15.6f, fa.y());
|
||||
|
||||
// double
|
||||
Vec2d d1(1.0, 2.6);
|
||||
Vec2d d2(4, 5.2);
|
||||
Vec2d da = d1 + d2;
|
||||
|
||||
ASSERT_DOUBLE_EQ(5.0, da.x());
|
||||
ASSERT_DOUBLE_EQ(7.8, da.y());
|
||||
|
||||
da += d1;
|
||||
|
||||
ASSERT_DOUBLE_EQ(6.0, da.x());
|
||||
ASSERT_DOUBLE_EQ(10.4, da.y());
|
||||
|
||||
da.add(d2);
|
||||
|
||||
ASSERT_DOUBLE_EQ(10.0, da.x());
|
||||
ASSERT_DOUBLE_EQ(15.6, da.y());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, Subtraction)
|
||||
{
|
||||
Vec2f f1(1.0f, 2.6f);
|
||||
Vec2f f2(4.0f,5.2f);
|
||||
Vec2f fa = f1 - f2;
|
||||
|
||||
ASSERT_FLOAT_EQ(-3.0f, fa.x());
|
||||
ASSERT_FLOAT_EQ(-2.6f, fa.y());
|
||||
|
||||
fa -= f1;
|
||||
|
||||
ASSERT_FLOAT_EQ(-4.0f, fa.x());
|
||||
ASSERT_FLOAT_EQ(-5.2f, fa.y());
|
||||
|
||||
fa.subtract(f2);
|
||||
|
||||
ASSERT_FLOAT_EQ(-8.0f, fa.x());
|
||||
ASSERT_FLOAT_EQ(-10.4f, fa.y());
|
||||
|
||||
// double
|
||||
Vec2d d1(1.0, 2.6);
|
||||
Vec2d d2(4, 5.2);
|
||||
Vec2d da = d1 - d2;
|
||||
|
||||
ASSERT_DOUBLE_EQ(-3.0, da.x());
|
||||
ASSERT_DOUBLE_EQ(-2.6, da.y());
|
||||
|
||||
da -= d1;
|
||||
|
||||
ASSERT_DOUBLE_EQ(-4.0, da.x());
|
||||
ASSERT_DOUBLE_EQ(-5.2, da.y());
|
||||
|
||||
da.subtract(d2);
|
||||
|
||||
ASSERT_DOUBLE_EQ(-8.0, da.x());
|
||||
ASSERT_DOUBLE_EQ(-10.4, da.y());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, Scale)
|
||||
{
|
||||
Vec2d d2(1.0,2.0);
|
||||
|
||||
d2.scale(2.3);
|
||||
ASSERT_DOUBLE_EQ(2.3, d2.x());
|
||||
ASSERT_DOUBLE_EQ(4.6, d2.y());
|
||||
|
||||
d2.scale(0.0);
|
||||
ASSERT_TRUE(d2.isZero());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, Multiply)
|
||||
{
|
||||
// float
|
||||
Vec2f f1(1.0f, 2.0f);
|
||||
|
||||
Vec2f f2 = f1*2.3f;
|
||||
ASSERT_FLOAT_EQ(2.3f, f2.x());
|
||||
ASSERT_FLOAT_EQ(4.6f, f2.y());
|
||||
|
||||
f2 = 2.3f*f1;
|
||||
ASSERT_FLOAT_EQ(2.3f, f2.x());
|
||||
ASSERT_FLOAT_EQ(4.6f, f2.y());
|
||||
|
||||
f2 *= 3.5f;
|
||||
ASSERT_FLOAT_EQ(8.05f, f2.x());
|
||||
ASSERT_FLOAT_EQ(16.1f, f2.y());
|
||||
|
||||
f2 *= 0.0f;
|
||||
ASSERT_TRUE(f2.isZero());
|
||||
|
||||
// double
|
||||
Vec2d d1(1.0, 2.0);
|
||||
|
||||
Vec2d d2 = d1*2.3;
|
||||
ASSERT_DOUBLE_EQ(2.3, d2.x());
|
||||
ASSERT_DOUBLE_EQ(4.6, d2.y());
|
||||
|
||||
d2 = 2.3*d1;
|
||||
ASSERT_DOUBLE_EQ(2.3, d2.x());
|
||||
ASSERT_DOUBLE_EQ(4.6, d2.y());
|
||||
|
||||
d2 *= 3.5;
|
||||
ASSERT_DOUBLE_EQ(8.05, d2.x());
|
||||
ASSERT_DOUBLE_EQ(16.1, d2.y());
|
||||
|
||||
d2 *= 0.0;
|
||||
ASSERT_TRUE(d2.isZero());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, Divide)
|
||||
{
|
||||
// float
|
||||
Vec2f f1(1.0f, 2.0f);
|
||||
Vec2f f2 = f1*2.3f;
|
||||
ASSERT_FLOAT_EQ(2.3f, f2.x());
|
||||
ASSERT_FLOAT_EQ(4.6f, f2.y());
|
||||
|
||||
f2 *= 3.5f;
|
||||
ASSERT_FLOAT_EQ(8.05f, f2.x());
|
||||
ASSERT_FLOAT_EQ(16.1f, f2.y());
|
||||
|
||||
// double
|
||||
Vec2d d1(1.0, 2.0);
|
||||
Vec2d d2 = d1*2.3;
|
||||
ASSERT_DOUBLE_EQ(2.3, d2.x());
|
||||
ASSERT_DOUBLE_EQ(4.6, d2.y());
|
||||
|
||||
d2 *= 3.5;
|
||||
ASSERT_DOUBLE_EQ(8.05, d2.x());
|
||||
ASSERT_DOUBLE_EQ(16.1, d2.y());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, Negate)
|
||||
{
|
||||
Vec2f f(1.0f, -2.0f);
|
||||
Vec2f fn = -f;
|
||||
ASSERT_FLOAT_EQ(-1.0f, fn.x());
|
||||
ASSERT_FLOAT_EQ( 2.0f, fn.y());
|
||||
|
||||
Vec2d d(1.0, -2.0);
|
||||
Vec2d dn = -d;
|
||||
ASSERT_DOUBLE_EQ(-1.0, dn.x());
|
||||
ASSERT_DOUBLE_EQ( 2.0, dn.y());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, DotProduct)
|
||||
{
|
||||
// float
|
||||
Vec2f f1(1.0f, 2.0f);
|
||||
Vec2f f2(5, 3.2f);
|
||||
|
||||
float fdot1 = f1*f2;
|
||||
ASSERT_FLOAT_EQ(11.4f, fdot1);
|
||||
|
||||
float fdot2 = f2.dot(f1);
|
||||
ASSERT_FLOAT_EQ(11.4f, fdot2);
|
||||
|
||||
// Double
|
||||
Vec2d d1(1.0, 2.0);
|
||||
Vec2d d2(5, 3.2);
|
||||
|
||||
double ddot1 = d1*d2;
|
||||
ASSERT_DOUBLE_EQ(11.4, ddot1);
|
||||
|
||||
double ddot2 = d2.dot(d1);
|
||||
ASSERT_DOUBLE_EQ(11.4, ddot2);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, Normalize)
|
||||
{
|
||||
// float
|
||||
Vec2f vf(1.5f, 2.5f);
|
||||
Vec2f vfz(0.0f, 0.0f);
|
||||
|
||||
ASSERT_TRUE(vf.normalize());
|
||||
ASSERT_FALSE(vfz.normalize());
|
||||
|
||||
ASSERT_FLOAT_EQ(1.0f, vf.length());
|
||||
ASSERT_FLOAT_EQ(0.0f, vfz.length());
|
||||
|
||||
// double
|
||||
Vec2d vd(1.5, 2.5);
|
||||
Vec2d vdz(0.0, 0.0);
|
||||
|
||||
ASSERT_TRUE(vd.normalize());
|
||||
ASSERT_FALSE(vdz.normalize());
|
||||
|
||||
ASSERT_DOUBLE_EQ(1.0, vd.length());
|
||||
ASSERT_DOUBLE_EQ(0.0, vdz.length());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, GetNormalized)
|
||||
{
|
||||
{
|
||||
const Vec2f v(1.5f, 2.5f);
|
||||
const Vec2f vz(0.0f, 0.0f);
|
||||
|
||||
Vec2f n1 = v.getNormalized();
|
||||
ASSERT_FLOAT_EQ(1.0f, n1.length());
|
||||
|
||||
bool normOK = false;
|
||||
Vec2f n2 = v.getNormalized(&normOK);
|
||||
ASSERT_TRUE(normOK);
|
||||
ASSERT_FLOAT_EQ(1.0f, n2.length());
|
||||
|
||||
Vec2f nz = vz.getNormalized(&normOK);
|
||||
ASSERT_FALSE(normOK);
|
||||
ASSERT_FLOAT_EQ(0.0f, nz.length());
|
||||
}
|
||||
|
||||
{
|
||||
const Vec2d v(1.5, 2.5);
|
||||
const Vec2d vz(0.0, 0.0);
|
||||
|
||||
Vec2d n1 = v.getNormalized();
|
||||
ASSERT_DOUBLE_EQ(1.0, n1.length());
|
||||
|
||||
bool normOK = false;
|
||||
Vec2d n2 = v.getNormalized(&normOK);
|
||||
ASSERT_TRUE(normOK);
|
||||
ASSERT_DOUBLE_EQ(1.0, n2.length());
|
||||
|
||||
Vec2d nz = vz.getNormalized(&normOK);
|
||||
ASSERT_FALSE(normOK);
|
||||
ASSERT_DOUBLE_EQ(0.0, nz.length());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, Comparison)
|
||||
{
|
||||
// float
|
||||
Vec2f f1(1,3);
|
||||
Vec2f f2(1,3);
|
||||
Vec2f f3(1,3.1f);
|
||||
|
||||
ASSERT_TRUE(f1.equals(f2));
|
||||
ASSERT_TRUE(f1 == f2);
|
||||
ASSERT_FALSE(f1 != f2);
|
||||
ASSERT_FALSE(f1 == f3);
|
||||
ASSERT_TRUE(f1 != f3);
|
||||
|
||||
// double
|
||||
Vec2d d1(1,3);
|
||||
Vec2d d2(1,3);
|
||||
Vec2d d3(1,3.1f);
|
||||
|
||||
ASSERT_TRUE(d1.equals(d2));
|
||||
ASSERT_TRUE(d1 == d2);
|
||||
ASSERT_FALSE(d1 != d2);
|
||||
ASSERT_FALSE(d1 == d3);
|
||||
ASSERT_TRUE(d1 != d3);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, OtherDataTypes)
|
||||
{
|
||||
Vec2i iVec(1,2);
|
||||
Vec2i iVec2(5,6);
|
||||
Vec2i iVec3 = iVec + iVec2;
|
||||
|
||||
ASSERT_EQ(6, iVec3.x());
|
||||
ASSERT_EQ(8, iVec3.y());
|
||||
ASSERT_EQ(100, iVec3.lengthSquared());
|
||||
|
||||
|
||||
typedef Vector2<String> Vec2s;
|
||||
|
||||
Vec2s s1("Yes", "No");
|
||||
Vec2s s2("Ja", "Nei");
|
||||
Vec2s s3 = s1 + s2;
|
||||
|
||||
ASSERT_TRUE(s3.x() == "YesJa");
|
||||
ASSERT_TRUE(s3.y() == "NoNei");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector2Test, IsUndefined)
|
||||
{
|
||||
{
|
||||
Vec2f v = Vec2f::UNDEFINED;
|
||||
EXPECT_TRUE(v.isUndefined());
|
||||
|
||||
v.x() = 0;
|
||||
EXPECT_TRUE(v.isUndefined());
|
||||
|
||||
v.y() = 0;
|
||||
EXPECT_FALSE(v.isUndefined());
|
||||
|
||||
v.x() = UNDEFINED_FLOAT;
|
||||
EXPECT_TRUE(v.isUndefined());
|
||||
}
|
||||
|
||||
{
|
||||
Vec2d v = Vec2d::UNDEFINED;
|
||||
EXPECT_TRUE(v.isUndefined());
|
||||
|
||||
v.x() = 0;
|
||||
EXPECT_TRUE(v.isUndefined());
|
||||
|
||||
v.y() = 0;
|
||||
EXPECT_FALSE(v.isUndefined());
|
||||
|
||||
v.x() = UNDEFINED_DOUBLE;
|
||||
EXPECT_TRUE(v.isUndefined());
|
||||
}
|
||||
}
|
||||
|
||||
1248
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfVector3-Test.cpp
Normal file
1248
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfVector3-Test.cpp
Normal file
File diff suppressed because it is too large
Load Diff
796
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfVector4-Test.cpp
Normal file
796
Fwk/VizFwk/Tests/LibCore_UnitTests/cvfVector4-Test.cpp
Normal file
@@ -0,0 +1,796 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfVector4.h"
|
||||
#include "cvfMatrix4.h"
|
||||
#include "cvfString.h" // Used for String vector test
|
||||
#include "cvfMath.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, Constants)
|
||||
{
|
||||
ASSERT_FLOAT_EQ(0.0f, Vec4f::ZERO.x());
|
||||
ASSERT_FLOAT_EQ(0.0f, Vec4f::ZERO.y());
|
||||
ASSERT_FLOAT_EQ(0.0f, Vec4f::ZERO.z());
|
||||
|
||||
ASSERT_DOUBLE_EQ(0.0, Vec4d::ZERO.x());
|
||||
ASSERT_DOUBLE_EQ(0.0, Vec4d::ZERO.y());
|
||||
ASSERT_DOUBLE_EQ(0.0, Vec4d::ZERO.z());
|
||||
|
||||
EXPECT_DOUBLE_EQ(UNDEFINED_DOUBLE, Vec4d::UNDEFINED.x());
|
||||
EXPECT_DOUBLE_EQ(UNDEFINED_DOUBLE, Vec4d::UNDEFINED.y());
|
||||
EXPECT_DOUBLE_EQ(UNDEFINED_DOUBLE, Vec4d::UNDEFINED.z());
|
||||
EXPECT_DOUBLE_EQ(UNDEFINED_DOUBLE, Vec4d::UNDEFINED.w());
|
||||
|
||||
EXPECT_FLOAT_EQ(UNDEFINED_FLOAT, Vec4f::UNDEFINED.x());
|
||||
EXPECT_FLOAT_EQ(UNDEFINED_FLOAT, Vec4f::UNDEFINED.y());
|
||||
EXPECT_FLOAT_EQ(UNDEFINED_FLOAT, Vec4f::UNDEFINED.z());
|
||||
EXPECT_FLOAT_EQ(UNDEFINED_FLOAT, Vec4f::UNDEFINED.w());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, BasicConstruction)
|
||||
{
|
||||
// float
|
||||
Vec4f v;
|
||||
v.set(1.0f, 2.5f, 3.0f, 4.0f);
|
||||
|
||||
ASSERT_FLOAT_EQ(1.0f, v.x());
|
||||
ASSERT_FLOAT_EQ(2.5f, v.y());
|
||||
ASSERT_FLOAT_EQ(3.0f, v.z());
|
||||
ASSERT_FLOAT_EQ(4.0f, v.w());
|
||||
|
||||
Vec4f v2;
|
||||
v2.setZero();
|
||||
|
||||
ASSERT_FLOAT_EQ(0.0f, v2.x());
|
||||
ASSERT_FLOAT_EQ(0.0f, v2.y());
|
||||
ASSERT_FLOAT_EQ(0.0f, v2.z());
|
||||
ASSERT_FLOAT_EQ(0.0f, v2.w());
|
||||
|
||||
ASSERT_TRUE(v2.isZero());
|
||||
ASSERT_FALSE(v.isZero());
|
||||
|
||||
// double
|
||||
Vec4d d;
|
||||
d.set(1.0, 2.5, 3.0, 4.0);
|
||||
|
||||
ASSERT_DOUBLE_EQ(1.0, d.x());
|
||||
ASSERT_DOUBLE_EQ(2.5, d.y());
|
||||
ASSERT_DOUBLE_EQ(3.0, d.z());
|
||||
ASSERT_DOUBLE_EQ(4.0, d.w());
|
||||
|
||||
Vec4f d2;
|
||||
d2.setZero();
|
||||
|
||||
ASSERT_DOUBLE_EQ(0.0, d2.x());
|
||||
ASSERT_DOUBLE_EQ(0.0, d2.y());
|
||||
ASSERT_DOUBLE_EQ(0.0, d2.z());
|
||||
ASSERT_DOUBLE_EQ(0.0, d2.w());
|
||||
|
||||
ASSERT_TRUE(d2.isZero());
|
||||
ASSERT_FALSE(d.isZero());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, CopyConstructor)
|
||||
{
|
||||
// float
|
||||
Vec4f v1(1.0f, 2.5f, 3.0f, 4.0f);
|
||||
Vec4f v2(v1);
|
||||
Vec4f v3 = v1;
|
||||
Vec4f v4;
|
||||
v4 = v1;
|
||||
|
||||
ASSERT_FLOAT_EQ(1.0f, v1.x());
|
||||
ASSERT_FLOAT_EQ(2.5f, v1.y());
|
||||
ASSERT_FLOAT_EQ(3.0f, v1.z());
|
||||
ASSERT_FLOAT_EQ(4.0f, v1.w());
|
||||
ASSERT_FLOAT_EQ(1.0f, v2.x());
|
||||
ASSERT_FLOAT_EQ(2.5f, v2.y());
|
||||
ASSERT_FLOAT_EQ(3.0f, v2.z());
|
||||
ASSERT_FLOAT_EQ(4.0f, v2.w());
|
||||
ASSERT_FLOAT_EQ(1.0f, v3.x());
|
||||
ASSERT_FLOAT_EQ(2.5f, v3.y());
|
||||
ASSERT_FLOAT_EQ(3.0f, v3.z());
|
||||
ASSERT_FLOAT_EQ(4.0f, v3.w());
|
||||
ASSERT_FLOAT_EQ(1.0f, v4.x());
|
||||
ASSERT_FLOAT_EQ(2.5f, v4.y());
|
||||
ASSERT_FLOAT_EQ(3.0f, v4.z());
|
||||
ASSERT_FLOAT_EQ(4.0f, v4.w());
|
||||
|
||||
// double
|
||||
Vec4d d1(1.0, 2.5, 3.0, 4.0);
|
||||
Vec4d d2(d1);
|
||||
Vec4d d3 = d1;
|
||||
Vec4d d4;
|
||||
d4 = d1;
|
||||
|
||||
ASSERT_DOUBLE_EQ(1.0, d1.x());
|
||||
ASSERT_DOUBLE_EQ(2.5, d1.y());
|
||||
ASSERT_DOUBLE_EQ(3.0, d1.z());
|
||||
ASSERT_DOUBLE_EQ(4.0, d1.w());
|
||||
ASSERT_DOUBLE_EQ(1.0, d2.x());
|
||||
ASSERT_DOUBLE_EQ(2.5, d2.y());
|
||||
ASSERT_DOUBLE_EQ(3.0, d2.z());
|
||||
ASSERT_DOUBLE_EQ(4.0, d2.w());
|
||||
ASSERT_DOUBLE_EQ(1.0, d3.x());
|
||||
ASSERT_DOUBLE_EQ(2.5, d3.y());
|
||||
ASSERT_DOUBLE_EQ(3.0, d3.z());
|
||||
ASSERT_DOUBLE_EQ(4.0, d3.w());
|
||||
ASSERT_DOUBLE_EQ(1.0, d4.x());
|
||||
ASSERT_DOUBLE_EQ(2.5, d4.y());
|
||||
ASSERT_DOUBLE_EQ(3.0, d4.z());
|
||||
ASSERT_DOUBLE_EQ(4.0, d4.w());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, ConstructionFromScalars)
|
||||
{
|
||||
float data[] = {1.0f,2.2f,3.0f,4.0f};
|
||||
|
||||
Vec4f vf = Vec4f(data[0], data[1], data[2], data[3]);
|
||||
|
||||
EXPECT_EQ(1.0f, vf[0]);
|
||||
EXPECT_EQ(2.2f, vf[1]);
|
||||
EXPECT_EQ(3.0f, vf[2]);
|
||||
EXPECT_EQ(4.0f, vf[3]);
|
||||
|
||||
double datad[] = {1.0,2.2,3.0,4.0};
|
||||
|
||||
Vec4d vd = Vec4d(datad[0], datad[1], datad[2], datad[3]);
|
||||
|
||||
EXPECT_EQ(1.0, vd[0]);
|
||||
EXPECT_EQ(2.2, vd[1]);
|
||||
EXPECT_EQ(3.0, vd[2]);
|
||||
EXPECT_EQ(4.0, vd[3]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, AssignMemebers)
|
||||
{
|
||||
// float
|
||||
Vec4f vf;
|
||||
|
||||
vf.x() = 1.0f + 2.5f*3.0f;
|
||||
vf.y() = 2.0f - 2.5f*3.0f;
|
||||
vf.z() = 3.0f + 2.5f*2.0f;
|
||||
|
||||
ASSERT_FLOAT_EQ(8.5f, vf.x());
|
||||
ASSERT_FLOAT_EQ(-5.5f, vf.y());
|
||||
ASSERT_FLOAT_EQ(8.0f, vf.z());
|
||||
|
||||
vf.x() = 0.0f;
|
||||
vf.y() = 0.0f;
|
||||
vf.z() = 0.0f;
|
||||
ASSERT_TRUE(vf.isZero());
|
||||
|
||||
vf.y() = 0.1f;
|
||||
ASSERT_FALSE(vf.isZero());
|
||||
|
||||
// double
|
||||
Vec4d vd;
|
||||
|
||||
vd.x() = 1.0 + 2.5*3.0;
|
||||
vd.y() = 2.0 - 2.5*3.0;
|
||||
vd.z() = 3.0 + 2.5*2.0;
|
||||
|
||||
ASSERT_DOUBLE_EQ(8.5, vd.x());
|
||||
ASSERT_DOUBLE_EQ(-5.5, vd.y());
|
||||
ASSERT_DOUBLE_EQ(8.0, vd.z());
|
||||
|
||||
vd.x() = 0.0;
|
||||
vd.y() = 0.0;
|
||||
vd.z() = 0.0;
|
||||
ASSERT_TRUE(vd.isZero());
|
||||
|
||||
vd.y() = 0.1;
|
||||
ASSERT_FALSE(vd.isZero());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, IndexOperator)
|
||||
{
|
||||
Vec4d v;
|
||||
|
||||
v[0] = 1.0;
|
||||
v[1] = 2.0;
|
||||
v[2] = 3.0;
|
||||
v[3] = 4.0;
|
||||
|
||||
EXPECT_EQ(1.0, v[0]);
|
||||
EXPECT_EQ(2.0, v[1]);
|
||||
EXPECT_EQ(3.0, v[2]);
|
||||
EXPECT_EQ(4.0, v[3]);
|
||||
|
||||
Vec4f vf;
|
||||
|
||||
vf[0] = 1.0f;
|
||||
vf[1] = 2.0f;
|
||||
vf[2] = 3.0f;
|
||||
vf[3] = 4.0f;
|
||||
|
||||
EXPECT_EQ(1.0f, vf[0]);
|
||||
EXPECT_EQ(2.0f, vf[1]);
|
||||
EXPECT_EQ(3.0f, vf[2]);
|
||||
EXPECT_EQ(4.0f, vf[3]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#ifdef _DEBUG
|
||||
TEST(Vector4DeathTest, IndexOperator)
|
||||
{
|
||||
Vec3d v;
|
||||
|
||||
EXPECT_DEATH(v[-1], "Assertion");
|
||||
EXPECT_DEATH(v[3], "Assertion");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, Conversion)
|
||||
{
|
||||
Vec4f vf1(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
Vec4d vd1(vf1);
|
||||
Vec4f vf2(4.0f, 5.0f, 6.0f, 7.0f);
|
||||
Vec4d vd2;
|
||||
vd2.set(vf2);
|
||||
|
||||
ASSERT_FLOAT_EQ(1.0, vf1.x());
|
||||
ASSERT_FLOAT_EQ(2.0, vf1.y());
|
||||
ASSERT_FLOAT_EQ(3.0, vf1.z());
|
||||
ASSERT_FLOAT_EQ(4.0, vf1.w());
|
||||
ASSERT_DOUBLE_EQ(1.0, vd1.x());
|
||||
ASSERT_DOUBLE_EQ(2.0, vd1.y());
|
||||
ASSERT_DOUBLE_EQ(3.0, vd1.z());
|
||||
ASSERT_DOUBLE_EQ(4.0, vd1.w());
|
||||
|
||||
ASSERT_FLOAT_EQ(4.0, vf2.x());
|
||||
ASSERT_FLOAT_EQ(5.0, vf2.y());
|
||||
ASSERT_FLOAT_EQ(6.0, vf2.z());
|
||||
ASSERT_DOUBLE_EQ(4.0, vd2.x());
|
||||
ASSERT_DOUBLE_EQ(5.0, vd2.y());
|
||||
ASSERT_DOUBLE_EQ(6.0, vd2.z());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, ConversionFromVector3)
|
||||
{
|
||||
Vec3d vec3(1, 2, 3);
|
||||
|
||||
Vec4d v(vec3, 9.0);
|
||||
EXPECT_DOUBLE_EQ(1.0, v.x());
|
||||
EXPECT_DOUBLE_EQ(2.0, v.y());
|
||||
EXPECT_DOUBLE_EQ(3.0, v.z());
|
||||
EXPECT_DOUBLE_EQ(9.0, v.w());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, DataAccess)
|
||||
{
|
||||
Vec4f vf(1.0f, 2.5f, 3.0f, 4.0f);
|
||||
Vec4d vd(4,5.5,6,7);
|
||||
|
||||
float* pfData = vf.ptr();
|
||||
double* pdData = vd.ptr();
|
||||
|
||||
ASSERT_EQ(1.0f, pfData[0]);
|
||||
ASSERT_EQ(2.5f, pfData[1]);
|
||||
ASSERT_EQ(3.0f, pfData[2]);
|
||||
ASSERT_EQ(4.0f, pfData[3]);
|
||||
ASSERT_EQ(vf.x(), pfData[0]);
|
||||
ASSERT_EQ(vf.y(), pfData[1]);
|
||||
ASSERT_EQ(vf.z(), pfData[2]);
|
||||
ASSERT_EQ(vf.w(), pfData[3]);
|
||||
|
||||
ASSERT_EQ(4.0, pdData[0]);
|
||||
ASSERT_EQ(5.5, pdData[1]);
|
||||
ASSERT_EQ(6.0, pdData[2]);
|
||||
ASSERT_EQ(7.0, pdData[3]);
|
||||
ASSERT_EQ(vf.x(), pfData[0]);
|
||||
ASSERT_EQ(vf.y(), pfData[1]);
|
||||
ASSERT_EQ(vf.z(), pfData[2]);
|
||||
ASSERT_EQ(vf.w(), pfData[3]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, Length)
|
||||
{
|
||||
Vec4f vf(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
Vec4d vd(4,5,6,7);
|
||||
Vec4d vzero(0,0,0,0);
|
||||
|
||||
ASSERT_FLOAT_EQ(5.4772255f, vf.length());
|
||||
ASSERT_DOUBLE_EQ(11.22497216032182415675, vd.length());
|
||||
ASSERT_DOUBLE_EQ(0.0, vzero.length());
|
||||
|
||||
ASSERT_FLOAT_EQ(30.0f, vf.lengthSquared());
|
||||
ASSERT_DOUBLE_EQ(126.0, vd.lengthSquared());
|
||||
ASSERT_DOUBLE_EQ(0.0, vzero.lengthSquared());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, SetLength)
|
||||
{
|
||||
Vec4d vx = Vec4d(1,0,0,0);
|
||||
vx.setLength(10);
|
||||
ASSERT_DOUBLE_EQ(10, vx.length());
|
||||
|
||||
Vec4d vy = Vec4d(0,0,0,1);
|
||||
vy.setLength(10);
|
||||
ASSERT_DOUBLE_EQ(10, vy.length());
|
||||
|
||||
|
||||
Vec4d v0(0, 0, 0, 0);
|
||||
ASSERT_FALSE(v0.setLength(2));
|
||||
ASSERT_DOUBLE_EQ(0, v0.length());
|
||||
|
||||
Vec4d v1(1, 1, 1, 1);
|
||||
ASSERT_TRUE(v1.setLength(0));
|
||||
ASSERT_DOUBLE_EQ(0, v1.length());
|
||||
|
||||
Vec4d v2(1, 1, 1, 1);
|
||||
ASSERT_TRUE(v2.setLength(12));
|
||||
ASSERT_DOUBLE_EQ(12, v2.length());
|
||||
|
||||
Vec4d v3(4, -5, 6, 5);
|
||||
ASSERT_TRUE(v3.setLength(33));
|
||||
ASSERT_DOUBLE_EQ(33, v3.length());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, Addition)
|
||||
{
|
||||
Vec4f f1(1.0f, 2.6f, 3.0f, 4.0f);
|
||||
Vec4f f2(4.0f,5.2f,6.0f, 7.0f);
|
||||
Vec4f fa = f1 + f2;
|
||||
|
||||
ASSERT_FLOAT_EQ(5.0f, fa.x());
|
||||
ASSERT_FLOAT_EQ(7.8f, fa.y());
|
||||
ASSERT_FLOAT_EQ(9.0f, fa.z());
|
||||
ASSERT_FLOAT_EQ(11.0f, fa.w());
|
||||
|
||||
fa += f1;
|
||||
|
||||
ASSERT_FLOAT_EQ(6.0f, fa.x());
|
||||
ASSERT_FLOAT_EQ(10.4f, fa.y());
|
||||
ASSERT_FLOAT_EQ(12.0f, fa.z());
|
||||
ASSERT_FLOAT_EQ(15.0f, fa.w());
|
||||
|
||||
fa.add(f2);
|
||||
|
||||
ASSERT_FLOAT_EQ(10.0f, fa.x());
|
||||
ASSERT_FLOAT_EQ(15.6f, fa.y());
|
||||
ASSERT_FLOAT_EQ(18.0f, fa.z());
|
||||
ASSERT_FLOAT_EQ(22.0f, fa.w());
|
||||
|
||||
// double
|
||||
Vec4d d1(1.0, 2.6, 3.0, 4.0);
|
||||
Vec4d d2(4,5.2,6,7);
|
||||
Vec4d da = d1 + d2;
|
||||
|
||||
ASSERT_DOUBLE_EQ(5.0, da.x());
|
||||
ASSERT_DOUBLE_EQ(7.8, da.y());
|
||||
ASSERT_DOUBLE_EQ(9.0, da.z());
|
||||
ASSERT_DOUBLE_EQ(11.0, da.w());
|
||||
|
||||
da += d1;
|
||||
|
||||
ASSERT_DOUBLE_EQ(6.0, da.x());
|
||||
ASSERT_DOUBLE_EQ(10.4, da.y());
|
||||
ASSERT_DOUBLE_EQ(12.0, da.z());
|
||||
ASSERT_DOUBLE_EQ(15.0, da.w());
|
||||
|
||||
da.add(d2);
|
||||
|
||||
ASSERT_DOUBLE_EQ(10.0, da.x());
|
||||
ASSERT_DOUBLE_EQ(15.6, da.y());
|
||||
ASSERT_DOUBLE_EQ(18.0, da.z());
|
||||
ASSERT_DOUBLE_EQ(22.0, da.w());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, Subtraction)
|
||||
{
|
||||
Vec4f f1(1.0f, 2.6f, 3.0f, 4.0f);
|
||||
Vec4f f2(4.0f,5.2f,6.0f, 7.0f);
|
||||
Vec4f fa = f1 - f2;
|
||||
|
||||
ASSERT_FLOAT_EQ(-3.0f, fa.x());
|
||||
ASSERT_FLOAT_EQ(-2.6f, fa.y());
|
||||
ASSERT_FLOAT_EQ(-3.0f, fa.z());
|
||||
ASSERT_FLOAT_EQ(-3.0f, fa.w());
|
||||
|
||||
fa -= f1;
|
||||
|
||||
ASSERT_FLOAT_EQ(-4.0f, fa.x());
|
||||
ASSERT_FLOAT_EQ(-5.2f, fa.y());
|
||||
ASSERT_FLOAT_EQ(-6.0f, fa.z());
|
||||
ASSERT_FLOAT_EQ(-7.0f, fa.w());
|
||||
|
||||
fa.subtract(f2);
|
||||
|
||||
ASSERT_FLOAT_EQ(-8.0f, fa.x());
|
||||
ASSERT_FLOAT_EQ(-10.4f, fa.y());
|
||||
ASSERT_FLOAT_EQ(-12.0f, fa.z());
|
||||
ASSERT_FLOAT_EQ(-14.0f, fa.w());
|
||||
|
||||
// double
|
||||
Vec4d d1(1.0, 2.6, 3.0, 4.0);
|
||||
Vec4d d2(4,5.2,6,7);
|
||||
Vec4d da = d1 - d2;
|
||||
|
||||
ASSERT_DOUBLE_EQ(-3.0, da.x());
|
||||
ASSERT_DOUBLE_EQ(-2.6, da.y());
|
||||
ASSERT_DOUBLE_EQ(-3.0, da.z());
|
||||
ASSERT_DOUBLE_EQ(-3.0, da.w());
|
||||
|
||||
da -= d1;
|
||||
|
||||
ASSERT_DOUBLE_EQ(-4.0, da.x());
|
||||
ASSERT_DOUBLE_EQ(-5.2, da.y());
|
||||
ASSERT_DOUBLE_EQ(-6.0, da.z());
|
||||
ASSERT_DOUBLE_EQ(-7.0, da.w());
|
||||
|
||||
da.subtract(d2);
|
||||
|
||||
ASSERT_DOUBLE_EQ(-8.0, da.x());
|
||||
ASSERT_DOUBLE_EQ(-10.4, da.y());
|
||||
ASSERT_DOUBLE_EQ(-12.0, da.z());
|
||||
ASSERT_DOUBLE_EQ(-14.0, da.w());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, Scale)
|
||||
{
|
||||
Vec4d d2(1.0,2.0,3.7, 2.0);
|
||||
|
||||
d2.scale(2.3);
|
||||
ASSERT_DOUBLE_EQ(2.3, d2.x());
|
||||
ASSERT_DOUBLE_EQ(4.6, d2.y());
|
||||
ASSERT_DOUBLE_EQ(8.51, d2.z());
|
||||
ASSERT_DOUBLE_EQ(4.6, d2.w());
|
||||
|
||||
d2.scale(0.0);
|
||||
ASSERT_TRUE(d2.isZero());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, Multiply)
|
||||
{
|
||||
// float
|
||||
Vec4f f1(1.0f,2.0f,3.7f, 2.0f);
|
||||
Vec4f f2 = f1*2.3f;
|
||||
ASSERT_FLOAT_EQ(2.3f, f2.x());
|
||||
ASSERT_FLOAT_EQ(4.6f, f2.y());
|
||||
ASSERT_FLOAT_EQ(8.51f, f2.z());
|
||||
ASSERT_FLOAT_EQ(4.6f, f2.w());
|
||||
|
||||
f2 *= 3.5f;
|
||||
ASSERT_FLOAT_EQ(8.05f, f2.x());
|
||||
ASSERT_FLOAT_EQ(16.1f, f2.y());
|
||||
ASSERT_FLOAT_EQ(29.785f, f2.z());
|
||||
ASSERT_FLOAT_EQ(16.1f, f2.w());
|
||||
|
||||
f2 *= 0.0f;
|
||||
ASSERT_TRUE(f2.isZero());
|
||||
|
||||
// double
|
||||
Vec4d d1(1.0,2.0,3.7, 2.0);
|
||||
Vec4d d2 = d1*2.3;
|
||||
ASSERT_DOUBLE_EQ(2.3, d2.x());
|
||||
ASSERT_DOUBLE_EQ(4.6, d2.y());
|
||||
ASSERT_DOUBLE_EQ(8.51, d2.z());
|
||||
ASSERT_DOUBLE_EQ(4.6, d2.w());
|
||||
|
||||
d2 *= 3.5;
|
||||
ASSERT_DOUBLE_EQ(8.05, d2.x());
|
||||
ASSERT_DOUBLE_EQ(16.1, d2.y());
|
||||
ASSERT_DOUBLE_EQ(29.785, d2.z());
|
||||
ASSERT_DOUBLE_EQ(16.1, d2.w());
|
||||
|
||||
d2 *= 0.0;
|
||||
ASSERT_TRUE(d2.isZero());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, Divide)
|
||||
{
|
||||
// float
|
||||
Vec4f f1(1.0f,2.0f,3.7f, 2.0f);
|
||||
Vec4f f2 = f1*2.3f;
|
||||
ASSERT_FLOAT_EQ(2.3f, f2.x());
|
||||
ASSERT_FLOAT_EQ(4.6f, f2.y());
|
||||
ASSERT_FLOAT_EQ(8.51f, f2.z());
|
||||
ASSERT_FLOAT_EQ(4.6f, f2.w());
|
||||
|
||||
f2 *= 3.5f;
|
||||
ASSERT_FLOAT_EQ(8.05f, f2.x());
|
||||
ASSERT_FLOAT_EQ(16.1f, f2.y());
|
||||
ASSERT_FLOAT_EQ(29.785f, f2.z());
|
||||
ASSERT_FLOAT_EQ(16.1f, f2.w());
|
||||
|
||||
// double
|
||||
Vec4d d1(1.0,2.0,3.7, 2.0);
|
||||
Vec4d d2 = d1*2.3;
|
||||
ASSERT_DOUBLE_EQ(2.3, d2.x());
|
||||
ASSERT_DOUBLE_EQ(4.6, d2.y());
|
||||
ASSERT_DOUBLE_EQ(8.51, d2.z());
|
||||
ASSERT_DOUBLE_EQ(4.6, d2.w());
|
||||
|
||||
d2 *= 3.5;
|
||||
ASSERT_DOUBLE_EQ(8.05, d2.x());
|
||||
ASSERT_DOUBLE_EQ(16.1, d2.y());
|
||||
ASSERT_DOUBLE_EQ(29.785, d2.z());
|
||||
ASSERT_DOUBLE_EQ(16.1, d2.w());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, Negate)
|
||||
{
|
||||
Vec4f f(1.0f, -2.0f, 3.7f, 3.0f);
|
||||
Vec4f fn = -f;
|
||||
ASSERT_FLOAT_EQ(-1.0f, fn.x());
|
||||
ASSERT_FLOAT_EQ( 2.0f, fn.y());
|
||||
ASSERT_FLOAT_EQ(-3.7f, fn.z());
|
||||
ASSERT_FLOAT_EQ(-3.0f, fn.w());
|
||||
|
||||
Vec4d d(1.0, -2.0, 3.7, 3.0);
|
||||
Vec4d dn = -d;
|
||||
ASSERT_DOUBLE_EQ(-1.0, dn.x());
|
||||
ASSERT_DOUBLE_EQ( 2.0, dn.y());
|
||||
ASSERT_DOUBLE_EQ(-3.7, dn.z());
|
||||
ASSERT_DOUBLE_EQ(-3.0, dn.w());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, DotProduct)
|
||||
{
|
||||
// float
|
||||
Vec4f f1(1.0f,2.0f,3.7f, 2.0f);
|
||||
Vec4f f2(5,3.2f, 2.3f, 3.2f);
|
||||
|
||||
float fdot1 = f1*f2;
|
||||
ASSERT_FLOAT_EQ(26.31f, fdot1);
|
||||
|
||||
float fdot2 = f2.dot(f1);
|
||||
ASSERT_FLOAT_EQ(26.31f, fdot2);
|
||||
|
||||
// Double
|
||||
Vec4d d1(1.0, 2.0, 3.7, 2.0);
|
||||
Vec4d d2(5, 3.2, 2.3, 3.2);
|
||||
|
||||
double ddot1 = d1*d2;
|
||||
ASSERT_DOUBLE_EQ(26.31, ddot1);
|
||||
|
||||
double ddot2 = d2.dot(d1);
|
||||
ASSERT_DOUBLE_EQ(26.31, ddot2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, Normalize)
|
||||
{
|
||||
// float
|
||||
Vec4f vf(1.5f, 2.5f, 3.2f, 6.3f);
|
||||
Vec4f vfz(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
ASSERT_TRUE(vf.normalize());
|
||||
ASSERT_FALSE(vfz.normalize());
|
||||
|
||||
ASSERT_FLOAT_EQ(1.0f, vf.length());
|
||||
ASSERT_FLOAT_EQ(0.0f, vfz.length());
|
||||
|
||||
// double
|
||||
Vec4d vd(1.5, 2.5, 3.2, 6.3);
|
||||
Vec4d vdz(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
ASSERT_TRUE(vd.normalize());
|
||||
ASSERT_FALSE(vdz.normalize());
|
||||
|
||||
ASSERT_DOUBLE_EQ(1.0, vd.length());
|
||||
ASSERT_DOUBLE_EQ(0.0, vdz.length());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, GetNormalized)
|
||||
{
|
||||
{
|
||||
const Vec4f v(1.5f, 2.5f, 3.2f, 6.3f);
|
||||
const Vec4f vz(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
Vec4f n1 = v.getNormalized();
|
||||
ASSERT_FLOAT_EQ(1.0f, n1.length());
|
||||
|
||||
bool normOK = false;
|
||||
Vec4f n2 = v.getNormalized(&normOK);
|
||||
ASSERT_TRUE(normOK);
|
||||
ASSERT_FLOAT_EQ(1.0f, n2.length());
|
||||
|
||||
Vec4f nz = vz.getNormalized(&normOK);
|
||||
ASSERT_FALSE(normOK);
|
||||
ASSERT_FLOAT_EQ(0.0f, nz.length());
|
||||
}
|
||||
|
||||
{
|
||||
const Vec4d v(1.5, 2.5, 3.2, 6.3);
|
||||
const Vec4d vz(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
Vec4d n1 = v.getNormalized();
|
||||
ASSERT_DOUBLE_EQ(1.0, n1.length());
|
||||
|
||||
bool normOK = false;
|
||||
Vec4d n2 = v.getNormalized(&normOK);
|
||||
ASSERT_TRUE(normOK);
|
||||
ASSERT_DOUBLE_EQ(1.0, n2.length());
|
||||
|
||||
Vec4d nz = vz.getNormalized(&normOK);
|
||||
ASSERT_FALSE(normOK);
|
||||
ASSERT_DOUBLE_EQ(0.0, nz.length());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, Comparison)
|
||||
{
|
||||
// float
|
||||
Vec4f f1(1,2,3,4);
|
||||
Vec4f f2(1,2,3,4);
|
||||
Vec4f f3(1,2,3.1f,3.4f);
|
||||
|
||||
ASSERT_TRUE(f1.equals(f2));
|
||||
ASSERT_TRUE(f1 == f2);
|
||||
ASSERT_FALSE(f1 != f2);
|
||||
ASSERT_FALSE(f1 == f3);
|
||||
ASSERT_TRUE(f1 != f3);
|
||||
|
||||
// double
|
||||
Vec4d d1(1,2,3,4);
|
||||
Vec4d d2(1,2,3,4);
|
||||
Vec4d d3(1,2,3.1f,3.4);
|
||||
|
||||
ASSERT_TRUE(d1.equals(d2));
|
||||
ASSERT_TRUE(d1 == d2);
|
||||
ASSERT_FALSE(d1 != d2);
|
||||
ASSERT_FALSE(d1 == d3);
|
||||
ASSERT_TRUE(d1 != d3);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(Vector4Test, OtherDataTypes)
|
||||
{
|
||||
typedef Vector4<int> Vec3i;
|
||||
|
||||
Vec3i iVec(1,2,3,4);
|
||||
Vec3i iVec2(5,6,7,8);
|
||||
Vec3i iVec3 = iVec + iVec2;
|
||||
|
||||
ASSERT_EQ(6, iVec3.x());
|
||||
ASSERT_EQ(8, iVec3.y());
|
||||
ASSERT_EQ(10, iVec3.z());
|
||||
ASSERT_EQ(12, iVec3.w());
|
||||
ASSERT_EQ(344, iVec3.lengthSquared());
|
||||
|
||||
|
||||
typedef Vector4<String> Vec3s;
|
||||
|
||||
Vec3s s1("Yes", "No", "Maybe", "w");
|
||||
Vec3s s2("Ja", "Nei", "Kanskje", "W");
|
||||
Vec3s s3 = s1 + s2;
|
||||
|
||||
ASSERT_TRUE(s3.x() == "YesJa");
|
||||
ASSERT_TRUE(s3.y() == "NoNei");
|
||||
ASSERT_TRUE(s3.z() == "MaybeKanskje");
|
||||
ASSERT_TRUE(s3.w() == "wW");
|
||||
}
|
||||
39
Fwk/VizFwk/Tests/LibGeometry_UnitTests/CMakeLists.txt
Normal file
39
Fwk/VizFwk/Tests/LibGeometry_UnitTests/CMakeLists.txt
Normal file
@@ -0,0 +1,39 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(LibGeometry_UnitTests)
|
||||
|
||||
# Compile flags should already be setup by caller
|
||||
|
||||
|
||||
include_directories(${LibCore_SOURCE_DIR})
|
||||
include_directories(${LibGeometry_SOURCE_DIR})
|
||||
include_directories(${VizFramework_SOURCE_DIR}/ThirdParty)
|
||||
|
||||
set(CEE_LIBS LibGeometry LibCore)
|
||||
|
||||
|
||||
set(CEE_SOURCE_FILES
|
||||
cvfArrowGenerator-Test.cpp
|
||||
cvfBoundingBox-Test.cpp
|
||||
cvfBoxGenerator-Test.cpp
|
||||
cvfFrustum-Test.cpp
|
||||
cvfEdgeKey-Test.cpp
|
||||
cvfGeometryBuilderFaceList-Test.cpp
|
||||
cvfGeometryBuilderTriangles-Test.cpp
|
||||
cvfGeometryBuilder-Test.cpp
|
||||
cvfGeometryUtils-Test.cpp
|
||||
cvfMeshEdgeExtractor-Test.cpp
|
||||
cvfOutlineEdgeExtractor-Test.cpp
|
||||
cvfPatchGenerator-Test.cpp
|
||||
cvfRay-Test.cpp
|
||||
cvfTriangleMeshEdgeExtractor-Test.cpp
|
||||
cvfTriangleVertexSplitter-Test.cpp
|
||||
cvfVertexCompactor-Test.cpp
|
||||
cvfVertexWelder-Test.cpp
|
||||
../../ThirdParty/gtest/gtest-all.cpp
|
||||
LibGeometry_UnitTests.cpp
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${CEE_SOURCE_FILES})
|
||||
target_link_libraries(${PROJECT_NAME} ${CEE_LIBS} ${CEE_PLATFORM_LIBS} )
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
//printf("Running main() from LibGeometry_UnitTests.cpp\n");
|
||||
|
||||
cvf::Assert::setReportMode(cvf::Assert::CONSOLE);
|
||||
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@@ -0,0 +1,302 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug MD TBB|Win32">
|
||||
<Configuration>Debug MD TBB</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug MD TBB|x64">
|
||||
<Configuration>Debug MD TBB</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug MD|Win32">
|
||||
<Configuration>Debug MD</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug MD|x64">
|
||||
<Configuration>Debug MD</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD TBB|Win32">
|
||||
<Configuration>Release MD TBB</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD TBB|x64">
|
||||
<Configuration>Release MD TBB</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD|Win32">
|
||||
<Configuration>Release MD</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD|x64">
|
||||
<Configuration>Release MD</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{86969588-4AA4-AFC9-EA54-FD5BC86810FC}</ProjectGuid>
|
||||
<RootNamespace>LibGeometry_UnitTests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\ThirdParty\gtest\gtest-all.cpp" />
|
||||
<ClCompile Include="cvfArrowGenerator-Test.cpp" />
|
||||
<ClCompile Include="cvfBoundingBox-Test.cpp" />
|
||||
<ClCompile Include="cvfBoxGenerator-Test.cpp" />
|
||||
<ClCompile Include="cvfEdgeKey-Test.cpp" />
|
||||
<ClCompile Include="cvfFrustum-Test.cpp" />
|
||||
<ClCompile Include="cvfGeometryBuilder-Test.cpp" />
|
||||
<ClCompile Include="cvfGeometryBuilderFaceList-Test.cpp" />
|
||||
<ClCompile Include="cvfGeometryBuilderTriangles-Test.cpp" />
|
||||
<ClCompile Include="cvfGeometryUtils-Test.cpp" />
|
||||
<ClCompile Include="cvfMeshEdgeExtractor-Test.cpp" />
|
||||
<ClCompile Include="cvfOutlineEdgeExtractor-Test.cpp" />
|
||||
<ClCompile Include="cvfPatchGenerator-Test.cpp" />
|
||||
<ClCompile Include="cvfRay-Test.cpp" />
|
||||
<ClCompile Include="cvfTriangleMeshEdgeExtractor-Test.cpp" />
|
||||
<ClCompile Include="cvfTriangleVertexSplitter-Test.cpp" />
|
||||
<ClCompile Include="cvfVertexCompactor-Test.cpp" />
|
||||
<ClCompile Include="cvfVertexWelder-Test.cpp" />
|
||||
<ClCompile Include="LibGeometry_UnitTests.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="CMakeLists.txt" />
|
||||
<CustomBuild Include="TriggerTBBCopy.txt">
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb_debug.dll" + NUL "$(TargetDir)tbb_debug.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">$(TargetDir)tbb_debug.dll</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb.dll" + NUL "$(TargetDir)tbb.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">$(TargetDir)tbb.dll</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb_debug.dll" + NUL "$(TargetDir)tbb_debug.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">$(TargetDir)tbb_debug.dll</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb.dll" + NUL "$(TargetDir)tbb.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">$(TargetDir)tbb.dll</Outputs>
|
||||
</CustomBuild>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\LibCore\LibCore.vcxproj">
|
||||
<Project>{a9c7a239-b761-a892-bf34-5aeca0d9ee88}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\LibGeometry\LibGeometry.vcxproj">
|
||||
<Project>{efd5c9ac-8988-f190-aa2c-e36ebe361e90}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="utestGeometryBuilders.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\ThirdParty\gtest\gtest-all.cpp" />
|
||||
<ClCompile Include="cvfArrowGenerator-Test.cpp" />
|
||||
<ClCompile Include="cvfBoundingBox-Test.cpp" />
|
||||
<ClCompile Include="cvfBoxGenerator-Test.cpp" />
|
||||
<ClCompile Include="cvfEdgeKey-Test.cpp" />
|
||||
<ClCompile Include="cvfFrustum-Test.cpp" />
|
||||
<ClCompile Include="cvfGeometryBuilderFaceList-Test.cpp" />
|
||||
<ClCompile Include="cvfGeometryBuilder-Test.cpp" />
|
||||
<ClCompile Include="cvfGeometryBuilderTriangles-Test.cpp" />
|
||||
<ClCompile Include="cvfGeometryUtils-Test.cpp" />
|
||||
<ClCompile Include="cvfMeshEdgeExtractor-Test.cpp" />
|
||||
<ClCompile Include="cvfOutlineEdgeExtractor-Test.cpp" />
|
||||
<ClCompile Include="cvfPatchGenerator-Test.cpp" />
|
||||
<ClCompile Include="cvfRay-Test.cpp" />
|
||||
<ClCompile Include="cvfVertexWelder-Test.cpp" />
|
||||
<ClCompile Include="LibGeometry_UnitTests.cpp" />
|
||||
<ClCompile Include="cvfTriangleVertexSplitter-Test.cpp" />
|
||||
<ClCompile Include="cvfVertexCompactor-Test.cpp" />
|
||||
<ClCompile Include="cvfTriangleMeshEdgeExtractor-Test.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="CMakeLists.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="TriggerTBBCopy.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="utestGeometryBuilders.h" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
Sole purpose of this file is to have custom build rules to trigger copying of TBB DLLs
|
||||
@@ -0,0 +1,95 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfArrowGenerator.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
#include "utestGeometryBuilders.h"
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(ArrowGeneratorTest, DefaultArrow)
|
||||
{
|
||||
ArrowGenerator gen;
|
||||
|
||||
BuilderTrisQuads builder;
|
||||
gen.generate(&builder);
|
||||
BoundingBox bb = builder.vertexBoundingBox();
|
||||
EXPECT_DOUBLE_EQ(-0.085f, bb.min().x());
|
||||
EXPECT_DOUBLE_EQ(-0.085f, bb.min().y());
|
||||
EXPECT_DOUBLE_EQ(0.0f, bb.min().z());
|
||||
EXPECT_DOUBLE_EQ(0.085f, bb.max().x());
|
||||
EXPECT_DOUBLE_EQ(0.085f, bb.max().y());
|
||||
EXPECT_DOUBLE_EQ(1.0f, bb.max().z());
|
||||
|
||||
// Default num slices is 20
|
||||
EXPECT_EQ(60, builder.triCount()); // 20 + 20 in cone and 20 in bottom of cylinder
|
||||
EXPECT_EQ(20, builder.quadCount()); // 20 on sides of cylinder
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(ArrowGeneratorTest, CustomArrow)
|
||||
{
|
||||
ArrowGenerator gen;
|
||||
|
||||
gen.setShaftRelativeRadius(0.4f);
|
||||
gen.setHeadRelativeRadius(0.3f);
|
||||
gen.setHeadRelativeLength(0.5f);
|
||||
gen.setNumSlices(12);
|
||||
|
||||
BuilderTrisQuads builder;
|
||||
gen.generate(&builder);
|
||||
BoundingBox bb = builder.vertexBoundingBox();
|
||||
EXPECT_DOUBLE_EQ(-0.4f, bb.min().x());
|
||||
EXPECT_DOUBLE_EQ(-0.4f, bb.min().y());
|
||||
EXPECT_DOUBLE_EQ(0.0f, bb.min().z());
|
||||
EXPECT_DOUBLE_EQ(0.4f, bb.max().x());
|
||||
EXPECT_DOUBLE_EQ(0.4f, bb.max().y());
|
||||
EXPECT_DOUBLE_EQ(1.0f, bb.max().z());
|
||||
|
||||
EXPECT_EQ(36, builder.triCount());
|
||||
EXPECT_EQ(12, builder.quadCount());
|
||||
}
|
||||
390
Fwk/VizFwk/Tests/LibGeometry_UnitTests/cvfBoundingBox-Test.cpp
Normal file
390
Fwk/VizFwk/Tests/LibGeometry_UnitTests/cvfBoundingBox-Test.cpp
Normal file
@@ -0,0 +1,390 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfBoundingBox.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(BoundingBoxTest, BasicConstruction)
|
||||
{
|
||||
BoundingBox bb;
|
||||
|
||||
bb.add(Vec3f(10, 20, 30));
|
||||
EXPECT_EQ(10, bb.min().x());
|
||||
EXPECT_EQ(20, bb.min().y());
|
||||
EXPECT_EQ(30, bb.min().z());
|
||||
EXPECT_EQ(10, bb.max().x());
|
||||
EXPECT_EQ(20, bb.max().y());
|
||||
EXPECT_EQ(30, bb.max().z());
|
||||
|
||||
bb.add(Vec3f(1, 2, 3));
|
||||
EXPECT_EQ(1, bb.min().x());
|
||||
EXPECT_EQ(2, bb.min().y());
|
||||
EXPECT_EQ(3, bb.min().z());
|
||||
EXPECT_EQ(10, bb.max().x());
|
||||
EXPECT_EQ(20, bb.max().y());
|
||||
EXPECT_EQ(30, bb.max().z());
|
||||
|
||||
bb.add(Vec3f(-1, -2, -3));
|
||||
EXPECT_EQ(-1, bb.min().x());
|
||||
EXPECT_EQ(-2, bb.min().y());
|
||||
EXPECT_EQ(-3, bb.min().z());
|
||||
EXPECT_EQ(10, bb.max().x());
|
||||
EXPECT_EQ(20, bb.max().y());
|
||||
EXPECT_EQ(30, bb.max().z());
|
||||
|
||||
|
||||
// Constructor with two input points
|
||||
Vec3d vec1(-100, -200, -300);
|
||||
Vec3d vec2(10, 20, 30);
|
||||
|
||||
BoundingBox bb2(vec1, vec2);
|
||||
EXPECT_TRUE(vec1 == bb2.min());
|
||||
EXPECT_TRUE(vec2 == bb2.max());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(BoundingBoxTest, CopyConstructor)
|
||||
{
|
||||
{
|
||||
BoundingBox bb1;
|
||||
bb1.add(Vec3d::ZERO);
|
||||
EXPECT_TRUE(bb1.isValid());
|
||||
EXPECT_DOUBLE_EQ(0, bb1.radius());
|
||||
|
||||
BoundingBox bb2(bb1);
|
||||
EXPECT_TRUE(bb2.isValid());
|
||||
EXPECT_DOUBLE_EQ(0, bb2.radius());
|
||||
}
|
||||
|
||||
{
|
||||
const BoundingBox bb1;
|
||||
EXPECT_FALSE(bb1.isValid());
|
||||
|
||||
BoundingBox bb2(bb1);
|
||||
EXPECT_FALSE(bb2.isValid());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(BoundingBoxTest, Assignment)
|
||||
{
|
||||
{
|
||||
BoundingBox bb1;
|
||||
bb1.add(Vec3d::ZERO);
|
||||
EXPECT_TRUE(bb1.isValid());
|
||||
EXPECT_DOUBLE_EQ(0, bb1.radius());
|
||||
|
||||
BoundingBox bb2;
|
||||
bb2 = bb1;
|
||||
EXPECT_TRUE(bb2.isValid());
|
||||
EXPECT_DOUBLE_EQ(0, bb2.radius());
|
||||
}
|
||||
|
||||
{
|
||||
const BoundingBox bb1;
|
||||
EXPECT_FALSE(bb1.isValid());
|
||||
|
||||
BoundingBox bb2;
|
||||
bb2 = bb1;
|
||||
EXPECT_FALSE(bb2.isValid());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(BoundingBoxTest, State)
|
||||
{
|
||||
BoundingBox bb;
|
||||
EXPECT_FALSE(bb.isValid());
|
||||
|
||||
bb.add(Vec3f(10, 20, 30));
|
||||
|
||||
EXPECT_TRUE(bb.isValid());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(BoundingBoxTest, AddBB)
|
||||
{
|
||||
BoundingBox bb;
|
||||
bb.add(Vec3f(10, 20, 30));
|
||||
bb.add(Vec3f(100, 200, 300));
|
||||
|
||||
BoundingBox bb2;
|
||||
bb2.add(bb);
|
||||
|
||||
EXPECT_TRUE(bb.min() == bb2.min());
|
||||
EXPECT_TRUE(bb.max() == bb2.max());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(BoundingBoxTest, AddPoints)
|
||||
{
|
||||
Vec3dArray vA;
|
||||
vA.resize(4);
|
||||
ASSERT_EQ(4u, vA.size());
|
||||
|
||||
vA[0] = Vec3d(1,2,3);
|
||||
vA[1] = Vec3d(1.1f, 2.2f, 3.3f);
|
||||
vA[2] = Vec3d(0,0,0);
|
||||
vA[3] = Vec3d(-4,-5,-6);
|
||||
|
||||
BoundingBox bb;
|
||||
bb.add(vA);
|
||||
|
||||
EXPECT_TRUE(bb.min() == vA[3]);
|
||||
EXPECT_TRUE(bb.max() == vA[1]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(BoundingBoxTest, Computations)
|
||||
{
|
||||
BoundingBox bb;
|
||||
Vec3d v1 = Vec3d(2, 4, 6);
|
||||
Vec3d v2 = Vec3d(4, 8, 12);
|
||||
bb.add(v1);
|
||||
bb.add(v2);
|
||||
|
||||
Vec3d expectedCenter(3, 6, 9);
|
||||
EXPECT_TRUE(expectedCenter == bb.center());
|
||||
|
||||
Vec3d expectedExtent = v2 - v1;
|
||||
EXPECT_TRUE(expectedExtent == bb.extent());
|
||||
|
||||
const double expectedRadius = (v1 - v2).length() / 2.0;
|
||||
EXPECT_EQ(expectedRadius, bb.radius());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#ifdef _DEBUG
|
||||
TEST(BoundingBoxDeathTest, AccessInvalidBox)
|
||||
{
|
||||
BoundingBox bb;
|
||||
EXPECT_DEATH(bb.min(), "Assertion");
|
||||
EXPECT_DEATH(bb.max(), "Assertion");
|
||||
EXPECT_DEATH(bb.center(), "Assertion");
|
||||
EXPECT_DEATH(bb.extent(), "Assertion");
|
||||
EXPECT_DEATH(bb.radius(), "Assertion");
|
||||
|
||||
bb.reset();
|
||||
EXPECT_DEATH(bb.min(), "Assertion");
|
||||
EXPECT_DEATH(bb.max(), "Assertion");
|
||||
EXPECT_DEATH(bb.center(), "Assertion");
|
||||
EXPECT_DEATH(bb.extent(), "Assertion");
|
||||
EXPECT_DEATH(bb.radius(), "Assertion");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(BoundingBoxTest, ContainsPoint)
|
||||
{
|
||||
const BoundingBox bb(Vec3d(1.0, 1.0, 1.0), Vec3d(3.0, 3.0, 3.0));
|
||||
|
||||
EXPECT_TRUE(bb.contains(Vec3d(1.0, 1.0, 1.0)));
|
||||
EXPECT_TRUE(bb.contains(Vec3d(3.0, 3.0, 3.0)));
|
||||
EXPECT_TRUE(bb.contains(Vec3d(1.0, 2.0, 3.0)));
|
||||
EXPECT_TRUE(bb.contains(Vec3d(1.1, 2.0, 2.9)));
|
||||
|
||||
EXPECT_FALSE(bb.contains(Vec3d( 0.0, 0.0, 0.0)));
|
||||
EXPECT_FALSE(bb.contains(Vec3d(-1.0, -2.0, -3.0)));
|
||||
EXPECT_FALSE(bb.contains(Vec3d( 1.0, 2.0, 4.0)));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(BoundingBoxTest, Intersects)
|
||||
{
|
||||
const BoundingBox bb0(Vec3d(1.0, 1.0, 1.0), Vec3d(4.0, 4.0, 4.0));
|
||||
|
||||
{
|
||||
BoundingBox bb(Vec3d(2.0, 2.0, 2.0), Vec3d(3.0, 3.0, 3.0));
|
||||
EXPECT_TRUE(bb0.intersects(bb));
|
||||
EXPECT_TRUE(bb.intersects(bb0));
|
||||
}
|
||||
|
||||
{
|
||||
BoundingBox bb(Vec3d(0.0, 0.0, 0.0), Vec3d(1.0, 1.0, 1.0));
|
||||
EXPECT_TRUE(bb0.intersects(bb));
|
||||
EXPECT_TRUE(bb.intersects(bb0));
|
||||
}
|
||||
|
||||
{
|
||||
BoundingBox bb(Vec3d(0.0, 0.0, 0.0), Vec3d(0.5, 0.5, 0.5));
|
||||
EXPECT_FALSE(bb0.intersects(bb));
|
||||
EXPECT_FALSE(bb.intersects(bb0));
|
||||
}
|
||||
|
||||
{
|
||||
BoundingBox bb(Vec3d(5.0, 6.0, 7.0), Vec3d(5.0, 6.0, 7.0));
|
||||
EXPECT_FALSE(bb0.intersects(bb));
|
||||
EXPECT_FALSE(bb.intersects(bb0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(BoundingBoxTest, CornerPoints)
|
||||
{
|
||||
const BoundingBox bb(Vec3d(1.0, 2.0, 3.0), Vec3d(4.0, 5.0, 6.0));
|
||||
|
||||
// 7---------6
|
||||
// /| /| |z
|
||||
// / | / | | / y
|
||||
// 4---------5 | |/
|
||||
// | 3------|--2 *---x
|
||||
// | / | /
|
||||
// |/ |/
|
||||
// 0---------1
|
||||
|
||||
Vec3d c[8];
|
||||
bb.cornerVertices(c);
|
||||
|
||||
EXPECT_TRUE(Vec3d(1, 2, 3) == c[0]);
|
||||
EXPECT_TRUE(Vec3d(4, 2, 3) == c[1]);
|
||||
EXPECT_TRUE(Vec3d(4, 5, 3) == c[2]);
|
||||
EXPECT_TRUE(Vec3d(1, 5, 3) == c[3]);
|
||||
|
||||
EXPECT_TRUE(Vec3d(1, 2, 6) == c[4]);
|
||||
EXPECT_TRUE(Vec3d(4, 2, 6) == c[5]);
|
||||
EXPECT_TRUE(Vec3d(4, 5, 6) == c[6]);
|
||||
EXPECT_TRUE(Vec3d(1, 5, 6) == c[7]);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(BoundingBoxTest, Transform)
|
||||
{
|
||||
BoundingBox bb;
|
||||
Vec3d v1 = Vec3d(2, 4, 6);
|
||||
Vec3d v2 = Vec3d(4, 8, 12);
|
||||
bb.add(v1);
|
||||
bb.add(v2);
|
||||
|
||||
Mat4d m;
|
||||
Vec3d t(1,2,3);
|
||||
m.setTranslation(t);
|
||||
|
||||
bb.transform(m);
|
||||
|
||||
EXPECT_EQ(3, bb.min().x());
|
||||
EXPECT_EQ(6, bb.min().y());
|
||||
EXPECT_EQ(9, bb.min().z());
|
||||
EXPECT_EQ(5, bb.max().x());
|
||||
EXPECT_EQ(10, bb.max().y());
|
||||
EXPECT_EQ(15, bb.max().z());
|
||||
|
||||
BoundingBox b2 = bb.getTransformed(m);
|
||||
|
||||
EXPECT_EQ(3, bb.min().x());
|
||||
EXPECT_EQ(6, bb.min().y());
|
||||
EXPECT_EQ(9, bb.min().z());
|
||||
EXPECT_EQ(5, bb.max().x());
|
||||
EXPECT_EQ(10, bb.max().y());
|
||||
EXPECT_EQ(15, bb.max().z());
|
||||
|
||||
EXPECT_EQ(4, b2.min().x());
|
||||
EXPECT_EQ(8, b2.min().y());
|
||||
EXPECT_EQ(12, b2.min().z());
|
||||
EXPECT_EQ(6, b2.max().x());
|
||||
EXPECT_EQ(12, b2.max().y());
|
||||
EXPECT_EQ(18, b2.max().z());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(BoundingBoxTest, Expand)
|
||||
{
|
||||
BoundingBox bb;
|
||||
Vec3d v1 = Vec3d(1, 2, 3);
|
||||
Vec3d v2 = Vec3d(3, 6, 9);
|
||||
bb.add(v1);
|
||||
bb.add(v2);
|
||||
|
||||
Vec3d extent1 = bb.extent();
|
||||
ASSERT_DOUBLE_EQ(2, extent1.x());
|
||||
ASSERT_DOUBLE_EQ(4, extent1.y());
|
||||
ASSERT_DOUBLE_EQ(6, extent1.z());
|
||||
|
||||
bb.expand(3);
|
||||
Vec3d extent2 = bb.extent();
|
||||
EXPECT_DOUBLE_EQ(5, extent2.x());
|
||||
EXPECT_DOUBLE_EQ(7, extent2.y());
|
||||
EXPECT_DOUBLE_EQ(9, extent2.z());
|
||||
}
|
||||
|
||||
|
||||
132
Fwk/VizFwk/Tests/LibGeometry_UnitTests/cvfBoxGenerator-Test.cpp
Normal file
132
Fwk/VizFwk/Tests/LibGeometry_UnitTests/cvfBoxGenerator-Test.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfBoxGenerator.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
#include "utestGeometryBuilders.h"
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(BoxGeneratorTest, GenerateSimple)
|
||||
{
|
||||
// From min/max
|
||||
{
|
||||
BoxGenerator gen;
|
||||
gen.setMinMax(Vec3d(10, 20, 30), Vec3d(20, 40, 60));
|
||||
|
||||
BuilderTrisQuads builder;
|
||||
gen.generate(&builder);
|
||||
BoundingBox bb = builder.vertexBoundingBox();
|
||||
EXPECT_DOUBLE_EQ(10, bb.min().x());
|
||||
EXPECT_DOUBLE_EQ(20, bb.min().y());
|
||||
EXPECT_DOUBLE_EQ(30, bb.min().z());
|
||||
EXPECT_DOUBLE_EQ(20, bb.max().x());
|
||||
EXPECT_DOUBLE_EQ(40, bb.max().y());
|
||||
EXPECT_DOUBLE_EQ(60, bb.max().z());
|
||||
|
||||
EXPECT_EQ(0, builder.triCount());
|
||||
EXPECT_EQ(6, builder.quadCount());
|
||||
}
|
||||
|
||||
// From origin and extent
|
||||
{
|
||||
BoxGenerator gen;
|
||||
gen.setOriginAndExtent(Vec3d(10, 20, 30), Vec3d(100, 200, 300));
|
||||
|
||||
BuilderTrisQuads builder;
|
||||
gen.generate(&builder);
|
||||
BoundingBox bb = builder.vertexBoundingBox();
|
||||
EXPECT_DOUBLE_EQ(10, bb.min().x());
|
||||
EXPECT_DOUBLE_EQ(20, bb.min().y());
|
||||
EXPECT_DOUBLE_EQ(30, bb.min().z());
|
||||
EXPECT_DOUBLE_EQ(110, bb.max().x());
|
||||
EXPECT_DOUBLE_EQ(220, bb.max().y());
|
||||
EXPECT_DOUBLE_EQ(330, bb.max().z());
|
||||
}
|
||||
|
||||
// From center and extent
|
||||
{
|
||||
BoxGenerator gen;
|
||||
gen.setCenterAndExtent(Vec3d(100, 200, 300), Vec3d(10, 20, 30));
|
||||
|
||||
BuilderTrisQuads builder;
|
||||
gen.generate(&builder);
|
||||
BoundingBox bb = builder.vertexBoundingBox();
|
||||
EXPECT_DOUBLE_EQ(95, bb.min().x());
|
||||
EXPECT_DOUBLE_EQ(190, bb.min().y());
|
||||
EXPECT_DOUBLE_EQ(285, bb.min().z());
|
||||
EXPECT_DOUBLE_EQ(105, bb.max().x());
|
||||
EXPECT_DOUBLE_EQ(210, bb.max().y());
|
||||
EXPECT_DOUBLE_EQ(315, bb.max().z());
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(BoxGeneratorTest, GenerateWithSubdivisions)
|
||||
{
|
||||
BoxGenerator gen;
|
||||
gen.setMinMax(Vec3d(10, 20, 30), Vec3d(20, 40, 60));
|
||||
gen.setSubdivisions(2, 4, 6);
|
||||
|
||||
BuilderTrisQuads builder;
|
||||
gen.generate(&builder);
|
||||
BoundingBox bb = builder.vertexBoundingBox();
|
||||
EXPECT_DOUBLE_EQ(10, bb.min().x());
|
||||
EXPECT_DOUBLE_EQ(20, bb.min().y());
|
||||
EXPECT_DOUBLE_EQ(30, bb.min().z());
|
||||
EXPECT_DOUBLE_EQ(20, bb.max().x());
|
||||
EXPECT_DOUBLE_EQ(40, bb.max().y());
|
||||
EXPECT_DOUBLE_EQ(60, bb.max().z());
|
||||
|
||||
EXPECT_EQ(0, builder.triCount());
|
||||
|
||||
// top/bot: 2*(2*4) = 16
|
||||
// front/back: 2*(2*6) = 24
|
||||
// left/right: 2*(4*6) = 48
|
||||
EXPECT_EQ(88, builder.quadCount());
|
||||
}
|
||||
|
||||
152
Fwk/VizFwk/Tests/LibGeometry_UnitTests/cvfEdgeKey-Test.cpp
Normal file
152
Fwk/VizFwk/Tests/LibGeometry_UnitTests/cvfEdgeKey-Test.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfEdgeKey.h"
|
||||
#include "cvfMath.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(EdgeKeyTest, Constructor)
|
||||
{
|
||||
{
|
||||
EdgeKey ek(1, 2);
|
||||
EXPECT_EQ(1, ek.index1());
|
||||
EXPECT_EQ(2, ek.index2());
|
||||
}
|
||||
|
||||
{
|
||||
EdgeKey ek(2, 1);
|
||||
EXPECT_EQ(1, ek.index1());
|
||||
EXPECT_EQ(2, ek.index2());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(EdgeKeyTest, EqualOperator)
|
||||
{
|
||||
const EdgeKey ek01(0u, 1u);
|
||||
const EdgeKey ek10(1u, 0u);
|
||||
const EdgeKey ek12(1u, 2u);
|
||||
|
||||
EXPECT_TRUE(ek01 == ek01);
|
||||
EXPECT_TRUE(ek01 == ek10);
|
||||
EXPECT_FALSE(ek01 == ek12);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(EdgeKeyTest, LessThanOperator)
|
||||
{
|
||||
const EdgeKey ek01(0u, 1u);
|
||||
const EdgeKey ek10(1u, 0u);
|
||||
const EdgeKey ek02(0u, 2u);
|
||||
const EdgeKey ek12(1u, 2u);
|
||||
|
||||
EXPECT_FALSE(ek01 < ek01);
|
||||
EXPECT_FALSE(ek01 < ek10);
|
||||
EXPECT_FALSE(ek01.toKeyVal() < ek01.toKeyVal());
|
||||
EXPECT_FALSE(ek01.toKeyVal() < ek10.toKeyVal());
|
||||
|
||||
|
||||
EXPECT_TRUE(ek01 < ek02);
|
||||
EXPECT_TRUE(ek10 < ek02);
|
||||
EXPECT_TRUE(ek01 < ek12);
|
||||
EXPECT_TRUE(ek02 < ek12);
|
||||
EXPECT_TRUE(ek01.toKeyVal() < ek02.toKeyVal());
|
||||
EXPECT_TRUE(ek10.toKeyVal() < ek02.toKeyVal());
|
||||
EXPECT_TRUE(ek01.toKeyVal() < ek12.toKeyVal());
|
||||
EXPECT_TRUE(ek02.toKeyVal() < ek12.toKeyVal());
|
||||
|
||||
|
||||
EXPECT_FALSE(ek02 < ek01);
|
||||
EXPECT_FALSE(ek02 < ek10);
|
||||
EXPECT_FALSE(ek12 < ek01);
|
||||
EXPECT_FALSE(ek12 < ek02);
|
||||
EXPECT_FALSE(ek02.toKeyVal() < ek01.toKeyVal());
|
||||
EXPECT_FALSE(ek02.toKeyVal() < ek10.toKeyVal());
|
||||
EXPECT_FALSE(ek12.toKeyVal() < ek01.toKeyVal());
|
||||
EXPECT_FALSE(ek12.toKeyVal() < ek02.toKeyVal());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(EdgeKeyTest, ToFromKeyVal)
|
||||
{
|
||||
{
|
||||
EdgeKey ek(987654321, 123456789);
|
||||
ASSERT_EQ(123456789, ek.index1());
|
||||
ASSERT_EQ(987654321, ek.index2());
|
||||
|
||||
int64 val = ek.toKeyVal();
|
||||
|
||||
EdgeKey ek2 = EdgeKey::fromkeyVal(val);
|
||||
ASSERT_EQ(123456789, ek2.index1());
|
||||
ASSERT_EQ(987654321, ek2.index2());
|
||||
}
|
||||
|
||||
{
|
||||
const cvf::uint idx2 = UNDEFINED_UINT;
|
||||
const cvf::uint idx1 = UNDEFINED_UINT - 1;
|
||||
EdgeKey ek(idx2, idx1);
|
||||
ASSERT_EQ(idx1, ek.index1());
|
||||
ASSERT_EQ(idx2, ek.index2());
|
||||
|
||||
int64 val = ek.toKeyVal();
|
||||
|
||||
EdgeKey ek2 = EdgeKey::fromkeyVal(val);
|
||||
ASSERT_EQ(idx1, ek2.index1());
|
||||
ASSERT_EQ(idx2, ek2.index2());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
232
Fwk/VizFwk/Tests/LibGeometry_UnitTests/cvfFrustum-Test.cpp
Normal file
232
Fwk/VizFwk/Tests/LibGeometry_UnitTests/cvfFrustum-Test.cpp
Normal file
@@ -0,0 +1,232 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfFrustum.h"
|
||||
#include "cvfVector3.h"
|
||||
#include "cvfBoundingBox.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(FrustumTest, BasicConstruction)
|
||||
{
|
||||
Frustum f1;
|
||||
Frustum f2(f1);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(FrustumTest, Operators)
|
||||
{
|
||||
Frustum f1;
|
||||
Frustum f2;
|
||||
|
||||
Vec3d center(0.0, 0.0, 0.0);
|
||||
double radius = 1.0;
|
||||
|
||||
Plane planeBottom; planeBottom.setFromPointAndNormal(center - (Vec3d::Y_AXIS*radius), Vec3d::Y_AXIS);
|
||||
Plane planeTop; planeTop.setFromPointAndNormal( center + (Vec3d::Y_AXIS*radius), -Vec3d::Y_AXIS);
|
||||
Plane planeLeft; planeLeft.setFromPointAndNormal( center - (Vec3d::X_AXIS*radius), Vec3d::X_AXIS);
|
||||
Plane planeRight; planeRight.setFromPointAndNormal( center + (Vec3d::X_AXIS*radius), -Vec3d::X_AXIS);
|
||||
Plane planeFront; planeFront.setFromPointAndNormal( center - (Vec3d::Z_AXIS*radius), Vec3d::Z_AXIS);
|
||||
Plane planeBack; planeBack.setFromPointAndNormal( center + (Vec3d::Z_AXIS*radius), -Vec3d::Z_AXIS);
|
||||
|
||||
f1.setPlane(Frustum::BOTTOM, planeBottom);
|
||||
f1.setPlane(Frustum::TOP, planeTop);
|
||||
f1.setPlane(Frustum::LEFT, planeLeft);
|
||||
f1.setPlane(Frustum::RIGHT, planeRight);
|
||||
f1.setPlane(Frustum::FRONT, planeFront);
|
||||
f1.setPlane(Frustum::BACK, planeBack);
|
||||
|
||||
EXPECT_FALSE(f1 == f2);
|
||||
EXPECT_TRUE(f1 != f2);
|
||||
|
||||
f1 = f2;
|
||||
EXPECT_TRUE(f1 == f2);
|
||||
EXPECT_FALSE(f1 != f2);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(FrustumTest, SetGetPlane)
|
||||
{
|
||||
Frustum f;
|
||||
|
||||
Vec3d center(0.0, 0.0, 0.0);
|
||||
double radius = 1.0;
|
||||
|
||||
Plane planeBottom; planeBottom.setFromPointAndNormal(center - (Vec3d::Y_AXIS*radius), Vec3d::Y_AXIS);
|
||||
Plane planeTop; planeTop.setFromPointAndNormal( center + (Vec3d::Y_AXIS*radius), -Vec3d::Y_AXIS);
|
||||
Plane planeLeft; planeLeft.setFromPointAndNormal( center - (Vec3d::X_AXIS*radius), Vec3d::X_AXIS);
|
||||
Plane planeRight; planeRight.setFromPointAndNormal( center + (Vec3d::X_AXIS*radius), -Vec3d::X_AXIS);
|
||||
Plane planeFront; planeFront.setFromPointAndNormal( center - (Vec3d::Z_AXIS*radius), Vec3d::Z_AXIS);
|
||||
Plane planeBack; planeBack.setFromPointAndNormal( center + (Vec3d::Z_AXIS*radius), -Vec3d::Z_AXIS);
|
||||
|
||||
f.setPlane(Frustum::BOTTOM, planeBottom);
|
||||
f.setPlane(Frustum::TOP, planeTop);
|
||||
f.setPlane(Frustum::LEFT, planeLeft);
|
||||
|
||||
Plane fPlaneBottom = f.plane(Frustum::BOTTOM);
|
||||
Plane fPlaneTop = f.plane(Frustum::TOP);
|
||||
Plane fPlaneLeft = f.plane(Frustum::LEFT);
|
||||
Plane fPlaneRight = f.plane(Frustum::RIGHT);
|
||||
Plane fPlaneFront = f.plane(Frustum::FRONT);
|
||||
Plane fPlaneBack = f.plane(Frustum::BACK);
|
||||
|
||||
// Check existence
|
||||
EXPECT_TRUE( fPlaneBottom.isValid());
|
||||
EXPECT_TRUE( fPlaneTop.isValid());
|
||||
EXPECT_TRUE( fPlaneLeft.isValid());
|
||||
EXPECT_FALSE(fPlaneRight.isValid());
|
||||
EXPECT_FALSE(fPlaneFront.isValid());
|
||||
EXPECT_FALSE(fPlaneBack.isValid());
|
||||
|
||||
// Check if the planes are correct
|
||||
EXPECT_TRUE(fPlaneBottom == planeBottom);
|
||||
EXPECT_TRUE(fPlaneTop == planeTop);
|
||||
EXPECT_TRUE(fPlaneLeft == planeLeft);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(FrustumTest, IsOutsidePoint)
|
||||
{
|
||||
Frustum f;
|
||||
|
||||
Vec3d center(0.0, 0.0, 0.0);
|
||||
double radius = 1.0;
|
||||
|
||||
Plane planeBottom; planeBottom.setFromPointAndNormal(center - (Vec3d::Y_AXIS*radius), Vec3d::Y_AXIS);
|
||||
Plane planeTop; planeTop.setFromPointAndNormal( center + (Vec3d::Y_AXIS*radius), -Vec3d::Y_AXIS);
|
||||
Plane planeLeft; planeLeft.setFromPointAndNormal( center - (Vec3d::X_AXIS*radius), Vec3d::X_AXIS);
|
||||
Plane planeRight; planeRight.setFromPointAndNormal( center + (Vec3d::X_AXIS*radius), -Vec3d::X_AXIS);
|
||||
Plane planeFront; planeFront.setFromPointAndNormal( center - (Vec3d::Z_AXIS*radius), Vec3d::Z_AXIS);
|
||||
Plane planeBack; planeBack.setFromPointAndNormal( center + (Vec3d::Z_AXIS*radius), -Vec3d::Z_AXIS);
|
||||
|
||||
f.setPlane(Frustum::BOTTOM, planeBottom);
|
||||
f.setPlane(Frustum::TOP, planeTop);
|
||||
f.setPlane(Frustum::LEFT, planeLeft);
|
||||
f.setPlane(Frustum::RIGHT, planeRight);
|
||||
f.setPlane(Frustum::FRONT, planeFront);
|
||||
f.setPlane(Frustum::BACK, planeBack);
|
||||
|
||||
EXPECT_FALSE(f.isOutside(center + Vec3d::X_AXIS*radius*0.9)); // Inside
|
||||
EXPECT_FALSE(f.isOutside(center + Vec3d::X_AXIS*radius)); // On boundary
|
||||
EXPECT_TRUE( f.isOutside(center + Vec3d::X_AXIS*radius*1.1)); // Outside
|
||||
|
||||
EXPECT_FALSE(f.isOutside(center + Vec3d::Y_AXIS*radius*0.9)); // Inside
|
||||
EXPECT_FALSE(f.isOutside(center + Vec3d::Y_AXIS*radius)); // On boundary
|
||||
EXPECT_TRUE( f.isOutside(center + Vec3d::Y_AXIS*radius*1.1)); // Outside
|
||||
|
||||
EXPECT_FALSE(f.isOutside(center + Vec3d::Z_AXIS*radius*0.9)); // Inside
|
||||
EXPECT_FALSE(f.isOutside(center + Vec3d::Z_AXIS*radius)); // On boundary
|
||||
EXPECT_TRUE( f.isOutside(center + Vec3d::Z_AXIS*radius*1.1)); // Outside
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(FrustumTest, IsOutsideBoundingBox)
|
||||
{
|
||||
Frustum f;
|
||||
|
||||
Vec3d center(0.0, 0.0, 0.0);
|
||||
double radius = 1.0;
|
||||
|
||||
Plane planeBottom; planeBottom.setFromPointAndNormal(center - (Vec3d::Y_AXIS*radius), Vec3d::Y_AXIS);
|
||||
Plane planeTop; planeTop.setFromPointAndNormal( center + (Vec3d::Y_AXIS*radius), -Vec3d::Y_AXIS);
|
||||
Plane planeLeft; planeLeft.setFromPointAndNormal( center - (Vec3d::X_AXIS*radius), Vec3d::X_AXIS);
|
||||
Plane planeRight; planeRight.setFromPointAndNormal( center + (Vec3d::X_AXIS*radius), -Vec3d::X_AXIS);
|
||||
Plane planeFront; planeFront.setFromPointAndNormal( center - (Vec3d::Z_AXIS*radius), Vec3d::Z_AXIS);
|
||||
Plane planeBack; planeBack.setFromPointAndNormal( center + (Vec3d::Z_AXIS*radius), -Vec3d::Z_AXIS);
|
||||
|
||||
f.setPlane(Frustum::BOTTOM, planeBottom);
|
||||
f.setPlane(Frustum::TOP, planeTop);
|
||||
f.setPlane(Frustum::LEFT, planeLeft);
|
||||
f.setPlane(Frustum::RIGHT, planeRight);
|
||||
f.setPlane(Frustum::FRONT, planeFront);
|
||||
f.setPlane(Frustum::BACK, planeBack);
|
||||
|
||||
Vec3d min = center - (Vec3d::X_AXIS*radius) - (Vec3d::Y_AXIS*radius) - (Vec3d::Z_AXIS*radius);
|
||||
Vec3d max = center + (Vec3d::X_AXIS*radius) + (Vec3d::Y_AXIS*radius) + (Vec3d::Z_AXIS*radius);
|
||||
Vec3d diagonal = max - min;
|
||||
|
||||
|
||||
// Inside tests
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
// Test when frustum = boundingbox
|
||||
EXPECT_FALSE(f.isOutside(BoundingBox(min, max)));
|
||||
|
||||
// Test when boundingbox is inside frustum
|
||||
EXPECT_FALSE(f.isOutside(BoundingBox(min + diagonal*0.1, max - diagonal*0.1)));
|
||||
|
||||
// Test when boundingbox envelops the frustum frustum
|
||||
EXPECT_FALSE(f.isOutside(BoundingBox(min - diagonal*0.1, max + diagonal*0.1)));
|
||||
|
||||
// Test when min is inside and max outside frustum (Partly inside and outside)
|
||||
EXPECT_FALSE(f.isOutside(BoundingBox(min + diagonal*0.1, max + diagonal*0.1)));
|
||||
|
||||
// Test when min is outside and max inside frustum (Partly inside and outside)
|
||||
EXPECT_FALSE(f.isOutside(BoundingBox(min - diagonal*0.1, max - diagonal*0.1)));
|
||||
|
||||
|
||||
// Outside test
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
// Test both min an max is below and to the left of the frustum
|
||||
EXPECT_TRUE(f.isOutside(BoundingBox(min - diagonal*0.5, max - diagonal*1.4)));
|
||||
|
||||
// Test both min an max is above and to the right of the frustum
|
||||
EXPECT_TRUE(f.isOutside(BoundingBox(min + diagonal*1.4, max + diagonal*0.5)));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,372 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfGeometryBuilder.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
#include "utestGeometryBuilders.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderTest, CheckImplOfPureVirtualMembers)
|
||||
{
|
||||
Vec3fArray vertexArr;
|
||||
vertexArr.reserve(3);
|
||||
vertexArr.add(Vec3f::X_AXIS);
|
||||
vertexArr.add(Vec3f::Y_AXIS);
|
||||
vertexArr.add(Vec3f::Z_AXIS);
|
||||
|
||||
BuilderTris b;
|
||||
int indexOfFirstVertex = b.addVertices(vertexArr);
|
||||
EXPECT_EQ(0, indexOfFirstVertex);
|
||||
EXPECT_EQ(3u, b.vertexArr.size());
|
||||
EXPECT_EQ(3, b.vertexCount());
|
||||
|
||||
indexOfFirstVertex = b.addVertices(vertexArr);
|
||||
EXPECT_EQ(3, indexOfFirstVertex);
|
||||
EXPECT_EQ(6u, b.vertexArr.size());
|
||||
|
||||
|
||||
ASSERT_EQ(0u, b.triArr.size());
|
||||
b.addTriangle(10, 11, 12);
|
||||
ASSERT_EQ(3u, b.triArr.size());
|
||||
EXPECT_EQ(10, b.triArr[0]);
|
||||
EXPECT_EQ(11, b.triArr[1]);
|
||||
EXPECT_EQ(12, b.triArr[2]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderTest, AddSingleTriangleFromVertices)
|
||||
{
|
||||
const Vec3f v0(0, 0, 0);
|
||||
const Vec3f v1(1, 0, 0);
|
||||
const Vec3f v2(2, 0, 0);
|
||||
|
||||
BuilderTris b;
|
||||
b.addTriangleByVertices(v0, v1, v2);
|
||||
EXPECT_EQ(3u, b.vertexArr.size());
|
||||
ASSERT_EQ(3u, b.triArr.size());
|
||||
|
||||
EXPECT_EQ(0, b.triArr[0]);
|
||||
EXPECT_EQ(1, b.triArr[1]);
|
||||
EXPECT_EQ(2, b.triArr[2]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderTest, AddMultipleTriangles)
|
||||
{
|
||||
IntArray indices;
|
||||
indices.reserve(6);
|
||||
indices.add(0); indices.add(1); indices.add(2);
|
||||
indices.add(10); indices.add(11); indices.add(12);
|
||||
|
||||
BuilderTris b;
|
||||
b.addTriangles(indices);
|
||||
ASSERT_EQ(6u, b.triArr.size());
|
||||
EXPECT_EQ(0, b.triArr[0]);
|
||||
EXPECT_EQ(1, b.triArr[1]);
|
||||
EXPECT_EQ(2, b.triArr[2]);
|
||||
EXPECT_EQ(10, b.triArr[3]);
|
||||
EXPECT_EQ(11, b.triArr[4]);
|
||||
EXPECT_EQ(12, b.triArr[5]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderTest, AddTriangleFan)
|
||||
{
|
||||
UIntArray indices;
|
||||
indices.reserve(5);
|
||||
indices.add(0);
|
||||
indices.add(1);
|
||||
indices.add(2);
|
||||
indices.add(3);
|
||||
indices.add(4);
|
||||
|
||||
BuilderTris b;
|
||||
b.addTriangleFan(indices);
|
||||
ASSERT_EQ(9u, b.triArr.size());
|
||||
|
||||
EXPECT_EQ(0, b.triArr[0]);
|
||||
EXPECT_EQ(1, b.triArr[1]);
|
||||
EXPECT_EQ(2, b.triArr[2]);
|
||||
|
||||
EXPECT_EQ(0, b.triArr[3]);
|
||||
EXPECT_EQ(2, b.triArr[4]);
|
||||
EXPECT_EQ(3, b.triArr[5]);
|
||||
|
||||
EXPECT_EQ(0, b.triArr[6]);
|
||||
EXPECT_EQ(3, b.triArr[7]);
|
||||
EXPECT_EQ(4, b.triArr[8]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderTest, AddTriangleStrip)
|
||||
{
|
||||
UIntArray indices;
|
||||
indices.reserve(6);
|
||||
indices.add(0);
|
||||
indices.add(1);
|
||||
indices.add(2);
|
||||
indices.add(3);
|
||||
indices.add(4);
|
||||
indices.add(5);
|
||||
|
||||
BuilderTris b;
|
||||
b.addTriangleStrip(indices);
|
||||
ASSERT_EQ(12u, b.triArr.size());
|
||||
|
||||
EXPECT_EQ(0, b.triArr[0]);
|
||||
EXPECT_EQ(1, b.triArr[1]);
|
||||
EXPECT_EQ(2, b.triArr[2]);
|
||||
|
||||
EXPECT_EQ(2, b.triArr[3]);
|
||||
EXPECT_EQ(1, b.triArr[4]);
|
||||
EXPECT_EQ(3, b.triArr[5]);
|
||||
|
||||
EXPECT_EQ(2, b.triArr[6]);
|
||||
EXPECT_EQ(3, b.triArr[7]);
|
||||
EXPECT_EQ(4, b.triArr[8]);
|
||||
|
||||
EXPECT_EQ(4, b.triArr[9]);
|
||||
EXPECT_EQ(3, b.triArr[10]);
|
||||
EXPECT_EQ(5, b.triArr[11]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderTest, AddSingleQuad)
|
||||
{
|
||||
BuilderTris b;
|
||||
b.addQuad(10, 11, 12, 13);
|
||||
ASSERT_EQ(6u, b.triArr.size());
|
||||
|
||||
EXPECT_EQ(10, b.triArr[0]);
|
||||
EXPECT_EQ(11, b.triArr[1]);
|
||||
EXPECT_EQ(12, b.triArr[2]);
|
||||
EXPECT_EQ(10, b.triArr[3]);
|
||||
EXPECT_EQ(12, b.triArr[4]);
|
||||
EXPECT_EQ(13, b.triArr[5]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderTest, AddMultipleQuads)
|
||||
{
|
||||
IntArray indices;
|
||||
indices.reserve(8);
|
||||
indices.add(0); indices.add(1); indices.add(2); indices.add(3);
|
||||
indices.add(10); indices.add(11); indices.add(12); indices.add(13);
|
||||
|
||||
BuilderTris b;
|
||||
b.addQuads(indices);
|
||||
ASSERT_EQ(12u, b.triArr.size());
|
||||
|
||||
EXPECT_EQ(0, b.triArr[0]);
|
||||
EXPECT_EQ(1, b.triArr[1]);
|
||||
EXPECT_EQ(2, b.triArr[2]);
|
||||
EXPECT_EQ(0, b.triArr[3]);
|
||||
EXPECT_EQ(2, b.triArr[4]);
|
||||
EXPECT_EQ(3, b.triArr[5]);
|
||||
|
||||
EXPECT_EQ(10, b.triArr[6]);
|
||||
EXPECT_EQ(11, b.triArr[7]);
|
||||
EXPECT_EQ(12, b.triArr[8]);
|
||||
EXPECT_EQ(10, b.triArr[9]);
|
||||
EXPECT_EQ(12, b.triArr[10]);
|
||||
EXPECT_EQ(13, b.triArr[11]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderTest, AddQuadStrip)
|
||||
{
|
||||
// v0 v2 v4 v6 Resulting quads:
|
||||
// *-----*-----*-----* q1: v0, v1, v3, v2
|
||||
// | | | | q2: v2, v3, v5, v4
|
||||
// | | | | q3: v4, v5, v7, v6
|
||||
// | | | |
|
||||
// *-----*-----*-----*
|
||||
// v1 v3 v5 v7
|
||||
|
||||
UIntArray indices;
|
||||
indices.reserve(8);
|
||||
indices.add(0);
|
||||
indices.add(1);
|
||||
indices.add(2);
|
||||
indices.add(3);
|
||||
indices.add(4);
|
||||
indices.add(5);
|
||||
indices.add(6);
|
||||
indices.add(7);
|
||||
|
||||
BuilderTris b;
|
||||
b.addQuadStrip(indices);
|
||||
ASSERT_EQ(18u, b.triArr.size());
|
||||
|
||||
EXPECT_EQ(0, b.triArr[0]);
|
||||
EXPECT_EQ(1, b.triArr[1]);
|
||||
EXPECT_EQ(3, b.triArr[2]);
|
||||
EXPECT_EQ(0, b.triArr[3]);
|
||||
EXPECT_EQ(3, b.triArr[4]);
|
||||
EXPECT_EQ(2, b.triArr[5]);
|
||||
|
||||
EXPECT_EQ(2, b.triArr[6]);
|
||||
EXPECT_EQ(3, b.triArr[7]);
|
||||
EXPECT_EQ(5, b.triArr[8]);
|
||||
EXPECT_EQ(2, b.triArr[9]);
|
||||
EXPECT_EQ(5, b.triArr[10]);
|
||||
EXPECT_EQ(4, b.triArr[11]);
|
||||
|
||||
EXPECT_EQ(4, b.triArr[12]);
|
||||
EXPECT_EQ(5, b.triArr[13]);
|
||||
EXPECT_EQ(7, b.triArr[14]);
|
||||
EXPECT_EQ(4, b.triArr[15]);
|
||||
EXPECT_EQ(7, b.triArr[16]);
|
||||
EXPECT_EQ(6, b.triArr[17]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderTest, AddSingleQuadFromVertices)
|
||||
{
|
||||
const Vec3f v0(0, 0, 0);
|
||||
const Vec3f v1(1, 0, 0);
|
||||
const Vec3f v2(2, 0, 0);
|
||||
const Vec3f v3(3, 0, 0);
|
||||
|
||||
BuilderTris b;
|
||||
b.addQuadByVertices(v0, v1, v2, v3);
|
||||
EXPECT_EQ(4u, b.vertexArr.size());
|
||||
ASSERT_EQ(6u, b.triArr.size());
|
||||
|
||||
EXPECT_EQ(0, b.triArr[0]);
|
||||
EXPECT_EQ(1, b.triArr[1]);
|
||||
EXPECT_EQ(2, b.triArr[2]);
|
||||
EXPECT_EQ(0, b.triArr[3]);
|
||||
EXPECT_EQ(2, b.triArr[4]);
|
||||
EXPECT_EQ(3, b.triArr[5]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderTest, AddFace)
|
||||
{
|
||||
BuilderTris b;
|
||||
|
||||
{
|
||||
UIntArray indices;
|
||||
indices.reserve(3);
|
||||
indices.add(0);
|
||||
indices.add(1);
|
||||
indices.add(2);
|
||||
b.addFace(indices);
|
||||
}
|
||||
|
||||
{
|
||||
UIntArray indices;
|
||||
indices.reserve(4);
|
||||
indices.add(10);
|
||||
indices.add(11);
|
||||
indices.add(12);
|
||||
indices.add(13);
|
||||
b.addFace(indices);
|
||||
}
|
||||
|
||||
{
|
||||
UIntArray indices;
|
||||
indices.reserve(5);
|
||||
indices.add(20);
|
||||
indices.add(21);
|
||||
indices.add(22);
|
||||
indices.add(23);
|
||||
indices.add(24);
|
||||
b.addFace(indices);
|
||||
}
|
||||
|
||||
ASSERT_EQ(18u, b.triArr.size());
|
||||
|
||||
EXPECT_EQ(0, b.triArr[0]);
|
||||
EXPECT_EQ(1, b.triArr[1]);
|
||||
EXPECT_EQ(2, b.triArr[2]);
|
||||
|
||||
EXPECT_EQ(10, b.triArr[3]);
|
||||
EXPECT_EQ(11, b.triArr[4]);
|
||||
EXPECT_EQ(12, b.triArr[5]);
|
||||
EXPECT_EQ(10, b.triArr[6]);
|
||||
EXPECT_EQ(12, b.triArr[7]);
|
||||
EXPECT_EQ(13, b.triArr[8]);
|
||||
|
||||
EXPECT_EQ(20, b.triArr[9]);
|
||||
EXPECT_EQ(21, b.triArr[10]);
|
||||
EXPECT_EQ(22, b.triArr[11]);
|
||||
EXPECT_EQ(20, b.triArr[12]);
|
||||
EXPECT_EQ(22, b.triArr[13]);
|
||||
EXPECT_EQ(23, b.triArr[14]);
|
||||
EXPECT_EQ(20, b.triArr[15]);
|
||||
EXPECT_EQ(23, b.triArr[16]);
|
||||
EXPECT_EQ(24, b.triArr[17]);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfGeometryBuilderFaceList.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderFaceList, BasicConstruction)
|
||||
{
|
||||
GeometryBuilderFaceList b;
|
||||
ref<Vec3fArray> vertices = b.vertices();
|
||||
ref<UIntArray> faceList = b.faceList();
|
||||
EXPECT_EQ(0u, vertices->size());
|
||||
EXPECT_EQ(0u, faceList->size());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderFaceList, AddVertices)
|
||||
{
|
||||
Vec3fArray inputVertexArr;
|
||||
inputVertexArr.reserve(3);
|
||||
inputVertexArr.add(Vec3f::X_AXIS);
|
||||
inputVertexArr.add(Vec3f::Y_AXIS);
|
||||
inputVertexArr.add(Vec3f::Z_AXIS);
|
||||
|
||||
GeometryBuilderFaceList b;
|
||||
int indexOfFirstVertex = b.addVertices(inputVertexArr);
|
||||
EXPECT_EQ(0, indexOfFirstVertex);
|
||||
EXPECT_EQ(3u, b.vertices()->size());
|
||||
|
||||
indexOfFirstVertex = b.addVertices(inputVertexArr);
|
||||
EXPECT_EQ(3, indexOfFirstVertex);
|
||||
|
||||
ref<Vec3fArray> va = b.vertices();
|
||||
EXPECT_EQ(6u, va->size());
|
||||
|
||||
EXPECT_TRUE(va->get(0) == Vec3f::X_AXIS);
|
||||
EXPECT_TRUE(va->get(1) == Vec3f::Y_AXIS);
|
||||
EXPECT_TRUE(va->get(2) == Vec3f::Z_AXIS);
|
||||
EXPECT_TRUE(va->get(3) == Vec3f::X_AXIS);
|
||||
EXPECT_TRUE(va->get(4) == Vec3f::Y_AXIS);
|
||||
EXPECT_TRUE(va->get(5) == Vec3f::Z_AXIS);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderFaceList, AddTriangle)
|
||||
{
|
||||
GeometryBuilderFaceList b;
|
||||
ASSERT_EQ(0u, b.faceList()->size());
|
||||
|
||||
b.addTriangle(10, 11, 12);
|
||||
ref<UIntArray> faceList = b.faceList();
|
||||
|
||||
ASSERT_EQ(4u, faceList->size());
|
||||
ASSERT_EQ(3, faceList->get(0));
|
||||
EXPECT_EQ(10, faceList->get(1));
|
||||
EXPECT_EQ(11, faceList->get(2));
|
||||
EXPECT_EQ(12, faceList->get(3));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderFaceList, AddQuad)
|
||||
{
|
||||
GeometryBuilderFaceList b;
|
||||
ASSERT_EQ(0u, b.faceList()->size());
|
||||
|
||||
b.addQuad(10, 11, 12, 13);
|
||||
ref<UIntArray> faceList = b.faceList();
|
||||
|
||||
ASSERT_EQ(5u, faceList->size());
|
||||
ASSERT_EQ(4, faceList->get(0));
|
||||
EXPECT_EQ(10, faceList->get(1));
|
||||
EXPECT_EQ(11, faceList->get(2));
|
||||
EXPECT_EQ(12, faceList->get(3));
|
||||
EXPECT_EQ(13, faceList->get(4));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfGeometryBuilderTriangles.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderTrianglesTest, BasicConstruction)
|
||||
{
|
||||
GeometryBuilderTriangles b;
|
||||
ref<Vec3fArray> vertices = b.vertices();
|
||||
ref<UIntArray> faceList = b.triangles();
|
||||
EXPECT_EQ(0u, vertices->size());
|
||||
EXPECT_EQ(0u, faceList->size());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderTrianglesTest, AddVertices)
|
||||
{
|
||||
Vec3fArray inputVertexArr;
|
||||
inputVertexArr.reserve(3);
|
||||
inputVertexArr.add(Vec3f::X_AXIS);
|
||||
inputVertexArr.add(Vec3f::Y_AXIS);
|
||||
inputVertexArr.add(Vec3f::Z_AXIS);
|
||||
|
||||
GeometryBuilderTriangles b;
|
||||
int indexOfFirstVertex = b.addVertices(inputVertexArr);
|
||||
EXPECT_EQ(0, indexOfFirstVertex);
|
||||
EXPECT_EQ(3u, b.vertices()->size());
|
||||
|
||||
indexOfFirstVertex = b.addVertices(inputVertexArr);
|
||||
EXPECT_EQ(3, indexOfFirstVertex);
|
||||
|
||||
ref<Vec3fArray> va = b.vertices();
|
||||
EXPECT_EQ(6u, va->size());
|
||||
|
||||
EXPECT_TRUE(va->get(0) == Vec3f::X_AXIS);
|
||||
EXPECT_TRUE(va->get(1) == Vec3f::Y_AXIS);
|
||||
EXPECT_TRUE(va->get(2) == Vec3f::Z_AXIS);
|
||||
EXPECT_TRUE(va->get(3) == Vec3f::X_AXIS);
|
||||
EXPECT_TRUE(va->get(4) == Vec3f::Y_AXIS);
|
||||
EXPECT_TRUE(va->get(5) == Vec3f::Z_AXIS);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderTrianglesTest, AddTriangle)
|
||||
{
|
||||
GeometryBuilderTriangles b;
|
||||
ASSERT_EQ(0u, b.triangles()->size());
|
||||
|
||||
b.addTriangle(10, 11, 12);
|
||||
ref<UIntArray> tris = b.triangles();
|
||||
|
||||
ASSERT_EQ(3u, tris->size());
|
||||
EXPECT_EQ(10, tris->get(0));
|
||||
EXPECT_EQ(11, tris->get(1));
|
||||
EXPECT_EQ(12, tris->get(2));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderTrianglesTest, AddQuad)
|
||||
{
|
||||
GeometryBuilderTriangles b;
|
||||
ASSERT_EQ(0u, b.triangles()->size());
|
||||
|
||||
b.addQuad(10, 11, 12, 13);
|
||||
ref<UIntArray> tris = b.triangles();
|
||||
|
||||
ASSERT_EQ(6u, tris->size());
|
||||
EXPECT_EQ(10, tris->get(0));
|
||||
EXPECT_EQ(11, tris->get(1));
|
||||
EXPECT_EQ(12, tris->get(2));
|
||||
EXPECT_EQ(10, tris->get(3));
|
||||
EXPECT_EQ(12, tris->get(4));
|
||||
EXPECT_EQ(13, tris->get(5));
|
||||
}
|
||||
|
||||
472
Fwk/VizFwk/Tests/LibGeometry_UnitTests/cvfGeometryUtils-Test.cpp
Normal file
472
Fwk/VizFwk/Tests/LibGeometry_UnitTests/cvfGeometryUtils-Test.cpp
Normal file
@@ -0,0 +1,472 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfGeometryUtils.h"
|
||||
#include "cvfGeometryBuilderFaceList.h"
|
||||
#include "cvfBoundingBox.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryUtilsTest, CreatePatch)
|
||||
{
|
||||
// v8-----v9----v10----v11
|
||||
// | | | |
|
||||
// origin | | | |
|
||||
// + vunit v4-----v5-----v6-----v7
|
||||
// | | | |
|
||||
// | | | |
|
||||
// v0-----v1-----v2-----v3
|
||||
// origin origin
|
||||
// + uUnit
|
||||
|
||||
GeometryBuilderFaceList builder;
|
||||
|
||||
const Vec3f origin(10, 20, 2);
|
||||
const Vec3f u(2, 0, 0);
|
||||
const Vec3f v(0, 1, 0);
|
||||
const int uCount = 3;
|
||||
const int vCount = 2;
|
||||
GeometryUtils::createPatch(origin, u, v, uCount, vCount, &builder);
|
||||
|
||||
ref<Vec3fArray> vertices = builder.vertices();
|
||||
ref<UIntArray> faceList = builder.faceList();
|
||||
|
||||
ASSERT_EQ(12, vertices->size());
|
||||
ASSERT_EQ(6*5, faceList->size());
|
||||
|
||||
BoundingBox bb;
|
||||
bb.add(*vertices);
|
||||
const Vec3d& bbMin = bb.min();
|
||||
const Vec3d& bbMax = bb.max();
|
||||
EXPECT_DOUBLE_EQ(10, bbMin.x());
|
||||
EXPECT_DOUBLE_EQ(20, bbMin.y());
|
||||
EXPECT_DOUBLE_EQ(2, bbMin.z());
|
||||
EXPECT_DOUBLE_EQ(16, bbMax.x());
|
||||
EXPECT_DOUBLE_EQ(22, bbMax.y());
|
||||
EXPECT_DOUBLE_EQ(2, bbMax.z());
|
||||
|
||||
// v0
|
||||
{
|
||||
const Vec3f& v = vertices->get(0);
|
||||
EXPECT_FLOAT_EQ(10, v.x());
|
||||
EXPECT_FLOAT_EQ(20, v.y());
|
||||
}
|
||||
|
||||
// v3
|
||||
{
|
||||
const Vec3f& v = vertices->get(3);
|
||||
EXPECT_FLOAT_EQ(16, v.x());
|
||||
EXPECT_FLOAT_EQ(20, v.y());
|
||||
}
|
||||
|
||||
// v11
|
||||
{
|
||||
const Vec3f& v = vertices->get(11);
|
||||
EXPECT_FLOAT_EQ(16, v.x());
|
||||
EXPECT_FLOAT_EQ(22, v.y());
|
||||
}
|
||||
|
||||
|
||||
// First quad
|
||||
int idx = 0*5;
|
||||
ASSERT_EQ(4, faceList->get(idx + 0));
|
||||
ASSERT_EQ(4, faceList->get(idx + 1));
|
||||
ASSERT_EQ(0, faceList->get(idx + 2));
|
||||
ASSERT_EQ(1, faceList->get(idx + 3));
|
||||
ASSERT_EQ(5, faceList->get(idx + 4));
|
||||
|
||||
// Third quad
|
||||
idx = 2*5;
|
||||
ASSERT_EQ(4, faceList->get(idx + 0));
|
||||
ASSERT_EQ(6, faceList->get(idx + 1));
|
||||
ASSERT_EQ(2, faceList->get(idx + 2));
|
||||
ASSERT_EQ(3, faceList->get(idx + 3));
|
||||
ASSERT_EQ(7, faceList->get(idx + 4));
|
||||
|
||||
// Last quad
|
||||
idx = 5*5;
|
||||
ASSERT_EQ(4, faceList->get(idx + 0));
|
||||
ASSERT_EQ(10, faceList->get(idx + 1));
|
||||
ASSERT_EQ(6, faceList->get(idx + 2));
|
||||
ASSERT_EQ(7, faceList->get(idx + 3));
|
||||
ASSERT_EQ(11, faceList->get(idx + 4));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryUtilsTest, CreateSphere)
|
||||
{
|
||||
GeometryBuilderFaceList builder;
|
||||
|
||||
|
||||
//
|
||||
// 1 .-------. 3
|
||||
// /\ /\ 3 triangles seen from
|
||||
// / \ / \ the top of the sphere
|
||||
// | \0/ |
|
||||
// | * |
|
||||
// \ | /
|
||||
// \ | /
|
||||
// `'-----'<27>
|
||||
// 2
|
||||
//
|
||||
//
|
||||
// 0
|
||||
// ..---|---..
|
||||
// 1/ | \3
|
||||
// /------|2---- \ Quadstrip seen from the side
|
||||
// 4|______5|_______|6
|
||||
// | | |
|
||||
// \------|8-----/
|
||||
// 7 \ | /9
|
||||
// `'--|--'<27>
|
||||
// 10
|
||||
GeometryUtils::createSphere(1, 3, 4, &builder);
|
||||
|
||||
ref<Vec3fArray> vertices = builder.vertices();
|
||||
ref<UIntArray> faceList = builder.faceList();
|
||||
|
||||
ASSERT_EQ(11u, vertices->size());
|
||||
ASSERT_EQ(42u + 12u, faceList->size());
|
||||
|
||||
int idx = 0;
|
||||
|
||||
// First row (Triangles)
|
||||
ASSERT_EQ(3, faceList->get(idx++));
|
||||
ASSERT_EQ(0, faceList->get(idx++));
|
||||
ASSERT_EQ(1, faceList->get(idx++));
|
||||
ASSERT_EQ(2, faceList->get(idx++));
|
||||
|
||||
ASSERT_EQ(3, faceList->get(idx++));
|
||||
ASSERT_EQ(0, faceList->get(idx++));
|
||||
ASSERT_EQ(2, faceList->get(idx++));
|
||||
ASSERT_EQ(3, faceList->get(idx++));
|
||||
|
||||
ASSERT_EQ(3, faceList->get(idx++));
|
||||
ASSERT_EQ(0, faceList->get(idx++));
|
||||
ASSERT_EQ(3, faceList->get(idx++));
|
||||
ASSERT_EQ(1, faceList->get(idx++));
|
||||
|
||||
// Second row (Quads)
|
||||
ASSERT_EQ(4, faceList->get(idx++));
|
||||
ASSERT_EQ(1, faceList->get(idx++));
|
||||
ASSERT_EQ(4, faceList->get(idx++));
|
||||
ASSERT_EQ(5, faceList->get(idx++));
|
||||
ASSERT_EQ(2, faceList->get(idx++));
|
||||
|
||||
ASSERT_EQ(4, faceList->get(idx++));
|
||||
ASSERT_EQ(2, faceList->get(idx++));
|
||||
ASSERT_EQ(5, faceList->get(idx++));
|
||||
ASSERT_EQ(6, faceList->get(idx++));
|
||||
ASSERT_EQ(3, faceList->get(idx++));
|
||||
|
||||
ASSERT_EQ(4, faceList->get(idx++));
|
||||
ASSERT_EQ(3, faceList->get(idx++));
|
||||
ASSERT_EQ(6, faceList->get(idx++));
|
||||
ASSERT_EQ(4, faceList->get(idx++));
|
||||
ASSERT_EQ(1, faceList->get(idx++));
|
||||
|
||||
// Third row (Quads)
|
||||
ASSERT_EQ(4, faceList->get(idx++));
|
||||
ASSERT_EQ(4, faceList->get(idx++));
|
||||
ASSERT_EQ(7, faceList->get(idx++));
|
||||
ASSERT_EQ(8, faceList->get(idx++));
|
||||
ASSERT_EQ(5, faceList->get(idx++));
|
||||
|
||||
ASSERT_EQ(4, faceList->get(idx++));
|
||||
ASSERT_EQ(5, faceList->get(idx++));
|
||||
ASSERT_EQ(8, faceList->get(idx++));
|
||||
ASSERT_EQ(9, faceList->get(idx++));
|
||||
ASSERT_EQ(6, faceList->get(idx++));
|
||||
|
||||
ASSERT_EQ(4, faceList->get(idx++));
|
||||
ASSERT_EQ(6, faceList->get(idx++));
|
||||
ASSERT_EQ(9, faceList->get(idx++));
|
||||
ASSERT_EQ(7, faceList->get(idx++));
|
||||
ASSERT_EQ(4, faceList->get(idx++));
|
||||
|
||||
// Last row (Triangles)
|
||||
ASSERT_EQ(3, faceList->get(idx++));
|
||||
ASSERT_EQ(10,faceList->get(idx++));
|
||||
ASSERT_EQ(9, faceList->get(idx++));
|
||||
ASSERT_EQ(8, faceList->get(idx++));
|
||||
|
||||
ASSERT_EQ(3, faceList->get(idx++));
|
||||
ASSERT_EQ(10,faceList->get(idx++));
|
||||
ASSERT_EQ(8, faceList->get(idx++));
|
||||
ASSERT_EQ(7, faceList->get(idx++));
|
||||
|
||||
ASSERT_EQ(3, faceList->get(idx++));
|
||||
ASSERT_EQ(10,faceList->get(idx++));
|
||||
ASSERT_EQ(7, faceList->get(idx++));
|
||||
ASSERT_EQ(9, faceList->get(idx++));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryUtilsTest, IsConvexQuad)
|
||||
{
|
||||
{
|
||||
// a------d
|
||||
// | |
|
||||
// | |
|
||||
// b------c
|
||||
Vec3f a(-2, 2, 0);
|
||||
Vec3f b(-2, -2, 0);
|
||||
Vec3f c( 2, -2, 0);
|
||||
Vec3f d( 2, 2, 0);
|
||||
|
||||
EXPECT_TRUE(GeometryUtils::isConvexQuad(a, b, c, d));
|
||||
}
|
||||
|
||||
{
|
||||
// Arrow pointing left
|
||||
// d
|
||||
//
|
||||
// a c
|
||||
//
|
||||
// b
|
||||
Vec3f a(-2, 0, 0);
|
||||
Vec3f b( 2, -2, 0);
|
||||
Vec3f c( 1, 0, 0);
|
||||
Vec3f d( 2, 2, 0);
|
||||
|
||||
EXPECT_FALSE(GeometryUtils::isConvexQuad(a, b, c, d));
|
||||
}
|
||||
|
||||
{
|
||||
// Arrow pointing down
|
||||
// a c
|
||||
// d
|
||||
//
|
||||
// b
|
||||
Vec3f a(-2, 2, 0);
|
||||
Vec3f b( 0, -2, 0);
|
||||
Vec3f c( 2, 2, 0);
|
||||
Vec3f d( 0, 1, 0);
|
||||
|
||||
EXPECT_FALSE(GeometryUtils::isConvexQuad(a, b, c, d));
|
||||
}
|
||||
|
||||
{
|
||||
// Arrow pointing right
|
||||
// a
|
||||
//
|
||||
// b d
|
||||
//
|
||||
// c
|
||||
Vec3f a(-2, 2, 0);
|
||||
Vec3f b(-1, 0, 0);
|
||||
Vec3f c(-2, -2, 0);
|
||||
Vec3f d( 2, 0, 0);
|
||||
|
||||
EXPECT_FALSE(GeometryUtils::isConvexQuad(a, b, c, d));
|
||||
}
|
||||
|
||||
{
|
||||
// Arrow pointing up
|
||||
// a
|
||||
//
|
||||
// c
|
||||
// b d
|
||||
Vec3f a( 0, 2, 0);
|
||||
Vec3f b(-2, -2, 0);
|
||||
Vec3f c( 0, -1, 0);
|
||||
Vec3f d( 2, -2, 0);
|
||||
|
||||
EXPECT_FALSE(GeometryUtils::isConvexQuad(a, b, c, d));
|
||||
}
|
||||
|
||||
{
|
||||
// a---d
|
||||
// \ /
|
||||
// X
|
||||
// / \ Bowtie
|
||||
// c---b
|
||||
Vec3f a(-2, 2, 0);
|
||||
Vec3f b( 2, -2, 0);
|
||||
Vec3f c(-2, -2, 0);
|
||||
Vec3f d( 2, 2, 0);
|
||||
|
||||
EXPECT_FALSE(GeometryUtils::isConvexQuad(a, b, c, d));
|
||||
}
|
||||
|
||||
{
|
||||
// a--b--c--d
|
||||
Vec3f a(-2, 0, 0);
|
||||
Vec3f b(-1, 0, 0);
|
||||
Vec3f c( 1, 0, 0);
|
||||
Vec3f d( 2, 0, 0);
|
||||
|
||||
EXPECT_FALSE(GeometryUtils::isConvexQuad(a, b, c, d));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryUtilsTest, QuadNormal)
|
||||
{
|
||||
Vec3fArray va;
|
||||
va.reserve(4);
|
||||
va.add(Vec3f(10, 20, 3));
|
||||
va.add(Vec3f(11, 20, 3));
|
||||
va.add(Vec3f(11, 22, 3));
|
||||
va.add(Vec3f(10, 22, 3));
|
||||
|
||||
{
|
||||
Vec3f n = GeometryUtils::quadNormal(va[0], va[1], va[2], va[3]);
|
||||
EXPECT_NEAR(0, n.x(), 1e-10);
|
||||
EXPECT_NEAR(0, n.y(), 1e-10);
|
||||
EXPECT_NEAR(1, n.z(), 1e-10);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryUtilsTest, PolygonNormal)
|
||||
{
|
||||
Vec3fArray va;
|
||||
va.reserve(5);
|
||||
va.add(Vec3f(10, 20, 3));
|
||||
va.add(Vec3f(11, 20, 3));
|
||||
va.add(Vec3f(11, 22, 3));
|
||||
va.add(Vec3f(10, 22, 3));
|
||||
va.add(Vec3f(10, 21, 3));
|
||||
|
||||
{
|
||||
cvf::uint indices[] = { 0, 1, 2, 3, 4 };
|
||||
Vec3f n = GeometryUtils::polygonNormal(va, indices, 5);
|
||||
EXPECT_NEAR(0, n.x(), 1e-10);
|
||||
EXPECT_NEAR(0, n.y(), 1e-10);
|
||||
EXPECT_NEAR(1, n.z(), 1e-10);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryUtilsTest, RemoveUnusedVertices)
|
||||
{
|
||||
{
|
||||
UIntArray indices;
|
||||
indices.reserve(9);
|
||||
indices.add(2);
|
||||
indices.add(1);
|
||||
indices.add(0);
|
||||
indices.add(1);
|
||||
indices.add(2);
|
||||
indices.add(3);
|
||||
indices.add(6);
|
||||
indices.add(7);
|
||||
indices.add(8);
|
||||
|
||||
UIntArray newIndices, newToOldVertexMapping;
|
||||
GeometryUtils::removeUnusedVertices(indices, &newIndices, &newToOldVertexMapping, 10);
|
||||
EXPECT_EQ(9, newIndices.size());
|
||||
EXPECT_EQ(7, newToOldVertexMapping.size());
|
||||
|
||||
EXPECT_EQ(0, newIndices[0]);
|
||||
EXPECT_EQ(1, newIndices[1]);
|
||||
EXPECT_EQ(2, newIndices[2]);
|
||||
EXPECT_EQ(1, newIndices[3]);
|
||||
EXPECT_EQ(0, newIndices[4]);
|
||||
EXPECT_EQ(3, newIndices[5]);
|
||||
EXPECT_EQ(4, newIndices[6]);
|
||||
EXPECT_EQ(5, newIndices[7]);
|
||||
EXPECT_EQ(6, newIndices[8]);
|
||||
}
|
||||
|
||||
// Empty source arrays
|
||||
{
|
||||
UIntArray indices;
|
||||
|
||||
UIntArray newIndices, newToOldVertexMapping;
|
||||
GeometryUtils::removeUnusedVertices(indices, &newIndices, &newToOldVertexMapping, 10);
|
||||
size_t zero = 0;
|
||||
EXPECT_EQ(zero, newIndices.size());
|
||||
EXPECT_EQ(zero, newToOldVertexMapping.size());
|
||||
|
||||
// Test if NULL
|
||||
GeometryUtils::removeUnusedVertices(indices, NULL, &newToOldVertexMapping, 10);
|
||||
GeometryUtils::removeUnusedVertices(indices, &newIndices, NULL, 10);
|
||||
}
|
||||
|
||||
// All nodes are used, source and compact are equal
|
||||
{
|
||||
UIntArray indices;
|
||||
indices.reserve(9);
|
||||
indices.add(0);
|
||||
indices.add(1);
|
||||
indices.add(2);
|
||||
indices.add(1);
|
||||
indices.add(2);
|
||||
indices.add(3);
|
||||
indices.add(1);
|
||||
indices.add(2);
|
||||
indices.add(3);
|
||||
|
||||
UIntArray newIndices, newToOldVertexMapping;
|
||||
GeometryUtils::removeUnusedVertices(indices, &newIndices, &newToOldVertexMapping, 10);
|
||||
EXPECT_EQ(9, newIndices.size());
|
||||
EXPECT_EQ(4, newToOldVertexMapping.size());
|
||||
|
||||
EXPECT_EQ(indices[0], newIndices[0]);
|
||||
EXPECT_EQ(indices[1], newIndices[1]);
|
||||
EXPECT_EQ(indices[2], newIndices[2]);
|
||||
EXPECT_EQ(indices[3], newIndices[3]);
|
||||
EXPECT_EQ(indices[4], newIndices[4]);
|
||||
EXPECT_EQ(indices[5], newIndices[5]);
|
||||
EXPECT_EQ(indices[6], newIndices[6]);
|
||||
EXPECT_EQ(indices[7], newIndices[7]);
|
||||
EXPECT_EQ(indices[8], newIndices[8]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfMeshEdgeExtractor.h"
|
||||
#include "cvfMath.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MeshEdgeExtractorTest, EmptyOrNoInput)
|
||||
{
|
||||
MeshEdgeExtractor ee;
|
||||
|
||||
{
|
||||
ref<UIntArray> ind = ee.lineIndices();
|
||||
ASSERT_TRUE(ind.notNull());
|
||||
EXPECT_EQ(0, ind->size());
|
||||
}
|
||||
|
||||
UIntArray emptyArr;
|
||||
ee.addPrimitives(4, emptyArr);
|
||||
|
||||
{
|
||||
ref<UIntArray> ind = ee.lineIndices();
|
||||
ASSERT_TRUE(ind.notNull());
|
||||
EXPECT_EQ(0, ind->size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MeshEdgeExtractorTest, ThreeQuadsFromUIntArray)
|
||||
{
|
||||
// 3------4------5 9------8
|
||||
// | | | | |
|
||||
// | | | | |
|
||||
// 0------1------2 6------7
|
||||
|
||||
MeshEdgeExtractor ee;
|
||||
|
||||
// Two connected quads
|
||||
{
|
||||
UIntArray q;
|
||||
q.reserve(2*4);
|
||||
|
||||
// Observe different winding
|
||||
q.add(0); q.add(1); q.add(4); q.add(3);
|
||||
q.add(1); q.add(4); q.add(5); q.add(2);
|
||||
|
||||
ee.addPrimitives(4, q);
|
||||
}
|
||||
|
||||
// Single loose quad
|
||||
{
|
||||
UIntArray q;
|
||||
q.reserve(4);
|
||||
q.add(6); q.add(7); q.add(8); q.add(9);
|
||||
|
||||
ee.addPrimitives(4, q);
|
||||
}
|
||||
|
||||
ref<UIntArray> li = ee.lineIndices();
|
||||
ASSERT_EQ(2*11, li->size());
|
||||
|
||||
EXPECT_EQ(0, li->get(0)); EXPECT_EQ(1, li->get(1));
|
||||
EXPECT_EQ(0, li->get(2)); EXPECT_EQ(3, li->get(3));
|
||||
EXPECT_EQ(1, li->get(4)); EXPECT_EQ(2, li->get(5));
|
||||
EXPECT_EQ(1, li->get(6)); EXPECT_EQ(4, li->get(7));
|
||||
EXPECT_EQ(2, li->get(8)); EXPECT_EQ(5, li->get(9));
|
||||
EXPECT_EQ(3, li->get(10)); EXPECT_EQ(4, li->get(11));
|
||||
EXPECT_EQ(4, li->get(12)); EXPECT_EQ(5, li->get(13));
|
||||
|
||||
EXPECT_EQ(6, li->get(14)); EXPECT_EQ(7, li->get(15));
|
||||
EXPECT_EQ(6, li->get(16)); EXPECT_EQ(9, li->get(17));
|
||||
EXPECT_EQ(7, li->get(18)); EXPECT_EQ(8, li->get(19));
|
||||
EXPECT_EQ(8, li->get(20)); EXPECT_EQ(9, li->get(21));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MeshEdgeExtractorTest, PrimitiveMixFromRawArrays)
|
||||
{
|
||||
// 6----5
|
||||
// / \ *11
|
||||
// / \ *12
|
||||
// 8------7 4-----9
|
||||
// | |\ / |
|
||||
// | | \ / |
|
||||
// 0------1--2----3 10
|
||||
|
||||
const cvf::uint points[2] = { 11, 12 };
|
||||
const cvf::uint lines[4] = { 4, 9, 10, 9 };
|
||||
const cvf::uint tri[3] = { 1, 2, 7 };
|
||||
const cvf::uint quad[4] = { 0, 1, 7, 8 };
|
||||
const cvf::uint poly[6] = { 2, 3, 4, 5, 6, 7 };
|
||||
|
||||
MeshEdgeExtractor ee;
|
||||
ee.addPrimitives(1, points, 2);
|
||||
ee.addPrimitives(2, lines, 4);
|
||||
ee.addPrimitives(3, tri, 3);
|
||||
ee.addPrimitives(4, quad, 4);
|
||||
ee.addPrimitives(6, poly, 6);
|
||||
|
||||
UIntArray li = *ee.lineIndices();
|
||||
ASSERT_EQ(2*13, li.size());
|
||||
|
||||
EXPECT_EQ(0, li[ 0]); EXPECT_EQ(1, li[ 1]);
|
||||
EXPECT_EQ(0, li[ 2]); EXPECT_EQ(8, li[ 3]);
|
||||
EXPECT_EQ(1, li[ 4]); EXPECT_EQ(2, li[ 5]);
|
||||
EXPECT_EQ(1, li[ 6]); EXPECT_EQ(7, li[ 7]);
|
||||
EXPECT_EQ(2, li[ 8]); EXPECT_EQ(3, li[ 9]);
|
||||
EXPECT_EQ(2, li[10]); EXPECT_EQ(7, li[11]);
|
||||
EXPECT_EQ(3, li[12]); EXPECT_EQ(4, li[13]);
|
||||
EXPECT_EQ(4, li[14]); EXPECT_EQ(5, li[15]);
|
||||
EXPECT_EQ(4, li[16]); EXPECT_EQ(9, li[17]);
|
||||
EXPECT_EQ(5, li[18]); EXPECT_EQ(6, li[19]);
|
||||
EXPECT_EQ(6, li[20]); EXPECT_EQ(7, li[21]);
|
||||
EXPECT_EQ(7, li[22]); EXPECT_EQ(8, li[23]);
|
||||
EXPECT_EQ(9, li[24]); EXPECT_EQ(10,li[25]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MeshEdgeExtractorTest, PrimitiveMixFromFaceList)
|
||||
{
|
||||
// 6----5
|
||||
// / \ *11
|
||||
// / \ *12
|
||||
// 8------7 4-----9
|
||||
// | |\ / |
|
||||
// | | \ / |
|
||||
// 0------1--2----3 10
|
||||
|
||||
UIntArray fl;
|
||||
fl.reserve(26);
|
||||
|
||||
fl.add(1); fl.add(11);
|
||||
fl.add(1); fl.add(12);
|
||||
fl.add(2); fl.add(4); fl.add(9);
|
||||
fl.add(2); fl.add(10); fl.add(9);
|
||||
fl.add(3); fl.add(1); fl.add(2); fl.add(7);
|
||||
fl.add(4); fl.add(0); fl.add(1); fl.add(7); fl.add(8);
|
||||
fl.add(6); fl.add(2); fl.add(3); fl.add(4); fl.add(5); fl.add(6); fl.add(7);
|
||||
ASSERT_EQ(26, fl.size());
|
||||
|
||||
|
||||
MeshEdgeExtractor ee;
|
||||
ee.addFaceList(fl);
|
||||
|
||||
UIntArray li = *ee.lineIndices();
|
||||
ASSERT_EQ(2*13, li.size());
|
||||
|
||||
EXPECT_EQ(0, li[ 0]); EXPECT_EQ(1, li[ 1]);
|
||||
EXPECT_EQ(0, li[ 2]); EXPECT_EQ(8, li[ 3]);
|
||||
EXPECT_EQ(1, li[ 4]); EXPECT_EQ(2, li[ 5]);
|
||||
EXPECT_EQ(1, li[ 6]); EXPECT_EQ(7, li[ 7]);
|
||||
EXPECT_EQ(2, li[ 8]); EXPECT_EQ(3, li[ 9]);
|
||||
EXPECT_EQ(2, li[10]); EXPECT_EQ(7, li[11]);
|
||||
EXPECT_EQ(3, li[12]); EXPECT_EQ(4, li[13]);
|
||||
EXPECT_EQ(4, li[14]); EXPECT_EQ(5, li[15]);
|
||||
EXPECT_EQ(4, li[16]); EXPECT_EQ(9, li[17]);
|
||||
EXPECT_EQ(5, li[18]); EXPECT_EQ(6, li[19]);
|
||||
EXPECT_EQ(6, li[20]); EXPECT_EQ(7, li[21]);
|
||||
EXPECT_EQ(7, li[22]); EXPECT_EQ(8, li[23]);
|
||||
EXPECT_EQ(9, li[24]); EXPECT_EQ(10,li[25]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MeshEdgeExtractorTest, CollapsedQuads)
|
||||
{
|
||||
// 4------3 6,6
|
||||
// | |\ |
|
||||
// | | \ |
|
||||
// 0------1--2,2 5,5
|
||||
|
||||
const cvf::uint quads[12] = { 0, 1, 3, 4, 1, 2, 2, 3, 6, 5, 5, 6 };
|
||||
|
||||
MeshEdgeExtractor ee;
|
||||
ee.addPrimitives(4, quads, 12);
|
||||
|
||||
UIntArray li = *ee.lineIndices();
|
||||
ASSERT_EQ(2*7, li.size());
|
||||
|
||||
EXPECT_EQ(0, li[ 0]); EXPECT_EQ(1, li[ 1]);
|
||||
EXPECT_EQ(0, li[ 2]); EXPECT_EQ(4, li[ 3]);
|
||||
EXPECT_EQ(1, li[ 4]); EXPECT_EQ(2, li[ 5]);
|
||||
EXPECT_EQ(1, li[ 6]); EXPECT_EQ(3, li[ 7]);
|
||||
EXPECT_EQ(2, li[ 8]); EXPECT_EQ(3, li[ 9]);
|
||||
EXPECT_EQ(3, li[10]); EXPECT_EQ(4, li[11]);
|
||||
EXPECT_EQ(5, li[12]); EXPECT_EQ(6, li[13]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,390 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfOutlineEdgeExtractor.h"
|
||||
#include "cvfMath.h"
|
||||
#include "cvfEdgeKey.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OutlineEdgeExtractorTest, Constructor)
|
||||
{
|
||||
ref<Vec3fArray> va = new Vec3fArray;
|
||||
OutlineEdgeExtractor ee(0, *va);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OutlineEdgeExtractorTest, SinglePrimitives)
|
||||
{
|
||||
ref<Vec3fArray> va = new Vec3fArray;
|
||||
va->reserve(4);
|
||||
va->add(Vec3f(0, 0, 0));
|
||||
va->add(Vec3f(1, 0, 0));
|
||||
va->add(Vec3f(1, 1, 0));
|
||||
va->add(Vec3f(0, 1, 0));
|
||||
|
||||
// Point
|
||||
{
|
||||
const cvf::uint conn[1] = { 0 };
|
||||
OutlineEdgeExtractor ee(0, *va);
|
||||
ee.addPrimitives(1, conn, 1);
|
||||
|
||||
UIntArray li = *ee.lineIndices();
|
||||
ASSERT_EQ(0, li.size());
|
||||
}
|
||||
|
||||
// Line
|
||||
{
|
||||
const cvf::uint conn[2] = { 0, 1 };
|
||||
OutlineEdgeExtractor ee(0, *va);
|
||||
ee.addPrimitives(2, conn, 2);
|
||||
|
||||
UIntArray li = *ee.lineIndices();
|
||||
ASSERT_EQ(2, li.size());
|
||||
ASSERT_EQ(0, li[0]);
|
||||
ASSERT_EQ(1, li[1]);
|
||||
}
|
||||
|
||||
// Tri
|
||||
{
|
||||
const cvf::uint conn[3] = { 0, 1, 2 };
|
||||
OutlineEdgeExtractor ee(0, *va);
|
||||
ee.addPrimitives(3, conn, 3);
|
||||
|
||||
UIntArray li = *ee.lineIndices();
|
||||
ASSERT_EQ(6, li.size());
|
||||
ASSERT_EQ(0, li[0]);
|
||||
ASSERT_EQ(1, li[1]);
|
||||
ASSERT_EQ(0, li[2]);
|
||||
ASSERT_EQ(2, li[3]);
|
||||
ASSERT_EQ(1, li[4]);
|
||||
ASSERT_EQ(2, li[5]);
|
||||
}
|
||||
|
||||
// Quad
|
||||
{
|
||||
const cvf::uint conn[4] = { 0, 1, 2, 3};
|
||||
OutlineEdgeExtractor ee(0, *va);
|
||||
ee.addPrimitives(4, conn, 4);
|
||||
|
||||
UIntArray li = *ee.lineIndices();
|
||||
ASSERT_EQ(8, li.size());
|
||||
ASSERT_EQ(0, li[0]);
|
||||
ASSERT_EQ(1, li[1]);
|
||||
ASSERT_EQ(0, li[2]);
|
||||
ASSERT_EQ(3, li[3]);
|
||||
ASSERT_EQ(1, li[4]);
|
||||
ASSERT_EQ(2, li[5]);
|
||||
ASSERT_EQ(2, li[6]);
|
||||
ASSERT_EQ(3, li[7]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OutlineEdgeExtractorTest, CollapsedPrimitives)
|
||||
{
|
||||
ref<Vec3fArray> va = new Vec3fArray;
|
||||
va->reserve(4);
|
||||
va->add(Vec3f(0, 0, 0));
|
||||
va->add(Vec3f(1, 0, 0));
|
||||
va->add(Vec3f(1, 1, 0));
|
||||
|
||||
// Collapsed tris
|
||||
{
|
||||
const cvf::uint conn[3] = { 0, 1, 0 };
|
||||
OutlineEdgeExtractor ee(0, *va);
|
||||
ee.addPrimitives(3, conn, 3);
|
||||
|
||||
UIntArray li = *ee.lineIndices();
|
||||
ASSERT_EQ(2, li.size());
|
||||
EXPECT_EQ(0, li[0]);
|
||||
EXPECT_EQ(1, li[1]);
|
||||
}
|
||||
|
||||
{
|
||||
const cvf::uint conn[3] = { 0, 0, 1 };
|
||||
OutlineEdgeExtractor ee(0, *va);
|
||||
ee.addPrimitives(3, conn, 3);
|
||||
|
||||
UIntArray li = *ee.lineIndices();
|
||||
ASSERT_EQ(2, li.size());
|
||||
EXPECT_EQ(0, li[0]);
|
||||
EXPECT_EQ(1, li[1]);
|
||||
}
|
||||
|
||||
{
|
||||
const cvf::uint conn[3] = { 1, 1, 1 };
|
||||
OutlineEdgeExtractor ee(0, *va);
|
||||
ee.addPrimitives(3, conn, 3);
|
||||
|
||||
UIntArray li = *ee.lineIndices();
|
||||
EXPECT_EQ(0, li.size());
|
||||
}
|
||||
|
||||
|
||||
// Collapsed quads
|
||||
{
|
||||
const cvf::uint conn[4] = { 0, 1, 1, 2};
|
||||
OutlineEdgeExtractor ee(0, *va);
|
||||
ee.addPrimitives(4, conn, 4);
|
||||
|
||||
UIntArray li = *ee.lineIndices();
|
||||
ASSERT_EQ(6, li.size());
|
||||
EXPECT_EQ(0, li[0]);
|
||||
EXPECT_EQ(1, li[1]);
|
||||
EXPECT_EQ(0, li[2]);
|
||||
EXPECT_EQ(2, li[3]);
|
||||
EXPECT_EQ(1, li[4]);
|
||||
EXPECT_EQ(2, li[5]);
|
||||
}
|
||||
|
||||
{
|
||||
const cvf::uint conn[4] = { 0, 1, 2, 0};
|
||||
OutlineEdgeExtractor ee(0, *va);
|
||||
ee.addPrimitives(4, conn, 4);
|
||||
|
||||
UIntArray li = *ee.lineIndices();
|
||||
ASSERT_EQ(6, li.size());
|
||||
EXPECT_EQ(0, li[0]);
|
||||
EXPECT_EQ(1, li[1]);
|
||||
EXPECT_EQ(0, li[2]);
|
||||
EXPECT_EQ(2, li[3]);
|
||||
EXPECT_EQ(1, li[4]);
|
||||
EXPECT_EQ(2, li[5]);
|
||||
}
|
||||
|
||||
{
|
||||
const cvf::uint conn[4] = { 0, 1, 0, 1};
|
||||
OutlineEdgeExtractor ee(0, *va);
|
||||
ee.addPrimitives(4, conn, 4);
|
||||
|
||||
UIntArray li = *ee.lineIndices();
|
||||
ASSERT_EQ(2, li.size());
|
||||
EXPECT_EQ(0, li[0]);
|
||||
EXPECT_EQ(1, li[1]);
|
||||
}
|
||||
|
||||
{
|
||||
const cvf::uint conn[4] = { 1, 1, 0, 1};
|
||||
OutlineEdgeExtractor ee(0, *va);
|
||||
ee.addPrimitives(4, conn, 4);
|
||||
|
||||
UIntArray li = *ee.lineIndices();
|
||||
ASSERT_EQ(2, li.size());
|
||||
EXPECT_EQ(0, li[0]);
|
||||
EXPECT_EQ(1, li[1]);
|
||||
}
|
||||
|
||||
{
|
||||
const cvf::uint conn[4] = { 2, 2, 2, 2};
|
||||
OutlineEdgeExtractor ee(0, *va);
|
||||
ee.addPrimitives(4, conn, 4);
|
||||
|
||||
UIntArray li = *ee.lineIndices();
|
||||
EXPECT_EQ(0, li.size());
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OutlineEdgeExtractorTest, MultipleAdds)
|
||||
{
|
||||
ref<Vec3fArray> va = new Vec3fArray;
|
||||
va->reserve(4);
|
||||
va->add(Vec3f(0, 0, 0));
|
||||
va->add(Vec3f(1, 0, 0));
|
||||
va->add(Vec3f(1, 1, 0));
|
||||
va->add(Vec3f(0, 1, 0));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OutlineEdgeExtractorTest, ThreeQuads)
|
||||
{
|
||||
ref<Vec3fArray> va = new Vec3fArray;
|
||||
va->reserve(8);
|
||||
va->add(Vec3f(0, 0, 0));
|
||||
va->add(Vec3f(1, 0, 0));
|
||||
va->add(Vec3f(2, 0, 0));
|
||||
va->add(Vec3f(3, 0, 0));
|
||||
va->add(Vec3f(0, 1, 0));
|
||||
va->add(Vec3f(1, 1, 0));
|
||||
va->add(Vec3f(2, 1, 0));
|
||||
va->add(Vec3f(3, 1, 0));
|
||||
|
||||
// 4------5------6------7
|
||||
// | | | |
|
||||
// | | | |
|
||||
// 0------1------2------3
|
||||
|
||||
OutlineEdgeExtractor ee(0, *va);
|
||||
|
||||
{
|
||||
const cvf::uint conn[8] = { 0, 1, 5, 4, 1, 2, 6, 5 };
|
||||
ee.addPrimitives(4, conn, 8);
|
||||
}
|
||||
|
||||
{
|
||||
const cvf::uint conn[4] = { 2, 3, 7, 6 };
|
||||
ee.addPrimitives(4, conn, 4);
|
||||
}
|
||||
|
||||
UIntArray li = *ee.lineIndices();
|
||||
ASSERT_EQ(2*8, li.size());
|
||||
|
||||
EXPECT_TRUE( EdgeKey(0, 1) == EdgeKey(li[ 0], li[ 1]) );
|
||||
EXPECT_TRUE( EdgeKey(0, 4) == EdgeKey(li[ 2], li[ 3]) );
|
||||
EXPECT_TRUE( EdgeKey(1, 2) == EdgeKey(li[ 4], li[ 5]) );
|
||||
EXPECT_TRUE( EdgeKey(2, 3) == EdgeKey(li[ 6], li[ 7]) );
|
||||
EXPECT_TRUE( EdgeKey(3, 7) == EdgeKey(li[ 8], li[ 9]) );
|
||||
EXPECT_TRUE( EdgeKey(4, 5) == EdgeKey(li[10], li[11]) );
|
||||
EXPECT_TRUE( EdgeKey(5, 6) == EdgeKey(li[12], li[13]) );
|
||||
EXPECT_TRUE( EdgeKey(6, 7) == EdgeKey(li[14], li[15]) );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OutlineEdgeExtractorTest, PrimitiveMixFromFaceList)
|
||||
{
|
||||
ref<Vec3fArray> va = new Vec3fArray;
|
||||
va->resize(13);
|
||||
va->set( 0, Vec3f(0, 0, 0));
|
||||
va->set( 1, Vec3f(1, 0, 0));
|
||||
va->set( 2, Vec3f(2, 0, 0));
|
||||
va->set( 3, Vec3f(3, 0, 0));
|
||||
va->set( 4, Vec3f(4, 1, 0));
|
||||
va->set( 5, Vec3f(3, 2, 0));
|
||||
va->set( 6, Vec3f(2, 2, 0));
|
||||
va->set( 7, Vec3f(1, 1, 0));
|
||||
va->set( 8, Vec3f(0, 1, 0));
|
||||
va->set( 9, Vec3f(5, 1, 0));
|
||||
va->set(10, Vec3f(5, 0, 0));
|
||||
va->set(11, Vec3f(6, 6, 0));
|
||||
va->set(12, Vec3f(7, 7, 0));
|
||||
|
||||
//
|
||||
// *11
|
||||
// *12
|
||||
// 8------7 4-----9
|
||||
// | |\ |
|
||||
// | | \ |
|
||||
// 0------1--2 10
|
||||
|
||||
UIntArray fl;
|
||||
fl.reserve(26);
|
||||
|
||||
fl.add(1); fl.add(11);
|
||||
fl.add(1); fl.add(12);
|
||||
fl.add(2); fl.add(4); fl.add(9);
|
||||
fl.add(2); fl.add(10); fl.add(9);
|
||||
fl.add(3); fl.add(1); fl.add(2); fl.add(7);
|
||||
fl.add(4); fl.add(0); fl.add(1); fl.add(7); fl.add(8);
|
||||
ASSERT_EQ(19, fl.size());
|
||||
|
||||
OutlineEdgeExtractor ee(0, *va);
|
||||
ee.addFaceList(fl);
|
||||
|
||||
UIntArray li = *ee.lineIndices();
|
||||
ASSERT_EQ(2*7, li.size());
|
||||
|
||||
EXPECT_TRUE( EdgeKey(0, 1) == EdgeKey(li[ 0], li[ 1]) );
|
||||
EXPECT_TRUE( EdgeKey(0, 8) == EdgeKey(li[ 2], li[ 3]) );
|
||||
EXPECT_TRUE( EdgeKey(1, 2) == EdgeKey(li[ 4], li[ 5]) );
|
||||
EXPECT_TRUE( EdgeKey(2, 7) == EdgeKey(li[ 6], li[ 7]) );
|
||||
EXPECT_TRUE( EdgeKey(4, 9) == EdgeKey(li[ 8], li[ 9]) );
|
||||
EXPECT_TRUE( EdgeKey(7, 8) == EdgeKey(li[10], li[11]) );
|
||||
EXPECT_TRUE( EdgeKey(9,10) == EdgeKey(li[12], li[13]) );
|
||||
|
||||
/*
|
||||
// 6----5
|
||||
// / \ *11
|
||||
// / \ *12
|
||||
// 8------7 4-----9
|
||||
// | |\ / |
|
||||
// | | \ / |
|
||||
// 0------1--2----3 10
|
||||
|
||||
fl.add(1); fl.add(11);
|
||||
fl.add(1); fl.add(12);
|
||||
fl.add(2); fl.add(4); fl.add(9);
|
||||
fl.add(2); fl.add(10); fl.add(9);
|
||||
fl.add(3); fl.add(1); fl.add(2); fl.add(7);
|
||||
fl.add(4); fl.add(0); fl.add(1); fl.add(7); fl.add(8);
|
||||
fl.add(6); fl.add(2); fl.add(3); fl.add(4); fl.add(5); fl.add(6); fl.add(7);
|
||||
ASSERT_EQ(26, fl.size());
|
||||
|
||||
OutlineEdgeExtractor ee(0, *va);
|
||||
ee.addFaceList(fl);
|
||||
|
||||
UIntArray li = *ee.lineIndices();
|
||||
ASSERT_EQ(2*11, li.size());
|
||||
|
||||
EXPECT_TRUE( EdgeKey(0, 1) == EdgeKey(li[ 0], li[ 1]) );
|
||||
EXPECT_TRUE( EdgeKey(0, 8) == EdgeKey(li[ 2], li[ 3]) );
|
||||
EXPECT_TRUE( EdgeKey(1, 2) == EdgeKey(li[ 4], li[ 5]) );
|
||||
EXPECT_TRUE( EdgeKey(2, 3) == EdgeKey(li[ 6], li[ 7]) );
|
||||
EXPECT_TRUE( EdgeKey(3, 4) == EdgeKey(li[ 8], li[ 9]) );
|
||||
EXPECT_TRUE( EdgeKey(4, 5) == EdgeKey(li[10], li[11]) );
|
||||
EXPECT_TRUE( EdgeKey(4, 9) == EdgeKey(li[12], li[13]) );
|
||||
EXPECT_TRUE( EdgeKey(5, 6) == EdgeKey(li[14], li[15]) );
|
||||
EXPECT_TRUE( EdgeKey(6, 7) == EdgeKey(li[16], li[17]) );
|
||||
EXPECT_TRUE( EdgeKey(7, 8) == EdgeKey(li[18], li[19]) );
|
||||
EXPECT_TRUE( EdgeKey(9,10) == EdgeKey(li[20], li[21]) );
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfPatchGenerator.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
#include "utestGeometryBuilders.h"
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PatchGeneratorTest, Generate)
|
||||
{
|
||||
PatchGenerator gen;
|
||||
gen.setOrigin(Vec3d(1, 2, 3));
|
||||
gen.setExtent(10, 20);
|
||||
gen.setSubdivisions(3, 4);
|
||||
|
||||
{
|
||||
BuilderTrisQuads builder;
|
||||
gen.generate(&builder);
|
||||
BoundingBox bb = builder.vertexBoundingBox();
|
||||
EXPECT_DOUBLE_EQ(1, bb.min().x());
|
||||
EXPECT_DOUBLE_EQ(2, bb.min().y());
|
||||
EXPECT_DOUBLE_EQ(3, bb.min().z());
|
||||
EXPECT_DOUBLE_EQ(11, bb.max().x());
|
||||
EXPECT_DOUBLE_EQ(22, bb.max().y());
|
||||
EXPECT_DOUBLE_EQ(3, bb.max().z());
|
||||
|
||||
EXPECT_EQ(0, builder.triCount());
|
||||
EXPECT_EQ(12, builder.quadCount());
|
||||
}
|
||||
|
||||
gen.setQuads(false);
|
||||
|
||||
{
|
||||
BuilderTrisQuads builder;
|
||||
gen.generate(&builder);
|
||||
BoundingBox bb = builder.vertexBoundingBox();
|
||||
EXPECT_DOUBLE_EQ(1, bb.min().x());
|
||||
EXPECT_DOUBLE_EQ(2, bb.min().y());
|
||||
EXPECT_DOUBLE_EQ(3, bb.min().z());
|
||||
EXPECT_DOUBLE_EQ(11, bb.max().x());
|
||||
EXPECT_DOUBLE_EQ(22, bb.max().y());
|
||||
EXPECT_DOUBLE_EQ(3, bb.max().z());
|
||||
|
||||
EXPECT_EQ(24, builder.triCount());
|
||||
EXPECT_EQ(0, builder.quadCount());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
324
Fwk/VizFwk/Tests/LibGeometry_UnitTests/cvfRay-Test.cpp
Normal file
324
Fwk/VizFwk/Tests/LibGeometry_UnitTests/cvfRay-Test.cpp
Normal file
@@ -0,0 +1,324 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfRay.h"
|
||||
#include "cvfPlane.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "cvfBoundingBox.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RayTest, GettersAndSetters)
|
||||
{
|
||||
Ray r;
|
||||
|
||||
r.setOrigin(Vec3d(1,2,3));
|
||||
r.setDirection(Vec3d(0,1,0));
|
||||
|
||||
EXPECT_TRUE(r.origin() == Vec3d(1,2,3));
|
||||
EXPECT_TRUE(r.direction() == Vec3d(0,1,0));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RayTest, LimitedRangeSettersAndGetters)
|
||||
{
|
||||
Ray r;
|
||||
|
||||
EXPECT_TRUE(r.minimumDistance() > cvf::UNDEFINED_DOUBLE_THRESHOLD);
|
||||
EXPECT_TRUE(r.maximumDistance() > cvf::UNDEFINED_DOUBLE_THRESHOLD);
|
||||
|
||||
r.setMinimumDistance(10.0);
|
||||
r.setMaximumDistance(20.0);
|
||||
EXPECT_DOUBLE_EQ(10.0, r.minimumDistance());
|
||||
EXPECT_DOUBLE_EQ(20.0, r.maximumDistance());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RayTest, LimitedRangeTriangleIntersect)
|
||||
{
|
||||
Ray r;
|
||||
|
||||
r.setOrigin(Vec3d::ZERO);
|
||||
r.setDirection(Vec3d::Z_AXIS);
|
||||
|
||||
Vec3d v1 = Vec3d(-1, -1, 15);
|
||||
Vec3d v2 = Vec3d( 2, -1, 15);
|
||||
Vec3d v3 = Vec3d(-1, 2, 15);
|
||||
|
||||
EXPECT_TRUE(r.triangleIntersect(v1, v2, v3));
|
||||
|
||||
r.setMinimumDistance(10.0);
|
||||
r.setMaximumDistance(20.0);
|
||||
EXPECT_TRUE(r.triangleIntersect(v1, v2, v3));
|
||||
|
||||
r.setMinimumDistance(10.0);
|
||||
r.setMaximumDistance(cvf::UNDEFINED_DOUBLE);
|
||||
EXPECT_TRUE(r.triangleIntersect(v1, v2, v3));
|
||||
|
||||
r.setMinimumDistance(20.0);
|
||||
r.setMaximumDistance(cvf::UNDEFINED_DOUBLE);
|
||||
EXPECT_FALSE(r.triangleIntersect(v1, v2, v3));
|
||||
|
||||
r.setMinimumDistance(cvf::UNDEFINED_DOUBLE);
|
||||
r.setMaximumDistance(20.0);
|
||||
EXPECT_TRUE(r.triangleIntersect(v1, v2, v3));
|
||||
|
||||
r.setMinimumDistance(cvf::UNDEFINED_DOUBLE);
|
||||
r.setMaximumDistance(10.0);
|
||||
EXPECT_FALSE(r.triangleIntersect(v1, v2, v3));
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RayTest, LimitedRangeQuadIntersect)
|
||||
{
|
||||
Ray r;
|
||||
|
||||
r.setOrigin(Vec3d::ZERO);
|
||||
r.setDirection(Vec3d::Z_AXIS);
|
||||
|
||||
Vec3d v1 = Vec3d(-1, -1, 15);
|
||||
Vec3d v2 = Vec3d( 2, -1, 15);
|
||||
Vec3d v3 = Vec3d( 2, 2, 15);
|
||||
Vec3d v4 = Vec3d(-1, 2, 15);
|
||||
|
||||
EXPECT_TRUE(r.quadIntersect(v1, v2, v3, v4));
|
||||
|
||||
r.setMinimumDistance(10.0);
|
||||
r.setMaximumDistance(20.0);
|
||||
EXPECT_TRUE(r.quadIntersect(v1, v2, v3, v4));
|
||||
|
||||
r.setMinimumDistance(10.0);
|
||||
r.setMaximumDistance(cvf::UNDEFINED_DOUBLE);
|
||||
EXPECT_TRUE(r.quadIntersect(v1, v2, v3, v4));
|
||||
|
||||
r.setMinimumDistance(20.0);
|
||||
r.setMaximumDistance(cvf::UNDEFINED_DOUBLE);
|
||||
EXPECT_FALSE(r.quadIntersect(v1, v2, v3, v4));
|
||||
|
||||
r.setMinimumDistance(cvf::UNDEFINED_DOUBLE);
|
||||
r.setMaximumDistance(20.0);
|
||||
EXPECT_TRUE(r.quadIntersect(v1, v2, v3, v4));
|
||||
|
||||
r.setMinimumDistance(cvf::UNDEFINED_DOUBLE);
|
||||
r.setMaximumDistance(10.0);
|
||||
EXPECT_FALSE(r.quadIntersect(v1, v2, v3, v4));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RayTest, LimitedRangeBoxIntersect)
|
||||
{
|
||||
Ray r;
|
||||
|
||||
r.setOrigin(Vec3d::ZERO);
|
||||
r.setDirection(Vec3d::Z_AXIS);
|
||||
|
||||
BoundingBox box(Vec3d(-1, -1, 14), Vec3d(1,1,16));
|
||||
EXPECT_TRUE(r.boxIntersect(box));
|
||||
|
||||
r.setMinimumDistance(10.0);
|
||||
r.setMaximumDistance(20.0);
|
||||
EXPECT_TRUE(r.boxIntersect(box));
|
||||
|
||||
r.setMinimumDistance(20.0);
|
||||
r.setMaximumDistance(50.0);
|
||||
EXPECT_FALSE(r.boxIntersect(box));
|
||||
|
||||
r.setMinimumDistance(0.0);
|
||||
r.setMaximumDistance(10.0);
|
||||
EXPECT_FALSE(r.boxIntersect(box));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RayTest, LimitedRangePlaneIntersect)
|
||||
{
|
||||
Ray r;
|
||||
|
||||
r.setOrigin(Vec3d::ZERO);
|
||||
r.setDirection(Vec3d::Z_AXIS);
|
||||
|
||||
Plane plane(0,0,1,-15);
|
||||
EXPECT_TRUE(r.planeIntersect(plane));
|
||||
|
||||
r.setMinimumDistance(10.0);
|
||||
r.setMaximumDistance(20.0);
|
||||
EXPECT_TRUE(r.planeIntersect(plane));
|
||||
|
||||
r.setMinimumDistance(20.0);
|
||||
r.setMaximumDistance(50.0);
|
||||
EXPECT_FALSE(r.planeIntersect(plane));
|
||||
|
||||
r.setMinimumDistance(0.0);
|
||||
r.setMaximumDistance(10.0);
|
||||
EXPECT_FALSE(r.planeIntersect(plane));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RayTest, Transform)
|
||||
{
|
||||
Ray r;
|
||||
|
||||
r.setOrigin(Vec3d(1,2,3));
|
||||
r.setDirection(Vec3d(0,1,0));
|
||||
|
||||
Mat4d m;
|
||||
Vec3d t(1,2,3);
|
||||
m.setTranslation(t);
|
||||
|
||||
r.transform(m);
|
||||
|
||||
EXPECT_EQ(2, r.origin().x());
|
||||
EXPECT_EQ(4, r.origin().y());
|
||||
EXPECT_EQ(6, r.origin().z());
|
||||
EXPECT_EQ(0, r.direction().x());
|
||||
EXPECT_EQ(1, r.direction().y());
|
||||
EXPECT_EQ(0, r.direction().z());
|
||||
|
||||
Ray r2 = r.getTransformed(m);
|
||||
|
||||
EXPECT_EQ(2, r.origin().x());
|
||||
EXPECT_EQ(4, r.origin().y());
|
||||
EXPECT_EQ(6, r.origin().z());
|
||||
EXPECT_EQ(0, r.direction().x());
|
||||
EXPECT_EQ(1, r.direction().y());
|
||||
EXPECT_EQ(0, r.direction().z());
|
||||
|
||||
EXPECT_EQ(3, r2.origin().x());
|
||||
EXPECT_EQ(6, r2.origin().y());
|
||||
EXPECT_EQ(9, r2.origin().z());
|
||||
EXPECT_EQ(0, r2.direction().x());
|
||||
EXPECT_EQ(1, r2.direction().y());
|
||||
EXPECT_EQ(0, r2.direction().z());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RayTest, PlaneInersect)
|
||||
{
|
||||
{
|
||||
Ray r;
|
||||
r.setOrigin(Vec3d(1, 2, 5));
|
||||
r.setDirection(Vec3d(0, 0, -5));
|
||||
|
||||
// Plane normal going towards ray
|
||||
Plane p1;
|
||||
p1.setFromPointAndNormal(Vec3d(0, 0, 4), Vec3d(0, 0, 7));
|
||||
|
||||
Vec3d isect(0, 0, 0);
|
||||
EXPECT_TRUE(r.planeIntersect(p1, &isect));
|
||||
EXPECT_DOUBLE_EQ(1.0, isect.x());
|
||||
EXPECT_DOUBLE_EQ(2.0, isect.y());
|
||||
EXPECT_DOUBLE_EQ(4.0, isect.z());
|
||||
|
||||
// Plane normal facing 'away' from plane
|
||||
Plane p2;
|
||||
p2.setFromPointAndNormal(Vec3d(0, 0, 4), Vec3d(0, 0, -7));
|
||||
|
||||
isect.setZero();
|
||||
EXPECT_TRUE(r.planeIntersect(p2, &isect));
|
||||
EXPECT_DOUBLE_EQ(1.0, isect.x());
|
||||
EXPECT_DOUBLE_EQ(2.0, isect.y());
|
||||
EXPECT_DOUBLE_EQ(4.0, isect.z());
|
||||
}
|
||||
|
||||
{
|
||||
// Ray origin behind the plane
|
||||
Ray r;
|
||||
r.setOrigin(Vec3d(1, 2, 3));
|
||||
r.setDirection(Vec3d(0, 0, -5));
|
||||
|
||||
Plane p;
|
||||
p.setFromPointAndNormal(Vec3d(0, 0, 4), Vec3d(0, 0, 7));
|
||||
|
||||
Vec3d isect(0, 0, 0);
|
||||
EXPECT_FALSE(r.planeIntersect(p, &isect));
|
||||
EXPECT_DOUBLE_EQ(0.0, isect.x());
|
||||
EXPECT_DOUBLE_EQ(0.0, isect.y());
|
||||
EXPECT_DOUBLE_EQ(0.0, isect.z());
|
||||
}
|
||||
|
||||
{
|
||||
// Ray lying in plane
|
||||
Ray r;
|
||||
r.setOrigin(Vec3d(1, 2, 3));
|
||||
r.setDirection(Vec3d(0, 2, 3));
|
||||
|
||||
Plane p;
|
||||
p.setFromPointAndNormal(Vec3d(4, 5, 6), Vec3d(1, 0, 0));
|
||||
|
||||
EXPECT_FALSE(r.planeIntersect(p, NULL));
|
||||
}
|
||||
|
||||
{
|
||||
// Ray lying in plane
|
||||
Ray r;
|
||||
r.setOrigin(Vec3d(-6, -7, 3));
|
||||
r.setDirection(Vec3d(10, 0, -14));
|
||||
|
||||
Plane p;
|
||||
p.setFromPointAndNormal(Vec3d(4, 5, -6), Vec3d(0, -6, 0));
|
||||
|
||||
EXPECT_FALSE(r.planeIntersect(p, NULL));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfTriangleMeshEdgeExtractor.h"
|
||||
#include "cvfMath.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(TriangleMeshEdgeExtractorTest, EmptyOrNoInput)
|
||||
{
|
||||
TriangleMeshEdgeExtractor ee;
|
||||
|
||||
{
|
||||
ref<UIntArray> ind = ee.lineIndices();
|
||||
ASSERT_TRUE(ind.notNull());
|
||||
EXPECT_EQ(0, ind->size());
|
||||
}
|
||||
|
||||
UIntArray emptyArr;
|
||||
ee.addTriangles(emptyArr, emptyArr);
|
||||
|
||||
{
|
||||
ref<UIntArray> ind = ee.lineIndices();
|
||||
ASSERT_TRUE(ind.notNull());
|
||||
EXPECT_EQ(0, ind->size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(TriangleMeshEdgeExtractorTest, ThreeQuadsFromUIntArray)
|
||||
{
|
||||
// 3------4------5 9------8
|
||||
// | / | \ | | / |
|
||||
// | / | \ | | / |
|
||||
// 0------1------2 6------7
|
||||
// ID=1 ID=2 ID=33
|
||||
//
|
||||
TriangleMeshEdgeExtractor ee;
|
||||
|
||||
// Two connected quads
|
||||
{
|
||||
const cvf::uint conn[] =
|
||||
{
|
||||
0, 1, 4,
|
||||
0, 4, 3,
|
||||
1, 2, 4,
|
||||
2, 5, 4,
|
||||
};
|
||||
|
||||
UIntArray indices(conn, sizeof(conn)/sizeof(cvf::uint));
|
||||
|
||||
const cvf::uint aid[] = { 1, 1, 2, 2 };
|
||||
UIntArray ids(aid, sizeof(aid)/sizeof(cvf::uint));
|
||||
|
||||
ee.addTriangles(indices, ids);
|
||||
}
|
||||
|
||||
// Single loose quad
|
||||
{
|
||||
const cvf::uint conn[] =
|
||||
{
|
||||
6, 7, 8,
|
||||
6, 9, 8,
|
||||
};
|
||||
|
||||
UIntArray indices(conn, sizeof(conn)/sizeof(cvf::uint));
|
||||
|
||||
const cvf::uint aid[] = { 33, 33 };
|
||||
UIntArray ids(aid, sizeof(aid)/sizeof(cvf::uint));
|
||||
|
||||
ee.addTriangles(indices, ids);
|
||||
}
|
||||
|
||||
ref<UIntArray> li = ee.lineIndices();
|
||||
ASSERT_EQ(2*11, li->size());
|
||||
|
||||
/*
|
||||
EXPECT_EQ(0, li->get(0)); EXPECT_EQ(1, li->get(1));
|
||||
EXPECT_EQ(0, li->get(2)); EXPECT_EQ(3, li->get(3));
|
||||
EXPECT_EQ(1, li->get(4)); EXPECT_EQ(2, li->get(5));
|
||||
EXPECT_EQ(1, li->get(6)); EXPECT_EQ(4, li->get(7));
|
||||
EXPECT_EQ(2, li->get(8)); EXPECT_EQ(5, li->get(9));
|
||||
EXPECT_EQ(3, li->get(10)); EXPECT_EQ(4, li->get(11));
|
||||
EXPECT_EQ(4, li->get(12)); EXPECT_EQ(5, li->get(13));
|
||||
|
||||
EXPECT_EQ(6, li->get(14)); EXPECT_EQ(7, li->get(15));
|
||||
EXPECT_EQ(6, li->get(16)); EXPECT_EQ(9, li->get(17));
|
||||
EXPECT_EQ(7, li->get(18)); EXPECT_EQ(8, li->get(19));
|
||||
EXPECT_EQ(8, li->get(20)); EXPECT_EQ(9, li->get(21));
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MeshEdgeExtractorTest, CollapsedQuads)
|
||||
{
|
||||
// 4------3 6,6
|
||||
// | |\ |
|
||||
// | | \ |
|
||||
// 0------1--2,2 5,5
|
||||
|
||||
const cvf::uint quads[12] = { 0, 1, 3, 4, 1, 2, 2, 3, 6, 5, 5, 6 };
|
||||
|
||||
MeshEdgeExtractor ee;
|
||||
ee.addPrimitives(4, quads, 12);
|
||||
|
||||
UIntArray li = *ee.lineIndices();
|
||||
ASSERT_EQ(2*7, li.size());
|
||||
|
||||
EXPECT_EQ(0, li[ 0]); EXPECT_EQ(1, li[ 1]);
|
||||
EXPECT_EQ(0, li[ 2]); EXPECT_EQ(4, li[ 3]);
|
||||
EXPECT_EQ(1, li[ 4]); EXPECT_EQ(2, li[ 5]);
|
||||
EXPECT_EQ(1, li[ 6]); EXPECT_EQ(3, li[ 7]);
|
||||
EXPECT_EQ(2, li[ 8]); EXPECT_EQ(3, li[ 9]);
|
||||
EXPECT_EQ(3, li[10]); EXPECT_EQ(4, li[11]);
|
||||
EXPECT_EQ(5, li[12]); EXPECT_EQ(6, li[13]);
|
||||
}
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,408 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfTriangleVertexSplitter.h"
|
||||
#include "cvfMath.h"
|
||||
#include "cvfGeometryBuilderTriangles.h"
|
||||
#include "cvfGeometryUtils.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(TriangleVertexSplitterTest, Constructor)
|
||||
{
|
||||
ref<Vec3fArray> va = new Vec3fArray;
|
||||
ref<UIntArray> ta = new UIntArray;
|
||||
TriangleVertexSplitter splitter(cvf::Math::toRadians(60.0), *ta, *va);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(TriangleVertexSplitterTest, EmptyInputs)
|
||||
{
|
||||
ref<Vec3fArray> orgVertices = new Vec3fArray;
|
||||
ref<UIntArray> orgIndices = new UIntArray;
|
||||
TriangleVertexSplitter splitter(cvf::Math::toRadians(60.0), *orgIndices, *orgVertices);
|
||||
|
||||
ref<UIntArray> indices = splitter.triangleIndices();
|
||||
ref<Vec3fArray> va = splitter.vertexArray();
|
||||
ref<UIntArray> vertexSourceIndices = splitter.perVertexOriginalIndices();
|
||||
|
||||
ASSERT_TRUE(indices.notNull());
|
||||
ASSERT_TRUE(va.notNull());
|
||||
ASSERT_TRUE(vertexSourceIndices.notNull());
|
||||
|
||||
EXPECT_EQ(0, indices->size());
|
||||
EXPECT_EQ(0, va->size());
|
||||
EXPECT_EQ(0, vertexSourceIndices->size());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(TriangleVertexSplitterTest, TwoTriangelsAngleBelowThreshold)
|
||||
{
|
||||
//
|
||||
// 2
|
||||
// /|\ |z
|
||||
// / | \ | /y
|
||||
// / | \ |/
|
||||
// 0---1---3 *---x
|
||||
|
||||
Vec3f v0(0, 0, 0);
|
||||
Vec3f v1(1, 0, 0);
|
||||
Vec3f v2(1, 0, 1);
|
||||
Vec3f v3(2, 1, 0);
|
||||
|
||||
Vec3fArray orgVertices;
|
||||
orgVertices.reserve(4);
|
||||
orgVertices.add(v0);
|
||||
orgVertices.add(v1);
|
||||
orgVertices.add(v2);
|
||||
orgVertices.add(v3);
|
||||
|
||||
UIntArray orgIndices;
|
||||
orgIndices.reserve(6);
|
||||
orgIndices.add(0);
|
||||
orgIndices.add(1);
|
||||
orgIndices.add(2);
|
||||
orgIndices.add(1);
|
||||
orgIndices.add(3);
|
||||
orgIndices.add(2);
|
||||
|
||||
TriangleVertexSplitter splitter(cvf::Math::toRadians(60.0), orgIndices, orgVertices);
|
||||
|
||||
ref<UIntArray> indices = splitter.triangleIndices();
|
||||
ref<Vec3fArray> va = splitter.vertexArray();
|
||||
ref<UIntArray> vertexSourceIndices = splitter.perVertexOriginalIndices();
|
||||
|
||||
ASSERT_TRUE(indices.notNull());
|
||||
ASSERT_TRUE(va.notNull());
|
||||
ASSERT_TRUE(vertexSourceIndices.notNull());
|
||||
|
||||
ASSERT_EQ(6, indices->size());
|
||||
ASSERT_EQ(4, va->size());
|
||||
ASSERT_EQ(4, vertexSourceIndices->size());
|
||||
|
||||
EXPECT_EQ(0, indices->get(0));
|
||||
EXPECT_EQ(1, indices->get(1));
|
||||
EXPECT_EQ(2, indices->get(2));
|
||||
|
||||
EXPECT_EQ(1, indices->get(3));
|
||||
EXPECT_EQ(3, indices->get(4));
|
||||
EXPECT_EQ(2, indices->get(5));
|
||||
|
||||
EXPECT_EQ(0, vertexSourceIndices->get(0));
|
||||
EXPECT_EQ(1, vertexSourceIndices->get(1));
|
||||
EXPECT_EQ(2, vertexSourceIndices->get(2));
|
||||
EXPECT_EQ(3, vertexSourceIndices->get(3));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(TriangleVertexSplitterTest, TwoTriangels)
|
||||
{
|
||||
//
|
||||
// 2
|
||||
// /|\ |z
|
||||
// / | /3 | /y
|
||||
// / |/ |/
|
||||
// 0---1 *---x
|
||||
|
||||
Vec3f v0(0, 0, 0);
|
||||
Vec3f v1(1, 0, 0);
|
||||
Vec3f v2(1, 0, 1);
|
||||
Vec3f v3(1, 1, 0);
|
||||
|
||||
Vec3fArray orgVertices;
|
||||
orgVertices.reserve(4);
|
||||
orgVertices.add(v0);
|
||||
orgVertices.add(v1);
|
||||
orgVertices.add(v2);
|
||||
orgVertices.add(v3);
|
||||
|
||||
UIntArray orgIndices;
|
||||
orgIndices.reserve(6);
|
||||
orgIndices.add(0);
|
||||
orgIndices.add(1);
|
||||
orgIndices.add(2);
|
||||
orgIndices.add(1);
|
||||
orgIndices.add(3);
|
||||
orgIndices.add(2);
|
||||
|
||||
TriangleVertexSplitter splitter(cvf::Math::toRadians(60.0), orgIndices, orgVertices);
|
||||
|
||||
ref<UIntArray> indices = splitter.triangleIndices();
|
||||
ref<Vec3fArray> va = splitter.vertexArray();
|
||||
ref<UIntArray> vertexSourceIndices = splitter.perVertexOriginalIndices();
|
||||
|
||||
ASSERT_TRUE(indices.notNull());
|
||||
ASSERT_TRUE(va.notNull());
|
||||
ASSERT_TRUE(vertexSourceIndices.notNull());
|
||||
|
||||
ASSERT_EQ(6, indices->size());
|
||||
ASSERT_EQ(6, va->size());
|
||||
ASSERT_EQ(6, vertexSourceIndices->size());
|
||||
|
||||
EXPECT_EQ(0, indices->get(0));
|
||||
EXPECT_EQ(1, indices->get(1));
|
||||
EXPECT_EQ(2, indices->get(2));
|
||||
|
||||
EXPECT_EQ(3, indices->get(3));
|
||||
EXPECT_EQ(4, indices->get(4));
|
||||
EXPECT_EQ(5, indices->get(5));
|
||||
|
||||
EXPECT_EQ(0, vertexSourceIndices->get(0));
|
||||
EXPECT_EQ(1, vertexSourceIndices->get(1));
|
||||
EXPECT_EQ(2, vertexSourceIndices->get(2));
|
||||
EXPECT_EQ(1, vertexSourceIndices->get(3));
|
||||
EXPECT_EQ(3, vertexSourceIndices->get(4));
|
||||
EXPECT_EQ(2, vertexSourceIndices->get(5));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(TriangleVertexSplitterTest, ThreeTriangels)
|
||||
{
|
||||
//
|
||||
// 4---2
|
||||
// | /|\ |z
|
||||
// | / | /3 | /y
|
||||
// |/ |/ |/
|
||||
// 0---1 *---x
|
||||
|
||||
Vec3f v0(0, 0, 0);
|
||||
Vec3f v1(1, 0, 0);
|
||||
Vec3f v2(1, 0, 1);
|
||||
Vec3f v3(1, 1, 0);
|
||||
Vec3f v4(0, 0, 1);
|
||||
|
||||
Vec3fArray orgVertices;
|
||||
orgVertices.reserve(5);
|
||||
orgVertices.add(v0);
|
||||
orgVertices.add(v1);
|
||||
orgVertices.add(v2);
|
||||
orgVertices.add(v3);
|
||||
orgVertices.add(v4);
|
||||
|
||||
UIntArray orgIndices;
|
||||
orgIndices.reserve(9);
|
||||
orgIndices.add(0);
|
||||
orgIndices.add(1);
|
||||
orgIndices.add(2);
|
||||
orgIndices.add(1);
|
||||
orgIndices.add(3);
|
||||
orgIndices.add(2);
|
||||
orgIndices.add(0);
|
||||
orgIndices.add(2);
|
||||
orgIndices.add(4);
|
||||
|
||||
TriangleVertexSplitter splitter(cvf::Math::toRadians(60.0), orgIndices, orgVertices);
|
||||
|
||||
ref<UIntArray> indices = splitter.triangleIndices();
|
||||
ref<Vec3fArray> va = splitter.vertexArray();
|
||||
ref<UIntArray> vertexSourceIndices = splitter.perVertexOriginalIndices();
|
||||
|
||||
ASSERT_TRUE(indices.notNull());
|
||||
ASSERT_TRUE(va.notNull());
|
||||
ASSERT_TRUE(vertexSourceIndices.notNull());
|
||||
|
||||
ASSERT_EQ(9, indices->size());
|
||||
ASSERT_EQ(7, va->size());
|
||||
ASSERT_EQ(7, vertexSourceIndices->size());
|
||||
|
||||
EXPECT_EQ(0, indices->get(0));
|
||||
EXPECT_EQ(1, indices->get(1));
|
||||
EXPECT_EQ(2, indices->get(2));
|
||||
|
||||
EXPECT_EQ(3, indices->get(3));
|
||||
EXPECT_EQ(4, indices->get(4));
|
||||
EXPECT_EQ(5, indices->get(5));
|
||||
|
||||
EXPECT_EQ(0, indices->get(6));
|
||||
EXPECT_EQ(2, indices->get(7));
|
||||
EXPECT_EQ(6, indices->get(8));
|
||||
|
||||
EXPECT_EQ(0, vertexSourceIndices->get(0));
|
||||
EXPECT_EQ(1, vertexSourceIndices->get(1));
|
||||
EXPECT_EQ(2, vertexSourceIndices->get(2));
|
||||
EXPECT_EQ(1, vertexSourceIndices->get(3));
|
||||
EXPECT_EQ(3, vertexSourceIndices->get(4));
|
||||
EXPECT_EQ(2, vertexSourceIndices->get(5));
|
||||
EXPECT_EQ(4, vertexSourceIndices->get(6));
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(TriangleVertexSplitterTest, PartialBoxTest)
|
||||
{
|
||||
// 6 ------ 5 Faces:
|
||||
// / \ /| |z 0 bottom 0, 3, 2, 1
|
||||
// / \ / | | /y 1 top 4, 5, 6, 7
|
||||
// 3---------4 | |/ 2 front 4, 0, 1, 5
|
||||
// | / | \2 *---x 3 right 5, 1, 2, 6
|
||||
// | / | / 4 back 6, 2, 3, 7
|
||||
// | / |/ 5 left 7, 3, 0, 4
|
||||
// 0---------1
|
||||
|
||||
Vec3f v0(0, 0, 0);
|
||||
Vec3f v1(1, 0, 0);
|
||||
Vec3f v2(1, 1, 0);
|
||||
Vec3f v3(0, 0, 1);
|
||||
Vec3f v4(1, 0, 1);
|
||||
Vec3f v5(1, 1, 1);
|
||||
Vec3f v6(0, 1, 1);
|
||||
|
||||
Vec3fArray orgVertices;
|
||||
orgVertices.reserve(7);
|
||||
orgVertices.add(v0);
|
||||
orgVertices.add(v1);
|
||||
orgVertices.add(v2);
|
||||
orgVertices.add(v3);
|
||||
orgVertices.add(v4);
|
||||
orgVertices.add(v5);
|
||||
orgVertices.add(v6);
|
||||
|
||||
const cvf::uint conn[] =
|
||||
{
|
||||
0, 1, 4,
|
||||
0, 4, 3,
|
||||
1, 2, 4,
|
||||
2, 5, 4,
|
||||
3, 4, 6,
|
||||
4, 5, 6,
|
||||
};
|
||||
|
||||
UIntArray orgIndices(conn, sizeof(conn)/sizeof(cvf::uint));
|
||||
|
||||
TriangleVertexSplitter splitter(cvf::Math::toRadians(60.0), orgIndices, orgVertices);
|
||||
|
||||
ref<UIntArray> indices = splitter.triangleIndices();
|
||||
ref<Vec3fArray> va = splitter.vertexArray();
|
||||
ref<UIntArray> vertexSourceIndices = splitter.perVertexOriginalIndices();
|
||||
|
||||
ASSERT_TRUE(indices.notNull());
|
||||
ASSERT_TRUE(va.notNull());
|
||||
ASSERT_TRUE(vertexSourceIndices.notNull());
|
||||
|
||||
EXPECT_EQ(18, indices->size());
|
||||
EXPECT_EQ(12, va->size());
|
||||
EXPECT_EQ(12, vertexSourceIndices->size());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(TriangleVertexSplitterTest, BoxTest)
|
||||
{
|
||||
// The ordering of the faces is consistent with GLviewAPI's hexahedron element.
|
||||
// Note that the vertex ordering within a face is not consistent
|
||||
//
|
||||
// 7---------6 Faces:
|
||||
// /| /| |z 0 bottom 0, 3, 2, 1
|
||||
// / | / | | /y 1 top 4, 5, 6, 7
|
||||
// 4---------5 | |/ 2 front 4, 0, 1, 5
|
||||
// | 3------|--2 *---x 3 right 5, 1, 2, 6
|
||||
// | / | / 4 back 6, 2, 3, 7
|
||||
// |/ |/ 5 left 7, 3, 0, 4
|
||||
// 0---------1
|
||||
|
||||
Vec3f min(0,0,0);
|
||||
Vec3f max(1,1,1);
|
||||
|
||||
ref<Vec3fArray> orgVertices = new Vec3fArray;
|
||||
orgVertices->reserve(8);
|
||||
|
||||
orgVertices->add(Vec3f(min.x(), min.y(), min.z()));
|
||||
orgVertices->add(Vec3f(max.x(), min.y(), min.z()));
|
||||
orgVertices->add(Vec3f(max.x(), max.y(), min.z()));
|
||||
orgVertices->add(Vec3f(min.x(), max.y(), min.z()));
|
||||
|
||||
orgVertices->add(Vec3f(min.x(), min.y(), max.z()));
|
||||
orgVertices->add(Vec3f(max.x(), min.y(), max.z()));
|
||||
orgVertices->add(Vec3f(max.x(), max.y(), max.z()));
|
||||
orgVertices->add(Vec3f(min.x(), max.y(), max.z()));
|
||||
|
||||
const cvf::uint conn[] =
|
||||
{
|
||||
0, 1, 5, 0, 5, 4, // Front
|
||||
1, 2, 6, 1, 6, 5, // Right
|
||||
2, 3, 7, 2, 7, 6, // Back
|
||||
0, 4, 7, 0, 7, 3, // Left
|
||||
0, 3, 2, 0, 2, 1, // Bottom
|
||||
4, 5, 6, 4, 6, 7 // Top
|
||||
};
|
||||
|
||||
ref<UIntArray> orgIndices = new UIntArray(conn, sizeof(conn)/sizeof(cvf::uint));
|
||||
|
||||
ASSERT_EQ(8, orgVertices->size());
|
||||
ASSERT_EQ(12*3, orgIndices->size());
|
||||
|
||||
TriangleVertexSplitter splitter(cvf::Math::toRadians(60.0), *orgIndices, *orgVertices);
|
||||
|
||||
ref<UIntArray> indices = splitter.triangleIndices();
|
||||
ref<Vec3fArray> va = splitter.vertexArray();
|
||||
ref<UIntArray> vertexSourceIndices = splitter.perVertexOriginalIndices();
|
||||
|
||||
ASSERT_TRUE(indices.notNull());
|
||||
ASSERT_TRUE(va.notNull());
|
||||
ASSERT_TRUE(vertexSourceIndices.notNull());
|
||||
|
||||
// Expecting same triangle count, but 4 separate vertices per box side -> 24 nodes
|
||||
|
||||
// HACK - these will fail until this is properly implemented.
|
||||
EXPECT_EQ(12*3, indices->size());
|
||||
EXPECT_EQ(6*4, va->size());
|
||||
EXPECT_EQ(6*4, vertexSourceIndices->size());
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfVertexCompactor.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VertexCompactorTest, Constructor)
|
||||
{
|
||||
ref<Vec3fArray> orgVertices = new Vec3fArray;
|
||||
ref<UIntArray> orgIndices = new UIntArray;
|
||||
VertexCompactor vc(*orgIndices, *orgVertices);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VertexCompactorTest, EmptyInputs)
|
||||
{
|
||||
ref<Vec3fArray> orgVertices = new Vec3fArray;
|
||||
ref<UIntArray> orgIndices = new UIntArray;
|
||||
VertexCompactor vc(*orgIndices, *orgVertices);
|
||||
|
||||
ref<UIntArray> indices = vc.indices();
|
||||
ref<Vec3fArray> va = vc.vertexArray();
|
||||
ref<UIntArray> vertexSourceIndices = vc.perVertexOriginalIndices();
|
||||
|
||||
ASSERT_TRUE(indices.notNull());
|
||||
ASSERT_TRUE(va.notNull());
|
||||
ASSERT_TRUE(vertexSourceIndices.notNull());
|
||||
|
||||
EXPECT_EQ(0, indices->size());
|
||||
EXPECT_EQ(0, va->size());
|
||||
EXPECT_EQ(0, vertexSourceIndices->size());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VertexCompactorTest, Quads)
|
||||
{
|
||||
// Vertices, three possible quads
|
||||
// 4------5------6------7
|
||||
// | Q1 | Q2 | Q3 |
|
||||
// | | | |
|
||||
// 0------1------2------3
|
||||
|
||||
Vec3fArray orgVertices;
|
||||
orgVertices.reserve(8);
|
||||
orgVertices.add(Vec3f(0, 0, 0));
|
||||
orgVertices.add(Vec3f(1, 0, 0));
|
||||
orgVertices.add(Vec3f(2, 0, 0));
|
||||
orgVertices.add(Vec3f(3, 0, 0));
|
||||
orgVertices.add(Vec3f(0, 1, 0));
|
||||
orgVertices.add(Vec3f(1, 1, 0));
|
||||
orgVertices.add(Vec3f(2, 1, 0));
|
||||
orgVertices.add(Vec3f(3, 1, 0));
|
||||
|
||||
const cvf::uint connQ1[4] = { 0, 1, 5, 4 };
|
||||
const cvf::uint connQ2[4] = { 1, 2, 6, 5 };
|
||||
//const cvf::uint connQ3[4] = { 2, 3, 7, 6 };
|
||||
|
||||
// Q2
|
||||
{
|
||||
UIntArray orgConn(connQ2, 4);
|
||||
VertexCompactor vc(orgConn, orgVertices);
|
||||
|
||||
ref<UIntArray> indices = vc.indices();
|
||||
ASSERT_EQ(4, indices->size());
|
||||
EXPECT_EQ(0, indices->get(0));
|
||||
EXPECT_EQ(1, indices->get(1));
|
||||
EXPECT_EQ(2, indices->get(2));
|
||||
EXPECT_EQ(3, indices->get(3));
|
||||
|
||||
ref<Vec3fArray> va = vc.vertexArray();
|
||||
ASSERT_EQ(4, va->size());
|
||||
EXPECT_TRUE(Vec3f(1, 0, 0) == va->get(0));
|
||||
EXPECT_TRUE(Vec3f(2, 0, 0) == va->get(1));
|
||||
EXPECT_TRUE(Vec3f(2, 1, 0) == va->get(2));
|
||||
EXPECT_TRUE(Vec3f(1, 1, 0) == va->get(3));
|
||||
|
||||
ref<UIntArray> vertexSourceIndices = vc.perVertexOriginalIndices();
|
||||
ASSERT_EQ(4, vertexSourceIndices->size());
|
||||
EXPECT_EQ(1, vertexSourceIndices->get(0));
|
||||
EXPECT_EQ(2, vertexSourceIndices->get(1));
|
||||
EXPECT_EQ(6, vertexSourceIndices->get(2));
|
||||
EXPECT_EQ(5, vertexSourceIndices->get(3));
|
||||
}
|
||||
|
||||
// Q1 + Q2
|
||||
{
|
||||
UIntArray orgConn(8);
|
||||
orgConn.copyData(connQ1, 4, 0);
|
||||
orgConn.copyData(connQ2, 4, 4);
|
||||
|
||||
VertexCompactor vc(orgConn, orgVertices);
|
||||
|
||||
ref<UIntArray> indices = vc.indices();
|
||||
ASSERT_EQ(8, indices->size());
|
||||
EXPECT_EQ(0, indices->get(0));
|
||||
EXPECT_EQ(1, indices->get(1));
|
||||
EXPECT_EQ(2, indices->get(2));
|
||||
EXPECT_EQ(3, indices->get(3));
|
||||
EXPECT_EQ(1, indices->get(4));
|
||||
EXPECT_EQ(4, indices->get(5));
|
||||
EXPECT_EQ(5, indices->get(6));
|
||||
EXPECT_EQ(2, indices->get(7));
|
||||
|
||||
ref<Vec3fArray> va = vc.vertexArray();
|
||||
ASSERT_EQ(6, va->size());
|
||||
EXPECT_TRUE(Vec3f(0, 0, 0) == va->get(0));
|
||||
EXPECT_TRUE(Vec3f(1, 0, 0) == va->get(1));
|
||||
EXPECT_TRUE(Vec3f(1, 1, 0) == va->get(2));
|
||||
EXPECT_TRUE(Vec3f(0, 1, 0) == va->get(3));
|
||||
EXPECT_TRUE(Vec3f(2, 0, 0) == va->get(4));
|
||||
EXPECT_TRUE(Vec3f(2, 1, 0) == va->get(5));
|
||||
|
||||
ref<UIntArray> vertexSourceIndices = vc.perVertexOriginalIndices();
|
||||
ASSERT_EQ(6, vertexSourceIndices->size());
|
||||
EXPECT_EQ(0, vertexSourceIndices->get(0));
|
||||
EXPECT_EQ(1, vertexSourceIndices->get(1));
|
||||
EXPECT_EQ(5, vertexSourceIndices->get(2));
|
||||
EXPECT_EQ(4, vertexSourceIndices->get(3));
|
||||
EXPECT_EQ(2, vertexSourceIndices->get(4));
|
||||
EXPECT_EQ(6, vertexSourceIndices->get(5));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
157
Fwk/VizFwk/Tests/LibGeometry_UnitTests/cvfVertexWelder-Test.cpp
Normal file
157
Fwk/VizFwk/Tests/LibGeometry_UnitTests/cvfVertexWelder-Test.cpp
Normal file
@@ -0,0 +1,157 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfVertexWelder.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VertexWelderTest, Basic)
|
||||
{
|
||||
VertexWelder w;
|
||||
w.initialize(0.01, 0.1, 100);
|
||||
|
||||
{
|
||||
bool wasWelded = false;
|
||||
cvf::uint idx = w.weldVertex(Vec3f(0, 0, 0), &wasWelded);
|
||||
EXPECT_FALSE(wasWelded);
|
||||
EXPECT_EQ(0, idx);
|
||||
}
|
||||
|
||||
{
|
||||
bool wasWelded = false;
|
||||
cvf::uint idx = w.weldVertex(Vec3f(0, 0, 0), &wasWelded);
|
||||
EXPECT_TRUE(wasWelded);
|
||||
EXPECT_EQ(0, idx);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
bool wasWelded = false;
|
||||
cvf::uint idx = w.weldVertex(Vec3f(1, 0, 0), &wasWelded);
|
||||
EXPECT_FALSE(wasWelded);
|
||||
EXPECT_EQ(1, idx);
|
||||
}
|
||||
|
||||
{
|
||||
bool wasWelded = false;
|
||||
cvf::uint idx = w.weldVertex(Vec3f(0, 2, 0), &wasWelded);
|
||||
EXPECT_FALSE(wasWelded);
|
||||
EXPECT_EQ(2, idx);
|
||||
}
|
||||
|
||||
{
|
||||
bool wasWelded = false;
|
||||
cvf::uint idx = w.weldVertex(Vec3f(0, 0, 3), &wasWelded);
|
||||
EXPECT_FALSE(wasWelded);
|
||||
EXPECT_EQ(3, idx);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
bool wasWelded = false;
|
||||
cvf::uint idx = w.weldVertex(Vec3f(0, 2.001f, 0), &wasWelded);
|
||||
EXPECT_TRUE(wasWelded);
|
||||
EXPECT_EQ(2, idx);
|
||||
}
|
||||
|
||||
{
|
||||
bool wasWelded = false;
|
||||
cvf::uint idx = w.weldVertex(Vec3f(0, 2.02f, 0), &wasWelded);
|
||||
EXPECT_FALSE(wasWelded);
|
||||
EXPECT_EQ(4, idx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(VertexWelderTest, WeldBunchOfPointsAndCheckDistance)
|
||||
{
|
||||
|
||||
const int numSrcPoints = 100;
|
||||
Vec3fArray weldedVerts;
|
||||
weldedVerts.reserve(numSrcPoints);
|
||||
|
||||
const double weldDist = 0.05;
|
||||
const double cellSize = 10*weldDist;
|
||||
VertexWelder w;
|
||||
w.initialize(weldDist, cellSize, 100);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < numSrcPoints; i++)
|
||||
{
|
||||
Vec3f v((float)i/numSrcPoints, (float)sin(i/10.0), (float)cos(i/20.0));
|
||||
|
||||
bool wasWelded = false;
|
||||
w.weldVertex(v, &wasWelded);
|
||||
if (!wasWelded)
|
||||
{
|
||||
weldedVerts.add(v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int numPoints = static_cast<int>(weldedVerts.size());
|
||||
|
||||
for (i = 0; i < numPoints; i++)
|
||||
{
|
||||
Vec3f v0 = weldedVerts[i];
|
||||
|
||||
int j;
|
||||
for (j = 0; j < numPoints; j++)
|
||||
{
|
||||
if (j != i)
|
||||
{
|
||||
double dist = v0.pointDistance(weldedVerts[j]);
|
||||
EXPECT_LT(weldDist, dist);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
134
Fwk/VizFwk/Tests/LibGeometry_UnitTests/utestGeometryBuilders.h
Normal file
134
Fwk/VizFwk/Tests/LibGeometry_UnitTests/utestGeometryBuilders.h
Normal file
@@ -0,0 +1,134 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cvfBoundingBox.h"
|
||||
#include "cvfGeometryBuilder.h"
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
// GeometryBuilder implementation that only builds triangles, for use in unit tests
|
||||
//
|
||||
//==================================================================================================
|
||||
class BuilderTris : public GeometryBuilder
|
||||
{
|
||||
public:
|
||||
virtual cvf::uint addVertices(const Vec3fArray& vertices)
|
||||
{
|
||||
cvf::uint numExistingVerts = static_cast<cvf::uint>(vertexArr.size());
|
||||
|
||||
size_t i;
|
||||
for (i = 0; i < vertices.size(); i++)
|
||||
{
|
||||
vertexArr.push_back(vertices[i]);
|
||||
}
|
||||
|
||||
return numExistingVerts;
|
||||
}
|
||||
|
||||
virtual cvf::uint vertexCount() const
|
||||
{
|
||||
return static_cast<cvf::uint>(vertexArr.size());
|
||||
}
|
||||
|
||||
virtual void transformVertexRange(cvf::uint startIdx, cvf::uint endIdx, const Mat4f& mat)
|
||||
{
|
||||
size_t i;
|
||||
for (i = static_cast<size_t>(startIdx); i <= static_cast<size_t>(endIdx); i++)
|
||||
{
|
||||
vertexArr[i].transformPoint(mat);
|
||||
}
|
||||
}
|
||||
|
||||
BoundingBox vertexBoundingBox() const
|
||||
{
|
||||
BoundingBox bb;
|
||||
|
||||
size_t i;
|
||||
for (i = 0; i < vertexArr.size(); i++)
|
||||
{
|
||||
bb.add(vertexArr[i]);
|
||||
}
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
||||
virtual void addTriangle(cvf::uint i0, cvf::uint i1, cvf::uint i2)
|
||||
{
|
||||
triArr.push_back(i0);
|
||||
triArr.push_back(i1);
|
||||
triArr.push_back(i2);
|
||||
}
|
||||
|
||||
cvf::uint triCount()
|
||||
{
|
||||
return static_cast<cvf::uint>(triArr.size()/3);
|
||||
}
|
||||
|
||||
public:
|
||||
std::vector<Vec3f> vertexArr;
|
||||
std::vector<cvf::uint> triArr;
|
||||
};
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
// GeometryBuilder implementation that builds triangles and quads, for use in unit tests
|
||||
//
|
||||
//==================================================================================================
|
||||
class BuilderTrisQuads : public BuilderTris
|
||||
{
|
||||
public:
|
||||
virtual void addQuad(cvf::uint i0, cvf::uint i1, cvf::uint i2, cvf::uint i3)
|
||||
{
|
||||
quadArr.push_back(i0);
|
||||
quadArr.push_back(i1);
|
||||
quadArr.push_back(i2);
|
||||
quadArr.push_back(i3);
|
||||
}
|
||||
|
||||
cvf::uint quadCount()
|
||||
{
|
||||
return static_cast<cvf::uint>(quadArr.size()/4);
|
||||
}
|
||||
|
||||
public:
|
||||
std::vector<cvf::uint> quadArr;
|
||||
};
|
||||
32
Fwk/VizFwk/Tests/LibGuiQt_UnitTests/CMakeLists.txt
Normal file
32
Fwk/VizFwk/Tests/LibGuiQt_UnitTests/CMakeLists.txt
Normal file
@@ -0,0 +1,32 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(LibGuiQt_UnitTests)
|
||||
|
||||
# Compile flags should already be setup by caller
|
||||
|
||||
|
||||
find_package(OpenGL)
|
||||
|
||||
find_package(Qt4 COMPONENTS QtCore QtGui QtOpenGL REQUIRED)
|
||||
include(${QT_USE_FILE})
|
||||
|
||||
include_directories(${LibCore_SOURCE_DIR})
|
||||
include_directories(${LibIo_SOURCE_DIR})
|
||||
include_directories(${LibGeometry_SOURCE_DIR})
|
||||
include_directories(${LibRender_SOURCE_DIR})
|
||||
include_directories(${LibViewing_SOURCE_DIR})
|
||||
include_directories(${LibGuiQt_SOURCE_DIR})
|
||||
include_directories(${VizFramework_SOURCE_DIR}/ThirdParty)
|
||||
|
||||
set(CEE_LIBS LibGuiQt LibViewing LibRender LibGeometry LibIo LibCore)
|
||||
|
||||
|
||||
set(CEE_SOURCE_FILES
|
||||
cvfqtUtils-Test.cpp
|
||||
../../ThirdParty/gtest/gtest-all.cpp
|
||||
LibGuiQt_UnitTests.cpp
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${CEE_SOURCE_FILES})
|
||||
target_link_libraries(${PROJECT_NAME} ${CEE_LIBS} ${OPENGL_LIBRARIES} ${QT_LIBRARIES} ${CEE_PLATFORM_LIBS})
|
||||
|
||||
57
Fwk/VizFwk/Tests/LibGuiQt_UnitTests/LibGuiQt_UnitTests.cpp
Normal file
57
Fwk/VizFwk/Tests/LibGuiQt_UnitTests/LibGuiQt_UnitTests.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
//printf("Running main() from LibGuiQt_UnitTests.cpp\n");
|
||||
|
||||
cvf::Assert::setReportMode(cvf::Assert::CONSOLE);
|
||||
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
299
Fwk/VizFwk/Tests/LibGuiQt_UnitTests/LibGuiQt_UnitTests.vcxproj
Normal file
299
Fwk/VizFwk/Tests/LibGuiQt_UnitTests/LibGuiQt_UnitTests.vcxproj
Normal file
@@ -0,0 +1,299 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug MD TBB|Win32">
|
||||
<Configuration>Debug MD TBB</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug MD TBB|x64">
|
||||
<Configuration>Debug MD TBB</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug MD|Win32">
|
||||
<Configuration>Debug MD</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug MD|x64">
|
||||
<Configuration>Debug MD</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD TBB|Win32">
|
||||
<Configuration>Release MD TBB</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD TBB|x64">
|
||||
<Configuration>Release MD TBB</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD|Win32">
|
||||
<Configuration>Release MD</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD|x64">
|
||||
<Configuration>Release MD</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{8FF27114-B51E-405A-8A9E-011349E9EDF1}</ProjectGuid>
|
||||
<RootNamespace>LibGuiQt_UnitTests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<AdditionalIncludeDirectories>$(QTDIR)/include;$(QTDIR)/include/Qt;../../LibCore;../../LibGeometry;../../LibRender;../../LibViewing;../../LibGuiQt;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>QtCored4.lib;QtGuid4.lib;QtOpenGLd4.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(QTDIR)/lib</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<AdditionalIncludeDirectories>$(QTDIR)/include;$(QTDIR)/include/Qt;../../LibCore;../../LibGeometry;../../LibRender;../../LibViewing;../../LibGuiQt;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>QtCored4.lib;QtGuid4.lib;QtOpenGLd4.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(QTDIR)/lib;../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<AdditionalIncludeDirectories>$(QTDIR)/include;$(QTDIR)/include/Qt;../../LibCore;../../LibGeometry;../../LibRender;../../LibViewing;../../LibGuiQt;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>QtCored4.lib;QtGuid4.lib;QtOpenGLd4.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(QTDIR)/lib</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<AdditionalIncludeDirectories>$(QTDIR)/include;$(QTDIR)/include/Qt;../../LibCore;../../LibGeometry;../../LibRender;../../LibViewing;../../LibGuiQt;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>QtCored4.lib;QtGuid4.lib;QtOpenGLd4.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(QTDIR)/lib;../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<AdditionalIncludeDirectories>$(QTDIR)/include;$(QTDIR)/include/Qt;../../LibCore;../../LibGeometry;../../LibRender;../../LibViewing;../../LibGuiQt;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>QtCore4.lib;QtGui4.lib;QtOpenGL4.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(QTDIR)/lib</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<AdditionalIncludeDirectories>$(QTDIR)/include;$(QTDIR)/include/Qt;../../LibCore;../../LibGeometry;../../LibRender;../../LibViewing;../../LibGuiQt;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>QtCore4.lib;QtGui4.lib;QtOpenGL4.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(QTDIR)/lib;../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<AdditionalIncludeDirectories>$(QTDIR)/include;$(QTDIR)/include/Qt;../../LibCore;../../LibGeometry;../../LibRender;../../LibViewing;../../LibGuiQt;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>QtCore4.lib;QtGui4.lib;QtOpenGL4.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(QTDIR)/lib</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<AdditionalIncludeDirectories>$(QTDIR)/include;$(QTDIR)/include/Qt;../../LibCore;../../LibGeometry;../../LibRender;../../LibViewing;../../LibGuiQt;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>QtCore4.lib;QtGui4.lib;QtOpenGL4.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(QTDIR)/lib;../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\ThirdParty\gtest\gtest-all.cpp" />
|
||||
<ClCompile Include="cvfqtUtils-Test.cpp" />
|
||||
<ClCompile Include="LibGuiQt_UnitTests.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="CMakeLists.txt" />
|
||||
<CustomBuild Include="TriggerTBBCopy.txt">
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb_debug.dll" + NUL "$(TargetDir)tbb_debug.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">$(TargetDir)tbb_debug.dll</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb.dll" + NUL "$(TargetDir)tbb.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">$(TargetDir)tbb.dll</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb_debug.dll" + NUL "$(TargetDir)tbb_debug.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">$(TargetDir)tbb_debug.dll</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb.dll" + NUL "$(TargetDir)tbb.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">$(TargetDir)tbb.dll</Outputs>
|
||||
</CustomBuild>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\LibGuiQt\LibGuiQt.vcxproj">
|
||||
<Project>{fbfac173-30fe-2c09-3f2e-d54477b433de}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\LibIo\LibIo.vcxproj">
|
||||
<Project>{181472ee-4b37-01e8-49d5-6213678fe4f8}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\LibViewing\LibViewing.vcxproj">
|
||||
<Project>{122d4663-11d6-d12f-8748-629a34e9075e}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\LibCore\LibCore.vcxproj">
|
||||
<Project>{a9c7a239-b761-a892-bf34-5aeca0d9ee88}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\LibGeometry\LibGeometry.vcxproj">
|
||||
<Project>{efd5c9ac-8988-f190-aa2c-e36ebe361e90}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\LibRender\LibRender.vcxproj">
|
||||
<Project>{c07ade80-5c4f-e6e3-dd1a-5a619403fa9f}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\ThirdParty\gtest\gtest-all.cpp" />
|
||||
<ClCompile Include="cvfqtUtils-Test.cpp" />
|
||||
<ClCompile Include="LibGuiQt_UnitTests.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="CMakeLists.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="TriggerTBBCopy.txt" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
2
Fwk/VizFwk/Tests/LibGuiQt_UnitTests/TriggerTBBCopy.txt
Normal file
2
Fwk/VizFwk/Tests/LibGuiQt_UnitTests/TriggerTBBCopy.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
Sole purpose of this file is to have custom build rules to trigger copying of TBB DLLs
|
||||
248
Fwk/VizFwk/Tests/LibGuiQt_UnitTests/cvfqtUtils-Test.cpp
Normal file
248
Fwk/VizFwk/Tests/LibGuiQt_UnitTests/cvfqtUtils-Test.cpp
Normal file
@@ -0,0 +1,248 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfqtUtils.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "cvfDebugTimer.h"
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(UtilsTest, toQString)
|
||||
{
|
||||
const cvf::String str("abc");
|
||||
QString qStr = cvfqt::Utils::toQString(str);
|
||||
|
||||
EXPECT_STREQ(str.toAscii().ptr(), (const char*)qStr.toAscii());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(UtilsTest, toQImage_withEmptyImage)
|
||||
{
|
||||
cvf::TextureImage i;
|
||||
|
||||
QImage qi = cvfqt::Utils::toQImage(i);
|
||||
EXPECT_EQ(0, qi.width());
|
||||
EXPECT_EQ(0, qi.height());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(UtilsTest, toQImage_withSinglePixelImage)
|
||||
{
|
||||
cvf::TextureImage i;
|
||||
i.allocate(1, 1);
|
||||
i.fill(cvf::Color4ub(1, 2, 3,4));
|
||||
|
||||
QImage qi = cvfqt::Utils::toQImage(i);
|
||||
ASSERT_EQ(1, qi.width());
|
||||
ASSERT_EQ(1, qi.height());
|
||||
EXPECT_EQ(qRgba(1, 2, 3, 4), qi.pixel(0,0));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(UtilsTest, toQImage)
|
||||
{
|
||||
cvf::TextureImage i;
|
||||
i.allocate(4, 3);
|
||||
i.setPixel(0,2, cvf::Color4ub( 8,18,58,108)); i.setPixel(1,2, cvf::Color4ub( 9,19,59,109)); i.setPixel(2,2, cvf::Color4ub(10,20,60,110)); i.setPixel(3,2, cvf::Color4ub(11,21,61,111));
|
||||
i.setPixel(0,1, cvf::Color4ub( 4,14,54,104)); i.setPixel(1,1, cvf::Color4ub( 5,15,55,105)); i.setPixel(2,1, cvf::Color4ub( 6,16,56,106)); i.setPixel(3,1, cvf::Color4ub( 7,17,57,107));
|
||||
i.setPixel(0,0, cvf::Color4ub( 0,10,50,100)); i.setPixel(1,0, cvf::Color4ub( 1,11,51,101)); i.setPixel(2,0, cvf::Color4ub( 2,12,52,102)); i.setPixel(3,0, cvf::Color4ub( 3,13,53,103));
|
||||
|
||||
QImage qi = cvfqt::Utils::toQImage(i);
|
||||
EXPECT_EQ(qRgba( 8,18,58,108), qi.pixel(0,0)); EXPECT_EQ(qRgba( 9,19,59,109), qi.pixel(1,0)); EXPECT_EQ(qRgba(10,20,60,110), qi.pixel(2,0)); EXPECT_EQ(qRgba(11,21,61,111), qi.pixel(3,0));
|
||||
EXPECT_EQ(qRgba( 4,14,54,104), qi.pixel(0,1)); EXPECT_EQ(qRgba( 5,15,55,105), qi.pixel(1,1)); EXPECT_EQ(qRgba( 6,16,56,106), qi.pixel(2,1)); EXPECT_EQ(qRgba( 7,17,57,107), qi.pixel(3,1));
|
||||
EXPECT_EQ(qRgba( 0,10,50,100), qi.pixel(0,2)); EXPECT_EQ(qRgba( 1,11,51,101), qi.pixel(1,2)); EXPECT_EQ(qRgba( 2,12,52,102), qi.pixel(2,2)); EXPECT_EQ(qRgba( 3,13,53,103), qi.pixel(3,2));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(UtilsTest, fromQImage_withEmptyImage)
|
||||
{
|
||||
QImage qi;
|
||||
|
||||
cvf::TextureImage i;
|
||||
cvfqt::Utils::fromQImage(qi, &i);
|
||||
EXPECT_EQ(0, i.width());
|
||||
EXPECT_EQ(0, i.height());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(UtilsTest, fromQImage_withSinglePixelImage)
|
||||
{
|
||||
QImage qi(1, 1, QImage::Format_ARGB32);
|
||||
qi.setPixel(0,0, qRgba(1, 2, 3, 4));
|
||||
|
||||
cvf::TextureImage i;
|
||||
cvfqt::Utils::fromQImage(qi, &i);
|
||||
ASSERT_EQ(1, i.width());
|
||||
ASSERT_EQ(1, i.height());
|
||||
EXPECT_EQ(cvf::Color4ub(1, 2, 3, 4), i.pixel(0,0));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(UtilsTest, fromQImage)
|
||||
{
|
||||
QImage qi(4, 3, QImage::Format_ARGB32);
|
||||
qi.setPixel(0,0, qRgba( 0,10,50,100)); qi.setPixel(1,0, qRgba( 1,11,51,101)); qi.setPixel(2,0, qRgba( 2,12,52,102)); qi.setPixel(3,0, qRgba( 3,13,53,103));
|
||||
qi.setPixel(0,1, qRgba( 4,14,54,104)); qi.setPixel(1,1, qRgba( 5,15,55,105)); qi.setPixel(2,1, qRgba( 6,16,56,106)); qi.setPixel(3,1, qRgba( 7,17,57,107));
|
||||
qi.setPixel(0,2, qRgba( 8,18,58,108)); qi.setPixel(1,2, qRgba( 9,19,59,109)); qi.setPixel(2,2, qRgba(10,20,60,110)); qi.setPixel(3,2, qRgba(11,21,61,111));
|
||||
|
||||
cvf::TextureImage i;
|
||||
cvfqt::Utils::fromQImage(qi, &i);
|
||||
ASSERT_EQ(4, i.width());
|
||||
ASSERT_EQ(3, i.height());
|
||||
|
||||
EXPECT_EQ(cvf::Color4ub( 0,10,50,100), i.pixel(0,2)); EXPECT_EQ(cvf::Color4ub( 1,11,51,101), i.pixel(1,2)); EXPECT_EQ(cvf::Color4ub( 2,12,52,102), i.pixel(2,2)); EXPECT_EQ(cvf::Color4ub( 3,13,53,103), i.pixel(3,2));
|
||||
EXPECT_EQ(cvf::Color4ub( 4,14,54,104), i.pixel(0,1)); EXPECT_EQ(cvf::Color4ub( 5,15,55,105), i.pixel(1,1)); EXPECT_EQ(cvf::Color4ub( 6,16,56,106), i.pixel(2,1)); EXPECT_EQ(cvf::Color4ub( 7,17,57,107), i.pixel(3,1));
|
||||
EXPECT_EQ(cvf::Color4ub( 8,18,58,108), i.pixel(0,0)); EXPECT_EQ(cvf::Color4ub( 9,19,59,109), i.pixel(1,0)); EXPECT_EQ(cvf::Color4ub(10,20,60,110), i.pixel(2,0)); EXPECT_EQ(cvf::Color4ub(11,21,61,111), i.pixel(3,0));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(UtilsTest, fromQImage_premultipliedImageFormat)
|
||||
{
|
||||
QImage qi(4, 3, QImage::Format_ARGB32_Premultiplied);
|
||||
qi.setPixel(0,0, qRgba( 0,10,50,100)); qi.setPixel(1,0, qRgba( 1,11,51,101)); qi.setPixel(2,0, qRgba( 2,12,52,102)); qi.setPixel(3,0, qRgba( 3,13,53,103));
|
||||
qi.setPixel(0,1, qRgba( 4,14,54,104)); qi.setPixel(1,1, qRgba( 5,15,55,105)); qi.setPixel(2,1, qRgba( 6,16,56,106)); qi.setPixel(3,1, qRgba( 7,17,57,107));
|
||||
qi.setPixel(0,2, qRgba( 8,18,58,108)); qi.setPixel(1,2, qRgba( 9,19,59,109)); qi.setPixel(2,2, qRgba(10,20,60,110)); qi.setPixel(3,2, qRgba(11,21,61,111));
|
||||
|
||||
cvf::TextureImage i;
|
||||
cvfqt::Utils::fromQImage(qi, &i);
|
||||
ASSERT_EQ(4, i.width());
|
||||
ASSERT_EQ(3, i.height());
|
||||
|
||||
EXPECT_EQ(cvf::Color4ub( 0,10,50,100), i.pixel(0,2)); EXPECT_EQ(cvf::Color4ub( 1,11,51,101), i.pixel(1,2)); EXPECT_EQ(cvf::Color4ub( 2,12,52,102), i.pixel(2,2)); EXPECT_EQ(cvf::Color4ub( 3,13,53,103), i.pixel(3,2));
|
||||
EXPECT_EQ(cvf::Color4ub( 4,14,54,104), i.pixel(0,1)); EXPECT_EQ(cvf::Color4ub( 5,15,55,105), i.pixel(1,1)); EXPECT_EQ(cvf::Color4ub( 6,16,56,106), i.pixel(2,1)); EXPECT_EQ(cvf::Color4ub( 7,17,57,107), i.pixel(3,1));
|
||||
EXPECT_EQ(cvf::Color4ub( 8,18,58,108), i.pixel(0,0)); EXPECT_EQ(cvf::Color4ub( 9,19,59,109), i.pixel(1,0)); EXPECT_EQ(cvf::Color4ub(10,20,60,110), i.pixel(2,0)); EXPECT_EQ(cvf::Color4ub(11,21,61,111), i.pixel(3,0));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(UtilsTest, fromQImageRegion_emptyRegion)
|
||||
{
|
||||
QImage qi(3, 4, QImage::Format_ARGB32);
|
||||
|
||||
{
|
||||
cvf::TextureImage i;
|
||||
cvfqt::Utils::fromQImageRegion(qi, cvf::Vec2ui(1, 1), cvf::Vec2ui(0, 0), &i);
|
||||
EXPECT_EQ(0, i.width());
|
||||
EXPECT_EQ(0, i.height());
|
||||
}
|
||||
{
|
||||
cvf::TextureImage i;
|
||||
cvfqt::Utils::fromQImageRegion(qi, cvf::Vec2ui(1, 1), cvf::Vec2ui(1, 0), &i);
|
||||
EXPECT_EQ(0, i.width());
|
||||
EXPECT_EQ(0, i.height());
|
||||
}
|
||||
{
|
||||
cvf::TextureImage i;
|
||||
cvfqt::Utils::fromQImageRegion(qi, cvf::Vec2ui(1, 1), cvf::Vec2ui(0, 1), &i);
|
||||
EXPECT_EQ(0, i.width());
|
||||
EXPECT_EQ(0, i.height());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(UtilsTest, fromQImageRegion)
|
||||
{
|
||||
QImage qi(4, 3, QImage::Format_ARGB32);
|
||||
qi.setPixel(0,0, qRgba( 0,10,50,100)); qi.setPixel(1,0, qRgba( 1,11,51,101)); qi.setPixel(2,0, qRgba( 2,12,52,102)); qi.setPixel(3,0, qRgba( 3,13,53,103));
|
||||
qi.setPixel(0,1, qRgba( 4,14,54,104)); qi.setPixel(1,1, qRgba( 5,15,55,105)); qi.setPixel(2,1, qRgba( 6,16,56,106)); qi.setPixel(3,1, qRgba( 7,17,57,107));
|
||||
qi.setPixel(0,2, qRgba( 8,18,58,108)); qi.setPixel(1,2, qRgba( 9,19,59,109)); qi.setPixel(2,2, qRgba(10,20,60,110)); qi.setPixel(3,2, qRgba(11,21,61,111));
|
||||
|
||||
{
|
||||
cvf::TextureImage i;
|
||||
cvfqt::Utils::fromQImageRegion(qi, cvf::Vec2ui(0, 0), cvf::Vec2ui(2, 1), &i);
|
||||
ASSERT_EQ(2, i.width());
|
||||
ASSERT_EQ(1, i.height());
|
||||
EXPECT_EQ(cvf::Color4ub( 0,10,50,100), i.pixel(0,0)); EXPECT_EQ(cvf::Color4ub( 1,11,51,101), i.pixel(1,0));
|
||||
}
|
||||
{
|
||||
cvf::TextureImage i;
|
||||
cvfqt::Utils::fromQImageRegion(qi, cvf::Vec2ui(2, 1), cvf::Vec2ui(2, 2), &i);
|
||||
ASSERT_EQ(2, i.width());
|
||||
ASSERT_EQ(2, i.height());
|
||||
EXPECT_EQ(cvf::Color4ub( 6,16,56,106), i.pixel(0,1)); EXPECT_EQ(cvf::Color4ub( 7,17,57,107), i.pixel(1,1));
|
||||
EXPECT_EQ(cvf::Color4ub(10,20,60,110), i.pixel(0,0)); EXPECT_EQ(cvf::Color4ub(11,21,61,111), i.pixel(1,0));
|
||||
}
|
||||
{
|
||||
cvf::TextureImage i;
|
||||
cvfqt::Utils::fromQImageRegion(qi, cvf::Vec2ui(0, 2), cvf::Vec2ui(4, 1), &i);
|
||||
ASSERT_EQ(4, i.width());
|
||||
ASSERT_EQ(1, i.height());
|
||||
EXPECT_EQ(cvf::Color4ub( 8,18,58,108), i.pixel(0,0)); EXPECT_EQ(cvf::Color4ub( 9,19,59,109), i.pixel(1,0)); EXPECT_EQ(cvf::Color4ub(10,20,60,110), i.pixel(2,0)); EXPECT_EQ(cvf::Color4ub(11,21,61,111), i.pixel(3,0));
|
||||
}
|
||||
{
|
||||
cvf::TextureImage i;
|
||||
cvfqt::Utils::fromQImageRegion(qi, cvf::Vec2ui(3, 0), cvf::Vec2ui(1, 3), &i);
|
||||
ASSERT_EQ(1, i.width());
|
||||
ASSERT_EQ(3, i.height());
|
||||
EXPECT_EQ(cvf::Color4ub( 3,13,53,103), i.pixel(0,2));
|
||||
EXPECT_EQ(cvf::Color4ub( 7,17,57,107), i.pixel(0,1));
|
||||
EXPECT_EQ(cvf::Color4ub(11,21,61,111), i.pixel(0,0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
25
Fwk/VizFwk/Tests/LibIo_UnitTests/CMakeLists.txt
Normal file
25
Fwk/VizFwk/Tests/LibIo_UnitTests/CMakeLists.txt
Normal file
@@ -0,0 +1,25 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(LibIo_UnitTests)
|
||||
|
||||
# Compile flags should already be setup by caller
|
||||
|
||||
|
||||
include_directories(${LibCore_SOURCE_DIR})
|
||||
include_directories(${LibIo_SOURCE_DIR})
|
||||
include_directories(${VizFramework_SOURCE_DIR}/ThirdParty)
|
||||
|
||||
set(CEE_LIBS LibIo LibCore)
|
||||
|
||||
|
||||
set(CEE_SOURCE_FILES
|
||||
cvfFile-Test.cpp
|
||||
cvfPropertyXmlSerialization-Test.cpp
|
||||
cvfXml-Test.cpp
|
||||
../../ThirdParty/gtest/gtest-all.cpp
|
||||
LibIo_UnitTests.cpp
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${CEE_SOURCE_FILES})
|
||||
target_link_libraries(${PROJECT_NAME} ${CEE_LIBS} ${CEE_PLATFORM_LIBS} )
|
||||
|
||||
58
Fwk/VizFwk/Tests/LibIo_UnitTests/LibIo_UnitTests.cpp
Normal file
58
Fwk/VizFwk/Tests/LibIo_UnitTests/LibIo_UnitTests.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "cvfTrace.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
//printf("Running main() from LibIo_UnitTests.cpp\n");
|
||||
|
||||
cvf::Assert::setReportMode(cvf::Assert::CONSOLE);
|
||||
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
285
Fwk/VizFwk/Tests/LibIo_UnitTests/LibIo_UnitTests.vcxproj
Normal file
285
Fwk/VizFwk/Tests/LibIo_UnitTests/LibIo_UnitTests.vcxproj
Normal file
@@ -0,0 +1,285 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug MD TBB|Win32">
|
||||
<Configuration>Debug MD TBB</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug MD TBB|x64">
|
||||
<Configuration>Debug MD TBB</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug MD|Win32">
|
||||
<Configuration>Debug MD</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug MD|x64">
|
||||
<Configuration>Debug MD</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD TBB|Win32">
|
||||
<Configuration>Release MD TBB</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD TBB|x64">
|
||||
<Configuration>Release MD TBB</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD|Win32">
|
||||
<Configuration>Release MD</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD|x64">
|
||||
<Configuration>Release MD</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{93516308-F124-5AD1-40C1-93A4E1DA7E02}</ProjectGuid>
|
||||
<RootNamespace>LibIo_UnitTests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibIo;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibIo;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibIo;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibIo;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibIo;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibIo;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibIo;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibIo;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\ThirdParty\gtest\gtest-all.cpp" />
|
||||
<ClCompile Include="cvfFile-Test.cpp" />
|
||||
<ClCompile Include="cvfPropertyXmlSerialization-Test.cpp" />
|
||||
<ClCompile Include="cvfXml-Test.cpp" />
|
||||
<ClCompile Include="LibIo_UnitTests.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="CMakeLists.txt" />
|
||||
<CustomBuild Include="TriggerTBBCopy.txt">
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb_debug.dll" + NUL "$(TargetDir)tbb_debug.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">$(TargetDir)tbb_debug.dll</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb.dll" + NUL "$(TargetDir)tbb.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">$(TargetDir)tbb.dll</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb_debug.dll" + NUL "$(TargetDir)tbb_debug.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">$(TargetDir)tbb_debug.dll</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb.dll" + NUL "$(TargetDir)tbb.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">$(TargetDir)tbb.dll</Outputs>
|
||||
</CustomBuild>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\LibCore\LibCore.vcxproj">
|
||||
<Project>{a9c7a239-b761-a892-bf34-5aeca0d9ee88}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\LibIo\LibIo.vcxproj">
|
||||
<Project>{181472ee-4b37-01e8-49d5-6213678fe4f8}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\ThirdParty\gtest\gtest-all.cpp" />
|
||||
<ClCompile Include="cvfXml-Test.cpp" />
|
||||
<ClCompile Include="LibIo_UnitTests.cpp" />
|
||||
<ClCompile Include="cvfFile-Test.cpp" />
|
||||
<ClCompile Include="cvfPropertyXmlSerialization-Test.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="CMakeLists.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="TriggerTBBCopy.txt" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
2
Fwk/VizFwk/Tests/LibIo_UnitTests/TriggerTBBCopy.txt
Normal file
2
Fwk/VizFwk/Tests/LibIo_UnitTests/TriggerTBBCopy.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
Sole purpose of this file is to have custom build rules to trigger copying of TBB DLLs
|
||||
74
Fwk/VizFwk/Tests/LibIo_UnitTests/cvfFile-Test.cpp
Normal file
74
Fwk/VizFwk/Tests/LibIo_UnitTests/cvfFile-Test.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfFile.h"
|
||||
#include "cvfString.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(FileTest, fopen)
|
||||
{
|
||||
// Normal file name
|
||||
{
|
||||
const String fn("testfile_no_unicode.txt");
|
||||
FILE* fp = File::fopen(fn, "w");
|
||||
ASSERT_TRUE(fp != NULL);
|
||||
|
||||
fprintf(fp, "Dummy text");
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
// Greek small, alfa, beta, gamma, delta and epsilon in file name
|
||||
{
|
||||
const String fn(L"testfile_\x03B1\x03B2\x03B3\x03B4\x03B5.txt");
|
||||
FILE* fp = File::fopen(fn, "w");
|
||||
ASSERT_TRUE(fp != NULL);
|
||||
|
||||
fprintf(fp, "Dummy text");
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfPropertyXmlSerializer.h"
|
||||
#include "cvfPropertySetCollection.h"
|
||||
#include "cvfXml.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
static bool ArePropertySetCollectionsEqual(const PropertySetCollection& psc1, const PropertySetCollection& psc2)
|
||||
{
|
||||
size_t numPropSets = psc1.count();
|
||||
if (numPropSets != psc2.count())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < numPropSets; i++)
|
||||
{
|
||||
const PropertySet* ps1 = psc1.propertySet(i);
|
||||
const PropertySet* ps2 = psc2.propertySet(i);
|
||||
if (!(*ps1 == *ps2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PropertyXmlSerializationTest, SaveLoadSimplePropertySets)
|
||||
{
|
||||
ref<PropertySetCollection> psc0 = new PropertySetCollection;
|
||||
|
||||
// Create and save the prop set collection
|
||||
{
|
||||
{
|
||||
ref<PropertySet> ps = new PropertySet("classTypeA");
|
||||
ps->setValue("myInt", Variant(-123));
|
||||
ps->setValue("myUInt", Variant(456u));
|
||||
ps->setValue("myDouble", Variant(1.234));
|
||||
ps->setValue("myFloat", Variant(1.567f));
|
||||
ps->setValue("myBool1", Variant(true));
|
||||
ps->setValue("myBool2", Variant(false));
|
||||
ps->setValue("myString", Variant("stringInA"));
|
||||
ps->setValue("myVec3d", Variant(Vec3d(1, 2, 3)));
|
||||
ps->setValue("myColor3f", Variant(Color3f(0.1f, 0.2f, 0.3f)));
|
||||
|
||||
psc0->addPropertySet(ps.p());
|
||||
}
|
||||
|
||||
{
|
||||
ref<PropertySet> ps = new PropertySet("classTypeB");
|
||||
ps->setValue("myInt", Variant(101));
|
||||
ps->setValue("myString", Variant("stringInB"));
|
||||
ps->setValue("myString", Variant("string with double spaces"));
|
||||
|
||||
psc0->addPropertySet(ps.p());
|
||||
}
|
||||
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
XmlElement* root = doc->createRootElement("myRoot");
|
||||
PropertyXmlSerializer::toXml(*psc0, root);
|
||||
doc->saveFile("testfile_propertiesSimple.xml");
|
||||
}
|
||||
|
||||
// Read from the xml file, create property set and compare
|
||||
{
|
||||
ref<PropertySetCollection> psc = new PropertySetCollection;
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
doc->loadFile("testfile_propertiesSimple.xml");
|
||||
|
||||
const cvf::XmlElement* root = doc->getRootElement("");
|
||||
ASSERT_TRUE(root != NULL);
|
||||
const XmlElement* propertySetCollectionElem = root->firstChildElement("PropertySetCollection");
|
||||
ASSERT_TRUE(propertySetCollectionElem != NULL);
|
||||
|
||||
PropertyXmlSerializer::toPropertySetCollection(*propertySetCollectionElem, psc.p());
|
||||
}
|
||||
|
||||
// For debug/inspection, write out the property set collection
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
XmlElement* root = doc->createRootElement("myRoot");
|
||||
PropertyXmlSerializer::toXml(*psc, root);
|
||||
doc->saveFile("testfile_propertiesSimple_rewrite.xml");
|
||||
}
|
||||
|
||||
ASSERT_TRUE(psc.notNull());
|
||||
EXPECT_TRUE(ArePropertySetCollectionsEqual(*psc, *psc0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PropertyXmlSerializationTest, SaveLoadComplexPropertySet)
|
||||
{
|
||||
ref<PropertySetCollection> psc0 = new PropertySetCollection;
|
||||
|
||||
{
|
||||
ref<PropertySet> ps = new PropertySet("myClassType");
|
||||
|
||||
{
|
||||
std::vector<Variant> variantArr;
|
||||
variantArr.push_back(Variant(123));
|
||||
variantArr.push_back(Variant(1.23));
|
||||
variantArr.push_back(Variant("a string"));
|
||||
ps->setValue("myFlatArray", Variant(variantArr));
|
||||
}
|
||||
{
|
||||
std::vector<Variant> variantArr;
|
||||
variantArr.push_back(Variant(123));
|
||||
variantArr.push_back(Variant(1.23));
|
||||
variantArr.push_back(Variant("a string"));
|
||||
|
||||
{
|
||||
std::vector<Variant> variantSubArr;
|
||||
variantSubArr.push_back(Variant(101));
|
||||
variantSubArr.push_back("another string");
|
||||
variantArr.push_back(Variant(variantSubArr));
|
||||
}
|
||||
|
||||
ps->setValue("myNestedArray", Variant(variantArr));
|
||||
}
|
||||
|
||||
psc0->addPropertySet(ps.p());
|
||||
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
XmlElement* root = doc->createRootElement("myRoot");
|
||||
PropertyXmlSerializer::toXml(*psc0, root);
|
||||
doc->saveFile("testfile_propertiesComplex.xml");
|
||||
}
|
||||
|
||||
// Read from the xml file, create property set and compare
|
||||
{
|
||||
ref<PropertySetCollection> psc = new PropertySetCollection;
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
doc->loadFile("testfile_propertiesComplex.xml");
|
||||
|
||||
const cvf::XmlElement* root = doc->getRootElement("");
|
||||
ASSERT_TRUE(root != NULL);
|
||||
const XmlElement* propertySetCollectionElem = root->firstChildElement("PropertySetCollection");
|
||||
ASSERT_TRUE(propertySetCollectionElem != NULL);
|
||||
|
||||
PropertyXmlSerializer::toPropertySetCollection(*propertySetCollectionElem, psc.p());
|
||||
}
|
||||
|
||||
// For debug/inspection, write out the property set collection
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
XmlElement* root = doc->createRootElement("myRoot");
|
||||
PropertyXmlSerializer::toXml(*psc, root);
|
||||
doc->saveFile("testfile_propertiesComplex_rewrite.xml");
|
||||
}
|
||||
|
||||
ASSERT_TRUE(psc.notNull());
|
||||
EXPECT_TRUE(ArePropertySetCollectionsEqual(*psc, *psc0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
816
Fwk/VizFwk/Tests/LibIo_UnitTests/cvfXml-Test.cpp
Normal file
816
Fwk/VizFwk/Tests/LibIo_UnitTests/cvfXml-Test.cpp
Normal file
@@ -0,0 +1,816 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfXml.h"
|
||||
#include "cvfMath.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
// Helper to delete test files
|
||||
static void DeleteMyTestFile(const String& fileName)
|
||||
{
|
||||
#ifdef WIN32
|
||||
_wremove(fileName.c_str());
|
||||
#else
|
||||
remove(fileName.toUtf8().ptr());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(XmlTest, BoolValues)
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
EXPECT_TRUE(doc.notNull());
|
||||
|
||||
XmlElement* root = doc->createRootElement("TestRoot");
|
||||
EXPECT_TRUE(root != NULL);
|
||||
|
||||
XmlElement* child1 = root->addChildElement("FirstChild");
|
||||
child1->setAttributeBool("trueBool", true);
|
||||
child1->setAttributeBool("falseBool", false);
|
||||
|
||||
XmlElement* child2 = root->addChildElement("SecondChild");
|
||||
child2->setAttributeBool("trueBool", true);
|
||||
child2->setAttributeBool("falseBool", false);
|
||||
|
||||
String filename = "testBool.xml";
|
||||
doc->saveFile(filename);
|
||||
|
||||
ref<XmlDocument> doc2 = XmlDocument::create();
|
||||
doc2->loadFile(filename);
|
||||
|
||||
XmlElement* root2 = doc2->getRootElement("");
|
||||
EXPECT_TRUE(root2 != NULL);
|
||||
|
||||
XmlElement* elem = root2->firstChildElement();
|
||||
String attrName("trueBool");
|
||||
bool valueRead = elem->getAttributeBool(attrName, false);
|
||||
EXPECT_TRUE(valueRead);
|
||||
|
||||
attrName = "falseBool";
|
||||
valueRead = elem->getAttributeBool(attrName, false);
|
||||
EXPECT_TRUE(!valueRead);
|
||||
|
||||
bool result = false;
|
||||
attrName = "falseBool";
|
||||
valueRead = elem->getAttributeBool(attrName, false, &result);
|
||||
EXPECT_TRUE(!valueRead);
|
||||
EXPECT_TRUE(result);
|
||||
|
||||
attrName = "doesNotExits";
|
||||
valueRead = elem->getAttributeBool(attrName, false, &result);
|
||||
EXPECT_TRUE(!valueRead);
|
||||
EXPECT_TRUE(!result);
|
||||
|
||||
// Read second child
|
||||
elem = root->firstChildElement("SecondChild");
|
||||
attrName = "falseBool";
|
||||
valueRead = elem->getAttributeBool(attrName, false, &result);
|
||||
EXPECT_TRUE(!valueRead);
|
||||
EXPECT_TRUE(result);
|
||||
|
||||
attrName = "";
|
||||
valueRead = elem->getAttributeBool(attrName, false, &result);
|
||||
EXPECT_TRUE(!valueRead);
|
||||
EXPECT_TRUE(!result);
|
||||
|
||||
DeleteMyTestFile(filename);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(XmlTest, IntValues)
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
EXPECT_TRUE(doc.notNull());
|
||||
|
||||
XmlElement* root = doc->createRootElement("TestRoot");
|
||||
EXPECT_TRUE(root != NULL);
|
||||
|
||||
{
|
||||
int val = 0;
|
||||
XmlElement* child1 = root->addChildElement("IntValues");
|
||||
|
||||
val = std::numeric_limits<int>::max();
|
||||
child1->setAttributeInt("max", val);
|
||||
|
||||
val = std::numeric_limits<int>::min();
|
||||
child1->setAttributeInt("min", val);
|
||||
}
|
||||
|
||||
{
|
||||
// Int 64
|
||||
int64 val64 = 0;
|
||||
XmlElement* child2 = root->addChildElement("Int64Values");
|
||||
|
||||
val64 = std::numeric_limits<int64>::max();
|
||||
child2->setAttributeInt64("max", val64);
|
||||
|
||||
val64 = std::numeric_limits<int64>::min();
|
||||
child2->setAttributeInt64("min", val64);
|
||||
}
|
||||
|
||||
|
||||
String filename = "testInt.xml";
|
||||
doc->saveFile(filename);
|
||||
|
||||
ref<XmlDocument> doc2 = XmlDocument::create();
|
||||
doc2->loadFile(filename);
|
||||
|
||||
XmlElement* root2 = doc2->getRootElement("");
|
||||
EXPECT_TRUE(root2 != NULL);
|
||||
|
||||
XmlElement* elem = root2->firstChildElement();
|
||||
String attrName("max");
|
||||
int valueRead = elem->getAttributeInt(attrName, false);
|
||||
EXPECT_EQ(valueRead, std::numeric_limits<int>::max());
|
||||
|
||||
attrName = "min";
|
||||
valueRead = elem->getAttributeInt(attrName, false);
|
||||
EXPECT_EQ(valueRead, std::numeric_limits<int>::min());
|
||||
|
||||
elem = elem->nextSiblingElement();
|
||||
attrName = "max";
|
||||
int64 value64Read = elem->getAttributeInt64(attrName, false);
|
||||
EXPECT_EQ(value64Read, std::numeric_limits<int64>::max());
|
||||
|
||||
attrName = "min";
|
||||
value64Read = elem->getAttributeInt64(attrName, false);
|
||||
EXPECT_EQ(value64Read, std::numeric_limits<int64>::min());
|
||||
|
||||
DeleteMyTestFile(filename);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(XmlTest, FloatValues)
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
EXPECT_TRUE(doc.notNull());
|
||||
|
||||
XmlElement* root = doc->createRootElement("TestRoot");
|
||||
EXPECT_TRUE(root != NULL);
|
||||
|
||||
{
|
||||
float val = 0;
|
||||
XmlElement* child1 = root->addChildElement("FloatValues");
|
||||
|
||||
val = std::numeric_limits<float>::max();
|
||||
child1->setAttributeFloat("max", val);
|
||||
|
||||
val = std::numeric_limits<float>::min();
|
||||
child1->setAttributeFloat("min", val);
|
||||
}
|
||||
|
||||
|
||||
String filename = "testFloat.xml";
|
||||
doc->saveFile(filename);
|
||||
|
||||
ref<XmlDocument> doc2 = XmlDocument::create();
|
||||
doc2->loadFile(filename);
|
||||
|
||||
XmlElement* root2 = doc2->getRootElement("");
|
||||
EXPECT_TRUE(root2 != NULL);
|
||||
|
||||
XmlElement* elem = root2->firstChildElement();
|
||||
String attrName("max");
|
||||
float valueRead = elem->getAttributeFloat(attrName, false);
|
||||
EXPECT_FLOAT_EQ(valueRead, UNDEFINED_FLOAT);
|
||||
|
||||
attrName = "min";
|
||||
valueRead = elem->getAttributeFloat(attrName, false);
|
||||
EXPECT_NEAR(valueRead, std::numeric_limits<float>::min(), 1.0e-6);
|
||||
|
||||
elem = elem->nextSiblingElement();
|
||||
|
||||
DeleteMyTestFile(filename);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(XmlTest, DoubleValues)
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
EXPECT_TRUE(doc.notNull());
|
||||
|
||||
XmlElement* root = doc->createRootElement("TestRoot");
|
||||
EXPECT_TRUE(root != NULL);
|
||||
|
||||
{
|
||||
double val = 0;
|
||||
XmlElement* child1 = root->addChildElement("DoubleValues");
|
||||
|
||||
val = std::numeric_limits<double>::max();
|
||||
child1->setAttributeDouble("max", val);
|
||||
|
||||
val = std::numeric_limits<double>::min();
|
||||
child1->setAttributeDouble("min", val);
|
||||
|
||||
val = 0.0;
|
||||
child1->setAttributeDouble("zero", val);
|
||||
}
|
||||
|
||||
|
||||
String filename = "testDouble.xml";
|
||||
doc->saveFile(filename);
|
||||
|
||||
ref<XmlDocument> doc2 = XmlDocument::create();
|
||||
doc2->loadFile(filename);
|
||||
|
||||
XmlElement* root2 = doc2->getRootElement("");
|
||||
EXPECT_TRUE(root2 != NULL);
|
||||
|
||||
XmlElement* elem = root2->firstChildElement();
|
||||
String attrName("max");
|
||||
double valueRead = elem->getAttributeDouble(attrName, false);
|
||||
EXPECT_DOUBLE_EQ(valueRead, UNDEFINED_DOUBLE);
|
||||
|
||||
attrName = "min";
|
||||
valueRead = elem->getAttributeDouble(attrName, false);
|
||||
EXPECT_NEAR(valueRead, std::numeric_limits<double>::min(), 1.0e-6);
|
||||
|
||||
attrName = "zero";
|
||||
valueRead = elem->getAttributeDouble(attrName, false);
|
||||
EXPECT_EQ(valueRead, 0.0);
|
||||
|
||||
attrName = "doesNotExist";
|
||||
bool found = false;
|
||||
valueRead = elem->getAttributeDouble(attrName, 10.1, &found);
|
||||
EXPECT_EQ(valueRead, 10.1);
|
||||
EXPECT_TRUE(!found);
|
||||
|
||||
DeleteMyTestFile(filename);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(XmlTest, ColorValues)
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
EXPECT_TRUE(doc.notNull());
|
||||
|
||||
XmlElement* root = doc->createRootElement("TestRoot");
|
||||
EXPECT_TRUE(root != NULL);
|
||||
|
||||
{
|
||||
Color3f col(Color3f::BLACK);
|
||||
XmlElement* child1 = root->addChildElement("ColorValues");
|
||||
child1->setAttributeColor("black", col);
|
||||
|
||||
col = Color3f::WHITE;
|
||||
child1->setAttributeColor("white", col);
|
||||
|
||||
col = Color3f(0.0f, 0.4f, 1.0f);
|
||||
child1->setAttributeColor("bluish", col);
|
||||
}
|
||||
|
||||
|
||||
String filename = "testColor.xml";
|
||||
doc->saveFile(filename);
|
||||
|
||||
ref<XmlDocument> doc2 = XmlDocument::create();
|
||||
doc2->loadFile(filename);
|
||||
|
||||
XmlElement* root2 = doc2->getRootElement("");
|
||||
EXPECT_TRUE(root2 != NULL);
|
||||
|
||||
Color3f defaultColor = Color3f::PURPLE;
|
||||
|
||||
XmlElement* elem = root2->firstChildElement();
|
||||
String attrName("black");
|
||||
Color3f valueRead = elem->getAttributeColor(attrName, defaultColor);
|
||||
EXPECT_TRUE(valueRead == Color3f::BLACK);
|
||||
|
||||
attrName = "white";
|
||||
valueRead = elem->getAttributeColor(attrName, defaultColor);
|
||||
EXPECT_TRUE(valueRead == Color3f::WHITE);
|
||||
|
||||
attrName = "bluish";
|
||||
valueRead = elem->getAttributeColor(attrName, defaultColor);
|
||||
EXPECT_TRUE(valueRead == Color3f(0.0f, 0.4f, 1.0f));
|
||||
|
||||
attrName = "doesNotExist";
|
||||
bool found = false;
|
||||
valueRead = elem->getAttributeColor(attrName, defaultColor, &found);
|
||||
EXPECT_TRUE(valueRead == Color3f::PURPLE);
|
||||
EXPECT_TRUE(!found);
|
||||
|
||||
DeleteMyTestFile(filename);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(XmlTest, VectorValues)
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
EXPECT_TRUE(doc.notNull());
|
||||
|
||||
XmlElement* root = doc->createRootElement("TestRoot");
|
||||
EXPECT_TRUE(root != NULL);
|
||||
|
||||
{
|
||||
Vec3d vec(0,1,2);
|
||||
XmlElement* child1 = root->addChildElement("VectorValues");
|
||||
child1->setAttributeVector("first", vec);
|
||||
|
||||
vec.set(3,4,5);
|
||||
child1->setAttributeVector("second", vec);
|
||||
|
||||
vec.set(-1,2,-3);
|
||||
child1->setAttributeVector("Neg", vec);
|
||||
}
|
||||
|
||||
String filename = "testVector.xml";
|
||||
ASSERT_TRUE(doc->saveFile(filename));
|
||||
|
||||
ref<XmlDocument> doc2 = XmlDocument::create();
|
||||
ASSERT_TRUE(doc2->loadFile(filename));
|
||||
|
||||
XmlElement* root2 = doc2->getRootElement("");
|
||||
ASSERT_TRUE(root2 != NULL);
|
||||
|
||||
Vec3d defaultVal = Vec3d(999,999,999);
|
||||
|
||||
XmlElement* elem = root2->firstChildElement();
|
||||
String attrName("first");
|
||||
Vec3d valueRead = elem->getAttributeVector(attrName, defaultVal);
|
||||
EXPECT_TRUE(valueRead == Vec3d(0,1,2));
|
||||
|
||||
attrName = "second";
|
||||
valueRead = elem->getAttributeVector(attrName, defaultVal);
|
||||
EXPECT_TRUE(valueRead == Vec3d(3,4,5));
|
||||
|
||||
attrName = "Neg";
|
||||
valueRead = elem->getAttributeVector(attrName, defaultVal);
|
||||
EXPECT_TRUE(valueRead == Vec3d(-1,2,-3));
|
||||
|
||||
attrName = "doesNotExist";
|
||||
bool found = false;
|
||||
valueRead = elem->getAttributeVector(attrName, defaultVal, &found);
|
||||
EXPECT_TRUE(valueRead == Vec3d(999,999,999));
|
||||
EXPECT_TRUE(!found);
|
||||
|
||||
DeleteMyTestFile(filename);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(XmlTest, TestHierarchy)
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
EXPECT_TRUE(doc.notNull());
|
||||
|
||||
XmlElement* root = doc->createRootElement("TestRoot");
|
||||
EXPECT_TRUE(root != NULL);
|
||||
|
||||
XmlElement* child1 = root->addChildElement("Level1");
|
||||
XmlElement* child2 = child1->addChildElement("Level2");
|
||||
XmlElement* child3 = child2->addChildElement("Level3");
|
||||
XmlElement* child4 = child3->addChildElement("Level4");
|
||||
XmlElement* child5 = child4->addChildElement("Level5");
|
||||
XmlElement* child6 = child5->addChildElement("Level6");
|
||||
XmlElement* child7 = child6->addChildElement("Level7");
|
||||
child7->setAttributeString("test", "dette er en test");
|
||||
|
||||
String filename = "testHierarchy.xml";
|
||||
doc->saveFile(filename);
|
||||
|
||||
ref<XmlDocument> doc2 = XmlDocument::create();
|
||||
doc2->loadFile(filename);
|
||||
|
||||
XmlElement* root2 = doc2->getRootElement("");
|
||||
EXPECT_TRUE(root2 != NULL);
|
||||
|
||||
XmlElement* elem = root2->firstChildElement();
|
||||
EXPECT_STREQ("Level1", elem->name().toAscii().ptr());
|
||||
elem = elem->firstChildElement();
|
||||
EXPECT_STREQ("Level2", elem->name().toAscii().ptr());
|
||||
elem = elem->firstChildElement();
|
||||
EXPECT_STREQ("Level3", elem->name().toAscii().ptr());
|
||||
elem = elem->firstChildElement();
|
||||
EXPECT_STREQ("Level4", elem->name().toAscii().ptr());
|
||||
elem = elem->firstChildElement();
|
||||
EXPECT_STREQ("Level5", elem->name().toAscii().ptr());
|
||||
elem = elem->firstChildElement();
|
||||
EXPECT_STREQ("Level6", elem->name().toAscii().ptr());
|
||||
elem = elem->firstChildElement();
|
||||
EXPECT_STREQ("Level7", elem->name().toAscii().ptr());
|
||||
String valueRead = elem->getAttributeString("test");
|
||||
EXPECT_STREQ("dette er en test", valueRead.toAscii().ptr());
|
||||
|
||||
elem = elem->firstChildElement();
|
||||
EXPECT_TRUE(!elem);
|
||||
|
||||
DeleteMyTestFile(filename);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(XmlTest, SaveToNonASCIIFileName)
|
||||
{
|
||||
// <20><><EFBFBD>.xml
|
||||
const wchar_t* uniStr = L"\x00e6\x00f8\x00e5.xml";
|
||||
String filename(uniStr);
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
EXPECT_TRUE(doc.notNull());
|
||||
|
||||
XmlElement* root = doc->createRootElement("TestRoot");
|
||||
EXPECT_TRUE(root != NULL);
|
||||
|
||||
root->addChildElement("Child1");
|
||||
root->addChildElement("Child2");
|
||||
|
||||
ASSERT_TRUE(doc->saveFile(filename));
|
||||
}
|
||||
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
ASSERT_TRUE(doc->loadFile(filename));
|
||||
}
|
||||
|
||||
DeleteMyTestFile(filename);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(XmlTest, NonASCIICharacters)
|
||||
{
|
||||
const String filename = "testNonAsciiContents.xml";
|
||||
|
||||
const String uniStr1(L"abc");
|
||||
|
||||
// <20><><EFBFBD>
|
||||
const String uniStr2(L"\x00e6\x00f8\x00e5");
|
||||
|
||||
// Greek small, alfa, beta, gamma, delta and epsilon
|
||||
const String uniStr3(L"\x03B1\x03B2\x03B3\x03B4\x03B5");
|
||||
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
EXPECT_TRUE(doc.notNull());
|
||||
|
||||
XmlElement* root = doc->createRootElement("TestRoot");
|
||||
EXPECT_TRUE(root != NULL);
|
||||
|
||||
XmlElement* child1 = root->addChildElement("Child1");
|
||||
child1->setAttributeString("str1", uniStr1);
|
||||
child1->setAttributeString("str2", uniStr2);
|
||||
child1->setAttributeString("str3", uniStr3);
|
||||
|
||||
|
||||
XmlElement* child2 = root->addChildElement("Child2");
|
||||
child2->setAttributeString("str3", uniStr3);
|
||||
child2->setAttributeString("str2", uniStr2);
|
||||
child2->setAttributeString("str1", uniStr1);
|
||||
|
||||
ASSERT_TRUE(doc->saveFile(filename));
|
||||
}
|
||||
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
ASSERT_TRUE(doc->loadFile(filename));
|
||||
|
||||
XmlElement* root = doc->getRootElement("TestRoot");
|
||||
EXPECT_TRUE(root != NULL);
|
||||
|
||||
XmlElement* child1 = root->firstChildElement();
|
||||
ASSERT_TRUE(child1 != NULL);
|
||||
EXPECT_STREQ("Child1", child1->name().toAscii().ptr());
|
||||
|
||||
|
||||
String str;
|
||||
str = child1->getAttributeString("str1");
|
||||
EXPECT_TRUE(uniStr1 == str);
|
||||
|
||||
str = child1->getAttributeString("str2");
|
||||
EXPECT_TRUE(uniStr2 == str);
|
||||
|
||||
str = child1->getAttributeString("str3");
|
||||
EXPECT_TRUE(uniStr3 == str);
|
||||
|
||||
|
||||
XmlElement* child2 = child1->nextSiblingElement();
|
||||
ASSERT_TRUE(child2 != NULL);
|
||||
EXPECT_STREQ("Child2", child2->name().toAscii().ptr());
|
||||
|
||||
str = child2->getAttributeString("str1");
|
||||
EXPECT_TRUE(uniStr1 == str);
|
||||
|
||||
str = child2->getAttributeString("str2");
|
||||
EXPECT_TRUE(uniStr2 == str);
|
||||
|
||||
str = child2->getAttributeString("str3");
|
||||
EXPECT_TRUE(uniStr3 == str);
|
||||
}
|
||||
|
||||
DeleteMyTestFile(filename);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(XmlTest, WhiteSpace)
|
||||
{
|
||||
String filename = "testWhiteSpace.xml";
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
doc->preserveWhiteSpace(true);
|
||||
|
||||
XmlElement* root = doc->createRootElement("TestRoot");
|
||||
EXPECT_TRUE(root != NULL);
|
||||
|
||||
XmlElement* child1 = root->addChildElement("FirstChild");
|
||||
child1->setValueText(" space inside text ");
|
||||
|
||||
XmlElement* child2 = root->addChildElement("SecondChild");
|
||||
child2->setValueText(" ");
|
||||
|
||||
XmlElement* child3 = root->addChildElement("ThirdChild");
|
||||
child3->setValueText(" ");
|
||||
|
||||
doc->saveFile(filename);
|
||||
}
|
||||
|
||||
// Skip whitespace when loading XML file
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
doc->preserveWhiteSpace(false);
|
||||
doc->loadFile(filename);
|
||||
|
||||
XmlElement* root = doc->getRootElement("TestRoot");
|
||||
EXPECT_TRUE(root != NULL);
|
||||
|
||||
XmlElement* child1 = root->firstChildElement();
|
||||
ASSERT_TRUE(child1 != NULL);
|
||||
|
||||
String str;
|
||||
str = child1->valueText();
|
||||
EXPECT_STREQ("space inside text", str.toAscii().ptr());
|
||||
|
||||
XmlElement* child2 = child1->nextSiblingElement();
|
||||
ASSERT_TRUE(child2 != NULL);
|
||||
|
||||
str = child2->valueText();
|
||||
EXPECT_TRUE(str.isEmpty());
|
||||
|
||||
XmlElement* child3 = child2->nextSiblingElement();
|
||||
ASSERT_TRUE(child3 != NULL);
|
||||
|
||||
str = child3->valueText();
|
||||
EXPECT_TRUE(str.isEmpty());
|
||||
}
|
||||
|
||||
// Preserve whitespace when loading XML file, default behaviour
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
doc->loadFile(filename);
|
||||
|
||||
XmlElement* root = doc->getRootElement("TestRoot");
|
||||
EXPECT_TRUE(root != NULL);
|
||||
|
||||
XmlElement* child1 = root->firstChildElement();
|
||||
ASSERT_TRUE(child1 != NULL);
|
||||
|
||||
String str;
|
||||
str = child1->valueText();
|
||||
EXPECT_STREQ(" space inside text ", str.toAscii().ptr());
|
||||
|
||||
XmlElement* child2 = child1->nextSiblingElement();
|
||||
ASSERT_TRUE(child2 != NULL);
|
||||
|
||||
str = child2->valueText();
|
||||
EXPECT_STREQ(" ", str.toAscii().ptr());
|
||||
|
||||
XmlElement* child3 = child2->nextSiblingElement();
|
||||
ASSERT_TRUE(child3 != NULL);
|
||||
|
||||
str = child3->valueText();
|
||||
EXPECT_STREQ(" ", str.toAscii().ptr());
|
||||
|
||||
String filenameOut = "testWhiteSpacePreserved.xml";
|
||||
doc->saveFile(filenameOut);
|
||||
DeleteMyTestFile(filenameOut);
|
||||
}
|
||||
|
||||
// Compact XML file output
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
doc->loadFile(filename);
|
||||
|
||||
String filenameOut = "testWhiteSpaceCompact.xml";
|
||||
doc->saveCompactFile(filenameOut);
|
||||
|
||||
DeleteMyTestFile(filenameOut);
|
||||
}
|
||||
|
||||
|
||||
DeleteMyTestFile(filename);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(XmlTest, RootWithAttributes)
|
||||
{
|
||||
String filename = "testWhiteSpace.xml";
|
||||
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
|
||||
XmlElement* root = doc->createRootElement("TestRoot");
|
||||
EXPECT_TRUE(root != NULL);
|
||||
|
||||
root->setValueText("Value text");
|
||||
root->setAttributeString("AttribTest", "This is a test");
|
||||
doc->saveFile(filename);
|
||||
}
|
||||
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
doc->loadFile(filename);
|
||||
|
||||
XmlElement* root = doc->getRootElement("TestRoot");
|
||||
EXPECT_TRUE(root != NULL);
|
||||
|
||||
cvf::String str = root->getAttributeString("AttribTest");
|
||||
EXPECT_STREQ("This is a test", str.toAscii().ptr());
|
||||
|
||||
cvf::String valText = root->valueText();
|
||||
EXPECT_STREQ("Value text", valText.toAscii().ptr());
|
||||
}
|
||||
|
||||
DeleteMyTestFile(filename);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(XmlTest, GetAttributes)
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
EXPECT_TRUE(doc.notNull());
|
||||
|
||||
XmlElement* root = doc->createRootElement("TestRoot");
|
||||
EXPECT_TRUE(root != NULL);
|
||||
|
||||
XmlElement* child1 = root->addChildElement("FirstChild");
|
||||
child1->setAttributeBool("trueBool", true);
|
||||
child1->setAttributeBool("falseBool", false);
|
||||
|
||||
std::vector<cvf::String> names, values;
|
||||
child1->getAttributes(&names, &values);
|
||||
|
||||
EXPECT_EQ(2, names.size());
|
||||
EXPECT_EQ(2, values.size());
|
||||
|
||||
EXPECT_STREQ("trueBool", names[0].toAscii().ptr());
|
||||
EXPECT_STREQ("falseBool", names[1].toAscii().ptr());
|
||||
|
||||
EXPECT_STREQ("true", values[0].toAscii().ptr());
|
||||
EXPECT_STREQ("false", values[1].toAscii().ptr());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(XmlTest, RemoveChildElement)
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
EXPECT_TRUE(doc.notNull());
|
||||
|
||||
XmlElement* root = doc->createRootElement("TestRoot");
|
||||
EXPECT_TRUE(root != NULL);
|
||||
|
||||
XmlElement* child1 = root->addChildElement("FirstChild");
|
||||
XmlElement* child2 = root->addChildElement("SecondChild");
|
||||
XmlElement* child3 = root->addChildElement("ThirdChild");
|
||||
|
||||
root->removeChildElement(child2);
|
||||
|
||||
EXPECT_TRUE(child1 == root->firstChildElement());
|
||||
EXPECT_TRUE(child3 == root->firstChildElement()->nextSiblingElement());
|
||||
|
||||
root->removeChildElement(child3);
|
||||
|
||||
EXPECT_TRUE(child1 == root->firstChildElement());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(XmlTest, Clear)
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
EXPECT_TRUE(doc.notNull());
|
||||
|
||||
XmlElement* root = doc->createRootElement("TestRoot");
|
||||
EXPECT_TRUE(root != NULL);
|
||||
|
||||
root->addChildElement("FirstChild");
|
||||
root->addChildElement("SecondChild");
|
||||
root->addChildElement("ThirdChild");
|
||||
|
||||
doc->clear();
|
||||
|
||||
EXPECT_TRUE(NULL == doc->getRootElement("TestRoot"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(XmlTest, ToOrFromRawData)
|
||||
{
|
||||
ref<XmlDocument> doc = XmlDocument::create();
|
||||
EXPECT_TRUE(doc.notNull());
|
||||
|
||||
XmlElement* root = doc->createRootElement("TestRoot");
|
||||
EXPECT_TRUE(root != NULL);
|
||||
|
||||
root->addChildElement("FirstChild");
|
||||
root->addChildElement("SecondChild");
|
||||
root->addChildElement("ThirdChild");
|
||||
|
||||
cvf::UByteArray buffer;
|
||||
doc->getAsRawData(&buffer);
|
||||
|
||||
ref<XmlDocument> doc2 = XmlDocument::create();
|
||||
EXPECT_TRUE(doc2.notNull());
|
||||
|
||||
doc2->setFromRawData(buffer);
|
||||
XmlElement* root2 = doc2->getRootElement("TestRoot");
|
||||
ASSERT_TRUE(root2 != NULL);
|
||||
|
||||
ASSERT_TRUE(root2->firstChildElement() != NULL);
|
||||
ASSERT_TRUE(root2->firstChildElement()->nextSiblingElement() != NULL);
|
||||
ASSERT_TRUE(root2->firstChildElement()->nextSiblingElement()->nextSiblingElement() != NULL);
|
||||
|
||||
EXPECT_STREQ("FirstChild", root2->firstChildElement()->name().toAscii().ptr());
|
||||
EXPECT_STREQ("SecondChild", root2->firstChildElement()->nextSiblingElement()->name().toAscii().ptr());
|
||||
EXPECT_STREQ("ThirdChild", root2->firstChildElement()->nextSiblingElement()->nextSiblingElement()->name().toAscii().ptr());
|
||||
}
|
||||
|
||||
|
||||
30
Fwk/VizFwk/Tests/LibRegGrid2D_UnitTests/CMakeLists.txt
Normal file
30
Fwk/VizFwk/Tests/LibRegGrid2D_UnitTests/CMakeLists.txt
Normal file
@@ -0,0 +1,30 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(LibRegGrid2D_UnitTests)
|
||||
|
||||
# Compile flags should already be setup by caller
|
||||
|
||||
|
||||
find_package(OpenGL)
|
||||
|
||||
include_directories(${LibCore_SOURCE_DIR})
|
||||
include_directories(${LibIo_SOURCE_DIR})
|
||||
include_directories(${LibGeometry_SOURCE_DIR})
|
||||
include_directories(${LibRender_SOURCE_DIR})
|
||||
include_directories(${LibRegGrid2D_SOURCE_DIR})
|
||||
include_directories(${VizFramework_SOURCE_DIR}/ThirdParty)
|
||||
|
||||
set(CEE_LIBS LibRegGrid2D LibRender LibGeometry LibIo LibCore)
|
||||
|
||||
|
||||
set(CEE_SOURCE_FILES
|
||||
cvfRegGrid2D-Test.cpp
|
||||
cvfRegGrid2DExportImport-Test.cpp
|
||||
cvfRegGrid2DGeometry-Test.cpp
|
||||
../../ThirdParty/gtest/gtest-all.cpp
|
||||
LibRegGrid2D_UnitTests.cpp
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${CEE_SOURCE_FILES})
|
||||
target_link_libraries(${PROJECT_NAME} ${CEE_LIBS} ${OPENGL_LIBRARIES} ${CEE_PLATFORM_LIBS})
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
//printf("Running main() from LibRegGrid2D_UnitTests.cpp\n");
|
||||
|
||||
cvf::Assert::setReportMode(cvf::Assert::CONSOLE);
|
||||
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@@ -0,0 +1,297 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug MD TBB|Win32">
|
||||
<Configuration>Debug MD TBB</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug MD TBB|x64">
|
||||
<Configuration>Debug MD TBB</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug MD|Win32">
|
||||
<Configuration>Debug MD</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug MD|x64">
|
||||
<Configuration>Debug MD</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD TBB|Win32">
|
||||
<Configuration>Release MD TBB</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD TBB|x64">
|
||||
<Configuration>Release MD TBB</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD|Win32">
|
||||
<Configuration>Release MD</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD|x64">
|
||||
<Configuration>Release MD</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{BF85DFDC-7E61-D1CB-AAB3-FEA48EE57B9E}</ProjectGuid>
|
||||
<RootNamespace>LibRegGrid2D_UnitTests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../LibRender;../../LibViewing;../../LibIo;../../LibRegGrid2D;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../LibRender;../../LibViewing;../../LibIo;../../LibRegGrid2D;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../LibRender;../../LibViewing;../../LibIo;../../LibRegGrid2D;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../LibRender;../../LibViewing;../../LibIo;../../LibRegGrid2D;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../LibRender;../../LibViewing;../../LibIo;../../LibRegGrid2D;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../LibRender;../../LibViewing;../../LibIo;../../LibRegGrid2D;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../LibRender;../../LibViewing;../../LibIo;../../LibRegGrid2D;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../LibRender;../../LibViewing;../../LibIo;../../LibRegGrid2D;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\ThirdParty\gtest\gtest-all.cpp" />
|
||||
<ClCompile Include="cvfRegGrid2D-Test.cpp" />
|
||||
<ClCompile Include="cvfRegGrid2DExportImport-Test.cpp" />
|
||||
<ClCompile Include="cvfRegGrid2DGeometry-Test.cpp" />
|
||||
<ClCompile Include="LibRegGrid2D_UnitTests.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="CMakeLists.txt" />
|
||||
<CustomBuild Include="TriggerTBBCopy.txt">
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb_debug.dll" + NUL "$(TargetDir)tbb_debug.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">$(TargetDir)tbb_debug.dll</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb.dll" + NUL "$(TargetDir)tbb.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">$(TargetDir)tbb.dll</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb_debug.dll" + NUL "$(TargetDir)tbb_debug.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">$(TargetDir)tbb_debug.dll</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb.dll" + NUL "$(TargetDir)tbb.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">$(TargetDir)tbb.dll</Outputs>
|
||||
</CustomBuild>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\LibViewing\LibViewing.vcxproj">
|
||||
<Project>{122d4663-11d6-d12f-8748-629a34e9075e}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\LibCore\LibCore.vcxproj">
|
||||
<Project>{a9c7a239-b761-a892-bf34-5aeca0d9ee88}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\LibGeometry\LibGeometry.vcxproj">
|
||||
<Project>{efd5c9ac-8988-f190-aa2c-e36ebe361e90}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\LibIo\LibIo.vcxproj">
|
||||
<Project>{181472ee-4b37-01e8-49d5-6213678fe4f8}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\LibRegGrid2D\LibRegGrid2D.vcxproj">
|
||||
<Project>{7aef1888-268c-3bef-4080-743645180a59}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\LibRender\LibRender.vcxproj">
|
||||
<Project>{c07ade80-5c4f-e6e3-dd1a-5a619403fa9f}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\ThirdParty\gtest\gtest-all.cpp" />
|
||||
<ClCompile Include="cvfRegGrid2DGeometry-Test.cpp" />
|
||||
<ClCompile Include="cvfRegGrid2D-Test.cpp" />
|
||||
<ClCompile Include="LibRegGrid2D_UnitTests.cpp" />
|
||||
<ClCompile Include="cvfRegGrid2DExportImport-Test.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="CMakeLists.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="TriggerTBBCopy.txt" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
Sole purpose of this file is to have custom build rules to trigger copying of TBB DLLs
|
||||
604
Fwk/VizFwk/Tests/LibRegGrid2D_UnitTests/cvfRegGrid2D-Test.cpp
Normal file
604
Fwk/VizFwk/Tests/LibRegGrid2D_UnitTests/cvfRegGrid2D-Test.cpp
Normal file
@@ -0,0 +1,604 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfRegGrid2D.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RegGrid2D, AllocateGrid)
|
||||
{
|
||||
ref<RegGrid2D> regGrid2D = new RegGrid2D;
|
||||
EXPECT_TRUE(regGrid2D.notNull());
|
||||
|
||||
regGrid2D->allocateGrid(10, 20);
|
||||
EXPECT_EQ(10, regGrid2D->gridPointCountI());
|
||||
EXPECT_EQ(20, regGrid2D->gridPointCountJ());
|
||||
|
||||
regGrid2D->allocateGrid(0, 0);
|
||||
EXPECT_EQ(0, regGrid2D->gridPointCountI());
|
||||
EXPECT_EQ(0, regGrid2D->gridPointCountJ());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#ifdef CVF_ENABLE_ASSERTS
|
||||
TEST(RegGrid2DDeathTest, IllegalParametersAllocateGrid)
|
||||
{
|
||||
ref<RegGrid2D> regGrid2D = new RegGrid2D;
|
||||
EXPECT_TRUE(regGrid2D.notNull());
|
||||
|
||||
EXPECT_DEATH(regGrid2D->allocateGrid(-1, 10), "Assertion");
|
||||
EXPECT_DEATH(regGrid2D->allocateGrid(10, -1), "Assertion");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RegGrid2D, Spacing)
|
||||
{
|
||||
ref<RegGrid2D> regGrid2D = new RegGrid2D;
|
||||
EXPECT_TRUE(regGrid2D.notNull());
|
||||
|
||||
EXPECT_EQ(0.0, regGrid2D->spacing().x());
|
||||
EXPECT_EQ(0.0, regGrid2D->spacing().y());
|
||||
|
||||
regGrid2D->setSpacing(Vec2d(2.3, 5.4));
|
||||
EXPECT_EQ(2.3, regGrid2D->spacing().x());
|
||||
EXPECT_EQ(5.4, regGrid2D->spacing().y());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#ifdef CVF_ENABLE_ASSERTS
|
||||
TEST(RegGrid2DDeathTest, IllegalParametersSpacing)
|
||||
{
|
||||
ref<RegGrid2D> regGrid2D = new RegGrid2D;
|
||||
EXPECT_TRUE(regGrid2D.notNull());
|
||||
|
||||
EXPECT_DEATH(regGrid2D->setSpacing(Vec2d(-1, 10)), "Assertion");
|
||||
EXPECT_DEATH(regGrid2D->setSpacing(Vec2d(10, -1)), "Assertion");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RegGrid2D, Origo)
|
||||
{
|
||||
ref<RegGrid2D> regGrid2D = new RegGrid2D;
|
||||
EXPECT_TRUE(regGrid2D.notNull());
|
||||
|
||||
EXPECT_EQ(0.0, regGrid2D->offset().x());
|
||||
EXPECT_EQ(0.0, regGrid2D->offset().y());
|
||||
|
||||
regGrid2D->setOffset(Vec2d(2.3, 5.4));
|
||||
EXPECT_EQ(2.3, regGrid2D->offset().x());
|
||||
EXPECT_EQ(5.4, regGrid2D->offset().y());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RegGrid2D, ElevationValues)
|
||||
{
|
||||
ref<RegGrid2D> regGrid2D = new RegGrid2D;
|
||||
EXPECT_TRUE(regGrid2D.notNull());
|
||||
regGrid2D->allocateGrid(10, 20);
|
||||
|
||||
DoubleArray values;
|
||||
values.resize(10 * 20);
|
||||
values.setAll(5);
|
||||
values.set(0, -10);
|
||||
values.set(1, 50);
|
||||
values.set(10 * 20 - 1, -99);
|
||||
regGrid2D->setElevations(values);
|
||||
|
||||
double elevationValue = regGrid2D->elevation(0, 0);
|
||||
EXPECT_EQ(-10, elevationValue);
|
||||
|
||||
elevationValue = regGrid2D->elevation(1, 0);
|
||||
EXPECT_EQ(50, elevationValue);
|
||||
|
||||
elevationValue = regGrid2D->elevation(2, 0);
|
||||
EXPECT_EQ(5, elevationValue);
|
||||
|
||||
elevationValue = regGrid2D->elevation(9, 19);
|
||||
EXPECT_EQ(-99, elevationValue);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#ifdef CVF_ENABLE_ASSERTS
|
||||
TEST(RegGrid2DDeathTest, InvalidParametersElevation)
|
||||
{
|
||||
ref<RegGrid2D> regGrid2D = new RegGrid2D;
|
||||
EXPECT_TRUE(regGrid2D.notNull());
|
||||
|
||||
regGrid2D->allocateGrid(10, 20);
|
||||
EXPECT_DEATH(regGrid2D->setElevation(-1, 0, 0), "Assertion");
|
||||
EXPECT_DEATH(regGrid2D->setElevation(10, 0, 0), "Assertion");
|
||||
EXPECT_DEATH(regGrid2D->setElevation(0, -1, 0), "Assertion");
|
||||
EXPECT_DEATH(regGrid2D->setElevation(0, 20, 0), "Assertion");
|
||||
|
||||
DoubleArray values;
|
||||
values.resize(20 * 20);
|
||||
EXPECT_DEATH(regGrid2D->setElevations(values), "Assertion");
|
||||
EXPECT_DEATH(regGrid2D->setElevations(values.ptr(), 20*20), "Assertion");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RegGrid2D, PointEvaluation)
|
||||
{
|
||||
ref<RegGrid2D> regGrid2D = new RegGrid2D;
|
||||
EXPECT_TRUE(regGrid2D.notNull());
|
||||
|
||||
regGrid2D->allocateGrid(2, 2);
|
||||
regGrid2D->setSpacing(Vec2d(1, 1));
|
||||
|
||||
// y
|
||||
// /\ (line cannot end with \)
|
||||
// |
|
||||
// 4(0,1) -2(1,1)
|
||||
// |--------|
|
||||
// | |
|
||||
// | |
|
||||
// |--------|---> x
|
||||
// 2(0,0) 5(1,0)
|
||||
regGrid2D->setElevation(0, 0, 2);
|
||||
regGrid2D->setElevation(1, 0, 5);
|
||||
regGrid2D->setElevation(0, 1, 4);
|
||||
regGrid2D->setElevation(1, 1, -2);
|
||||
|
||||
|
||||
// Reg grid corners
|
||||
{
|
||||
Vec2d coord(0, 0);
|
||||
double elevationValue = regGrid2D->pointElevation(coord);
|
||||
EXPECT_EQ(2, elevationValue);
|
||||
}
|
||||
|
||||
{
|
||||
Vec2d coord(1, 0);
|
||||
double elevationValue = regGrid2D->pointElevation(coord);
|
||||
EXPECT_EQ(5, elevationValue);
|
||||
}
|
||||
|
||||
{
|
||||
Vec2d coord(0, 1);
|
||||
double elevationValue = regGrid2D->pointElevation(coord);
|
||||
EXPECT_EQ(4, elevationValue);
|
||||
}
|
||||
|
||||
{
|
||||
Vec2d coord(1, 1);
|
||||
double elevationValue = regGrid2D->pointElevation(coord);
|
||||
EXPECT_EQ(-2, elevationValue);
|
||||
}
|
||||
|
||||
// Undefined on edge of grid, not possible to use bilinear interpolation
|
||||
{
|
||||
Vec2d coord(0.5, 1);
|
||||
double elevationValue = regGrid2D->pointElevation(coord);
|
||||
EXPECT_EQ(UNDEFINED_DOUBLE, elevationValue);
|
||||
}
|
||||
|
||||
double coordOffset = 0.00001;
|
||||
double deltaValue = 0.001;
|
||||
|
||||
// Interpolation along sides
|
||||
{
|
||||
Vec2d coord(0.5, 0 + coordOffset);
|
||||
double elevationValue = regGrid2D->pointElevation(coord);
|
||||
EXPECT_NEAR(3.5, elevationValue, 0.01);
|
||||
}
|
||||
{
|
||||
Vec2d coord(0.5, 1 - coordOffset);
|
||||
double elevationValue = regGrid2D->pointElevation(coord);
|
||||
EXPECT_NEAR(1.0, elevationValue, deltaValue);
|
||||
}
|
||||
{
|
||||
Vec2d coord(0 + coordOffset, 0.5);
|
||||
double elevationValue = regGrid2D->pointElevation(coord);
|
||||
EXPECT_NEAR(3.0, elevationValue, deltaValue);
|
||||
}
|
||||
|
||||
{
|
||||
Vec2d coord(1 - coordOffset, 0.5);
|
||||
double elevationValue = regGrid2D->pointElevation(coord);
|
||||
EXPECT_NEAR(1.5, elevationValue, deltaValue);
|
||||
}
|
||||
|
||||
// Interpolation in center
|
||||
{
|
||||
Vec2d coord(0.5, 0.5);
|
||||
double elevationValue = regGrid2D->pointElevation(coord);
|
||||
EXPECT_EQ(2.25, elevationValue);
|
||||
}
|
||||
|
||||
|
||||
// Interpolation of coordinates outside grid
|
||||
{
|
||||
Vec2d coord(-0.5, 0.5);
|
||||
double elevationValue = regGrid2D->pointElevation(coord);
|
||||
EXPECT_EQ(elevationValue, UNDEFINED_DOUBLE);
|
||||
}
|
||||
|
||||
{
|
||||
Vec2d coord(-0.5, -0.5);
|
||||
double elevationValue = regGrid2D->pointElevation(coord);
|
||||
EXPECT_EQ(elevationValue, UNDEFINED_DOUBLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RegGrid2D, PointEvaluationOffset)
|
||||
{
|
||||
ref<RegGrid2D> regGrid2D = new RegGrid2D;
|
||||
EXPECT_TRUE(regGrid2D.notNull());
|
||||
|
||||
regGrid2D->allocateGrid(2, 2);
|
||||
regGrid2D->setSpacing(Vec2d(1, 1));
|
||||
regGrid2D->setOffset(Vec2d(1, 1));
|
||||
|
||||
// y
|
||||
// /\ (line cannot end with \)
|
||||
// |
|
||||
// 4(0,1) -2(1,1)
|
||||
// |--------|
|
||||
// | |
|
||||
// | |
|
||||
// |--------|---> x
|
||||
// 2(0,0) 5(1,0)
|
||||
regGrid2D->setElevation(0, 0, 2);
|
||||
regGrid2D->setElevation(1, 0, 5);
|
||||
regGrid2D->setElevation(0, 1, 4);
|
||||
regGrid2D->setElevation(1, 1, -2);
|
||||
|
||||
|
||||
// Outside reg grid
|
||||
{
|
||||
Vec2d coord(0, 0);
|
||||
double elevationValue = regGrid2D->pointElevation(coord);
|
||||
EXPECT_EQ(UNDEFINED_DOUBLE, elevationValue);
|
||||
}
|
||||
|
||||
// Lower left corner
|
||||
{
|
||||
Vec2d coord(1, 1);
|
||||
double elevationValue = regGrid2D->pointElevation(coord);
|
||||
EXPECT_EQ(2, elevationValue);
|
||||
}
|
||||
|
||||
// Center right corner
|
||||
{
|
||||
Vec2d coord(1.5, 1.5);
|
||||
double elevationValue = regGrid2D->pointElevation(coord);
|
||||
EXPECT_EQ(2.25, elevationValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RegGrid2D, MinMaxElevation)
|
||||
{
|
||||
ref<RegGrid2D> regGrid2D = new RegGrid2D;
|
||||
EXPECT_TRUE(regGrid2D.notNull());
|
||||
|
||||
regGrid2D->allocateGrid(2, 2);
|
||||
|
||||
DoubleArray values;
|
||||
values.resize(2 * 2);
|
||||
values.set(0, 2);
|
||||
values.set(1, 5);
|
||||
values.set(2, 4);
|
||||
values.set(3, -2);
|
||||
regGrid2D->setElevations(values);
|
||||
|
||||
double min, max;
|
||||
regGrid2D->minMaxElevation(&min, &max);
|
||||
EXPECT_EQ(-2, min);
|
||||
EXPECT_EQ(5, max);
|
||||
|
||||
regGrid2D->minMaxElevationInRegion(0, 0, 0, 0, &min, &max);
|
||||
EXPECT_EQ(2, min);
|
||||
EXPECT_EQ(2, max);
|
||||
|
||||
regGrid2D->minMaxElevationInRegion(0, 0, 1, 0, &min, &max);
|
||||
EXPECT_EQ(2, min);
|
||||
EXPECT_EQ(5, max);
|
||||
|
||||
regGrid2D->minMaxElevationInRegion(1, 1, 1, 1, &min, &max);
|
||||
EXPECT_EQ(-2, min);
|
||||
EXPECT_EQ(-2, max);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#ifdef CVF_ENABLE_ASSERTS
|
||||
TEST(RegGrid2DDeathTest, InvalidParametersMinMaxElevation)
|
||||
{
|
||||
ref<RegGrid2D> regGrid2D = new RegGrid2D;
|
||||
EXPECT_TRUE(regGrid2D.notNull());
|
||||
|
||||
regGrid2D->allocateGrid(10, 20);
|
||||
|
||||
double min, max;
|
||||
EXPECT_DEATH(regGrid2D->minMaxElevationInRegion(-1, 0, 0, 0, &min, &max), "Assertion");
|
||||
EXPECT_DEATH(regGrid2D->minMaxElevationInRegion(0, -1, 0, 0, &min, &max), "Assertion");
|
||||
EXPECT_DEATH(regGrid2D->minMaxElevationInRegion(0, 0, -1, 0, &min, &max), "Assertion");
|
||||
EXPECT_DEATH(regGrid2D->minMaxElevationInRegion(0, 0, 0, -1, &min, &max), "Assertion");
|
||||
|
||||
EXPECT_DEATH(regGrid2D->minMaxElevationInRegion(1, 0, 0, 0, &min, &max), "Assertion");
|
||||
EXPECT_DEATH(regGrid2D->minMaxElevationInRegion(0, 1, 0, 0, &min, &max), "Assertion");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RegGrid2D, MapLineSegmentOnGrid)
|
||||
{
|
||||
ref<RegGrid2D> regGrid2D = new RegGrid2D;
|
||||
EXPECT_TRUE(regGrid2D.notNull());
|
||||
|
||||
regGrid2D->allocateGrid(4, 4);
|
||||
regGrid2D->setSpacing(Vec2d(1, 1));
|
||||
|
||||
double delta = 0.001;
|
||||
|
||||
// Test increasing ij
|
||||
{
|
||||
Vec3dArray intersections;
|
||||
|
||||
Vec2d start(0.5, 0.5);
|
||||
Vec2d end(1.5, 2.5);
|
||||
regGrid2D->mapLineSegmentOnGrid(start, end, &intersections);
|
||||
EXPECT_EQ(5, intersections.size());
|
||||
|
||||
EXPECT_NEAR(0.5, intersections[0].x(), delta);
|
||||
EXPECT_NEAR(0.5, intersections[0].y(), delta);
|
||||
|
||||
EXPECT_NEAR(0.75, intersections[1].x(), delta);
|
||||
EXPECT_NEAR(1.0 , intersections[1].y(), delta);
|
||||
|
||||
EXPECT_NEAR(1.0, intersections[2].x(), delta);
|
||||
EXPECT_NEAR(1.5, intersections[2].y(), delta);
|
||||
|
||||
EXPECT_NEAR(1.25, intersections[3].x(), delta);
|
||||
EXPECT_NEAR(2.0 , intersections[3].y(), delta);
|
||||
|
||||
EXPECT_NEAR(1.5, intersections[4].x(), delta);
|
||||
EXPECT_NEAR(2.5, intersections[4].y(), delta);
|
||||
}
|
||||
|
||||
// Test increasing i, decreasing j
|
||||
{
|
||||
Vec3dArray intersections;
|
||||
|
||||
Vec2d start(0.5, 2.5);
|
||||
Vec2d end(1.5, 0.5);
|
||||
regGrid2D->mapLineSegmentOnGrid(start, end, &intersections);
|
||||
EXPECT_EQ(5, intersections.size());
|
||||
}
|
||||
|
||||
// Test decreasing i, increasing j
|
||||
{
|
||||
Vec3dArray intersections;
|
||||
|
||||
Vec2d start(1.5, 0.5);
|
||||
Vec2d end(0.5, 2.5);
|
||||
regGrid2D->mapLineSegmentOnGrid(start, end, &intersections);
|
||||
EXPECT_EQ(5, intersections.size());
|
||||
}
|
||||
|
||||
// Test decreasing ij
|
||||
{
|
||||
Vec3dArray intersections;
|
||||
|
||||
Vec2d start(1.5, 2.5);
|
||||
Vec2d end(0.5, 0.5);
|
||||
regGrid2D->mapLineSegmentOnGrid(start, end, &intersections);
|
||||
EXPECT_EQ(5, intersections.size());
|
||||
}
|
||||
|
||||
|
||||
// Intersection at gridpoints
|
||||
{
|
||||
Vec3dArray intersections;
|
||||
|
||||
Vec2d start(2.5, 2.5);
|
||||
Vec2d end(0.5, 0.5);
|
||||
regGrid2D->mapLineSegmentOnGrid(start, end, &intersections);
|
||||
EXPECT_EQ(4, intersections.size());
|
||||
}
|
||||
|
||||
// Intersection at gridpoints, start and end at gridpoints
|
||||
{
|
||||
Vec3dArray intersections;
|
||||
|
||||
Vec2d start(0, 0);
|
||||
Vec2d end(2, 2);
|
||||
regGrid2D->mapLineSegmentOnGrid(start, end, &intersections);
|
||||
EXPECT_EQ(3, intersections.size());
|
||||
}
|
||||
|
||||
// Intersection at gridpoints, start and end at gridpoints
|
||||
{
|
||||
Vec3dArray intersections;
|
||||
|
||||
Vec2d start(2, 2);
|
||||
Vec2d end(0, 0);
|
||||
regGrid2D->mapLineSegmentOnGrid(start, end, &intersections);
|
||||
EXPECT_EQ(3, intersections.size());
|
||||
}
|
||||
|
||||
// Vertical line ascending
|
||||
{
|
||||
Vec3dArray intersections;
|
||||
|
||||
Vec2d start(1.1, 0.1);
|
||||
Vec2d end(1.1, 2.1);
|
||||
regGrid2D->mapLineSegmentOnGrid(start, end, &intersections);
|
||||
EXPECT_EQ(4, intersections.size());
|
||||
}
|
||||
|
||||
// Vertical line descending
|
||||
{
|
||||
Vec3dArray intersections;
|
||||
|
||||
Vec2d start(1.1, 2.1);
|
||||
Vec2d end(1.1, 0.1);
|
||||
regGrid2D->mapLineSegmentOnGrid(start, end, &intersections);
|
||||
EXPECT_EQ(4, intersections.size());
|
||||
}
|
||||
|
||||
// Horizontal line ascending
|
||||
{
|
||||
Vec3dArray intersections;
|
||||
|
||||
Vec2d start(0.1, 1.1);
|
||||
Vec2d end(2.1, 1.1);
|
||||
regGrid2D->mapLineSegmentOnGrid(start, end, &intersections);
|
||||
EXPECT_EQ(4, intersections.size());
|
||||
}
|
||||
|
||||
// Horizontal line descending
|
||||
{
|
||||
Vec3dArray intersections;
|
||||
|
||||
Vec2d start(2.1, 1.1);
|
||||
Vec2d end(0.1, 1.1);
|
||||
regGrid2D->mapLineSegmentOnGrid(start, end, &intersections);
|
||||
EXPECT_EQ(4, intersections.size());
|
||||
}
|
||||
|
||||
// Line starting outside grid
|
||||
{
|
||||
Vec3dArray intersections;
|
||||
|
||||
Vec2d start(-1, 1);
|
||||
Vec2d end(10, 1);
|
||||
regGrid2D->mapLineSegmentOnGrid(start, end, &intersections);
|
||||
EXPECT_EQ(4, intersections.size());
|
||||
|
||||
EXPECT_NEAR(0, intersections[0].x(), delta);
|
||||
EXPECT_NEAR(1, intersections[0].y(), delta);
|
||||
|
||||
EXPECT_NEAR(1, intersections[1].x(), delta);
|
||||
EXPECT_NEAR(1, intersections[1].y(), delta);
|
||||
|
||||
EXPECT_NEAR(2, intersections[2].x(), delta);
|
||||
EXPECT_NEAR(1, intersections[2].y(), delta);
|
||||
|
||||
EXPECT_NEAR(3, intersections[3].x(), delta);
|
||||
EXPECT_NEAR(1, intersections[3].y(), delta);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RegGrid2D, GridCoordinate)
|
||||
{
|
||||
ref<RegGrid2D> regGrid2D = new RegGrid2D;
|
||||
EXPECT_TRUE(regGrid2D.notNull());
|
||||
|
||||
regGrid2D->allocateGrid(4, 4);
|
||||
|
||||
regGrid2D->setSpacing(Vec2d(1, 1));
|
||||
{
|
||||
Rectd boundingRect = regGrid2D->boundingRectangle();
|
||||
EXPECT_EQ(0.0, boundingRect.min().x());
|
||||
EXPECT_EQ(0.0, boundingRect.min().y());
|
||||
EXPECT_EQ(3.0, boundingRect.max().x());
|
||||
EXPECT_EQ(3.0, boundingRect.max().y());
|
||||
}
|
||||
|
||||
regGrid2D->setSpacing(Vec2d(2, 2));
|
||||
{
|
||||
Rectd boundingRect = regGrid2D->boundingRectangle();
|
||||
EXPECT_EQ(0.0, boundingRect.min().x());
|
||||
EXPECT_EQ(0.0, boundingRect.min().y());
|
||||
EXPECT_EQ(6.0, boundingRect.max().x());
|
||||
EXPECT_EQ(6.0, boundingRect.max().y());
|
||||
}
|
||||
|
||||
regGrid2D->setOffset(Vec2d(2, 2));
|
||||
regGrid2D->setSpacing(Vec2d(3, 3));
|
||||
{
|
||||
Rectd boundingRect = regGrid2D->boundingRectangle();
|
||||
EXPECT_EQ(2.0, boundingRect.min().x());
|
||||
EXPECT_EQ(2.0, boundingRect.min().y());
|
||||
EXPECT_EQ(11.0, boundingRect.max().x());
|
||||
EXPECT_EQ(11.0, boundingRect.max().y());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfRegGrid2DImportXml.h"
|
||||
#include "cvfRegGrid2DExportXml.h"
|
||||
#include "cvfRegGrid2D.h"
|
||||
#include "cvfString.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
// Helper to delete test files
|
||||
static void DeleteMyTestFile(const String& fileName)
|
||||
{
|
||||
#ifdef WIN32
|
||||
_wremove(fileName.c_str());
|
||||
#else
|
||||
remove(fileName.toUtf8().ptr());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RegGrid2DExportTest, Basic)
|
||||
{
|
||||
ref<RegGrid2D> regGridA = new RegGrid2D;
|
||||
ASSERT_TRUE(regGridA.notNull());
|
||||
|
||||
Vec2d offset(10, 20);
|
||||
int gridCountI = 2;
|
||||
int gridCountJ = 3;
|
||||
Vec2d spacing(10, 200);
|
||||
|
||||
regGridA->setOffset(offset);
|
||||
regGridA->setSpacing(spacing);
|
||||
regGridA->allocateGrid(gridCountI, gridCountJ);
|
||||
|
||||
DoubleArray values;
|
||||
values.resize(2 * 3);
|
||||
values.set(0, 2);
|
||||
values.set(1, 5);
|
||||
values.set(2, 4);
|
||||
values.set(3, -2);
|
||||
values.set(4, -2);
|
||||
values.set(5, -2);
|
||||
regGridA->setElevations(values);
|
||||
|
||||
String filename = "reggrid.xml";
|
||||
RegGrid2DExportXml::exportToXmlFile(*regGridA, 10, filename);
|
||||
|
||||
ref<RegGrid2D> regGridB = new RegGrid2D;
|
||||
ASSERT_TRUE(regGridB.notNull());
|
||||
|
||||
RegGrid2DImportXml::importFromXmlFile(filename, regGridB.p());
|
||||
EXPECT_EQ(regGridA->offset().x(), regGridB->offset().x());
|
||||
EXPECT_EQ(regGridA->offset().y(), regGridB->offset().y());
|
||||
EXPECT_EQ(regGridA->spacing().x(), regGridB->spacing().x());
|
||||
EXPECT_EQ(regGridA->spacing().y(), regGridB->spacing().y());
|
||||
|
||||
EXPECT_EQ(regGridA->gridPointCountI(), regGridB->gridPointCountI());
|
||||
EXPECT_EQ(regGridA->gridPointCountJ(), regGridB->gridPointCountJ());
|
||||
|
||||
|
||||
DeleteMyTestFile(filename);
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfRegGrid2DGeometry.h"
|
||||
#include "cvfRegGrid2D.h"
|
||||
#include "cvfDrawableGeo.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RegGrid2DGeometryTest, SurfaceConstruction)
|
||||
{
|
||||
ref<RegGrid2D> regGrid = new RegGrid2D;
|
||||
ASSERT_TRUE(regGrid.notNull());
|
||||
|
||||
int gridCountI = 2;
|
||||
int gridCountJ = 3;
|
||||
Vec2d spacing(1, 1);
|
||||
|
||||
regGrid->setSpacing(spacing);
|
||||
regGrid->allocateGrid(gridCountI, gridCountJ);
|
||||
|
||||
DoubleArray values;
|
||||
values.resize(2 * 3);
|
||||
values.setAll(5);
|
||||
regGrid->setElevations(values);
|
||||
|
||||
{
|
||||
ref<RegGrid2DGeometry> geoBuilder = new RegGrid2DGeometry(regGrid.p());
|
||||
|
||||
ref<DrawableGeo> geo = geoBuilder->generateSurface();
|
||||
ASSERT_TRUE(geo.notNull());
|
||||
|
||||
EXPECT_DOUBLE_EQ(0.0, geo->boundingBox().min().x());
|
||||
EXPECT_DOUBLE_EQ(0.0, geo->boundingBox().min().y());
|
||||
EXPECT_DOUBLE_EQ(5.0, geo->boundingBox().min().z());
|
||||
|
||||
EXPECT_DOUBLE_EQ(1.0, geo->boundingBox().max().x());
|
||||
EXPECT_DOUBLE_EQ(2.0, geo->boundingBox().max().y());
|
||||
EXPECT_DOUBLE_EQ(5.0, geo->boundingBox().max().z());
|
||||
}
|
||||
|
||||
{
|
||||
ref<RegGrid2DGeometry> geoBuilder = new RegGrid2DGeometry(regGrid.p());
|
||||
geoBuilder->setTranslation(Vec3d(10, 20, 0));
|
||||
|
||||
ref<DrawableGeo> geo = geoBuilder->generateSurface();
|
||||
ASSERT_TRUE(geo.notNull());
|
||||
|
||||
EXPECT_DOUBLE_EQ(10.0, geo->boundingBox().min().x());
|
||||
EXPECT_DOUBLE_EQ(20.0, geo->boundingBox().min().y());
|
||||
EXPECT_DOUBLE_EQ(5.0, geo->boundingBox().min().z());
|
||||
|
||||
EXPECT_DOUBLE_EQ(11.0, geo->boundingBox().max().x());
|
||||
EXPECT_DOUBLE_EQ(22.0, geo->boundingBox().max().y());
|
||||
EXPECT_DOUBLE_EQ(5.0, geo->boundingBox().max().z());
|
||||
}
|
||||
|
||||
{
|
||||
ref<RegGrid2DGeometry> geoBuilder = new RegGrid2DGeometry(regGrid.p());
|
||||
geoBuilder->setTranslation(Vec3d(10, 20, 2.0));
|
||||
geoBuilder->setElevationScaleFactor(-2.0);
|
||||
|
||||
ref<DrawableGeo> geo = geoBuilder->generateSurface();
|
||||
ASSERT_TRUE(geo.notNull());
|
||||
|
||||
EXPECT_DOUBLE_EQ(10.0, geo->boundingBox().min().x());
|
||||
EXPECT_DOUBLE_EQ(20.0, geo->boundingBox().min().y());
|
||||
EXPECT_DOUBLE_EQ(-8.0, geo->boundingBox().min().z());
|
||||
|
||||
EXPECT_DOUBLE_EQ(11.0, geo->boundingBox().max().x());
|
||||
EXPECT_DOUBLE_EQ(22.0, geo->boundingBox().max().y());
|
||||
EXPECT_DOUBLE_EQ(-8.0, geo->boundingBox().max().z());
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RegGrid2DGeometryTest, ClosedVolume)
|
||||
{
|
||||
ref<RegGrid2D> regGrid2D = new RegGrid2D;
|
||||
EXPECT_TRUE(regGrid2D.notNull());
|
||||
|
||||
regGrid2D->allocateGrid(10, 20);
|
||||
{
|
||||
ref<RegGrid2DGeometry> regGrid2DGeometryNoElevations = new RegGrid2DGeometry(regGrid2D.p());
|
||||
ref<DrawableGeo> closedVolumeGeo = regGrid2DGeometryNoElevations->generateClosedVolume(10);
|
||||
ASSERT_FALSE(closedVolumeGeo.notNull());
|
||||
|
||||
// It is allowed to create a surface when elevations are undefined. Should this be allowed?
|
||||
ref<DrawableGeo> surface = regGrid2DGeometryNoElevations->generateSurface();
|
||||
ASSERT_TRUE(surface.notNull());
|
||||
}
|
||||
|
||||
DoubleArray values;
|
||||
values.resize(10 * 20);
|
||||
values.setAll(5);
|
||||
|
||||
regGrid2D->setElevations(values);
|
||||
|
||||
ref<RegGrid2DGeometry> regGrid2DGeometry = new RegGrid2DGeometry(regGrid2D.p());
|
||||
|
||||
{
|
||||
ref<DrawableGeo> closedVolumeGeo = regGrid2DGeometry->generateClosedVolume(10);
|
||||
ASSERT_FALSE(closedVolumeGeo.notNull());
|
||||
}
|
||||
|
||||
{
|
||||
ref<DrawableGeo> closedVolumeGeo = regGrid2DGeometry->generateClosedVolume(-10);
|
||||
ASSERT_TRUE(closedVolumeGeo.notNull());
|
||||
}
|
||||
}
|
||||
|
||||
54
Fwk/VizFwk/Tests/LibRender_UnitTests/CMakeLists.txt
Normal file
54
Fwk/VizFwk/Tests/LibRender_UnitTests/CMakeLists.txt
Normal file
@@ -0,0 +1,54 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(LibRender_UnitTests)
|
||||
|
||||
# Compile flags should already be setup by caller
|
||||
|
||||
|
||||
find_package(OpenGL)
|
||||
|
||||
include_directories(${LibCore_SOURCE_DIR})
|
||||
include_directories(${LibGeometry_SOURCE_DIR})
|
||||
include_directories(${LibRender_SOURCE_DIR})
|
||||
include_directories(${VizFramework_SOURCE_DIR}/ThirdParty)
|
||||
|
||||
set(CEE_LIBS LibRender LibGeometry LibCore)
|
||||
|
||||
|
||||
set(CEE_SOURCE_FILES
|
||||
cvfCamera-Test.cpp
|
||||
cvfDrawableGeo-Test.cpp
|
||||
cvfGeometryBuilderDrawableGeo-Test.cpp
|
||||
cvfMatrixState-Test.cpp
|
||||
cvfOpenGLCapabilities-Test.cpp
|
||||
cvfOpenGLContextGroup-Test.cpp
|
||||
cvfOpenGLResourceManager-Test.cpp
|
||||
cvfOverlayColorLegend-Test.cpp
|
||||
cvfOverlayItem-Test.cpp
|
||||
cvfOverlayTextBox-Test.cpp
|
||||
cvfPrimitiveSetDirect-Test.cpp
|
||||
cvfPrimitiveSetIndexedUInt-Test.cpp
|
||||
cvfPrimitiveSetIndexedUIntScoped-Test.cpp
|
||||
cvfPrimitiveSetIndexedUShortScoped-Test.cpp
|
||||
cvfRenderState-Test.cpp
|
||||
cvfSampler-Test.cpp
|
||||
cvfScalarMapper-Test.cpp
|
||||
cvfScalarMapperUniformLevels-Test.cpp
|
||||
cvfShader-Test.cpp
|
||||
cvfShaderProgram-Test.cpp
|
||||
cvfShaderProgramGenerator-Test.cpp
|
||||
cvfShaderSourceRepository-Test.cpp
|
||||
cvfTexture-Test.cpp
|
||||
cvfTextureImage-Test.cpp
|
||||
cvfUniform-Test.cpp
|
||||
cvfUniformSet-Test.cpp
|
||||
cvfVertexAttribute-Test.cpp
|
||||
cvfVertexBundle-Test.cpp
|
||||
cvfViewport-Test.cpp
|
||||
../../ThirdParty/gtest/gtest-all.cpp
|
||||
LibRender_UnitTests.cpp
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${CEE_SOURCE_FILES})
|
||||
target_link_libraries(${PROJECT_NAME} ${CEE_LIBS} ${OPENGL_LIBRARIES} ${CEE_PLATFORM_LIBS})
|
||||
|
||||
56
Fwk/VizFwk/Tests/LibRender_UnitTests/LibRender_UnitTests.cpp
Normal file
56
Fwk/VizFwk/Tests/LibRender_UnitTests/LibRender_UnitTests.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
//printf("Running main() from LibRender_UnitTests.cpp\n");
|
||||
|
||||
cvf::Assert::setReportMode(cvf::Assert::CONSOLE);
|
||||
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
314
Fwk/VizFwk/Tests/LibRender_UnitTests/LibRender_UnitTests.vcxproj
Normal file
314
Fwk/VizFwk/Tests/LibRender_UnitTests/LibRender_UnitTests.vcxproj
Normal file
@@ -0,0 +1,314 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug MD TBB|Win32">
|
||||
<Configuration>Debug MD TBB</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug MD TBB|x64">
|
||||
<Configuration>Debug MD TBB</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug MD|Win32">
|
||||
<Configuration>Debug MD</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug MD|x64">
|
||||
<Configuration>Debug MD</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD TBB|Win32">
|
||||
<Configuration>Release MD TBB</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD TBB|x64">
|
||||
<Configuration>Release MD TBB</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD|Win32">
|
||||
<Configuration>Release MD</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release MD|x64">
|
||||
<Configuration>Release MD</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{E4C3CAB6-02B3-A353-1955-8DA235C4FB64}</ProjectGuid>
|
||||
<RootNamespace>LibRender_UnitTests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">
|
||||
<OutDir>$(Platform)_VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)_VS2010\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../LibRender;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../LibRender;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../LibRender;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../LibRender;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../LibRender;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../LibRender;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../LibRender;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../LibCore;../../LibGeometry;../../LibRender;../../ThirdParty</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;CVF_USE_TBB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>../../ThirdParty/TBB/lib/$(Platform)_VS2010</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\ThirdParty\gtest\gtest-all.cpp" />
|
||||
<ClCompile Include="cvfCamera-Test.cpp" />
|
||||
<ClCompile Include="cvfDrawableGeo-Test.cpp" />
|
||||
<ClCompile Include="cvfGeometryBuilderDrawableGeo-Test.cpp" />
|
||||
<ClCompile Include="cvfMatrixState-Test.cpp" />
|
||||
<ClCompile Include="cvfOpenGLCapabilities-Test.cpp" />
|
||||
<ClCompile Include="cvfOpenGLContextGroup-Test.cpp" />
|
||||
<ClCompile Include="cvfOpenGLResourceManager-Test.cpp" />
|
||||
<ClCompile Include="cvfOverlayColorLegend-Test.cpp" />
|
||||
<ClCompile Include="cvfOverlayItem-Test.cpp" />
|
||||
<ClCompile Include="cvfOverlayTextBox-Test.cpp" />
|
||||
<ClCompile Include="cvfPrimitiveSetDirect-Test.cpp" />
|
||||
<ClCompile Include="cvfPrimitiveSetIndexedUInt-Test.cpp" />
|
||||
<ClCompile Include="cvfPrimitiveSetIndexedUIntScoped-Test.cpp" />
|
||||
<ClCompile Include="cvfPrimitiveSetIndexedUShortScoped-Test.cpp" />
|
||||
<ClCompile Include="cvfRenderState-Test.cpp" />
|
||||
<ClCompile Include="cvfSampler-Test.cpp" />
|
||||
<ClCompile Include="cvfScalarMapper-Test.cpp" />
|
||||
<ClCompile Include="cvfScalarMapperUniformLevels-Test.cpp" />
|
||||
<ClCompile Include="cvfShader-Test.cpp" />
|
||||
<ClCompile Include="cvfShaderProgram-Test.cpp" />
|
||||
<ClCompile Include="cvfShaderProgramGenerator-Test.cpp" />
|
||||
<ClCompile Include="cvfShaderSourceRepository-Test.cpp" />
|
||||
<ClCompile Include="cvfTexture-Test.cpp" />
|
||||
<ClCompile Include="cvfTextureImage-Test.cpp" />
|
||||
<ClCompile Include="cvfUniform-Test.cpp" />
|
||||
<ClCompile Include="cvfUniformSet-Test.cpp" />
|
||||
<ClCompile Include="cvfVertexAttribute-Test.cpp" />
|
||||
<ClCompile Include="cvfVertexBundle-Test.cpp" />
|
||||
<ClCompile Include="cvfViewport-Test.cpp" />
|
||||
<ClCompile Include="LibRender_UnitTests.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="CMakeLists.txt" />
|
||||
<CustomBuild Include="TriggerTBBCopy.txt">
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb_debug.dll" + NUL "$(TargetDir)tbb_debug.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|Win32'">$(TargetDir)tbb_debug.dll</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb.dll" + NUL "$(TargetDir)tbb.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|Win32'">$(TargetDir)tbb.dll</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb_debug.dll" + NUL "$(TargetDir)tbb_debug.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug MD TBB|x64'">$(TargetDir)tbb_debug.dll</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">COPY /Y /B "..\..\ThirdParty\TBB\bin\$(Platform)_VS2010\tbb.dll" + NUL "$(TargetDir)tbb.dll"</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">Copying Intel Threading Building Blocks DLL...</Message>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release MD TBB|x64'">$(TargetDir)tbb.dll</Outputs>
|
||||
</CustomBuild>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\LibCore\LibCore.vcxproj">
|
||||
<Project>{a9c7a239-b761-a892-bf34-5aeca0d9ee88}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\LibGeometry\LibGeometry.vcxproj">
|
||||
<Project>{efd5c9ac-8988-f190-aa2c-e36ebe361e90}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\LibRender\LibRender.vcxproj">
|
||||
<Project>{c07ade80-5c4f-e6e3-dd1a-5a619403fa9f}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\ThirdParty\gtest\gtest-all.cpp" />
|
||||
<ClCompile Include="cvfCamera-Test.cpp" />
|
||||
<ClCompile Include="cvfDrawableGeo-Test.cpp" />
|
||||
<ClCompile Include="cvfGeometryBuilderDrawableGeo-Test.cpp" />
|
||||
<ClCompile Include="cvfOpenGLResourceManager-Test.cpp" />
|
||||
<ClCompile Include="cvfPrimitiveSetIndexedUInt-Test.cpp" />
|
||||
<ClCompile Include="cvfRenderState-Test.cpp" />
|
||||
<ClCompile Include="cvfSampler-Test.cpp" />
|
||||
<ClCompile Include="cvfScalarMapper-Test.cpp" />
|
||||
<ClCompile Include="cvfShaderProgram-Test.cpp" />
|
||||
<ClCompile Include="cvfShader-Test.cpp" />
|
||||
<ClCompile Include="cvfTextureImage-Test.cpp" />
|
||||
<ClCompile Include="cvfTexture-Test.cpp" />
|
||||
<ClCompile Include="cvfUniformSet-Test.cpp" />
|
||||
<ClCompile Include="cvfUniform-Test.cpp" />
|
||||
<ClCompile Include="cvfViewport-Test.cpp" />
|
||||
<ClCompile Include="LibRender_UnitTests.cpp" />
|
||||
<ClCompile Include="cvfShaderSourceRepository-Test.cpp" />
|
||||
<ClCompile Include="cvfScalarMapperUniformLevels-Test.cpp" />
|
||||
<ClCompile Include="cvfMatrixState-Test.cpp" />
|
||||
<ClCompile Include="cvfPrimitiveSetIndexedUIntScoped-Test.cpp" />
|
||||
<ClCompile Include="cvfShaderProgramGenerator-Test.cpp" />
|
||||
<ClCompile Include="cvfPrimitiveSetIndexedUShortScoped-Test.cpp" />
|
||||
<ClCompile Include="cvfVertexAttribute-Test.cpp" />
|
||||
<ClCompile Include="cvfPrimitiveSetDirect-Test.cpp" />
|
||||
<ClCompile Include="cvfOpenGLCapabilities-Test.cpp" />
|
||||
<ClCompile Include="cvfOpenGLContextGroup-Test.cpp" />
|
||||
<ClCompile Include="cvfOverlayTextBox-Test.cpp" />
|
||||
<ClCompile Include="cvfOverlayColorLegend-Test.cpp" />
|
||||
<ClCompile Include="cvfVertexBundle-Test.cpp" />
|
||||
<ClCompile Include="cvfOverlayItem-Test.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="CMakeLists.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="TriggerTBBCopy.txt" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
2
Fwk/VizFwk/Tests/LibRender_UnitTests/TriggerTBBCopy.txt
Normal file
2
Fwk/VizFwk/Tests/LibRender_UnitTests/TriggerTBBCopy.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
Sole purpose of this file is to have custom build rules to trigger copying of TBB DLLs
|
||||
449
Fwk/VizFwk/Tests/LibRender_UnitTests/cvfCamera-Test.cpp
Normal file
449
Fwk/VizFwk/Tests/LibRender_UnitTests/cvfCamera-Test.cpp
Normal file
@@ -0,0 +1,449 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfCamera.h"
|
||||
#include "cvfViewport.h"
|
||||
#include "cvfRay.h"
|
||||
#include "cvfBoundingBox.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CameraTest, DefaultValues)
|
||||
{
|
||||
Camera c;
|
||||
|
||||
EXPECT_EQ(40.0, c.fieldOfViewYDeg());
|
||||
EXPECT_EQ(0.05, c.nearPlane());
|
||||
EXPECT_EQ(10000.0, c.farPlane());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CameraTest, ViewMatrix)
|
||||
{
|
||||
ref<Camera> myCamera = new Camera;
|
||||
ASSERT_EQ(1, myCamera->refCount());
|
||||
|
||||
// Default identity view matrix
|
||||
EXPECT_TRUE(myCamera->viewMatrix().isIdentity());
|
||||
|
||||
myCamera->setViewMatrix(Mat4d::ZERO);
|
||||
EXPECT_TRUE(myCamera->viewMatrix() == Mat4d::ZERO);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CameraTest, LookAt)
|
||||
{
|
||||
Camera c;
|
||||
|
||||
Vec3d eye, vrp, vup, viewDir;
|
||||
c.toLookAt(&eye, &vrp, &vup);
|
||||
viewDir = (vrp - eye).getNormalized();
|
||||
|
||||
// Check default (like OpenGL)
|
||||
EXPECT_TRUE(eye == Vec3d::ZERO);
|
||||
EXPECT_TRUE(vup == Vec3d::Y_AXIS);
|
||||
EXPECT_TRUE(viewDir == -Vec3d::Z_AXIS);
|
||||
|
||||
c.setFromLookAt(Vec3d(1,2,3), Vec3d(1,5,3), Vec3d(5,0,0));
|
||||
c.toLookAt(&eye, &vrp, &vup);
|
||||
viewDir = (vrp - eye).getNormalized();
|
||||
|
||||
EXPECT_DOUBLE_EQ(1.0, eye.x());
|
||||
EXPECT_DOUBLE_EQ(2.0, eye.y());
|
||||
EXPECT_DOUBLE_EQ(3.0, eye.z());
|
||||
|
||||
EXPECT_DOUBLE_EQ(0.0, viewDir.x());
|
||||
EXPECT_DOUBLE_EQ(1.0, viewDir.y());
|
||||
EXPECT_DOUBLE_EQ(0.0, viewDir.z());
|
||||
|
||||
EXPECT_DOUBLE_EQ(1.0, vup.x());
|
||||
EXPECT_DOUBLE_EQ(0.0, vup.y());
|
||||
EXPECT_DOUBLE_EQ(0.0, vup.z());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CameraTest, RetrieveComponents)
|
||||
{
|
||||
Camera c;
|
||||
|
||||
{
|
||||
const Vec3d eye(3.0, 0, 0);
|
||||
const Vec3d vrp(0, 0, 0);
|
||||
const Vec3d up(0, 0, 2.0);
|
||||
c.setFromLookAt(eye, vrp, up);
|
||||
}
|
||||
|
||||
Vec3d pos = c.position();
|
||||
EXPECT_DOUBLE_EQ(3.0, pos.x());
|
||||
EXPECT_DOUBLE_EQ(0.0, pos.y());
|
||||
EXPECT_DOUBLE_EQ(0.0, pos.z());
|
||||
|
||||
Vec3d dir = c.direction();
|
||||
EXPECT_DOUBLE_EQ(-1.0, dir.x());
|
||||
EXPECT_DOUBLE_EQ( 0.0, dir.y());
|
||||
EXPECT_DOUBLE_EQ( 0.0, dir.z());
|
||||
|
||||
Vec3d up = c.up();
|
||||
EXPECT_DOUBLE_EQ( 0.0, up.x());
|
||||
EXPECT_DOUBLE_EQ( 0.0, up.y());
|
||||
EXPECT_DOUBLE_EQ( 1.0, up.z());
|
||||
|
||||
Vec3d right = c.right();
|
||||
EXPECT_DOUBLE_EQ( 0.0, right.x());
|
||||
EXPECT_DOUBLE_EQ( 1.0, right.y());
|
||||
EXPECT_DOUBLE_EQ( 0.0, right.z());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CameraTest, FitView)
|
||||
{
|
||||
Camera c;
|
||||
|
||||
BoundingBox bb;
|
||||
bb.add(Vec3d(0, 0, 0));
|
||||
bb.add(Vec3d(1, 1, 1));
|
||||
|
||||
Vec3d inViewDir(0, 1, 0);
|
||||
Vec3d inUp(0, 0, 1);
|
||||
double coverageFactor = 0.5;
|
||||
|
||||
c.fitView(bb, inViewDir, inUp, coverageFactor);
|
||||
|
||||
Vec3d eye, vrp, vup, viewDir;
|
||||
c.toLookAt(&eye, &vrp, &vup);
|
||||
viewDir = (vrp - eye).getNormalized();
|
||||
|
||||
EXPECT_DOUBLE_EQ(0.5, eye.x());
|
||||
EXPECT_DOUBLE_EQ(0.5, eye.z());
|
||||
|
||||
// Hard to estimate Y here, but with rel factor 2, it should be around -3.3 or something
|
||||
EXPECT_LT(eye.y(), -3.0);
|
||||
EXPECT_GT(eye.y(), -3.5);
|
||||
|
||||
EXPECT_DOUBLE_EQ(0.0, viewDir.x());
|
||||
EXPECT_DOUBLE_EQ(1.0, viewDir.y());
|
||||
EXPECT_DOUBLE_EQ(0.0, viewDir.z());
|
||||
|
||||
EXPECT_DOUBLE_EQ(0.0, vup.x());
|
||||
EXPECT_DOUBLE_EQ(0.0, vup.y());
|
||||
EXPECT_DOUBLE_EQ(1.0, vup.z());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CameraTest, setClipPlanesFromBoundingBox)
|
||||
{
|
||||
Camera c;
|
||||
|
||||
BoundingBox bb;
|
||||
bb.add(Vec3d(0, 0, 0));
|
||||
bb.add(Vec3d(1, 1, 1));
|
||||
|
||||
c.setFromLookAt(Vec3d(0.5,3,0.5), Vec3d(0.5,0.5,0.5), Vec3d(0,0,1));
|
||||
|
||||
double minNear = 0.005;
|
||||
c.setClipPlanesFromBoundingBox(bb, minNear);
|
||||
|
||||
EXPECT_LT(c.nearPlane(), 2.0);
|
||||
EXPECT_GE(c.nearPlane(), 1.0);
|
||||
EXPECT_GE(c.nearPlane(), minNear);
|
||||
|
||||
EXPECT_GE(c.farPlane(), 3.0);
|
||||
EXPECT_LE(c.farPlane(), 4.0);
|
||||
|
||||
c.setFromLookAt(Vec3d(0.5,0.5,0.5), Vec3d(0.5,0,0.5), Vec3d(0,0,1));
|
||||
|
||||
c.setClipPlanesFromBoundingBox(bb, minNear);
|
||||
EXPECT_DOUBLE_EQ(minNear, c.nearPlane());
|
||||
EXPECT_GE(c.farPlane(), 0.5);
|
||||
EXPECT_LE(c.farPlane(), 1.5);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CameraTest, setProjectionAsPerspective)
|
||||
{
|
||||
Camera c;
|
||||
c.viewport()->set(0,0,300, 200);
|
||||
c.setProjectionAsPerspective(50, 0.01, 20.0);
|
||||
|
||||
EXPECT_EQ(Camera::PERSPECTIVE, c.projection());
|
||||
EXPECT_EQ(50.0, c.fieldOfViewYDeg());
|
||||
EXPECT_EQ(0.01, c.nearPlane());
|
||||
EXPECT_EQ(20.0, c.farPlane());
|
||||
|
||||
EXPECT_NEAR(9.326153163e-3, c.frontPlaneFrustumHeight(), 1e-10);
|
||||
EXPECT_NEAR(9.326153163e-3/200, c.frontPlanePixelHeight(), 1e-10);
|
||||
|
||||
Mat4d pm = c.projectionMatrix();
|
||||
|
||||
// Check agains result of:
|
||||
// glMatrixMode(GL_PROJECTION);
|
||||
// glLoadIdentity();
|
||||
// gluPerspective(50, 1.5, 0.01, 20.0);
|
||||
//
|
||||
// GLdouble adProjectionMatrix[16];
|
||||
// glGetDoublev(GL_PROJECTION_MATRIX, adProjectionMatrix);
|
||||
//
|
||||
const double absErr = 1e-7;
|
||||
EXPECT_NEAR(1.4296712875366211, pm.rowCol(0,0), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(1,0), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(2,0), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(3,0), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(0,1), absErr);
|
||||
EXPECT_NEAR(2.1445069313049316, pm.rowCol(1,1), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(2,1), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(3,1), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(0,2), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(1,2), absErr);
|
||||
EXPECT_NEAR(-1.0010005235671997, pm.rowCol(2,2), absErr);
|
||||
EXPECT_NEAR(-1.0, pm.rowCol(3,2), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(0,3), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(1,3), absErr);
|
||||
EXPECT_NEAR(-0.020010005682706833, pm.rowCol(2,3), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(3,3), absErr);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CameraTest, setProjectionAsOrtho)
|
||||
{
|
||||
Camera c;
|
||||
c.viewport()->set(0,0,300, 200);
|
||||
c.setProjectionAsOrtho(4.0, 3.0, 8);
|
||||
|
||||
EXPECT_EQ(Camera::ORTHO, c.projection());
|
||||
EXPECT_EQ(UNDEFINED_DOUBLE, c.fieldOfViewYDeg());
|
||||
EXPECT_EQ(3.0, c.nearPlane());
|
||||
EXPECT_EQ(8.0, c.farPlane());
|
||||
|
||||
EXPECT_EQ(4.0, c.frontPlaneFrustumHeight());
|
||||
EXPECT_EQ(4.0/200, c.frontPlanePixelHeight());
|
||||
|
||||
Mat4d pm = c.projectionMatrix();
|
||||
|
||||
// Check agains result of:
|
||||
// glMatrixMode(GL_PROJECTION);
|
||||
// glLoadIdentity();
|
||||
// glOrtho(-3, 3, -2, 2, 3, 8);
|
||||
//
|
||||
// GLdouble adProjectionMatrix[16];
|
||||
// glGetDoublev(GL_PROJECTION_MATRIX, adProjectionMatrix);
|
||||
//
|
||||
const double absErr = 1e-7;
|
||||
EXPECT_NEAR(0.33333334326744080, pm.rowCol(0,0), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(1,0), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(2,0), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(3,0), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(0,1), absErr);
|
||||
EXPECT_NEAR(0.5, pm.rowCol(1,1), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(2,1), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(3,1), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(0,2), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(1,2), absErr);
|
||||
EXPECT_NEAR(-0.40000000596046448, pm.rowCol(2,2), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(3,2), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(0,3), absErr);
|
||||
EXPECT_NEAR(0.0, pm.rowCol(1,3), absErr);
|
||||
EXPECT_NEAR(-2.20000004768371583, pm.rowCol(2,3), absErr);
|
||||
EXPECT_NEAR(1.0, pm.rowCol(3,3), absErr);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CameraTest, SetViewport)
|
||||
{
|
||||
Camera c;
|
||||
|
||||
c.setViewport(0, 1, 100, 200);
|
||||
|
||||
EXPECT_EQ(0, c.viewport()->x());
|
||||
EXPECT_EQ(1, c.viewport()->y());
|
||||
EXPECT_EQ(100, c.viewport()->width());
|
||||
EXPECT_EQ(200, c.viewport()->height());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CameraTest, RayFromWinCoord)
|
||||
{
|
||||
Camera c;
|
||||
c.setFromLookAt(Vec3d(0,0,10), Vec3d(0,0,0), Vec3d(0,1,0));
|
||||
c.viewport()->set(0, 0, 300, 200);
|
||||
c.setProjectionAsPerspective(50, 0.01, 20.0);
|
||||
|
||||
ref<Ray> ray = c.rayFromWindowCoordinates(150,100);
|
||||
Vec3d o = ray->origin();
|
||||
Vec3d d = ray->direction();
|
||||
|
||||
ASSERT_TRUE(ray.notNull());
|
||||
ASSERT_DOUBLE_EQ(1.0, d.length());
|
||||
ASSERT_DOUBLE_EQ(0.0, o.x());
|
||||
ASSERT_DOUBLE_EQ(0.0, o.y());
|
||||
ASSERT_DOUBLE_EQ(9.99, o.z());
|
||||
ASSERT_DOUBLE_EQ(0.0, d.x());
|
||||
ASSERT_DOUBLE_EQ(0.0, d.y());
|
||||
ASSERT_DOUBLE_EQ(-1.0, d.z());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CameraTest, PlaneFromLineWinCoord)
|
||||
{
|
||||
Camera c;
|
||||
c.setFromLookAt(Vec3d(0,0,10), Vec3d(0,0,0), Vec3d(0,1,0));
|
||||
c.viewport()->set(0, 0, 300, 200);
|
||||
c.setProjectionAsPerspective(50, 0.01, 20.0);
|
||||
|
||||
ref<Plane> plane = c.planeFromLineWindowCoordinates(Vec2i(100,100), Vec2i(200,100));
|
||||
ASSERT_TRUE(plane.notNull());
|
||||
|
||||
// Should end up with normal pointing up
|
||||
Vec3d n = plane->normal().getNormalized();
|
||||
EXPECT_TRUE(n*Vec3d::Y_AXIS > 0.99);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CameraTest, unproject)
|
||||
{
|
||||
Camera c;
|
||||
|
||||
c.setFromLookAt(Vec3d(0,0,10), Vec3d(0,0,0), Vec3d(0,1,0));
|
||||
c.viewport()->set(0, 0, 300, 200);
|
||||
c.setProjectionAsPerspective(50, 0.01, 20.0);
|
||||
|
||||
Vec3d out;
|
||||
bool res = c.unproject(Vec3d(50,75,0), &out);
|
||||
|
||||
ASSERT_TRUE(res);
|
||||
|
||||
// Check agains result of:
|
||||
// Camera* camera = m_snippet->camera();
|
||||
//
|
||||
// camera->setFromLookAt(Vec3d(0,0,10), Vec3d(0,0,0), Vec3d(0,1,0));
|
||||
// camera->viewport()->set(0,0,300, 200);
|
||||
// camera->setProjectionAsPerspective(50, 0.01, 20.0);
|
||||
//
|
||||
// Mat4d viewMat = camera->viewMatrix();
|
||||
// Mat4d projMat = camera->projectionMatrix();
|
||||
//
|
||||
//
|
||||
// GLdouble dWinCoord[3];
|
||||
// GLdouble dCoord3D[3];
|
||||
// GLint pVP[4];
|
||||
//
|
||||
// pVP[0] = (GLint) camera->viewport()->x();
|
||||
// pVP[1] = (GLint) camera->viewport()->y();
|
||||
// pVP[2] = (GLint) camera->viewport()->width();
|
||||
// pVP[3] = (GLint) camera->viewport()->height();
|
||||
//
|
||||
// // Try and hit middle of pixel
|
||||
// dWinCoord[0] = 50;
|
||||
// dWinCoord[1] = 75;
|
||||
// dWinCoord[2] = 0;
|
||||
//
|
||||
// // Get the point
|
||||
// gluUnProject(dWinCoord[0], dWinCoord[1], dWinCoord[2], (GLdouble*)viewMat.ptr(), (GLdouble*)projMat.ptr(), pVP, &dCoord3D[0], &dCoord3D[1], &dCoord3D[2]);
|
||||
|
||||
const double absErr = 1e-7;
|
||||
EXPECT_NEAR(-0.0046630765815497853, out.x(), absErr);
|
||||
EXPECT_NEAR(-0.0011657691453874461, out.y(), absErr);
|
||||
EXPECT_NEAR(9.9900000000000002, out.z(), absErr);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(CameraTest, project)
|
||||
{
|
||||
Camera c;
|
||||
|
||||
c.setFromLookAt(Vec3d(0,0,10), Vec3d(0,0,0), Vec3d(0,1,0));
|
||||
c.viewport()->set(0, 0, 300, 200);
|
||||
c.setProjectionAsPerspective(50, 0.01, 20.0);
|
||||
|
||||
// See unproject test above
|
||||
Vec3d point(-0.0046630765815497853,
|
||||
-0.0011657691453874461,
|
||||
9.9900000000000002);
|
||||
|
||||
|
||||
Vec3d out;
|
||||
bool res = c.project(point, &out);
|
||||
ASSERT_TRUE(res);
|
||||
|
||||
const double absErr = 1e-7;
|
||||
EXPECT_NEAR(50, out.x(), absErr);
|
||||
EXPECT_NEAR(75, out.y(), absErr);
|
||||
EXPECT_NEAR(0, out.z(), absErr);
|
||||
}
|
||||
845
Fwk/VizFwk/Tests/LibRender_UnitTests/cvfDrawableGeo-Test.cpp
Normal file
845
Fwk/VizFwk/Tests/LibRender_UnitTests/cvfDrawableGeo-Test.cpp
Normal file
@@ -0,0 +1,845 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfDrawableGeo.h"
|
||||
#include "cvfGeometryBuilderFaceList.h"
|
||||
#include "cvfGeometryUtils.h"
|
||||
#include "cvfPrimitiveSetIndexedUInt.h"
|
||||
#include "cvfPrimitiveSetIndexedUShort.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(DrawableGeoTest, BasicConstruction)
|
||||
{
|
||||
ref<DrawableGeo> geo = new DrawableGeo;
|
||||
ASSERT_EQ(1, geo->refCount());
|
||||
|
||||
// Check default values
|
||||
ASSERT_EQ(DrawableGeo::VERTEX_ARRAY, geo->renderMode());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(DrawableGeoTest, ShallowCopy)
|
||||
{
|
||||
ref<Vec3fArray> verts = new Vec3fArray;
|
||||
ref<Vec3fArray> norms = new Vec3fArray;
|
||||
|
||||
ref<DrawableGeo> geo = new DrawableGeo;
|
||||
geo->setVertexArray(verts.p());
|
||||
geo->setNormalArray(norms.p());
|
||||
|
||||
ref<DrawableGeo> cpy = geo->shallowCopy();
|
||||
EXPECT_EQ(verts.p(), cpy->vertexArray());
|
||||
EXPECT_EQ(norms.p(), cpy->normalArray());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(DrawableGeoTest, RenderModeTest)
|
||||
{
|
||||
DrawableGeo geo;
|
||||
|
||||
geo.setRenderMode(DrawableGeo::BUFFER_OBJECT);
|
||||
|
||||
ASSERT_EQ(DrawableGeo::BUFFER_OBJECT, geo.renderMode());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(DrawableGeoTest, SetFromTriangleVertexArray)
|
||||
{
|
||||
ref<DrawableGeo> geo = new DrawableGeo;
|
||||
|
||||
ref<Vec3fArray> verts = new Vec3fArray;
|
||||
verts->reserve(6);
|
||||
verts->add(Vec3f(1, 1, 1));
|
||||
verts->add(Vec3f(2, 1, 1));
|
||||
verts->add(Vec3f(3, 1, 1));
|
||||
verts->add(Vec3f(4, 1, 1));
|
||||
verts->add(Vec3f(5, 1, 1));
|
||||
verts->add(Vec3f(6, 1, 1));
|
||||
|
||||
geo->setFromTriangleVertexArray(verts.p());
|
||||
|
||||
ASSERT_EQ(1, geo->primitiveSetCount());
|
||||
const PrimitiveSet* primSet = geo->primitiveSet(0);
|
||||
EXPECT_EQ(PT_TRIANGLES, primSet->primitiveType());
|
||||
ASSERT_EQ(2, primSet->triangleCount());
|
||||
|
||||
ASSERT_EQ(2, geo->faceCount());
|
||||
ASSERT_EQ(2, geo->triangleCount());
|
||||
|
||||
{
|
||||
UIntArray indices;
|
||||
geo->getFaceIndices(0, &indices);
|
||||
EXPECT_EQ(0, indices[0]);
|
||||
EXPECT_EQ(1, indices[1]);
|
||||
EXPECT_EQ(2, indices[2]);
|
||||
}
|
||||
|
||||
{
|
||||
UIntArray indices;
|
||||
geo->getFaceIndices(1, &indices);
|
||||
EXPECT_EQ(3, indices[0]);
|
||||
EXPECT_EQ(4, indices[1]);
|
||||
EXPECT_EQ(5, indices[2]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(DrawableGeoTest, SetFromQuadVertexArray)
|
||||
{
|
||||
ref<DrawableGeo> geo = new DrawableGeo;
|
||||
|
||||
ref<Vec3fArray> verts = new Vec3fArray;
|
||||
verts->reserve(8);
|
||||
verts->add(Vec3f(1, 1, 1));
|
||||
verts->add(Vec3f(2, 1, 1));
|
||||
verts->add(Vec3f(3, 1, 1));
|
||||
verts->add(Vec3f(4, 1, 1));
|
||||
verts->add(Vec3f(5, 1, 1));
|
||||
verts->add(Vec3f(6, 1, 1));
|
||||
verts->add(Vec3f(7, 1, 1));
|
||||
verts->add(Vec3f(8, 1, 1));
|
||||
|
||||
geo->setFromQuadVertexArray(verts.p());
|
||||
|
||||
ASSERT_EQ(1, geo->primitiveSetCount());
|
||||
const PrimitiveSet* primSet = geo->primitiveSet(0);
|
||||
EXPECT_EQ(PT_TRIANGLES, primSet->primitiveType());
|
||||
ASSERT_EQ(4, primSet->triangleCount());
|
||||
|
||||
ASSERT_EQ(4, geo->faceCount());
|
||||
ASSERT_EQ(4, geo->triangleCount());
|
||||
|
||||
{
|
||||
UIntArray indices;
|
||||
geo->getFaceIndices(0, &indices);
|
||||
EXPECT_EQ(0, indices[0]);
|
||||
EXPECT_EQ(1, indices[1]);
|
||||
EXPECT_EQ(2, indices[2]);
|
||||
}
|
||||
|
||||
{
|
||||
UIntArray indices;
|
||||
geo->getFaceIndices(1, &indices);
|
||||
EXPECT_EQ(0, indices[0]);
|
||||
EXPECT_EQ(2, indices[1]);
|
||||
EXPECT_EQ(3, indices[2]);
|
||||
}
|
||||
|
||||
{
|
||||
UIntArray indices;
|
||||
geo->getFaceIndices(2, &indices);
|
||||
EXPECT_EQ(4, indices[0]);
|
||||
EXPECT_EQ(5, indices[1]);
|
||||
EXPECT_EQ(6, indices[2]);
|
||||
}
|
||||
|
||||
{
|
||||
UIntArray indices;
|
||||
geo->getFaceIndices(3, &indices);
|
||||
EXPECT_EQ(4, indices[0]);
|
||||
EXPECT_EQ(6, indices[1]);
|
||||
EXPECT_EQ(7, indices[2]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(DrawableGeoTest, GetFacelistFromTriangleVertexArray)
|
||||
{
|
||||
ref<DrawableGeo> geo = new DrawableGeo;
|
||||
ASSERT_EQ(1, geo->refCount());
|
||||
|
||||
{
|
||||
// Test for valid facelist with no values
|
||||
ref<UIntArray> faceList = geo->toFaceList();
|
||||
UIntArray* faceListArray = faceList.p();
|
||||
ASSERT_TRUE(faceListArray != NULL);
|
||||
EXPECT_EQ(0u, faceListArray->size());
|
||||
|
||||
const Vec3fArray* vertices = geo->vertexArray();
|
||||
ASSERT_TRUE(vertices == NULL);
|
||||
}
|
||||
|
||||
ref<Vec3fArray> triangles = new Vec3fArray;
|
||||
triangles->reserve(6);
|
||||
triangles->add(Vec3f(1, 1, 1));
|
||||
triangles->add(Vec3f(2, 1, 1));
|
||||
triangles->add(Vec3f(3, 1, 1));
|
||||
triangles->add(Vec3f(4, 1, 1));
|
||||
triangles->add(Vec3f(5, 1, 1));
|
||||
triangles->add(Vec3f(6, 1, 1));
|
||||
|
||||
geo->setFromTriangleVertexArray(triangles.p());
|
||||
|
||||
ref<UIntArray> faceList = geo->toFaceList();
|
||||
UIntArray* faceListArray = faceList.p();
|
||||
|
||||
ASSERT_TRUE(faceListArray != NULL);
|
||||
EXPECT_EQ(8, faceListArray->size());
|
||||
|
||||
EXPECT_EQ(3, faceListArray->get(0));
|
||||
EXPECT_EQ(0, faceListArray->get(1));
|
||||
EXPECT_EQ(1, faceListArray->get(2));
|
||||
EXPECT_EQ(2, faceListArray->get(3));
|
||||
EXPECT_EQ(3, faceListArray->get(4));
|
||||
EXPECT_EQ(3, faceListArray->get(5));
|
||||
EXPECT_EQ(4, faceListArray->get(6));
|
||||
EXPECT_EQ(5, faceListArray->get(7));
|
||||
|
||||
const Vec3fArray* vertices = geo->vertexArray();
|
||||
ASSERT_TRUE(vertices != NULL);
|
||||
EXPECT_EQ(6, vertices->size());
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(DrawableGeoTest, SetFromFaceListTesselation)
|
||||
{
|
||||
cvf::uint fl[] =
|
||||
{
|
||||
3, 0, 1, 2, // 1 tri
|
||||
4, 3, 0, 1, 2, // 2 tris
|
||||
5, 1, 2, 3, 4, 5, // 3 tris
|
||||
6, 2, 3, 1, 5, 23, 12 // 4 tris
|
||||
};
|
||||
|
||||
ref<UIntArray> faceList = new UIntArray(fl, sizeof(fl)/sizeof(cvf::uint));
|
||||
ref<DrawableGeo> geo = new DrawableGeo;
|
||||
geo->setFromFaceList(*faceList);
|
||||
|
||||
ASSERT_EQ(1, geo->primitiveSetCount());
|
||||
|
||||
PrimitiveSetIndexedUShort* primSet = dynamic_cast<PrimitiveSetIndexedUShort*>(geo->primitiveSet(0));
|
||||
ASSERT_TRUE(primSet != NULL);
|
||||
|
||||
EXPECT_EQ(PT_TRIANGLES, primSet->primitiveType());
|
||||
EXPECT_EQ(10, primSet->triangleCount());
|
||||
EXPECT_EQ(30, primSet->indexCount());
|
||||
|
||||
// Tri
|
||||
EXPECT_EQ(0, primSet->index(0));
|
||||
EXPECT_EQ(1, primSet->index(1));
|
||||
EXPECT_EQ(2, primSet->index(2));
|
||||
|
||||
// Quad
|
||||
EXPECT_EQ(3, primSet->index(3));
|
||||
EXPECT_EQ(0, primSet->index(4));
|
||||
EXPECT_EQ(1, primSet->index(5));
|
||||
|
||||
EXPECT_EQ(3, primSet->index(6));
|
||||
EXPECT_EQ(1, primSet->index(7));
|
||||
EXPECT_EQ(2, primSet->index(8));
|
||||
|
||||
// 5-Poly
|
||||
EXPECT_EQ(1, primSet->index(9));
|
||||
EXPECT_EQ(2, primSet->index(10));
|
||||
EXPECT_EQ(3, primSet->index(11));
|
||||
|
||||
EXPECT_EQ(1, primSet->index(12));
|
||||
EXPECT_EQ(3, primSet->index(13));
|
||||
EXPECT_EQ(4, primSet->index(14));
|
||||
|
||||
EXPECT_EQ(1, primSet->index(15));
|
||||
EXPECT_EQ(4, primSet->index(16));
|
||||
EXPECT_EQ(5, primSet->index(17));
|
||||
|
||||
// .. and last one of the 6-poly
|
||||
EXPECT_EQ(2, primSet->index(27));
|
||||
EXPECT_EQ(23, primSet->index(28));
|
||||
EXPECT_EQ(12, primSet->index(29));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(DrawableGeoTest, SetFromFaceListOneLargePoly)
|
||||
{
|
||||
cvf::uint fl[] =
|
||||
{
|
||||
20, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 // 18 tris
|
||||
};
|
||||
|
||||
ref<UIntArray> faceList = new UIntArray(fl, sizeof(fl)/sizeof(cvf::uint));
|
||||
ref<DrawableGeo> geo = new DrawableGeo;
|
||||
geo->setFromFaceList(*faceList);
|
||||
|
||||
ASSERT_EQ(1, geo->primitiveSetCount());
|
||||
|
||||
PrimitiveSetIndexedUShort* primSet = dynamic_cast<PrimitiveSetIndexedUShort*>(geo->primitiveSet(0));
|
||||
ASSERT_TRUE(primSet != NULL);
|
||||
EXPECT_EQ(PT_TRIANGLES, primSet->primitiveType());
|
||||
EXPECT_EQ(18, primSet->triangleCount());
|
||||
EXPECT_EQ(54, primSet->indexCount());
|
||||
|
||||
EXPECT_EQ(0, primSet->index(0));
|
||||
EXPECT_EQ(1, primSet->index(1));
|
||||
EXPECT_EQ(2, primSet->index(2));
|
||||
|
||||
EXPECT_EQ(0, primSet->index(3));
|
||||
EXPECT_EQ(2, primSet->index(4));
|
||||
EXPECT_EQ(3, primSet->index(5));
|
||||
|
||||
EXPECT_EQ(0, primSet->index(6));
|
||||
EXPECT_EQ(3, primSet->index(7));
|
||||
EXPECT_EQ(4, primSet->index(8));
|
||||
|
||||
EXPECT_EQ(0, primSet->index(51));
|
||||
EXPECT_EQ(18, primSet->index(52));
|
||||
EXPECT_EQ(19, primSet->index(53));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(DrawableGeoTest, MergeIntoEmpty)
|
||||
{
|
||||
size_t geo1VerticesSize = 0;
|
||||
|
||||
size_t geo2VerticesSize = 0;
|
||||
|
||||
ref<DrawableGeo> geo1 = new DrawableGeo;
|
||||
{
|
||||
GeometryBuilderFaceList builder;
|
||||
GeometryUtils::createBox(Vec3f(0,0,0), 2.0, 2.0, 2.0, &builder);
|
||||
|
||||
ref<Vec3fArray> vertices = builder.vertices();
|
||||
geo1VerticesSize = vertices->size();
|
||||
EXPECT_EQ(24, geo1VerticesSize);
|
||||
|
||||
ref<UIntArray> faceList = builder.faceList();
|
||||
|
||||
geo1->setVertexArray(vertices.p());
|
||||
geo1->setFromFaceList(*faceList);
|
||||
}
|
||||
|
||||
EXPECT_EQ(geo1VerticesSize, geo1->vertexCount());
|
||||
|
||||
ref<DrawableGeo> geo2 = new DrawableGeo;
|
||||
{
|
||||
GeometryBuilderFaceList builder;
|
||||
GeometryUtils::createSphere(10, 2, 2, &builder);
|
||||
|
||||
ref<Vec3fArray> vertices = builder.vertices();
|
||||
geo2VerticesSize = vertices->size();
|
||||
EXPECT_EQ(4, geo2VerticesSize);
|
||||
|
||||
ref<UIntArray> faceList = builder.faceList();
|
||||
|
||||
geo2->setVertexArray(vertices.p());
|
||||
geo2->setFromFaceList(*faceList);
|
||||
}
|
||||
|
||||
EXPECT_EQ(geo2VerticesSize, geo2->vertexCount());
|
||||
|
||||
Collection<DrawableGeo> myCollection;
|
||||
myCollection.push_back(geo1.p());
|
||||
myCollection.push_back(geo2.p());
|
||||
|
||||
ref<DrawableGeo> mergedGeo = new DrawableGeo;
|
||||
mergedGeo->mergeInto(myCollection);
|
||||
EXPECT_EQ(geo1VerticesSize + geo2VerticesSize, mergedGeo->vertexCount());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(DrawableGeoTest, MergeIntoExisting)
|
||||
{
|
||||
size_t geo1VerticesSize = 0;
|
||||
|
||||
size_t geo2VerticesSize = 0;
|
||||
|
||||
ref<DrawableGeo> geo1 = new DrawableGeo;
|
||||
{
|
||||
GeometryBuilderFaceList builder;
|
||||
GeometryUtils::createBox(Vec3f(0,0,0), 2.0, 2.0, 2.0, &builder);
|
||||
|
||||
ref<Vec3fArray> vertices = builder.vertices();
|
||||
geo1VerticesSize = vertices->size();
|
||||
EXPECT_EQ(24, geo1VerticesSize);
|
||||
|
||||
ref<UIntArray> faceList = builder.faceList();
|
||||
|
||||
geo1->setVertexArray(vertices.p());
|
||||
geo1->setFromFaceList(*faceList);
|
||||
}
|
||||
|
||||
EXPECT_EQ(geo1VerticesSize, geo1->vertexCount());
|
||||
|
||||
ref<DrawableGeo> geo2 = new DrawableGeo;
|
||||
{
|
||||
GeometryBuilderFaceList builder;
|
||||
GeometryUtils::createSphere(10, 2, 2, &builder);
|
||||
|
||||
ref<Vec3fArray> vertices = builder.vertices();
|
||||
geo2VerticesSize = vertices->size();
|
||||
EXPECT_EQ(4, geo2VerticesSize);
|
||||
|
||||
ref<UIntArray> faceList = builder.faceList();
|
||||
|
||||
geo2->setVertexArray(vertices.p());
|
||||
geo2->setFromFaceList(*faceList);
|
||||
}
|
||||
|
||||
EXPECT_EQ(geo2VerticesSize, geo2->vertexCount());
|
||||
|
||||
Collection<DrawableGeo> myCollection;
|
||||
myCollection.push_back(geo2.p());
|
||||
|
||||
geo1->mergeInto(myCollection);
|
||||
EXPECT_EQ(geo1VerticesSize + geo2VerticesSize, geo1->vertexCount());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(DrawableGeoTest, GetFacelistFromTriangleStrip)
|
||||
{
|
||||
// Tri strip
|
||||
// -------------------------------------------------------------------------
|
||||
ref<DrawableGeo> geo1 = new DrawableGeo;
|
||||
|
||||
ref<PrimitiveSetIndexedUInt> triStrip = new PrimitiveSetIndexedUInt(PT_TRIANGLE_STRIP);
|
||||
|
||||
ref<UIntArray> triStripIndices = new UIntArray;
|
||||
triStripIndices->reserve(6);
|
||||
|
||||
triStripIndices->add(0);
|
||||
triStripIndices->add(1);
|
||||
triStripIndices->add(2);
|
||||
triStripIndices->add(3);
|
||||
triStripIndices->add(4);
|
||||
triStripIndices->add(5);
|
||||
|
||||
triStrip->setIndices(triStripIndices.p());
|
||||
|
||||
ref<Vec3fArray> triStripVertices = new Vec3fArray;
|
||||
triStripVertices->reserve(6);
|
||||
|
||||
triStripVertices->add(Vec3f(0,1,0));
|
||||
triStripVertices->add(Vec3f(0,0,0));
|
||||
triStripVertices->add(Vec3f(1,1,0));
|
||||
triStripVertices->add(Vec3f(2.5,0,0));
|
||||
triStripVertices->add(Vec3f(3,1,0));
|
||||
triStripVertices->add(Vec3f(3.5,-0.5,0));
|
||||
|
||||
geo1->addPrimitiveSet(triStrip.p());
|
||||
geo1->setVertexArray(triStripVertices.p());
|
||||
|
||||
ref<UIntArray> faceList = geo1->toFaceList();
|
||||
EXPECT_EQ(4 * 4, faceList->size());
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(DrawableGeoTest, GetFacelistFromTriangleFan)
|
||||
{
|
||||
// Tri fan
|
||||
// -------------------------------------------------------------------------
|
||||
ref<DrawableGeo> geo2 = new DrawableGeo;
|
||||
|
||||
ref<PrimitiveSetIndexedUInt> triFan = new PrimitiveSetIndexedUInt(PT_TRIANGLE_FAN);
|
||||
|
||||
ref<UIntArray> triFanIndices = new UIntArray;
|
||||
triFanIndices->reserve(5);
|
||||
|
||||
triFanIndices->add(0);
|
||||
triFanIndices->add(1);
|
||||
triFanIndices->add(2);
|
||||
triFanIndices->add(3);
|
||||
triFanIndices->add(4);
|
||||
|
||||
triFan->setIndices(triFanIndices.p());
|
||||
|
||||
ref<Vec3fArray> triFanVertices = new Vec3fArray;
|
||||
triFanVertices->reserve(5);
|
||||
|
||||
// Note that the example in the RedBook on page 36 (1 ed) leads to triangles with inward normal!
|
||||
triFanVertices->add(Vec3f(4,0,0));
|
||||
triFanVertices->add(Vec3f(5,-1.5,0));
|
||||
triFanVertices->add(Vec3f(5.5,0,0));
|
||||
triFanVertices->add(Vec3f(5,1.5,0));
|
||||
triFanVertices->add(Vec3f(4,2,0));
|
||||
|
||||
geo2->addPrimitiveSet(triFan.p());
|
||||
geo2->setVertexArray(triFanVertices.p());
|
||||
|
||||
ref<UIntArray> faceList = geo2->toFaceList();
|
||||
EXPECT_EQ(3 * 4, faceList->size());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(DrawableGeoTest, ConvertFromUIntToUShort)
|
||||
{
|
||||
ref<DrawableGeo> geo = new DrawableGeo;
|
||||
|
||||
ref<PrimitiveSetIndexedUInt> triStrip = new PrimitiveSetIndexedUInt(PT_TRIANGLE_STRIP);
|
||||
|
||||
ref<UIntArray> triStripIndices = new UIntArray;
|
||||
triStripIndices->reserve(6);
|
||||
|
||||
triStripIndices->add(0);
|
||||
triStripIndices->add(1);
|
||||
triStripIndices->add(2);
|
||||
triStripIndices->add(3);
|
||||
triStripIndices->add(4);
|
||||
triStripIndices->add(5);
|
||||
|
||||
triStrip->setIndices(triStripIndices.p());
|
||||
|
||||
ref<Vec3fArray> triStripVertices = new Vec3fArray;
|
||||
triStripVertices->reserve(6);
|
||||
|
||||
triStripVertices->add(Vec3f(0,1,0));
|
||||
triStripVertices->add(Vec3f(0,0,0));
|
||||
triStripVertices->add(Vec3f(1,1,0));
|
||||
triStripVertices->add(Vec3f(2.5,0,0));
|
||||
triStripVertices->add(Vec3f(3,1,0));
|
||||
triStripVertices->add(Vec3f(3.5,-0.5,0));
|
||||
|
||||
geo->addPrimitiveSet(triStrip.p());
|
||||
geo->setVertexArray(triStripVertices.p());
|
||||
|
||||
size_t numPrimitives = geo->primitiveSetCount();
|
||||
size_t i;
|
||||
for (i = 0; i < numPrimitives; i++)
|
||||
{
|
||||
const PrimitiveSet* primitive = geo->primitiveSet(i);
|
||||
EXPECT_TRUE(dynamic_cast<const PrimitiveSetIndexedUInt*>(primitive) != NULL);
|
||||
EXPECT_TRUE(dynamic_cast<const PrimitiveSetIndexedUShort*>(primitive) == NULL);
|
||||
}
|
||||
|
||||
// First conversion
|
||||
geo->convertFromUIntToUShort();
|
||||
for (i = 0; i < numPrimitives; i++)
|
||||
{
|
||||
const PrimitiveSet* primitive = geo->primitiveSet(i);
|
||||
EXPECT_TRUE(dynamic_cast<const PrimitiveSetIndexedUShort*>(primitive) != NULL);
|
||||
EXPECT_TRUE(dynamic_cast<const PrimitiveSetIndexedUInt*>(primitive) == NULL);
|
||||
}
|
||||
|
||||
// Second conversion, run same test as for first conversion
|
||||
geo->convertFromUIntToUShort();
|
||||
for (i = 0; i < numPrimitives; i++)
|
||||
{
|
||||
const PrimitiveSet* primitive = geo->primitiveSet(i);
|
||||
EXPECT_TRUE(dynamic_cast<const PrimitiveSetIndexedUShort*>(primitive) != NULL);
|
||||
EXPECT_TRUE(dynamic_cast<const PrimitiveSetIndexedUInt*>(primitive) == NULL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(DrawableGeoTest, ConvertFromUIntToUShortTooLargeModel)
|
||||
{
|
||||
ref<DrawableGeo> geo2 = new DrawableGeo;
|
||||
GeometryBuilderFaceList builder;
|
||||
GeometryUtils::createSphere(10, 300, 300, &builder);
|
||||
|
||||
ref<Vec3fArray> vertices = builder.vertices();
|
||||
ref<UIntArray> faceList = builder.faceList();
|
||||
|
||||
geo2->setVertexArray(vertices.p());
|
||||
geo2->setFromFaceList(*faceList);
|
||||
|
||||
size_t numPrimitives = geo2->primitiveSetCount();
|
||||
size_t i;
|
||||
for (i = 0; i < numPrimitives; i++)
|
||||
{
|
||||
const PrimitiveSet* primitive = geo2->primitiveSet(i);
|
||||
EXPECT_TRUE(dynamic_cast<const PrimitiveSetIndexedUInt*>(primitive) != NULL);
|
||||
EXPECT_TRUE(dynamic_cast<const PrimitiveSetIndexedUShort*>(primitive) == NULL);
|
||||
}
|
||||
|
||||
// As this model has too many vertices, the conversion will not
|
||||
// change the internal primitive set type
|
||||
// Run the same test as above to verify that the types has not changed
|
||||
geo2->convertFromUIntToUShort();
|
||||
for (i = 0; i < numPrimitives; i++)
|
||||
{
|
||||
const PrimitiveSet* primitive = geo2->primitiveSet(i);
|
||||
EXPECT_TRUE(dynamic_cast<const PrimitiveSetIndexedUInt*>(primitive) != NULL);
|
||||
EXPECT_TRUE(dynamic_cast<const PrimitiveSetIndexedUShort*>(primitive) == NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(DrawableGeoTest, MergeParts)
|
||||
{
|
||||
Vec3fArray* verts = new Vec3fArray;
|
||||
verts->reserve(3);
|
||||
verts->add(Vec3f(0, 0, 0));
|
||||
verts->add(Vec3f(1, 0, 0));
|
||||
verts->add(Vec3f(1, 1, 0));
|
||||
|
||||
Vec3fArray* norms = new Vec3fArray;
|
||||
norms->resize(3);
|
||||
norms->set(0, Vec3f::Z_AXIS);
|
||||
norms->set(1, Vec3f::Z_AXIS);
|
||||
norms->set(2, Vec3f::Z_AXIS);
|
||||
|
||||
ref<DrawableGeo> geo = new DrawableGeo;
|
||||
geo->setFromTriangleVertexArray(verts);
|
||||
geo->setNormalArray(norms);
|
||||
|
||||
ref<DrawableGeo> geo2 = new DrawableGeo;
|
||||
geo2->setFromTriangleVertexArray(verts);
|
||||
geo2->setNormalArray(norms);
|
||||
|
||||
Mat4d matrix;
|
||||
matrix.setTranslation(Vec3d(10, 20, 30));
|
||||
|
||||
ref<DrawableGeo> geoMerged = new DrawableGeo;
|
||||
geoMerged->mergeInto(*geo, NULL);
|
||||
EXPECT_EQ(3, geoMerged->vertexArray()->size());
|
||||
|
||||
const Vec3fArray* vertices = geoMerged->vertexArray();
|
||||
Vec3f v0 = vertices->get(0);
|
||||
EXPECT_EQ(0, v0.x());
|
||||
EXPECT_EQ(0, v0.y());
|
||||
EXPECT_EQ(0, v0.z());
|
||||
|
||||
Vec3f v1 = vertices->get(1);
|
||||
EXPECT_EQ(1, v1.x());
|
||||
EXPECT_EQ(0, v1.y());
|
||||
EXPECT_EQ(0, v1.z());
|
||||
|
||||
Vec3f v2 = vertices->get(2);
|
||||
EXPECT_EQ(1, v2.x());
|
||||
EXPECT_EQ(1, v2.y());
|
||||
EXPECT_EQ(0, v2.z());
|
||||
|
||||
geoMerged->mergeInto(*geo2, &matrix);
|
||||
vertices = geoMerged->vertexArray();
|
||||
EXPECT_EQ(6, vertices->size());
|
||||
|
||||
Vec3f v3 = vertices->get(3);
|
||||
EXPECT_EQ(10, v3.x());
|
||||
EXPECT_EQ(20, v3.y());
|
||||
EXPECT_EQ(30, v3.z());
|
||||
|
||||
Vec3f v4 = vertices->get(4);
|
||||
EXPECT_EQ(11, v4.x());
|
||||
EXPECT_EQ(20, v4.y());
|
||||
EXPECT_EQ(30, v4.z());
|
||||
|
||||
Vec3f v5 = vertices->get(5);
|
||||
EXPECT_EQ(11, v5.x());
|
||||
EXPECT_EQ(21, v5.y());
|
||||
EXPECT_EQ(30, v5.z());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(DrawableGeoTest, Transform)
|
||||
{
|
||||
ref<Vec3fArray> verts = new Vec3fArray;
|
||||
verts->reserve(3);
|
||||
verts->add(Vec3f(0, 0, 0));
|
||||
verts->add(Vec3f(1, 0, 0));
|
||||
verts->add(Vec3f(1, 1, 0));
|
||||
|
||||
ref<DrawableGeo> geo = new DrawableGeo;
|
||||
geo->setFromTriangleVertexArray(verts.p());
|
||||
BoundingBox bb0 = geo->boundingBox();
|
||||
EXPECT_TRUE(bb0.min() == Vec3d(0, 0, 0));
|
||||
EXPECT_TRUE(bb0.max() == Vec3d(1, 1, 0));
|
||||
|
||||
Mat4d matrix;
|
||||
matrix.setTranslation(Vec3d(10, 20, 30));
|
||||
|
||||
geo->transform(matrix);
|
||||
|
||||
const Vec3fArray* vertices = geo->vertexArray();
|
||||
|
||||
Vec3f v1 = vertices->get(1);
|
||||
EXPECT_EQ(11, v1.x());
|
||||
EXPECT_EQ(20, v1.y());
|
||||
EXPECT_EQ(30, v1.z());
|
||||
|
||||
BoundingBox bb1 = geo->boundingBox();
|
||||
EXPECT_TRUE(bb1.min() == Vec3d(10, 20, 30));
|
||||
EXPECT_TRUE(bb1.max() == Vec3d(11, 21, 30));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(DrawableGeoTest, ComputeNormals)
|
||||
{
|
||||
ref<Vec3fArray> verts = new Vec3fArray;
|
||||
verts->reserve(3);
|
||||
verts->add(Vec3f(0, 0, 0));
|
||||
verts->add(Vec3f(1, 0, 0));
|
||||
verts->add(Vec3f(1, 1, 0));
|
||||
|
||||
ref<DrawableGeo> geo = new DrawableGeo;
|
||||
geo->setFromTriangleVertexArray(verts.p());
|
||||
geo->computeNormals();
|
||||
|
||||
{
|
||||
const Vec3fArray* norms = geo->normalArray();
|
||||
ASSERT_TRUE(norms != NULL);
|
||||
EXPECT_EQ(3, norms->size());
|
||||
}
|
||||
|
||||
verts->reserve(6);
|
||||
verts->add(Vec3f(0, 0, 0));
|
||||
verts->add(Vec3f(0, 1, 0));
|
||||
verts->add(Vec3f(0, 1, 1));
|
||||
geo->setFromTriangleVertexArray(verts.p());
|
||||
geo->computeNormals();
|
||||
|
||||
{
|
||||
const Vec3fArray* norms = geo->normalArray();
|
||||
ASSERT_TRUE(norms != NULL);
|
||||
EXPECT_EQ(6, norms->size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(DrawableGeoTest, GetOpenGLPrimitiveConnByIndex)
|
||||
{
|
||||
UIntArray faceList;
|
||||
faceList.reserve(100);
|
||||
|
||||
faceList.add(3);
|
||||
faceList.add(10);
|
||||
faceList.add(11);
|
||||
faceList.add(12);
|
||||
|
||||
faceList.add(3);
|
||||
faceList.add(13);
|
||||
faceList.add(14);
|
||||
faceList.add(15);
|
||||
|
||||
faceList.add(4);
|
||||
faceList.add(20);
|
||||
faceList.add(21);
|
||||
faceList.add(22);
|
||||
faceList.add(23);
|
||||
|
||||
faceList.add(3);
|
||||
faceList.add(30);
|
||||
faceList.add(31);
|
||||
faceList.add(32);
|
||||
|
||||
DrawableGeo geo;
|
||||
geo.setFromFaceList(faceList);
|
||||
|
||||
ASSERT_EQ(5, geo.faceCount());
|
||||
|
||||
|
||||
UIntArray conn;
|
||||
|
||||
geo.getFaceIndices(0, &conn);
|
||||
ASSERT_EQ(3u, conn.size());
|
||||
EXPECT_EQ(10u, conn[0]);
|
||||
EXPECT_EQ(11u, conn[1]);
|
||||
EXPECT_EQ(12u, conn[2]);
|
||||
|
||||
geo.getFaceIndices(1, &conn);
|
||||
ASSERT_EQ(3u, conn.size());
|
||||
EXPECT_EQ(13u, conn[0]);
|
||||
EXPECT_EQ(14u, conn[1]);
|
||||
EXPECT_EQ(15u, conn[2]);
|
||||
|
||||
geo.getFaceIndices(2, &conn);
|
||||
ASSERT_EQ(3u, conn.size());
|
||||
EXPECT_EQ(20u, conn[0]);
|
||||
EXPECT_EQ(21u, conn[1]);
|
||||
EXPECT_EQ(22u, conn[2]);
|
||||
|
||||
geo.getFaceIndices(3, &conn);
|
||||
ASSERT_EQ(3u, conn.size());
|
||||
EXPECT_EQ(20u, conn[0]);
|
||||
EXPECT_EQ(22u, conn[1]);
|
||||
EXPECT_EQ(23u, conn[2]);
|
||||
|
||||
geo.getFaceIndices(4, &conn);
|
||||
ASSERT_EQ(3u, conn.size());
|
||||
EXPECT_EQ(30u, conn[0]);
|
||||
EXPECT_EQ(31u, conn[1]);
|
||||
EXPECT_EQ(32u, conn[2]);
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfGeometryBuilderDrawableGeo.h"
|
||||
#include "cvfPrimitiveSet.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderDrawableGeo, BasicConstruction)
|
||||
{
|
||||
GeometryBuilderDrawableGeo b;
|
||||
ref<DrawableGeo> geo = b.drawableGeo();
|
||||
|
||||
EXPECT_EQ(0u, geo->vertexCount());
|
||||
EXPECT_EQ(0u, geo->faceCount());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderDrawableGeo, AddVertices)
|
||||
{
|
||||
Vec3fArray inputVertexArr;
|
||||
inputVertexArr.reserve(3);
|
||||
inputVertexArr.add(Vec3f::X_AXIS);
|
||||
inputVertexArr.add(Vec3f::Y_AXIS);
|
||||
inputVertexArr.add(Vec3f::Z_AXIS);
|
||||
|
||||
GeometryBuilderDrawableGeo b;
|
||||
int indexOfFirstVertex = b.addVertices(inputVertexArr);
|
||||
EXPECT_EQ(0, indexOfFirstVertex);
|
||||
EXPECT_EQ(3u, b.drawableGeo()->vertexCount());
|
||||
|
||||
indexOfFirstVertex = b.addVertices(inputVertexArr);
|
||||
EXPECT_EQ(3, indexOfFirstVertex);
|
||||
|
||||
ref<DrawableGeo> geo = b.drawableGeo();
|
||||
const Vec3fArray* va = geo->vertexArray();
|
||||
EXPECT_EQ(6u, va->size());
|
||||
|
||||
EXPECT_TRUE(va->get(0) == Vec3f::X_AXIS);
|
||||
EXPECT_TRUE(va->get(1) == Vec3f::Y_AXIS);
|
||||
EXPECT_TRUE(va->get(2) == Vec3f::Z_AXIS);
|
||||
EXPECT_TRUE(va->get(3) == Vec3f::X_AXIS);
|
||||
EXPECT_TRUE(va->get(4) == Vec3f::Y_AXIS);
|
||||
EXPECT_TRUE(va->get(5) == Vec3f::Z_AXIS);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderDrawableGeo, AddTriangle)
|
||||
{
|
||||
GeometryBuilderDrawableGeo b;
|
||||
EXPECT_EQ(0u, b.drawableGeo()->faceCount());
|
||||
|
||||
b.addTriangle(10, 11, 12);
|
||||
|
||||
ref<DrawableGeo> geo = b.drawableGeo();
|
||||
|
||||
EXPECT_EQ(1u, geo->faceCount());
|
||||
ASSERT_EQ(1, geo->primitiveSetCount());
|
||||
|
||||
const PrimitiveSet* prim = geo->primitiveSet(0);
|
||||
|
||||
ASSERT_EQ(1, prim->faceCount());
|
||||
ASSERT_EQ(1, prim->triangleCount());
|
||||
ASSERT_EQ(3, prim->indexCount());
|
||||
EXPECT_EQ(10, prim->index(0));
|
||||
EXPECT_EQ(11, prim->index(1));
|
||||
EXPECT_EQ(12, prim->index(2));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(GeometryBuilderDrawableGeo, AddQuad)
|
||||
{
|
||||
GeometryBuilderDrawableGeo b;
|
||||
EXPECT_EQ(0u, b.drawableGeo()->faceCount());
|
||||
|
||||
b.addQuad(10, 11, 12, 13);
|
||||
|
||||
ref<DrawableGeo> geo = b.drawableGeo();
|
||||
|
||||
EXPECT_EQ(2u, geo->faceCount());
|
||||
ASSERT_EQ(1, geo->primitiveSetCount());
|
||||
|
||||
|
||||
const PrimitiveSet* prim = geo->primitiveSet(0);
|
||||
|
||||
ASSERT_EQ(2, prim->faceCount());
|
||||
ASSERT_EQ(2, prim->triangleCount());
|
||||
ASSERT_EQ(6, prim->indexCount());
|
||||
EXPECT_EQ(10, prim->index(0));
|
||||
EXPECT_EQ(11, prim->index(1));
|
||||
EXPECT_EQ(12, prim->index(2));
|
||||
EXPECT_EQ(10, prim->index(3));
|
||||
EXPECT_EQ(12, prim->index(4));
|
||||
EXPECT_EQ(13, prim->index(5));
|
||||
}
|
||||
|
||||
118
Fwk/VizFwk/Tests/LibRender_UnitTests/cvfMatrixState-Test.cpp
Normal file
118
Fwk/VizFwk/Tests/LibRender_UnitTests/cvfMatrixState-Test.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
|
||||
#include "cvfMatrixState.h"
|
||||
#include "cvfCamera.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MatrixStateTest, Constructor)
|
||||
{
|
||||
MatrixState ms(Vec2i::ZERO, Vec2ui::ZERO, Mat4d::IDENTITY, Mat4d::IDENTITY);
|
||||
|
||||
EXPECT_EQ(1, ms.versionTick());
|
||||
|
||||
// Might get into trouble here due to internal double to float conversion
|
||||
Mat4f pm = ms.projectionMatrix();
|
||||
EXPECT_TRUE(pm.isIdentity());
|
||||
|
||||
Mat4f vm = ms.viewMatrix();
|
||||
EXPECT_TRUE(vm.isIdentity());
|
||||
|
||||
Mat4f mm = ms.modelMatrix();
|
||||
EXPECT_TRUE(mm.isIdentity());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(MatrixStateTest, ModelViewMatrix)
|
||||
{
|
||||
const Vec3d eye(0, -2, 0);
|
||||
const Vec3d vrp(0, 0, 0);
|
||||
const Vec3d up(0, 0, 1);
|
||||
|
||||
Camera cam;
|
||||
cam.setFromLookAt(eye, vrp, up);
|
||||
MatrixState ms(Vec2i::ZERO, Vec2ui::ZERO, Mat4d::IDENTITY, cam.viewMatrix());
|
||||
|
||||
{
|
||||
Mat4f mvm = ms.modelViewMatrix();
|
||||
Mat4f mvmi = ms.modelViewMatrixInverse();
|
||||
|
||||
const Vec3f wc0(0, 0, 0);
|
||||
Vec3f ec = wc0.getTransformedPoint(mvm);
|
||||
EXPECT_FLOAT_EQ(0, ec.x());
|
||||
EXPECT_FLOAT_EQ(0, ec.y());
|
||||
EXPECT_FLOAT_EQ(-2, ec.z());
|
||||
|
||||
Vec3f wc = ec.getTransformedPoint(mvmi);
|
||||
EXPECT_FLOAT_EQ(0, wc.x());
|
||||
EXPECT_FLOAT_EQ(0, wc.y());
|
||||
EXPECT_FLOAT_EQ(0, wc.z());
|
||||
}
|
||||
|
||||
Mat4d transform = Mat4d::fromTranslation(Vec3d(2, 2, 0));
|
||||
ms.setModelMatrix(transform);
|
||||
{
|
||||
Mat4f mvm = ms.modelViewMatrix();
|
||||
Mat4f mvmi = ms.modelViewMatrixInverse();
|
||||
|
||||
const Vec3f wc0(0, 0, 0);
|
||||
Vec3f ec = wc0.getTransformedPoint(mvm);
|
||||
EXPECT_FLOAT_EQ(2, ec.x());
|
||||
EXPECT_FLOAT_EQ(0, ec.y());
|
||||
EXPECT_FLOAT_EQ(-4, ec.z());
|
||||
|
||||
Vec3f wc = ec.getTransformedPoint(mvmi);
|
||||
EXPECT_FLOAT_EQ(0, wc.x());
|
||||
EXPECT_FLOAT_EQ(0, wc.y());
|
||||
EXPECT_FLOAT_EQ(0, wc.z());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfOpenGLCapabilities.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OpenGLCapabilitiesTest, Defaults)
|
||||
{
|
||||
OpenGLCapabilities cap;
|
||||
EXPECT_FALSE(cap.hasCapability((OpenGLCapabilities::Capability)0xffffffff));
|
||||
EXPECT_FALSE(cap.supportsOpenGL2());
|
||||
EXPECT_TRUE(cap.supportsOpenGLVer(1));
|
||||
EXPECT_FALSE(cap.supportsOpenGLVer(2));
|
||||
EXPECT_FALSE(cap.supportsOpenGLVer(3));
|
||||
EXPECT_FALSE(cap.supportsFixedFunction());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OpenGLCapabilitiesTest, CopyConstructorAndAssignment)
|
||||
{
|
||||
OpenGLCapabilities cap;
|
||||
cap.addCapablity(OpenGLCapabilities::TEXTURE_FLOAT);
|
||||
cap.configureOpenGLSupport(2);
|
||||
cap.setSupportsFixedFunction(true);
|
||||
|
||||
{
|
||||
OpenGLCapabilities c(cap);
|
||||
EXPECT_TRUE(cap.hasCapability(OpenGLCapabilities::TEXTURE_FLOAT));
|
||||
EXPECT_TRUE(cap.supportsOpenGL2());
|
||||
EXPECT_TRUE(cap.supportsOpenGLVer(2));
|
||||
EXPECT_TRUE(cap.supportsFixedFunction());
|
||||
}
|
||||
|
||||
{
|
||||
OpenGLCapabilities c;
|
||||
c = cap;
|
||||
EXPECT_TRUE(cap.hasCapability(OpenGLCapabilities::TEXTURE_FLOAT));
|
||||
EXPECT_TRUE(cap.supportsOpenGL2());
|
||||
EXPECT_TRUE(cap.supportsOpenGLVer(2));
|
||||
EXPECT_TRUE(cap.supportsFixedFunction());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OpenGLCapabilitiesTest, AddRemoveCapabilties)
|
||||
{
|
||||
OpenGLCapabilities cap;
|
||||
|
||||
cap.addCapablity(OpenGLCapabilities::TEXTURE_FLOAT);
|
||||
cap.addCapablity(OpenGLCapabilities::TEXTURE_RECTANGLE);
|
||||
EXPECT_TRUE(cap.hasCapability(OpenGLCapabilities::TEXTURE_FLOAT));
|
||||
EXPECT_TRUE(cap.hasCapability(OpenGLCapabilities::TEXTURE_RECTANGLE));
|
||||
|
||||
cap.removeCapablity(OpenGLCapabilities::TEXTURE_RECTANGLE);
|
||||
EXPECT_TRUE(cap.hasCapability(OpenGLCapabilities::TEXTURE_FLOAT));
|
||||
EXPECT_FALSE(cap.hasCapability(OpenGLCapabilities::TEXTURE_RECTANGLE));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfOpenGLContextGroup.h"
|
||||
#include "cvfOpenGLContext.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
class MockContext : public OpenGLContext
|
||||
{
|
||||
public:
|
||||
MockContext(OpenGLContextGroup* contextGroup) : OpenGLContext(contextGroup) {}
|
||||
void makeCurrent() {}
|
||||
bool isCurrent() const {return true; }
|
||||
};
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OpenGLContextGroupTest, Defaults)
|
||||
{
|
||||
OpenGLContextGroup grp;
|
||||
EXPECT_TRUE(grp.resourceManager() != NULL);
|
||||
EXPECT_TRUE(grp.logger() != NULL);
|
||||
|
||||
EXPECT_FALSE(grp.isContextGroupInitialized());
|
||||
|
||||
EXPECT_TRUE(grp.capabilities() != NULL);
|
||||
|
||||
// Cannot do this - causes assert
|
||||
//EXPECT_TRUE(grp.glewContextStruct() != NULL);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OpenGLContextGroupTest, LifeCycle)
|
||||
{
|
||||
ref<OpenGLContextGroup> grp = new OpenGLContextGroup;
|
||||
|
||||
ref<OpenGLContext> ctx1 = new MockContext(grp.p());
|
||||
EXPECT_TRUE(grp->containsContext(ctx1.p()));
|
||||
EXPECT_EQ(grp.p(), ctx1->group());
|
||||
EXPECT_EQ(2, ctx1->refCount());
|
||||
|
||||
ref<OpenGLContext> ctx2 = new MockContext(grp.p());
|
||||
ref<OpenGLContext> ctx3 = new MockContext(grp.p());
|
||||
EXPECT_TRUE(grp->containsContext(ctx2.p()));
|
||||
EXPECT_TRUE(grp->containsContext(ctx3.p()));
|
||||
EXPECT_EQ(grp.p(), ctx2->group());
|
||||
EXPECT_EQ(grp.p(), ctx3->group());
|
||||
EXPECT_EQ(2, ctx2->refCount());
|
||||
EXPECT_EQ(2, ctx3->refCount());
|
||||
|
||||
ctx1->shutdownContext();
|
||||
EXPECT_EQ(1, ctx1->refCount());
|
||||
EXPECT_TRUE(ctx1->group() == NULL);
|
||||
EXPECT_FALSE(grp->containsContext(ctx1.p()));
|
||||
|
||||
ctx2 = NULL;
|
||||
|
||||
grp = NULL;
|
||||
EXPECT_EQ(1, ctx3->refCount());
|
||||
EXPECT_TRUE(ctx3->group() == NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfOpenGLResourceManager.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OpenGLResourceManagerTest, DefaultValues)
|
||||
{
|
||||
OpenGLResourceManager rcMgr;
|
||||
ASSERT_FALSE(rcMgr.hasAnyOpenGLResources());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfOverlayColorLegend.h"
|
||||
#include "cvfFixedAtlasFont.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OverlayColorLegendTest, Defaults)
|
||||
{
|
||||
ref<Font> myFont = new FixedAtlasFont(FixedAtlasFont::STANDARD);
|
||||
OverlayColorLegend cl(myFont.p());
|
||||
|
||||
EXPECT_EQ(200, cl.sizeHint().x());
|
||||
EXPECT_EQ(200, cl.sizeHint().y());
|
||||
|
||||
EXPECT_STREQ("", cl.title().toAscii().ptr());
|
||||
EXPECT_TRUE(Color3f(Color3::BLACK) == cl.color());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OverlayColorLegendTest, SizeHint)
|
||||
{
|
||||
ref<Font> myFont = new FixedAtlasFont(FixedAtlasFont::STANDARD);
|
||||
OverlayColorLegend cl(myFont.p());
|
||||
cl.setSizeHint(Vec2ui(500,100));
|
||||
|
||||
EXPECT_EQ(500, cl.sizeHint().x());
|
||||
EXPECT_EQ(100, cl.sizeHint().y());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OverlayColorLegendTest, GettersAndSetters)
|
||||
{
|
||||
ref<Font> myFont = new FixedAtlasFont(FixedAtlasFont::STANDARD);
|
||||
OverlayColorLegend cl(myFont.p());
|
||||
|
||||
cl.setColor(Color3::BROWN);
|
||||
EXPECT_TRUE(Color3f(Color3::BROWN) == cl.color());
|
||||
|
||||
cl.setTitle("Testing");
|
||||
EXPECT_STREQ("Testing", cl.title().toAscii().ptr());
|
||||
|
||||
cl.setTitle("Testing\nSecondLine\nThird");
|
||||
EXPECT_STREQ("Testing\nSecondLine\nThird", cl.title().toAscii().ptr());
|
||||
}
|
||||
|
||||
|
||||
136
Fwk/VizFwk/Tests/LibRender_UnitTests/cvfOverlayItem-Test.cpp
Normal file
136
Fwk/VizFwk/Tests/LibRender_UnitTests/cvfOverlayItem-Test.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfOverlayItem.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
class MyItem : public OverlayItem
|
||||
{
|
||||
public:
|
||||
MyItem() { m_size.set(0, 0); }
|
||||
void setSize(Vec2ui size) { m_size = size; }
|
||||
virtual Vec2ui sizeHint() { return m_size; }
|
||||
virtual void render(OpenGLContext*, const Vec2i&, const Vec2ui&) { }
|
||||
virtual void renderSoftware(OpenGLContext*, const Vec2i&, const Vec2ui&) { }
|
||||
|
||||
private:
|
||||
Vec2ui m_size;
|
||||
};
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OverlayItem, BasicConstruction)
|
||||
{
|
||||
ref<MyItem> item = new MyItem;
|
||||
|
||||
EXPECT_EQ(Vec2ui(0, 0), item->sizeHint());
|
||||
EXPECT_EQ(OverlayItem::HORIZONTAL, item->layoutScheme());
|
||||
EXPECT_EQ(OverlayItem::BOTTOM_LEFT, item->anchorCorner());
|
||||
EXPECT_EQ(Vec2i(0, 0), item->fixedPosition());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OverlayItem, setLayout)
|
||||
{
|
||||
ref<MyItem> item = new MyItem;
|
||||
|
||||
item->setLayout(OverlayItem::VERTICAL, OverlayItem::TOP_RIGHT);
|
||||
EXPECT_EQ(OverlayItem::VERTICAL, item->layoutScheme());
|
||||
EXPECT_EQ(OverlayItem::TOP_RIGHT, item->anchorCorner());
|
||||
EXPECT_EQ(Vec2i(0, 0), item->fixedPosition());
|
||||
|
||||
item->setLayout(OverlayItem::HORIZONTAL, OverlayItem::TOP_LEFT);
|
||||
EXPECT_EQ(OverlayItem::HORIZONTAL, item->layoutScheme());
|
||||
EXPECT_EQ(OverlayItem::TOP_LEFT, item->anchorCorner());
|
||||
EXPECT_EQ(Vec2i(0, 0), item->fixedPosition());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OverlayItem, setLayoutFixedPosition)
|
||||
{
|
||||
ref<MyItem> item = new MyItem;
|
||||
|
||||
item->setLayoutFixedPosition(Vec2i(1, 2));
|
||||
EXPECT_EQ(OverlayItem::FIXED_POSITION, item->layoutScheme());
|
||||
EXPECT_EQ(OverlayItem::BOTTOM_LEFT, item->anchorCorner());
|
||||
EXPECT_EQ(Vec2i(1, 2), item->fixedPosition());
|
||||
|
||||
item->setLayout(OverlayItem::HORIZONTAL, OverlayItem::TOP_LEFT);
|
||||
EXPECT_EQ(OverlayItem::HORIZONTAL, item->layoutScheme());
|
||||
EXPECT_EQ(OverlayItem::TOP_LEFT, item->anchorCorner());
|
||||
EXPECT_EQ(Vec2i(0, 0), item->fixedPosition());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OverlayItem, pick)
|
||||
{
|
||||
ref<MyItem> item = new MyItem;
|
||||
|
||||
EXPECT_TRUE(item->pick(0, 0, Vec2i(0, 0), Vec2ui(1, 1)));
|
||||
EXPECT_FALSE(item->pick(0, 0, Vec2i(0, 0), Vec2ui(0, 0)));
|
||||
|
||||
EXPECT_TRUE(item->pick(10, 10, Vec2i(10, 10), Vec2ui(2, 2)));
|
||||
EXPECT_TRUE(item->pick(11, 12, Vec2i(10, 10), Vec2ui(2, 2)));
|
||||
EXPECT_FALSE(item->pick( 9, 10, Vec2i(10, 10), Vec2ui(2, 2)));
|
||||
EXPECT_FALSE(item->pick(11, 9, Vec2i(10, 10), Vec2ui(2, 2)));
|
||||
EXPECT_FALSE(item->pick(13, 10, Vec2i(10, 10), Vec2ui(2, 2)));
|
||||
EXPECT_FALSE(item->pick(10, 14, Vec2i(10, 10), Vec2ui(2, 2)));
|
||||
|
||||
EXPECT_TRUE(item->pick(10, 10, Vec2i(10, 10), Vec2ui(1, 1)));
|
||||
EXPECT_FALSE(item->pick(10, 10, Vec2i(10, 10), Vec2ui(0, 0)));
|
||||
EXPECT_FALSE(item->pick(10, 10, Vec2i(10, 10), Vec2ui(1, 0)));
|
||||
EXPECT_FALSE(item->pick(10, 10, Vec2i(10, 10), Vec2ui(0, 1)));
|
||||
}
|
||||
|
||||
|
||||
109
Fwk/VizFwk/Tests/LibRender_UnitTests/cvfOverlayTextBox-Test.cpp
Normal file
109
Fwk/VizFwk/Tests/LibRender_UnitTests/cvfOverlayTextBox-Test.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfOverlayTextBox.h"
|
||||
#include "cvfFixedAtlasFont.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OverlayTextBoxTest, Defaults)
|
||||
{
|
||||
ref<Font> myFont = new FixedAtlasFont(FixedAtlasFont::STANDARD);
|
||||
OverlayTextBox tb(myFont.p());
|
||||
|
||||
EXPECT_EQ(200, tb.sizeHint().x());
|
||||
EXPECT_EQ( 50, tb.sizeHint().y());
|
||||
|
||||
EXPECT_STREQ("", tb.text().toAscii().ptr());
|
||||
EXPECT_TRUE(Color3f(Color3::WHITE) == tb.textColor());
|
||||
EXPECT_TRUE(Color3f(0.2f, 0.2f, 1.0f) == tb.backgroundColor());
|
||||
EXPECT_TRUE(Color3f(0.6f, 0.6f, 1.0f) == tb.borderColor());
|
||||
EXPECT_TRUE(tb.drawBackground());
|
||||
EXPECT_TRUE(tb.drawBorder());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OverlayTextBoxTest, SizeHint)
|
||||
{
|
||||
ref<Font> myFont = new FixedAtlasFont(FixedAtlasFont::STANDARD);
|
||||
OverlayTextBox tb(myFont.p());
|
||||
tb.setPixelSize(Vec2ui(500,100));
|
||||
|
||||
EXPECT_EQ(500, tb.sizeHint().x());
|
||||
EXPECT_EQ(100, tb.sizeHint().y());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(OverlayTextBoxTest, GettersAndSetters)
|
||||
{
|
||||
ref<Font> myFont = new FixedAtlasFont(FixedAtlasFont::STANDARD);
|
||||
OverlayTextBox tb(myFont.p());
|
||||
|
||||
tb.setText("Testing");
|
||||
tb.setTextColor(Color3::BROWN);
|
||||
tb.setBackgroundColor(Color3::MAGENTA);
|
||||
tb.setBorderColor(Color3::PURPLE);
|
||||
tb.setDrawBackground(true);
|
||||
tb.setDrawBorder(false);
|
||||
|
||||
EXPECT_STREQ("Testing", tb.text().toAscii().ptr());
|
||||
EXPECT_TRUE(Color3f(Color3::BROWN) == tb.textColor());
|
||||
EXPECT_TRUE(Color3f(Color3::MAGENTA) == tb.backgroundColor());
|
||||
EXPECT_TRUE(Color3f(Color3::PURPLE) == tb.borderColor());
|
||||
EXPECT_TRUE(tb.drawBackground());
|
||||
EXPECT_FALSE(tb.drawBorder());
|
||||
|
||||
tb.setDrawBackground(false);
|
||||
tb.setDrawBorder(true);
|
||||
|
||||
EXPECT_FALSE(tb.drawBackground());
|
||||
EXPECT_TRUE(tb.drawBorder());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfPrimitiveSetDirect.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "cvfOpenGL.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PrimitiveSetDirect, BasicConstructionAndEmptyObject)
|
||||
{
|
||||
ref<PrimitiveSetDirect> myPrim = new PrimitiveSetDirect(PT_POINTS);
|
||||
|
||||
EXPECT_EQ(GL_POINTS, static_cast<int>(myPrim->primitiveTypeOpenGL()));
|
||||
EXPECT_EQ(0u, myPrim->indexCount());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#if CVF_ENABLE_TIGHT_ASSERTS == 1
|
||||
TEST(PrimitiveSetDirectDeathTest, AccessOutOfBounds)
|
||||
{
|
||||
ref<PrimitiveSetDirect> myPrim = new PrimitiveSetDirect(PT_POINTS);
|
||||
EXPECT_EQ(0u, myPrim->indexCount());
|
||||
|
||||
EXPECT_DEATH(myPrim->index(0), "Assertion");
|
||||
|
||||
myPrim->setIndexCount(5);
|
||||
ASSERT_EQ(5, myPrim->indexCount());
|
||||
EXPECT_DEATH(myPrim->index(5), "Assertion");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PrimitiveSetDirect, SettingAndGettingIndices)
|
||||
{
|
||||
ref<PrimitiveSetDirect> myPrim = new PrimitiveSetDirect(PT_POINTS);
|
||||
EXPECT_EQ(0, myPrim->indexCount());
|
||||
|
||||
myPrim->setIndexCount(5);
|
||||
ASSERT_EQ(5, myPrim->indexCount());
|
||||
EXPECT_EQ(0, myPrim->index(0));
|
||||
EXPECT_EQ(4, myPrim->index(4));
|
||||
|
||||
myPrim->setStartIndex(10);
|
||||
ASSERT_EQ(5, myPrim->indexCount());
|
||||
EXPECT_EQ(10, myPrim->index(0));
|
||||
EXPECT_EQ(14, myPrim->index(4));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,419 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfPrimitiveSetIndexedUInt.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "cvfOpenGL.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PrimitiveSetIndexedUInt, CheckPrimitiveTypeMapping)
|
||||
{
|
||||
// This is really a test of functionality in the base!
|
||||
|
||||
PrimitiveSetIndexedUInt p1(PT_POINTS);
|
||||
PrimitiveSetIndexedUInt p2(PT_LINES);
|
||||
PrimitiveSetIndexedUInt p3(PT_LINE_LOOP);
|
||||
PrimitiveSetIndexedUInt p4(PT_LINE_STRIP);
|
||||
PrimitiveSetIndexedUInt p5(PT_TRIANGLES);
|
||||
PrimitiveSetIndexedUInt p6(PT_TRIANGLE_STRIP);
|
||||
PrimitiveSetIndexedUInt p7(PT_TRIANGLE_FAN);
|
||||
|
||||
EXPECT_EQ(GL_POINTS, static_cast<int>(p1.primitiveTypeOpenGL()));
|
||||
EXPECT_EQ(GL_LINES, static_cast<int>(p2.primitiveTypeOpenGL()));
|
||||
EXPECT_EQ(GL_LINE_LOOP, static_cast<int>(p3.primitiveTypeOpenGL()));
|
||||
EXPECT_EQ(GL_LINE_STRIP, static_cast<int>(p4.primitiveTypeOpenGL()));
|
||||
EXPECT_EQ(GL_TRIANGLES, static_cast<int>(p5.primitiveTypeOpenGL()));
|
||||
EXPECT_EQ(GL_TRIANGLE_STRIP, static_cast<int>(p6.primitiveTypeOpenGL()));
|
||||
EXPECT_EQ(GL_TRIANGLE_FAN, static_cast<int>(p7.primitiveTypeOpenGL()));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PrimitiveSetIndexedUInt, BasicConstructionAndEmptyObject)
|
||||
{
|
||||
ref<PrimitiveSetIndexedUInt> myPrim = new PrimitiveSetIndexedUInt(PT_POINTS);
|
||||
|
||||
EXPECT_EQ(0u, myPrim->indexCount());
|
||||
|
||||
myPrim->setIndices(NULL);
|
||||
EXPECT_EQ(0u, myPrim->indexCount());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#ifdef _DEBUG
|
||||
TEST(PrimitiveSetIndexedUIntDeathTest, AccessOutOfBounds)
|
||||
{
|
||||
ref<PrimitiveSetIndexedUInt> myPrim = new PrimitiveSetIndexedUInt(PT_POINTS);
|
||||
EXPECT_EQ(0u, myPrim->indexCount());
|
||||
|
||||
EXPECT_DEATH(myPrim->index(0), "Assertion");
|
||||
|
||||
ref<UIntArray> myIndices = new UIntArray;
|
||||
myIndices->reserve(2);
|
||||
myIndices->add(10);
|
||||
myIndices->add(11);
|
||||
|
||||
myPrim->setIndices(myIndices.p());
|
||||
ASSERT_EQ(2u, myPrim->indexCount());
|
||||
EXPECT_EQ(10, myPrim->index(0));
|
||||
EXPECT_EQ(11, myPrim->index(1));
|
||||
|
||||
EXPECT_DEATH(myPrim->index(2), "Assertion");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PrimitiveSetIndexedUInt, SettingAndGettingIndices)
|
||||
{
|
||||
ref<UIntArray> myIndices = new UIntArray;
|
||||
EXPECT_EQ(1, myIndices->refCount());
|
||||
myIndices->reserve(3);
|
||||
myIndices->add(10);
|
||||
myIndices->add(11);
|
||||
myIndices->add(12);
|
||||
|
||||
ref<PrimitiveSetIndexedUInt> myPrim = new PrimitiveSetIndexedUInt(PT_POINTS);
|
||||
EXPECT_EQ(0u, myPrim->indexCount());
|
||||
|
||||
myPrim->setIndices(myIndices.p());
|
||||
EXPECT_EQ(2, myIndices->refCount());
|
||||
|
||||
ASSERT_EQ(3u, myPrim->indexCount());
|
||||
EXPECT_EQ(10u, myPrim->index(0));
|
||||
EXPECT_EQ(11u, myPrim->index(1));
|
||||
EXPECT_EQ(12u, myPrim->index(2));
|
||||
|
||||
EXPECT_EQ(10u, myPrim->minIndex());
|
||||
EXPECT_EQ(12u, myPrim->maxIndex());
|
||||
|
||||
const UIntArray* indices = myPrim->indices();
|
||||
ASSERT_TRUE(indices != NULL);
|
||||
ASSERT_EQ(3u, indices->size());
|
||||
EXPECT_EQ(10u, indices->get(0));
|
||||
EXPECT_EQ(11u, indices->get(1));
|
||||
EXPECT_EQ(12u, indices->get(2));
|
||||
|
||||
myPrim->setIndices(NULL);
|
||||
EXPECT_EQ(1, myIndices->refCount());
|
||||
EXPECT_EQ(-1, myPrim->minIndex());
|
||||
EXPECT_EQ(-1, myPrim->maxIndex());
|
||||
EXPECT_EQ(UNDEFINED_UINT, myPrim->minIndex());
|
||||
EXPECT_EQ(UNDEFINED_UINT, myPrim->maxIndex());
|
||||
|
||||
ASSERT_EQ(0u, myPrim->indexCount());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PrimitiveSetIndexedUInt, GetOpenGLPrimitive_FromPoints)
|
||||
{
|
||||
ref<UIntArray> indices = new UIntArray;
|
||||
indices->reserve(3);
|
||||
indices->add(0);
|
||||
indices->add(1);
|
||||
indices->add(2);
|
||||
|
||||
ref<PrimitiveSetIndexedUInt> myPrim = new PrimitiveSetIndexedUInt(PT_POINTS);
|
||||
myPrim->setIndices(indices.p());
|
||||
|
||||
ASSERT_EQ(3u, myPrim->faceCount());
|
||||
|
||||
UIntArray conn;
|
||||
|
||||
myPrim->getFaceIndices(0, &conn);
|
||||
ASSERT_EQ(1u, conn.size());
|
||||
EXPECT_EQ(0u, conn.get(0));
|
||||
|
||||
myPrim->getFaceIndices(1, &conn);
|
||||
ASSERT_EQ(1u, conn.size());
|
||||
EXPECT_EQ(1u, conn.get(0));
|
||||
|
||||
myPrim->getFaceIndices(2, &conn);
|
||||
ASSERT_EQ(1u, conn.size());
|
||||
EXPECT_EQ(2u, conn.get(0));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PrimitiveSetIndexedUInt, GetOpenGLPrimitive_FromLines)
|
||||
{
|
||||
ref<UIntArray> indices = new UIntArray;
|
||||
indices->reserve(4);
|
||||
indices->add(0);
|
||||
indices->add(1);
|
||||
indices->add(2);
|
||||
indices->add(3);
|
||||
|
||||
ref<PrimitiveSetIndexedUInt> myPrim = new PrimitiveSetIndexedUInt(PT_LINES);
|
||||
myPrim->setIndices(indices.p());
|
||||
|
||||
ASSERT_EQ(2u, myPrim->faceCount());
|
||||
|
||||
UIntArray conn;
|
||||
|
||||
myPrim->getFaceIndices(0, &conn);
|
||||
ASSERT_EQ(2u, conn.size());
|
||||
EXPECT_EQ(0u, conn.get(0));
|
||||
EXPECT_EQ(1u, conn.get(1));
|
||||
|
||||
myPrim->getFaceIndices(1, &conn);
|
||||
ASSERT_EQ(2u, conn.size());
|
||||
EXPECT_EQ(2u, conn.get(0));
|
||||
EXPECT_EQ(3u, conn.get(1));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PrimitiveSetIndexedUInt, GetOpenGLPrimitive_FromLineLoop)
|
||||
{
|
||||
ref<UIntArray> indices = new UIntArray;
|
||||
indices->reserve(4);
|
||||
indices->add(0);
|
||||
indices->add(1);
|
||||
indices->add(2);
|
||||
indices->add(3);
|
||||
|
||||
ref<PrimitiveSetIndexedUInt> myPrim = new PrimitiveSetIndexedUInt(PT_LINE_LOOP);
|
||||
myPrim->setIndices(indices.p());
|
||||
|
||||
ASSERT_EQ(4u, myPrim->faceCount());
|
||||
|
||||
UIntArray conn;
|
||||
|
||||
myPrim->getFaceIndices(0, &conn);
|
||||
ASSERT_EQ(2u, conn.size());
|
||||
EXPECT_EQ(0u, conn.get(0));
|
||||
EXPECT_EQ(1u, conn.get(1));
|
||||
|
||||
myPrim->getFaceIndices(1, &conn);
|
||||
ASSERT_EQ(2u, conn.size());
|
||||
EXPECT_EQ(1u, conn.get(0));
|
||||
EXPECT_EQ(2u, conn.get(1));
|
||||
|
||||
myPrim->getFaceIndices(2, &conn);
|
||||
ASSERT_EQ(2u, conn.size());
|
||||
EXPECT_EQ(2u, conn.get(0));
|
||||
EXPECT_EQ(3u, conn.get(1));
|
||||
|
||||
myPrim->getFaceIndices(3, &conn);
|
||||
ASSERT_EQ(2u, conn.size());
|
||||
EXPECT_EQ(3u, conn.get(0));
|
||||
EXPECT_EQ(0u, conn.get(1));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PrimitiveSetIndexedUInt, GetOpenGLPrimitive_FromLineStrip)
|
||||
{
|
||||
ref<UIntArray> indices = new UIntArray;
|
||||
indices->reserve(4);
|
||||
indices->add(0);
|
||||
indices->add(1);
|
||||
indices->add(2);
|
||||
indices->add(3);
|
||||
|
||||
ref<PrimitiveSetIndexedUInt> myPrim = new PrimitiveSetIndexedUInt(PT_LINE_STRIP);
|
||||
myPrim->setIndices(indices.p());
|
||||
|
||||
ASSERT_EQ(3u, myPrim->faceCount());
|
||||
|
||||
UIntArray conn;
|
||||
|
||||
myPrim->getFaceIndices(0, &conn);
|
||||
ASSERT_EQ(2u, conn.size());
|
||||
EXPECT_EQ(0u, conn.get(0));
|
||||
EXPECT_EQ(1u, conn.get(1));
|
||||
|
||||
myPrim->getFaceIndices(1, &conn);
|
||||
ASSERT_EQ(2u, conn.size());
|
||||
EXPECT_EQ(1u, conn.get(0));
|
||||
EXPECT_EQ(2u, conn.get(1));
|
||||
|
||||
myPrim->getFaceIndices(2, &conn);
|
||||
ASSERT_EQ(2u, conn.size());
|
||||
EXPECT_EQ(2u, conn.get(0));
|
||||
EXPECT_EQ(3u, conn.get(1));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PrimitiveSetIndexedUInt, GetOpenGLPrimitive_FromTriangles)
|
||||
{
|
||||
ref<UIntArray> indices = new UIntArray;
|
||||
indices->reserve(6);
|
||||
indices->add(0);
|
||||
indices->add(1);
|
||||
indices->add(2);
|
||||
indices->add(3);
|
||||
indices->add(4);
|
||||
indices->add(5);
|
||||
|
||||
ref<PrimitiveSetIndexedUInt> myPrim = new PrimitiveSetIndexedUInt(PT_TRIANGLES);
|
||||
myPrim->setIndices(indices.p());
|
||||
|
||||
ASSERT_EQ(2u, myPrim->faceCount());
|
||||
|
||||
UIntArray conn;
|
||||
|
||||
myPrim->getFaceIndices(0, &conn);
|
||||
ASSERT_EQ(3u, conn.size());
|
||||
EXPECT_EQ(0u, conn.get(0));
|
||||
EXPECT_EQ(1u, conn.get(1));
|
||||
EXPECT_EQ(2u, conn.get(2));
|
||||
|
||||
myPrim->getFaceIndices(1, &conn);
|
||||
ASSERT_EQ(3u, conn.size());
|
||||
EXPECT_EQ(3u, conn.get(0));
|
||||
EXPECT_EQ(4u, conn.get(1));
|
||||
EXPECT_EQ(5u, conn.get(2));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PrimitiveSetIndexedUInt, GetOpenGLPrimitive_FromTriFan)
|
||||
{
|
||||
// See TEST(GeometryBuilderTest, AddTriangleFan)
|
||||
ref<UIntArray> indices = new UIntArray;
|
||||
indices->reserve(5);
|
||||
indices->add(0);
|
||||
indices->add(1);
|
||||
indices->add(2);
|
||||
indices->add(3);
|
||||
indices->add(4);
|
||||
|
||||
ref<PrimitiveSetIndexedUInt> myPrim = new PrimitiveSetIndexedUInt(PT_TRIANGLE_FAN);
|
||||
myPrim->setIndices(indices.p());
|
||||
|
||||
ASSERT_EQ(3u, myPrim->faceCount());
|
||||
|
||||
UIntArray conn;
|
||||
|
||||
myPrim->getFaceIndices(0, &conn);
|
||||
ASSERT_EQ(3u, conn.size());
|
||||
EXPECT_EQ(0u, conn.get(0));
|
||||
EXPECT_EQ(1u, conn.get(1));
|
||||
EXPECT_EQ(2u, conn.get(2));
|
||||
|
||||
myPrim->getFaceIndices(1, &conn);
|
||||
ASSERT_EQ(3u, conn.size());
|
||||
EXPECT_EQ(0u, conn.get(0));
|
||||
EXPECT_EQ(2u, conn.get(1));
|
||||
EXPECT_EQ(3u, conn.get(2));
|
||||
|
||||
myPrim->getFaceIndices(2, &conn);
|
||||
ASSERT_EQ(3u, conn.size());
|
||||
EXPECT_EQ(0u, conn.get(0));
|
||||
EXPECT_EQ(3u, conn.get(1));
|
||||
EXPECT_EQ(4u, conn.get(2));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PrimitiveSetIndexedUInt, GetOpenGLPrimitive_FromTriStrip)
|
||||
{
|
||||
// See TEST(GeometryBuilderTest, AddTriangleStrip)
|
||||
ref<UIntArray> indices = new UIntArray;
|
||||
indices->reserve(6);
|
||||
indices->add(0);
|
||||
indices->add(1);
|
||||
indices->add(2);
|
||||
indices->add(3);
|
||||
indices->add(4);
|
||||
indices->add(5);
|
||||
|
||||
ref<PrimitiveSetIndexedUInt> myPrim = new PrimitiveSetIndexedUInt(PT_TRIANGLE_STRIP);
|
||||
myPrim->setIndices(indices.p());
|
||||
|
||||
ASSERT_EQ(4u, myPrim->faceCount());
|
||||
|
||||
UIntArray conn;
|
||||
|
||||
myPrim->getFaceIndices(0, &conn);
|
||||
ASSERT_EQ(3u, conn.size());
|
||||
EXPECT_EQ(0u, conn.get(0));
|
||||
EXPECT_EQ(1u, conn.get(1));
|
||||
EXPECT_EQ(2u, conn.get(2));
|
||||
|
||||
myPrim->getFaceIndices(1, &conn);
|
||||
ASSERT_EQ(3u, conn.size());
|
||||
EXPECT_EQ(2u, conn.get(0));
|
||||
EXPECT_EQ(1u, conn.get(1));
|
||||
EXPECT_EQ(3u, conn.get(2));
|
||||
|
||||
myPrim->getFaceIndices(2, &conn);
|
||||
ASSERT_EQ(3u, conn.size());
|
||||
EXPECT_EQ(2u, conn.get(0));
|
||||
EXPECT_EQ(3u, conn.get(1));
|
||||
EXPECT_EQ(4u, conn.get(2));
|
||||
|
||||
myPrim->getFaceIndices(3, &conn);
|
||||
ASSERT_EQ(3u, conn.size());
|
||||
EXPECT_EQ(4u, conn.get(0));
|
||||
EXPECT_EQ(3u, conn.get(1));
|
||||
EXPECT_EQ(5u, conn.get(2));
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfPrimitiveSetIndexedUIntScoped.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "cvfOpenGL.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PrimitiveSetIndexedUIntScoped, BasicConstructionAndEmptyObject)
|
||||
{
|
||||
PrimitiveSetIndexedUIntScoped ps(PT_POINTS);
|
||||
EXPECT_EQ(0u, ps.indexCount());
|
||||
|
||||
ps.setIndices(NULL, 0, 0);
|
||||
EXPECT_EQ(0u, ps.indexCount());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PrimitiveSetIndexedUIntScoped, SettingFullScope)
|
||||
{
|
||||
ref<UIntArray> indices = new UIntArray;
|
||||
indices->reserve(2);
|
||||
indices->add(10);
|
||||
indices->add(11);
|
||||
|
||||
PrimitiveSetIndexedUIntScoped ps(PT_POINTS);
|
||||
ps.setIndices(indices.p(), 0, 2);
|
||||
ASSERT_EQ(2, ps.indexCount());
|
||||
EXPECT_EQ(10, ps.index(0));
|
||||
EXPECT_EQ(11, ps.index(1));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PrimitiveSetIndexedUIntScoped, SettingScoped)
|
||||
{
|
||||
ref<UIntArray> indices = new UIntArray;
|
||||
indices->reserve(3);
|
||||
indices->add(10);
|
||||
indices->add(11);
|
||||
indices->add(12);
|
||||
|
||||
PrimitiveSetIndexedUIntScoped ps(PT_POINTS);
|
||||
ps.setIndices(indices.p(), 0, 0);
|
||||
ASSERT_EQ(0, ps.indexCount());
|
||||
|
||||
ps.setIndices(indices.p(), 0, 2);
|
||||
ASSERT_EQ(2, ps.indexCount());
|
||||
EXPECT_EQ(10, ps.index(0));
|
||||
EXPECT_EQ(11, ps.index(1));
|
||||
|
||||
ps.setIndices(indices.p(), 1, 2);
|
||||
ASSERT_EQ(2, ps.indexCount());
|
||||
EXPECT_EQ(11, ps.index(0));
|
||||
EXPECT_EQ(12, ps.index(1));
|
||||
EXPECT_EQ(1, ps.scopeFirstElement());
|
||||
EXPECT_EQ(2, ps.scopeElementCount());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#if CVF_ENABLE_ASSERTS == 1
|
||||
TEST(PrimitiveSetIndexedUIntScopedDeathTest, IllegalSettingOfIndices)
|
||||
{
|
||||
ref<UIntArray> indices = new UIntArray;
|
||||
indices->reserve(2);
|
||||
indices->add(10);
|
||||
indices->add(11);
|
||||
|
||||
PrimitiveSetIndexedUIntScoped ps(PT_POINTS);
|
||||
EXPECT_DEATH(ps.setIndices(indices.p(), 0, 3), "Assertion");
|
||||
EXPECT_DEATH(ps.setIndices(indices.p(), 1, 2), "Assertion");
|
||||
EXPECT_DEATH(ps.setIndices(indices.p(), 2, 3), "Assertion");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#if CVF_ENABLE_ASSERTS == 1
|
||||
TEST(PrimitiveSetIndexedUIntScopedDeathTest, IllegalSettingOfNullIndices)
|
||||
{
|
||||
PrimitiveSetIndexedUIntScoped ps(PT_POINTS);
|
||||
EXPECT_DEATH(ps.setIndices(NULL, 1, 2), "Assertion");
|
||||
EXPECT_DEATH(ps.setIndices(NULL, 0, 3), "Assertion");
|
||||
EXPECT_DEATH(ps.setIndices(NULL, 3, 0), "Assertion");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PrimitiveSetIndexedUIntScoped, SettingScopeOnly)
|
||||
{
|
||||
ref<UIntArray> indices = new UIntArray;
|
||||
indices->reserve(3);
|
||||
indices->add(10);
|
||||
indices->add(11);
|
||||
indices->add(12);
|
||||
|
||||
PrimitiveSetIndexedUIntScoped ps(PT_POINTS);
|
||||
ps.setIndices(indices.p(), 0, 3);
|
||||
ASSERT_EQ(3, ps.indexCount());
|
||||
|
||||
ps.setScope(0, 2);
|
||||
ASSERT_EQ(2, ps.indexCount());
|
||||
EXPECT_EQ(10, ps.index(0));
|
||||
EXPECT_EQ(11, ps.index(1));
|
||||
|
||||
ps.setScope(1, 2);
|
||||
ASSERT_EQ(2, ps.indexCount());
|
||||
EXPECT_EQ(11, ps.index(0));
|
||||
EXPECT_EQ(12, ps.index(1));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#if CVF_ENABLE_TIGHT_ASSERTS == 1
|
||||
TEST(PrimitiveSetIndexedUIntScopedDeathTest, AccessOutOfBounds)
|
||||
{
|
||||
PrimitiveSetIndexedUIntScoped ps(PT_POINTS);
|
||||
EXPECT_EQ(0, ps.indexCount());
|
||||
EXPECT_DEATH(ps.index(0), "Assertion");
|
||||
|
||||
ref<UIntArray> indices = new UIntArray;
|
||||
indices->reserve(2);
|
||||
indices->add(10);
|
||||
indices->add(11);
|
||||
|
||||
ps.setIndices(indices.p(), 0, 2);
|
||||
EXPECT_DEATH(ps.index(2), "Assertion");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfPrimitiveSetIndexedUShortScoped.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "cvfOpenGL.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PrimitiveSetIndexedUShortScoped, BasicConstructionAndEmptyObject)
|
||||
{
|
||||
PrimitiveSetIndexedUShortScoped ps(PT_POINTS);
|
||||
EXPECT_EQ(0u, ps.indexCount());
|
||||
|
||||
ps.setIndices(NULL, 0, 0);
|
||||
EXPECT_EQ(0u, ps.indexCount());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PrimitiveSetIndexedUShortScoped, SettingFullScope)
|
||||
{
|
||||
ref<UShortArray> indices = new UShortArray;
|
||||
indices->reserve(2);
|
||||
indices->add(10);
|
||||
indices->add(11);
|
||||
|
||||
PrimitiveSetIndexedUShortScoped ps(PT_POINTS);
|
||||
ps.setIndices(indices.p(), 0, 2);
|
||||
ASSERT_EQ(2, ps.indexCount());
|
||||
EXPECT_EQ(10, ps.index(0));
|
||||
EXPECT_EQ(11, ps.index(1));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PrimitiveSetIndexedUShortScoped, SettingScoped)
|
||||
{
|
||||
ref<UShortArray> indices = new UShortArray;
|
||||
indices->reserve(3);
|
||||
indices->add(10);
|
||||
indices->add(11);
|
||||
indices->add(12);
|
||||
|
||||
PrimitiveSetIndexedUShortScoped ps(PT_POINTS);
|
||||
ps.setIndices(indices.p(), 0, 0);
|
||||
ASSERT_EQ(0, ps.indexCount());
|
||||
|
||||
ps.setIndices(indices.p(), 0, 2);
|
||||
ASSERT_EQ(2, ps.indexCount());
|
||||
EXPECT_EQ(10, ps.index(0));
|
||||
EXPECT_EQ(11, ps.index(1));
|
||||
|
||||
ps.setIndices(indices.p(), 1, 2);
|
||||
ASSERT_EQ(2, ps.indexCount());
|
||||
EXPECT_EQ(11, ps.index(0));
|
||||
EXPECT_EQ(12, ps.index(1));
|
||||
EXPECT_EQ(1, ps.scopeFirstElement());
|
||||
EXPECT_EQ(2, ps.scopeElementCount());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#if CVF_ENABLE_ASSERTS == 1
|
||||
TEST(PrimitiveSetIndexedUShortScopedDeathTest, IllegalSettingOfIndices)
|
||||
{
|
||||
ref<UShortArray> indices = new UShortArray;
|
||||
indices->reserve(2);
|
||||
indices->add(10);
|
||||
indices->add(11);
|
||||
|
||||
PrimitiveSetIndexedUShortScoped ps(PT_POINTS);
|
||||
EXPECT_DEATH(ps.setIndices(indices.p(), 0, 3), "Assertion");
|
||||
EXPECT_DEATH(ps.setIndices(indices.p(), 1, 2), "Assertion");
|
||||
EXPECT_DEATH(ps.setIndices(indices.p(), 2, 3), "Assertion");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#if CVF_ENABLE_ASSERTS == 1
|
||||
TEST(PrimitiveSetIndexedUShortScopedDeathTest, IllegalSettingOfNullIndices)
|
||||
{
|
||||
PrimitiveSetIndexedUShortScoped ps(PT_POINTS);
|
||||
EXPECT_DEATH(ps.setIndices(NULL, 1, 2), "Assertion");
|
||||
EXPECT_DEATH(ps.setIndices(NULL, 0, 3), "Assertion");
|
||||
EXPECT_DEATH(ps.setIndices(NULL, 3, 0), "Assertion");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(PrimitiveSetIndexedUShortScoped, SettingScopeOnly)
|
||||
{
|
||||
ref<UShortArray> indices = new UShortArray;
|
||||
indices->reserve(3);
|
||||
indices->add(10);
|
||||
indices->add(11);
|
||||
indices->add(12);
|
||||
|
||||
PrimitiveSetIndexedUShortScoped ps(PT_POINTS);
|
||||
ps.setIndices(indices.p(), 0, 3);
|
||||
ASSERT_EQ(3, ps.indexCount());
|
||||
|
||||
ps.setScope(0, 2);
|
||||
ASSERT_EQ(2, ps.indexCount());
|
||||
EXPECT_EQ(10, ps.index(0));
|
||||
EXPECT_EQ(11, ps.index(1));
|
||||
|
||||
ps.setScope(1, 2);
|
||||
ASSERT_EQ(2, ps.indexCount());
|
||||
EXPECT_EQ(11, ps.index(0));
|
||||
EXPECT_EQ(12, ps.index(1));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#if CVF_ENABLE_TIGHT_ASSERTS == 1
|
||||
TEST(PrimitiveSetIndexedUShortScopedDeathTest, AccessOutOfBounds)
|
||||
{
|
||||
PrimitiveSetIndexedUShortScoped ps(PT_POINTS);
|
||||
EXPECT_EQ(0, ps.indexCount());
|
||||
EXPECT_DEATH(ps.index(0), "Assertion");
|
||||
|
||||
ref<UShortArray> indices = new UShortArray;
|
||||
indices->reserve(2);
|
||||
indices->add(10);
|
||||
indices->add(11);
|
||||
|
||||
ps.setIndices(indices.p(), 0, 2);
|
||||
EXPECT_DEATH(ps.index(2), "Assertion");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
772
Fwk/VizFwk/Tests/LibRender_UnitTests/cvfRenderState-Test.cpp
Normal file
772
Fwk/VizFwk/Tests/LibRender_UnitTests/cvfRenderState-Test.cpp
Normal file
@@ -0,0 +1,772 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// 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.1 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 at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfRenderState.h"
|
||||
#include "cvfRenderStateSet.h"
|
||||
#include "cvfRenderStateBlending.h"
|
||||
#include "cvfRenderStateColorMask.h"
|
||||
#include "cvfRenderStateCullFace.h"
|
||||
#include "cvfRenderStateDepth.h"
|
||||
#include "cvfRenderStateFrontFace.h"
|
||||
#include "cvfRenderStateLine.h"
|
||||
#include "cvfRenderStatePoint.h"
|
||||
#include "cvfRenderStatePolygonMode.h"
|
||||
#include "cvfRenderStatePolygonOffset.h"
|
||||
#include "cvfRenderStateStencil.h"
|
||||
#include "cvfRenderStateTextureBindings.h"
|
||||
#include "cvfRenderState_FF.h"
|
||||
|
||||
#include "cvfTexture.h"
|
||||
#include "cvfTextureImage.h"
|
||||
#include "cvfSampler.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateSetTest, BasicLifeCycle)
|
||||
{
|
||||
RenderStateSet rss;
|
||||
ASSERT_EQ(0, rss.count());
|
||||
|
||||
ref<RenderStateMaterial_FF> rm1 = new RenderStateMaterial_FF;
|
||||
EXPECT_EQ(1, rm1->refCount());
|
||||
|
||||
rss.setRenderState(rm1.p());
|
||||
ASSERT_EQ(1, rss.count());
|
||||
EXPECT_EQ(2, rm1->refCount());
|
||||
|
||||
EXPECT_EQ(rm1.p(), rss.renderStateOfType(RenderState::MATERIAL_FF));
|
||||
EXPECT_EQ(rm1.p(), rss.renderState(0));
|
||||
|
||||
ref<RenderStateMaterial_FF> rm2 = new RenderStateMaterial_FF;
|
||||
EXPECT_EQ(1, rm2->refCount());
|
||||
|
||||
rss.setRenderState(rm2.p());
|
||||
ASSERT_EQ(1, rss.count());
|
||||
EXPECT_EQ(1, rm1->refCount());
|
||||
EXPECT_EQ(2, rm2->refCount());
|
||||
|
||||
EXPECT_EQ(rm2.p(), rss.renderStateOfType(RenderState::MATERIAL_FF));
|
||||
EXPECT_EQ(rm2.p(), rss.renderState(0));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateSetTest, AccessEmptyStateSet)
|
||||
{
|
||||
RenderStateSet rss;
|
||||
ASSERT_EQ(0, rss.count());
|
||||
|
||||
EXPECT_EQ(NULL, rss.renderStateOfType(RenderState::DEPTH));
|
||||
EXPECT_EQ(NULL, rss.renderStateOfType(RenderState::MATERIAL_FF));
|
||||
|
||||
EXPECT_EQ(NULL, rss.renderStateOfType(RenderState::COUNT));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#ifdef _DEBUG
|
||||
TEST(RenderStateSetDeathTest, AccessEmptyStateSet)
|
||||
{
|
||||
RenderStateSet rss;
|
||||
ASSERT_EQ(0, rss.count());
|
||||
|
||||
EXPECT_DEATH(rss.renderState(0), "Assertion");
|
||||
EXPECT_DEATH(rss.renderState(1), "Assertion");
|
||||
|
||||
rss.setRenderState(new RenderStateMaterial_FF);
|
||||
EXPECT_DEATH(rss.renderState(1), "Assertion");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateSetTest, AddAllStateTypes)
|
||||
{
|
||||
RenderStateSet rss;
|
||||
ASSERT_EQ(0, rss.count());
|
||||
|
||||
RenderStateBlending* pBlending = new RenderStateBlending;
|
||||
RenderStateColorMask* pColorMask = new RenderStateColorMask;
|
||||
RenderStateCullFace* pCullFace = new RenderStateCullFace;
|
||||
RenderStateDepth* pDepth = new RenderStateDepth;
|
||||
RenderStateFrontFace* pFrontFace = new RenderStateFrontFace;
|
||||
RenderStateLine* pLine = new RenderStateLine;
|
||||
RenderStatePoint* pPoint = new RenderStatePoint;
|
||||
RenderStatePolygonMode* pPolyMode = new RenderStatePolygonMode;
|
||||
RenderStatePolygonOffset* pPolyOffset = new RenderStatePolygonOffset;
|
||||
RenderStateStencil* pStencil = new RenderStateStencil;
|
||||
RenderStateTextureBindings* pTextureBindings = new RenderStateTextureBindings(new Texture(Texture::TEXTURE_2D, Texture::RGBA), new Sampler, "mySampler");
|
||||
|
||||
RenderStateLighting_FF* pLighting = new RenderStateLighting_FF;
|
||||
RenderStateMaterial_FF* pMaterial = new RenderStateMaterial_FF;
|
||||
RenderStateNormalize_FF* pNormalize = new RenderStateNormalize_FF;
|
||||
RenderStateTextureMapping_FF* pTextureMapping = new RenderStateTextureMapping_FF();
|
||||
RenderStateClipPlanes_FF* pClipPlanes = new RenderStateClipPlanes_FF();
|
||||
|
||||
rss.setRenderState(pBlending);
|
||||
rss.setRenderState(pColorMask);
|
||||
rss.setRenderState(pCullFace);
|
||||
rss.setRenderState(pDepth);
|
||||
rss.setRenderState(pFrontFace);
|
||||
rss.setRenderState(pLine);
|
||||
rss.setRenderState(pPoint);
|
||||
rss.setRenderState(pPolyMode);
|
||||
rss.setRenderState(pPolyOffset);
|
||||
rss.setRenderState(pStencil);
|
||||
rss.setRenderState(pTextureBindings);
|
||||
rss.setRenderState(pLighting);
|
||||
rss.setRenderState(pMaterial);
|
||||
rss.setRenderState(pNormalize);
|
||||
rss.setRenderState(pTextureMapping);
|
||||
rss.setRenderState(pClipPlanes);
|
||||
|
||||
EXPECT_EQ(RenderState::COUNT, rss.count());
|
||||
|
||||
EXPECT_EQ(pBlending, rss.renderState(0));
|
||||
EXPECT_EQ(pColorMask, rss.renderState(1));
|
||||
EXPECT_EQ(pCullFace, rss.renderState(2));
|
||||
EXPECT_EQ(pDepth, rss.renderState(3));
|
||||
EXPECT_EQ(pFrontFace, rss.renderState(4));
|
||||
EXPECT_EQ(pLine, rss.renderState(5));
|
||||
EXPECT_EQ(pPoint, rss.renderState(6));
|
||||
EXPECT_EQ(pPolyMode, rss.renderState(7));
|
||||
EXPECT_EQ(pPolyOffset, rss.renderState(8));
|
||||
EXPECT_EQ(pStencil, rss.renderState(9));
|
||||
EXPECT_EQ(pTextureBindings, rss.renderState(10));
|
||||
EXPECT_EQ(pLighting, rss.renderState(11));
|
||||
EXPECT_EQ(pMaterial, rss.renderState(12));
|
||||
EXPECT_EQ(pNormalize, rss.renderState(13));
|
||||
EXPECT_EQ(pTextureMapping, rss.renderState(14));
|
||||
|
||||
EXPECT_EQ(pBlending, rss.renderStateOfType(RenderState::BLENDING));
|
||||
EXPECT_EQ(pColorMask, rss.renderStateOfType(RenderState::COLOR_MASK));
|
||||
EXPECT_EQ(pCullFace, rss.renderStateOfType(RenderState::CULL_FACE));
|
||||
EXPECT_EQ(pDepth, rss.renderStateOfType(RenderState::DEPTH));
|
||||
EXPECT_EQ(pLine, rss.renderStateOfType(RenderState::LINE));
|
||||
EXPECT_EQ(pPoint, rss.renderStateOfType(RenderState::POINT));
|
||||
EXPECT_EQ(pPolyMode, rss.renderStateOfType(RenderState::POLYGON_MODE));
|
||||
EXPECT_EQ(pPolyOffset, rss.renderStateOfType(RenderState::POLYGON_OFFSET));
|
||||
EXPECT_EQ(pStencil, rss.renderStateOfType(RenderState::STENCIL));
|
||||
EXPECT_EQ(pTextureBindings, rss.renderStateOfType(RenderState::TEXTURE_BINDINGS));
|
||||
EXPECT_EQ(pLighting, rss.renderStateOfType(RenderState::LIGHTING_FF));
|
||||
EXPECT_EQ(pMaterial, rss.renderStateOfType(RenderState::MATERIAL_FF));
|
||||
EXPECT_EQ(pNormalize, rss.renderStateOfType(RenderState::NORMALIZE_FF));
|
||||
EXPECT_EQ(pTextureMapping, rss.renderStateOfType(RenderState::TEXTURE_MAPPING_FF));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateSetTest, AddRemoveRenderState)
|
||||
{
|
||||
RenderStateSet rss;
|
||||
|
||||
ref<RenderStateMaterial_FF> material1 = new RenderStateMaterial_FF;
|
||||
ref<RenderStateMaterial_FF> material2 = new RenderStateMaterial_FF;
|
||||
ref<RenderStatePolygonMode> polyMode = new RenderStatePolygonMode;
|
||||
ref<RenderStatePolygonOffset> polyOffset = new RenderStatePolygonOffset;
|
||||
|
||||
rss.setRenderState(material1.p());
|
||||
rss.setRenderState(polyMode.p());
|
||||
rss.setRenderState(polyOffset.p());
|
||||
EXPECT_EQ(3, rss.count());
|
||||
EXPECT_EQ(2, material1->refCount());
|
||||
EXPECT_EQ(1, material2->refCount());
|
||||
EXPECT_EQ(2, polyMode->refCount());
|
||||
EXPECT_EQ(2, polyOffset->refCount());
|
||||
|
||||
rss.setRenderState(material2.p());
|
||||
EXPECT_EQ(3, rss.count());
|
||||
EXPECT_EQ(1, material1->refCount());
|
||||
EXPECT_EQ(2, material2->refCount());
|
||||
|
||||
rss.removeRenderState(polyMode.p());
|
||||
EXPECT_EQ(2, rss.count());
|
||||
EXPECT_EQ(1, polyMode->refCount());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, ColorMaskDefaults)
|
||||
{
|
||||
RenderStateColorMask c;
|
||||
EXPECT_EQ(RenderState::COLOR_MASK, c.type());
|
||||
|
||||
EXPECT_TRUE(c.isRedEnabled());
|
||||
EXPECT_TRUE(c.isGreenEnabled());
|
||||
EXPECT_TRUE(c.isBlueEnabled());
|
||||
EXPECT_TRUE(c.isAlphaEnabled());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, ColorMaskConstructor)
|
||||
{
|
||||
{
|
||||
RenderStateColorMask c(false);
|
||||
|
||||
EXPECT_FALSE(c.isRedEnabled());
|
||||
EXPECT_FALSE(c.isGreenEnabled());
|
||||
EXPECT_FALSE(c.isBlueEnabled());
|
||||
EXPECT_FALSE(c.isAlphaEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, ColorMaskSetGet)
|
||||
{
|
||||
RenderStateColorMask c;
|
||||
|
||||
c.enableWriteAllComponents(false);
|
||||
EXPECT_FALSE(c.isRedEnabled());
|
||||
EXPECT_FALSE(c.isGreenEnabled());
|
||||
EXPECT_FALSE(c.isBlueEnabled());
|
||||
EXPECT_FALSE(c.isAlphaEnabled());
|
||||
|
||||
c.enable(true, false, true, false);
|
||||
EXPECT_TRUE( c.isRedEnabled());
|
||||
EXPECT_FALSE(c.isGreenEnabled());
|
||||
EXPECT_TRUE( c.isBlueEnabled());
|
||||
EXPECT_FALSE(c.isAlphaEnabled());
|
||||
|
||||
c.enable(false, true, false, true);
|
||||
EXPECT_FALSE(c.isRedEnabled());
|
||||
EXPECT_TRUE( c.isGreenEnabled());
|
||||
EXPECT_FALSE(c.isBlueEnabled());
|
||||
EXPECT_TRUE( c.isAlphaEnabled());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, CullFaceDefaults)
|
||||
{
|
||||
RenderStateCullFace c;
|
||||
EXPECT_EQ(RenderState::CULL_FACE, c.type());
|
||||
|
||||
EXPECT_EQ(RenderStateCullFace::BACK, c.mode());
|
||||
EXPECT_TRUE(c.isEnabled());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, CullFaceSetGet)
|
||||
{
|
||||
RenderStateCullFace c;
|
||||
|
||||
c.setMode(RenderStateCullFace::FRONT);
|
||||
c.enable(false);
|
||||
EXPECT_EQ(RenderStateCullFace::FRONT, c.mode());
|
||||
EXPECT_FALSE(c.isEnabled());
|
||||
|
||||
c.setMode(RenderStateCullFace::FRONT_AND_BACK);
|
||||
c.enable(true);
|
||||
EXPECT_EQ(RenderStateCullFace::FRONT_AND_BACK, c.mode());
|
||||
EXPECT_TRUE(c.isEnabled());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, FrontFaceDefaults)
|
||||
{
|
||||
RenderStateFrontFace c;
|
||||
EXPECT_EQ(RenderState::FRONT_FACE, c.type());
|
||||
|
||||
EXPECT_EQ(RenderStateFrontFace::CCW, c.mode());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, FrontFaceSetGet)
|
||||
{
|
||||
RenderStateFrontFace c;
|
||||
|
||||
c.setMode(RenderStateFrontFace::CW);
|
||||
EXPECT_EQ(RenderStateFrontFace::CW, c.mode());
|
||||
|
||||
c.setMode(RenderStateFrontFace::CCW);
|
||||
EXPECT_EQ(RenderStateFrontFace::CCW, c.mode());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, DepthDefaults)
|
||||
{
|
||||
RenderStateDepth d;
|
||||
EXPECT_EQ(RenderState::DEPTH, d.type());
|
||||
|
||||
EXPECT_EQ(RenderStateDepth::LESS, d.function());
|
||||
EXPECT_TRUE(d.isDepthTestEnabled());
|
||||
EXPECT_TRUE(d.isDepthWriteEnabled());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, DepthSetGet)
|
||||
{
|
||||
RenderStateDepth d;
|
||||
d.setFunction(RenderStateDepth::LEQUAL);
|
||||
d.enableDepthTest(false);
|
||||
d.enableDepthWrite(false);
|
||||
EXPECT_EQ(RenderStateDepth::LEQUAL, d.function());
|
||||
EXPECT_FALSE(d.isDepthTestEnabled());
|
||||
EXPECT_FALSE(d.isDepthWriteEnabled());
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, LightingDefaults)
|
||||
{
|
||||
RenderStateLighting_FF l;
|
||||
EXPECT_EQ(RenderState::LIGHTING_FF, l.type());
|
||||
|
||||
const Color3f expectedAmbient(0.2f, 0.2f, 0.2f);
|
||||
|
||||
EXPECT_TRUE(l.isEnabled());
|
||||
EXPECT_FALSE(l.isTwoSidedEnabled());
|
||||
EXPECT_FALSE(l.isLocalViewerEnabled());
|
||||
EXPECT_TRUE(l.ambientIntensity() == expectedAmbient);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, LightingSetGet)
|
||||
{
|
||||
RenderStateLighting_FF l;
|
||||
|
||||
l.enable(false);
|
||||
EXPECT_FALSE(l.isEnabled());
|
||||
|
||||
l.enableTwoSided(true);
|
||||
l.enableLocalViewer(false);
|
||||
EXPECT_TRUE(l.isTwoSidedEnabled());
|
||||
EXPECT_FALSE(l.isLocalViewerEnabled());
|
||||
|
||||
l.enableLocalViewer(true);
|
||||
l.enableTwoSided(false);
|
||||
EXPECT_TRUE(l.isLocalViewerEnabled());
|
||||
EXPECT_FALSE(l.isTwoSidedEnabled());
|
||||
|
||||
|
||||
const Color3f expectedAmbient(0.5f, 0.6f, 0.7f);
|
||||
l.setAmbientIntensity(expectedAmbient);
|
||||
EXPECT_TRUE(l.ambientIntensity() == expectedAmbient);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, MaterialDefaults)
|
||||
{
|
||||
RenderStateMaterial_FF m;
|
||||
EXPECT_EQ(RenderState::MATERIAL_FF, m.type());
|
||||
|
||||
// OpenGL defaults
|
||||
const Color3f defaultAmbient (0.2f, 0.2f, 0.2f);
|
||||
const Color3f defaultDiffuse (0.8f, 0.8f, 0.8f);
|
||||
const Color3f defaultSpecular(0.0f, 0.0f, 0.0f);
|
||||
const Color3f defaultEmission(0.0f, 0.0f, 0.0f);
|
||||
const float defaultShininess = 0;
|
||||
const float defaultAlpha = 1.0f;
|
||||
|
||||
EXPECT_TRUE(defaultAmbient == m.frontAmbient());
|
||||
EXPECT_TRUE(defaultDiffuse == m.frontDiffuse());
|
||||
EXPECT_TRUE(defaultSpecular == m.frontSpecular());
|
||||
EXPECT_TRUE(defaultEmission == m.frontEmission());
|
||||
EXPECT_FLOAT_EQ(defaultShininess, m.frontShininess());
|
||||
EXPECT_FLOAT_EQ(defaultAlpha, m.frontAlpha());
|
||||
EXPECT_FALSE(m.isColorMaterialEnabled());
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, MaterialSetGet)
|
||||
{
|
||||
RenderStateMaterial_FF m;
|
||||
m.setAmbientAndDiffuse(Color3f(0.1f, 0.2f, 0.3f));
|
||||
m.setSpecular(Color3f(0.5f, 0.5f, 0.5f));
|
||||
m.setAlpha(0.6f);
|
||||
m.enableColorMaterial(true);
|
||||
|
||||
const Color3f expectAmbient (0.1f, 0.2f, 0.3f);
|
||||
const Color3f expectDiffuse (0.1f, 0.2f, 0.3f);
|
||||
const Color3f expectSpecular(0.5f, 0.5f, 0.5f);
|
||||
const Color3f expectEmission(0.0f, 0.0f, 0.0f);
|
||||
const float expectShininess = 0;
|
||||
const float expectAlpha = 0.6f;
|
||||
|
||||
EXPECT_TRUE( expectAmbient == m.frontAmbient());
|
||||
EXPECT_TRUE( expectDiffuse == m.frontDiffuse());
|
||||
EXPECT_TRUE( expectSpecular == m.frontSpecular());
|
||||
EXPECT_TRUE( expectEmission == m.frontEmission());
|
||||
EXPECT_FLOAT_EQ(expectShininess, m.frontShininess());
|
||||
EXPECT_FLOAT_EQ(expectAlpha, m.frontAlpha());
|
||||
EXPECT_TRUE(m.isColorMaterialEnabled());
|
||||
|
||||
m.setDiffuse(Color3f(0.4f, 0.5f, 0.6f));
|
||||
|
||||
const Color3f expectDiffuse2(0.4f, 0.5f, 0.6f);
|
||||
|
||||
EXPECT_TRUE( expectAmbient == m.frontAmbient());
|
||||
EXPECT_TRUE( Color3f(0.4f, 0.5f, 0.6f) == m.frontDiffuse());
|
||||
EXPECT_TRUE( expectSpecular == m.frontSpecular());
|
||||
EXPECT_TRUE( expectEmission == m.frontEmission());
|
||||
EXPECT_FLOAT_EQ(expectShininess, m.frontShininess());
|
||||
EXPECT_FLOAT_EQ(expectAlpha, m.frontAlpha());
|
||||
EXPECT_TRUE(m.isColorMaterialEnabled());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, AmbienDiffuseConstructor)
|
||||
{
|
||||
RenderStateMaterial_FF m(Color3f(0.1f, 0.2f, 0.3f));
|
||||
|
||||
const Color3f expectAmbient(0.1f, 0.2f, 0.3f);
|
||||
const Color3f expectDiffuse(0.1f, 0.2f, 0.3f);
|
||||
const Color3f defaultSpecular(0.0f, 0.0f, 0.0f);
|
||||
const Color3f defaultEmission(0.0f, 0.0f, 0.0f);
|
||||
const float defaultShininess = 0;
|
||||
const float defaultAlpha = 1.0f;
|
||||
|
||||
EXPECT_TRUE(expectAmbient == m.frontAmbient());
|
||||
EXPECT_TRUE(expectDiffuse == m.frontDiffuse());
|
||||
EXPECT_TRUE(defaultSpecular == m.frontSpecular());
|
||||
EXPECT_TRUE(defaultEmission == m.frontEmission());
|
||||
EXPECT_FLOAT_EQ(defaultShininess, m.frontShininess());
|
||||
EXPECT_FLOAT_EQ(defaultAlpha, m.frontAlpha());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, ColorIdentConstructor)
|
||||
{
|
||||
{
|
||||
RenderStateMaterial_FF m(RenderStateMaterial_FF::PURE_WHITE);
|
||||
|
||||
const Color3f expectAmbient (1.0f, 1.0f, 1.0f);
|
||||
const Color3f expectDiffuse (1.0f, 1.0f, 1.0f);
|
||||
const Color3f expectSpecular(0.0f, 0.0f, 0.0f);
|
||||
const Color3f expectEmission(0.0f, 0.0f, 0.0f);
|
||||
const float expectShininess = 0;
|
||||
const float expectAlpha = 1.0f;
|
||||
|
||||
EXPECT_TRUE( expectAmbient == m.frontAmbient());
|
||||
EXPECT_TRUE( expectDiffuse == m.frontDiffuse());
|
||||
EXPECT_TRUE( expectSpecular == m.frontSpecular());
|
||||
EXPECT_TRUE( expectEmission == m.frontEmission());
|
||||
EXPECT_FLOAT_EQ(expectShininess, m.frontShininess());
|
||||
EXPECT_FLOAT_EQ(expectAlpha, m.frontAlpha());
|
||||
}
|
||||
|
||||
{
|
||||
RenderStateMaterial_FF m(RenderStateMaterial_FF::BRASS);
|
||||
|
||||
const Color3f expectAmbient (0.329412f, 0.223529f, 0.027451f);
|
||||
const Color3f expectDiffuse (0.780392f, 0.568627f, 0.113725f);
|
||||
const Color3f expectSpecular(0.992157f, 0.941176f, 0.807843f);
|
||||
const Color3f expectEmission(0.0f, 0.0f, 0.0f);
|
||||
const float expectShininess = 27.8974f;
|
||||
const float expectAlpha = 1.0f;
|
||||
|
||||
EXPECT_FLOAT_EQ(expectAmbient.r(), m.frontAmbient().r());
|
||||
EXPECT_FLOAT_EQ(expectAmbient.g(), m.frontAmbient().g());
|
||||
EXPECT_FLOAT_EQ(expectAmbient.b(), m.frontAmbient().b());
|
||||
|
||||
EXPECT_FLOAT_EQ(expectDiffuse.r(), m.frontDiffuse().r());
|
||||
EXPECT_FLOAT_EQ(expectDiffuse.g(), m.frontDiffuse().g());
|
||||
EXPECT_FLOAT_EQ(expectDiffuse.b(), m.frontDiffuse().b());
|
||||
|
||||
EXPECT_FLOAT_EQ(expectSpecular.r(), m.frontSpecular().r());
|
||||
EXPECT_FLOAT_EQ(expectSpecular.g(), m.frontSpecular().g());
|
||||
EXPECT_FLOAT_EQ(expectSpecular.b(), m.frontSpecular().b());
|
||||
|
||||
EXPECT_FLOAT_EQ(expectEmission.r(), m.frontEmission().r());
|
||||
EXPECT_FLOAT_EQ(expectEmission.g(), m.frontEmission().g());
|
||||
EXPECT_FLOAT_EQ(expectEmission.b(), m.frontEmission().b());
|
||||
|
||||
EXPECT_FLOAT_EQ(expectShininess, m.frontShininess());
|
||||
EXPECT_FLOAT_EQ(expectAlpha, m.frontAlpha());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, PolygonModeDefaults)
|
||||
{
|
||||
RenderStatePolygonMode p;
|
||||
EXPECT_EQ(RenderState::POLYGON_MODE, p.type());
|
||||
|
||||
EXPECT_EQ(RenderStatePolygonMode::FILL, p.frontFace());
|
||||
EXPECT_EQ(RenderStatePolygonMode::FILL, p.backFace());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, PolygonModeSetGet)
|
||||
{
|
||||
RenderStatePolygonMode p(RenderStatePolygonMode::POINT);
|
||||
EXPECT_EQ(RenderStatePolygonMode::POINT, p.frontFace());
|
||||
EXPECT_EQ(RenderStatePolygonMode::POINT, p.backFace());
|
||||
|
||||
p.set(RenderStatePolygonMode::FILL);
|
||||
EXPECT_EQ(RenderStatePolygonMode::FILL, p.frontFace());
|
||||
EXPECT_EQ(RenderStatePolygonMode::FILL, p.backFace());
|
||||
|
||||
p.setFrontFace(RenderStatePolygonMode::LINE);
|
||||
p.setBackFace(RenderStatePolygonMode::POINT);
|
||||
EXPECT_EQ(RenderStatePolygonMode::LINE, p.frontFace());
|
||||
EXPECT_EQ(RenderStatePolygonMode::POINT, p.backFace());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, PolygonOffsetDefaults)
|
||||
{
|
||||
RenderStatePolygonOffset p;
|
||||
EXPECT_FALSE(p.isFillModeEnabled());
|
||||
EXPECT_FALSE(p.isLineModeEnabled());
|
||||
EXPECT_FALSE(p.isPointModeEnabled());
|
||||
|
||||
EXPECT_FLOAT_EQ(0.0f, p.factor());
|
||||
EXPECT_FLOAT_EQ(0.0f, p.units());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, PolygonOffsetSetGet)
|
||||
{
|
||||
RenderStatePolygonOffset p;
|
||||
|
||||
p.enableFillMode(true);
|
||||
EXPECT_TRUE(p.isFillModeEnabled());
|
||||
EXPECT_FALSE(p.isLineModeEnabled());
|
||||
EXPECT_FALSE(p.isPointModeEnabled());
|
||||
|
||||
p.enableLineMode(true);
|
||||
EXPECT_TRUE(p.isFillModeEnabled());
|
||||
EXPECT_TRUE(p.isLineModeEnabled());
|
||||
EXPECT_FALSE(p.isPointModeEnabled());
|
||||
|
||||
p.enablePointMode(true);
|
||||
EXPECT_TRUE(p.isFillModeEnabled());
|
||||
EXPECT_TRUE(p.isLineModeEnabled());
|
||||
EXPECT_TRUE(p.isPointModeEnabled());
|
||||
|
||||
p.setFactor(0.2f);
|
||||
p.setUnits(0.3f);
|
||||
EXPECT_FLOAT_EQ(0.2f, p.factor());
|
||||
EXPECT_FLOAT_EQ(0.3f, p.units());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, PolygonOffsetConfigure)
|
||||
{
|
||||
{
|
||||
RenderStatePolygonOffset p;
|
||||
p.configurePolygonPositiveOffset();
|
||||
|
||||
EXPECT_TRUE(p.isFillModeEnabled());
|
||||
EXPECT_FALSE(p.isLineModeEnabled());
|
||||
EXPECT_FALSE(p.isPointModeEnabled());
|
||||
EXPECT_FLOAT_EQ(1.0f, p.factor());
|
||||
EXPECT_FLOAT_EQ(1.0f, p.units());
|
||||
}
|
||||
|
||||
{
|
||||
RenderStatePolygonOffset p;
|
||||
p.configureLineNegativeOffset();
|
||||
|
||||
EXPECT_FALSE(p.isFillModeEnabled());
|
||||
EXPECT_TRUE(p.isLineModeEnabled());
|
||||
EXPECT_FALSE(p.isPointModeEnabled());
|
||||
EXPECT_FLOAT_EQ(-1.0f, p.factor());
|
||||
EXPECT_FLOAT_EQ(-1.0f, p.units());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, TextureBindingsDefaults)
|
||||
{
|
||||
RenderStateTextureBindings b;
|
||||
|
||||
EXPECT_EQ(0, b.bindingCount());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, TextureBindingsSingle)
|
||||
{
|
||||
ref<TextureImage> img = new TextureImage;
|
||||
ref<Texture> t = new Texture(img.p());
|
||||
ref<Sampler> s = new Sampler;
|
||||
RenderStateTextureBindings b(t.p(), s.p(), "mySampler");
|
||||
|
||||
EXPECT_EQ(1, b.bindingCount());
|
||||
EXPECT_EQ(t.p(), b.texture(0));
|
||||
EXPECT_EQ(s.p(), b.sampler(0));
|
||||
EXPECT_STREQ("mySampler", b.samplerUniformName(0).toAscii().ptr());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RenderStateTest, TextureBindingsMultiple)
|
||||
{
|
||||
ref<TextureImage> img = new TextureImage;
|
||||
ref<Texture> t = new Texture(img.p());
|
||||
ref<Sampler> s = new Sampler;
|
||||
RenderStateTextureBindings b(t.p(), s.p(), "mySampler");
|
||||
|
||||
{
|
||||
ref<TextureImage> img = new TextureImage;
|
||||
ref<Texture> t = new Texture(img.p());
|
||||
ref<Sampler> s = new Sampler;
|
||||
b.addBinding(t.p(), s.p(), "mySampler1");
|
||||
}
|
||||
|
||||
ref<TextureImage> img1 = new TextureImage;
|
||||
ref<Texture> t1 = new Texture(img1.p());
|
||||
ref<Sampler> s1 = new Sampler;
|
||||
b.addBinding(t1.p(), s1.p(), "mySampler2");
|
||||
|
||||
EXPECT_EQ(3, b.bindingCount());
|
||||
EXPECT_EQ(t.p(), b.texture(0));
|
||||
EXPECT_EQ(s.p(), b.sampler(0));
|
||||
EXPECT_EQ(t1.p(), b.texture(2));
|
||||
EXPECT_EQ(s1.p(), b.sampler(2));
|
||||
EXPECT_STREQ("mySampler", b.samplerUniformName(0).toAscii().ptr());
|
||||
EXPECT_STREQ("mySampler1", b.samplerUniformName(1).toAscii().ptr());
|
||||
EXPECT_STREQ("mySampler2", b.samplerUniformName(2).toAscii().ptr());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#ifdef _DEBUG
|
||||
TEST(RenderStateSetDeathTest, TextureBindingsIllegalAccess)
|
||||
{
|
||||
RenderStateTextureBindings bEmpty;
|
||||
|
||||
ASSERT_EQ(0, bEmpty.bindingCount());
|
||||
|
||||
EXPECT_DEATH(bEmpty.texture(0), "Assertion");
|
||||
EXPECT_DEATH(bEmpty.sampler(0), "Assertion");
|
||||
EXPECT_DEATH(bEmpty.samplerUniformName(0), "Assertion");
|
||||
|
||||
|
||||
ref<TextureImage> img = new TextureImage;
|
||||
ref<Texture> t = new Texture(img.p());
|
||||
ref<Sampler> s = new Sampler;
|
||||
RenderStateTextureBindings b(t.p(), s.p(), "mySampler");
|
||||
|
||||
ASSERT_EQ(1, b.bindingCount());
|
||||
|
||||
EXPECT_DEATH(b.texture(1), "Assertion");
|
||||
EXPECT_DEATH(b.sampler(1), "Assertion");
|
||||
EXPECT_DEATH(b.samplerUniformName(1), "Assertion");
|
||||
|
||||
EXPECT_DEATH(b.texture(-1), "Assertion");
|
||||
EXPECT_DEATH(b.sampler(-1), "Assertion");
|
||||
EXPECT_DEATH(b.samplerUniformName(-1), "Assertion");
|
||||
}
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user