Created first unittest for OpenMesh.
git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@405 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
@@ -41,6 +41,7 @@ endif()
|
|||||||
add_subdirectory (src/OpenMesh/Core)
|
add_subdirectory (src/OpenMesh/Core)
|
||||||
add_subdirectory (src/OpenMesh/Tools)
|
add_subdirectory (src/OpenMesh/Tools)
|
||||||
add_subdirectory (src/OpenMesh/Apps)
|
add_subdirectory (src/OpenMesh/Apps)
|
||||||
|
add_subdirectory (src/Unittests)
|
||||||
add_subdirectory (Doc)
|
add_subdirectory (Doc)
|
||||||
|
|
||||||
# ========================================================================
|
# ========================================================================
|
||||||
|
|||||||
72
cmake/FindGoogleTest.cmake
Normal file
72
cmake/FindGoogleTest.cmake
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
# Locate and configure the Google Test libraries.
|
||||||
|
#
|
||||||
|
# Defines the following variable:
|
||||||
|
#
|
||||||
|
# GTEST_FOUND - Found the Google Test libraries
|
||||||
|
# GTEST_INCLUDE_DIRS - The directories needed on the include paths
|
||||||
|
# GTEST_LIBRARIES - The libraries to link to test executables
|
||||||
|
# GTEST_MAIN_LIBRARIES - The libraries to link for automatic main() provision
|
||||||
|
#
|
||||||
|
# Copyright 2008 Chandler Carruth
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
# use this file except in compliance with the License. You may obtain a copy
|
||||||
|
# of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
if(GTEST_INCLUDE_DIRS AND GTEST_LIBRARIES AND GTEST_MAIN_LIBRARIES)
|
||||||
|
set(GTEST_FOUND true)
|
||||||
|
else(GTEST_INCLUDE_DIRS AND GTEST_LIBRARIES AND GTEST_MAIN_LIBRARIES)
|
||||||
|
set(GTEST_PREFIX "" CACHE PATH "Installation prefix for Google Test")
|
||||||
|
if(GTEST_PREFIX)
|
||||||
|
find_path(_GTEST_INCLUDE_DIR "gtest/gtest.h"
|
||||||
|
PATHS "${GTEST_PREFIX}/include"
|
||||||
|
NO_DEFAULT_PATH)
|
||||||
|
find_library(_GTEST_LIBRARY gtest
|
||||||
|
PATHS "${GTEST_PREFIX}/lib"
|
||||||
|
NO_DEFAULT_PATH)
|
||||||
|
find_library(_GTEST_MAIN_LIBRARY gtest_main
|
||||||
|
PATHS "${GTEST_PREFIX}/lib"
|
||||||
|
NO_DEFAULT_PATH)
|
||||||
|
else(GTEST_PREFIX)
|
||||||
|
find_path(_GTEST_INCLUDE_DIR "gtest/gtest.h"
|
||||||
|
PATHS
|
||||||
|
~/sw/gtest/include
|
||||||
|
/opt/local/include
|
||||||
|
/usr/local/include)
|
||||||
|
find_library(_GTEST_LIBRARY gtest
|
||||||
|
PATHS
|
||||||
|
~/sw/gtest/lib
|
||||||
|
/opt/local/lib
|
||||||
|
/usr/local/lib)
|
||||||
|
find_library(_GTEST_MAIN_LIBRARY gtest_main
|
||||||
|
PATHS
|
||||||
|
~/sw/gtest/lib
|
||||||
|
/opt/local/lib
|
||||||
|
/usr/local/lib)
|
||||||
|
endif(GTEST_PREFIX)
|
||||||
|
if(_GTEST_INCLUDE_DIR AND _GTEST_LIBRARY AND _GTEST_MAIN_LIBRARY)
|
||||||
|
set(GTEST_FOUND true)
|
||||||
|
set(GTEST_INCLUDE_DIRS ${_GTEST_INCLUDE_DIR} CACHE PATH
|
||||||
|
"Include directories for Google Test framework")
|
||||||
|
set(GTEST_LIBRARIES ${_GTEST_LIBRARY} CACHE FILEPATH
|
||||||
|
"Libraries to link for Google Test framework")
|
||||||
|
set(GTEST_MAIN_LIBRARIES ${_GTEST_MAIN_LIBRARY} CACHE FILEPATH
|
||||||
|
"Libraries to link for Google Test automatic main() definition")
|
||||||
|
mark_as_advanced(GTEST_INCLUDE_DIRS GTEST_LIBRARIES GTEST_MAIN_LIBRARIES)
|
||||||
|
if(NOT GoogleTest_FIND_QUIETLY)
|
||||||
|
message(STATUS "Found Google Test: ${GTEST_LIBRARIES}")
|
||||||
|
endif(NOT GoogleTest_FIND_QUIETLY)
|
||||||
|
else(_GTEST_INCLUDE_DIR AND _GTEST_LIBRARY AND _GTEST_MAIN_LIBRARY)
|
||||||
|
if(GoogleTest_FIND_REQUIRED)
|
||||||
|
message(FATAL_ERROR "Could not find the Google Test framework")
|
||||||
|
endif(GoogleTest_FIND_REQUIRED)
|
||||||
|
endif(_GTEST_INCLUDE_DIR AND _GTEST_LIBRARY AND _GTEST_MAIN_LIBRARY)
|
||||||
|
endif(GTEST_INCLUDE_DIRS AND GTEST_LIBRARIES AND GTEST_MAIN_LIBRARIES)
|
||||||
27
src/Unittests/CMakeLists.txt
Normal file
27
src/Unittests/CMakeLists.txt
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
include (ACGCommon)
|
||||||
|
|
||||||
|
include_directories (
|
||||||
|
..
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Search for gtest headers and libraries
|
||||||
|
find_package(GoogleTest)
|
||||||
|
|
||||||
|
if(GTEST_FOUND)
|
||||||
|
|
||||||
|
# Set correct include paths so that the compiler can find the headers
|
||||||
|
include_directories(${GTEST_INCLUDE_DIRS})
|
||||||
|
# Create new target named unittests_hexmeshing
|
||||||
|
add_executable(unittests EXCLUDE_FROM_ALL unittests.cc)
|
||||||
|
# Link against all necessary libraries
|
||||||
|
target_link_libraries(unittests OpenMeshCore OpenMeshTools gtest gtest_main pthread)
|
||||||
|
# Set output directory to ${BINARY_DIR}/Unittests
|
||||||
|
set_target_properties(unittests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Unittests)
|
||||||
|
# Set compiler flags
|
||||||
|
set_target_properties(unittests PROPERTIES COMPILE_FLAGS "-g -pedantic -ansi -Wno-long-long")
|
||||||
|
acg_copy_after_build(unittests ${CMAKE_CURRENT_SOURCE_DIR}/TestFiles ${CMAKE_BINARY_DIR}/Unittests/)
|
||||||
|
|
||||||
|
else(GTEST_FOUND)
|
||||||
|
message("Google testing framework was not found!")
|
||||||
|
endif(GTEST_FOUND)
|
||||||
22576
src/Unittests/TestFiles/cube1.off
Normal file
22576
src/Unittests/TestFiles/cube1.off
Normal file
File diff suppressed because it is too large
Load Diff
9
src/Unittests/unittests.cc
Normal file
9
src/Unittests/unittests.cc
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "unittests_loading.hh"
|
||||||
|
|
||||||
|
int main(int _argc, char** _argv) {
|
||||||
|
|
||||||
|
testing::InitGoogleTest(&_argc, _argv);
|
||||||
|
return RUN_ALL_TESTS();
|
||||||
|
}
|
||||||
59
src/Unittests/unittests_loading.hh
Normal file
59
src/Unittests/unittests_loading.hh
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
#ifndef INCLUDE_UNITTESTS_LOADING_CC
|
||||||
|
#define INCLUDE_UNITTESTS_LOADING_CC
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <OpenMesh/Core/IO/MeshIO.hh>
|
||||||
|
|
||||||
|
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
|
||||||
|
|
||||||
|
struct CustomTraits : public OpenMesh::DefaultTraits {
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef OpenMesh::TriMesh_ArrayKernelT<CustomTraits> Mesh;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Simple test setting.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class OpenMeshLoader : public testing::Test {
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// This function is called before each test is run
|
||||||
|
virtual void SetUp() {
|
||||||
|
|
||||||
|
// Do some initial stuff with the member data here...
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function is called after all tests are through
|
||||||
|
virtual void TearDown() {
|
||||||
|
|
||||||
|
// Do some final stuff with the member data here...
|
||||||
|
}
|
||||||
|
|
||||||
|
// This member will be accessible in all tests
|
||||||
|
Mesh mesh_;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ====================================================================
|
||||||
|
* Define tests below
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Just load a simple mesh file in obj format and count whether
|
||||||
|
* the right number of entities has been loaded.
|
||||||
|
*/
|
||||||
|
TEST_F(OpenMeshLoader, LoadSimpleOFFFile) {
|
||||||
|
|
||||||
|
bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1.off");
|
||||||
|
|
||||||
|
EXPECT_TRUE(ok);
|
||||||
|
|
||||||
|
EXPECT_EQ(7526, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
|
||||||
|
EXPECT_EQ(22572, mesh_.n_edges()) << "The number of loaded edges is not correct!";
|
||||||
|
EXPECT_EQ(15048, mesh_.n_faces()) << "The number of loaded faces is not correct!";
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // INCLUDE GUARD
|
||||||
Reference in New Issue
Block a user