diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..1c28390 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 2.6.4 FATAL_ERROR) + +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 -std=c++11") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -std=c++11") + +add_subdirectory(gtest-1.7.0) +set(GTEST_MAIN_CPP "${CMAKE_SOURCE_DIR}/gtest-1.7.0/src/gtest_main.cc") +set(UNITTEST_DATA_DIR "${CMAKE_SOURCE_DIR}/../data") + +include_directories(SYSTEM + gtest-1.7.0/include +) +include_directories(../include) +add_subdirectory(unit) diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt new file mode 100644 index 0000000..fcdda18 --- /dev/null +++ b/test/unit/CMakeLists.txt @@ -0,0 +1,10 @@ +project(unit CXX) + +add_executable(${PROJECT_NAME} + ${GTEST_MAIN_CPP} + test_conversions.cpp +) + +target_link_libraries(${PROJECT_NAME} + gtest +) diff --git a/test/unit/sample_vectors.hpp b/test/unit/sample_vectors.hpp new file mode 100644 index 0000000..224c842 --- /dev/null +++ b/test/unit/sample_vectors.hpp @@ -0,0 +1,168 @@ +#ifndef id050D92FF58A04FCBB4ACD5FB1C73071F +#define id050D92FF58A04FCBB4ACD5FB1C73071F + +#include "vectorwrapper/vectorwrapper.hpp" +#include +#include + +namespace vwr { + struct SimpleVector2 { + float x; + float y; + }; + struct SimpleVector3 { + float x; + float y; + float z; + }; + + struct IntVector1 { + int64_t x; + }; + struct IntVector2 { + int64_t x; + int64_t y; + }; + struct IntVector3 { + int64_t x; + int64_t y; + int64_t z; + }; + + struct MixedDataVector3 { + float s; + float x; + float x1; + float y; + float y1; + float z; + float z1; + }; + + struct PaddedVector3 { + float a; + float b; + float x; + float y; + float z; + float c; + }; + + template <> + struct VectorWrapperInfo { + enum { dimensions = 1 }; + typedef float vector_type; + typedef float scalar_type; + typedef SimpleVector2 higher_vector_type; + + static scalar_type& get_at (std::size_t, vector_type& parVector) { + return parVector; + } + }; + template <> + struct VectorWrapperInfo { + enum { dimensions = 2 }; + + typedef float scalar_type; + typedef SimpleVector3 higher_vector_type; + typedef float lower_vector_type; + + enum { + offset_x = offsetof(SimpleVector2, x), + offset_y = offsetof(SimpleVector2, y) + }; + }; + template <> + struct VectorWrapperInfo { + enum { dimensions = 3 }; + + typedef float scalar_type; + typedef SimpleVector2 lower_vector_type; + + enum { + offset_x = offsetof(SimpleVector3, x), + offset_y = offsetof(SimpleVector3, y), + offset_z = offsetof(SimpleVector3, z) + }; + }; + + template <> + struct VectorWrapperInfo { + enum { dimensions = 1 }; + typedef decltype(IntVector1::x) scalar_type; + typedef IntVector2 higher_vector_type; + + enum { + offset_x = offsetof(IntVector1, x) + }; + }; + template <> + struct VectorWrapperInfo { + enum { dimensions = 2 }; + typedef VectorWrapperInfo::scalar_type scalar_type; + typedef IntVector1 lower_vector_type; + typedef IntVector3 higher_vector_type; + + enum { + offset_x = offsetof(IntVector2, x), + offset_y = offsetof(IntVector2, y) + }; + }; + template <> + struct VectorWrapperInfo { + enum { dimensions = 3 }; + typedef VectorWrapperInfo::scalar_type scalar_type; + typedef IntVector2 lower_vector_type; + + enum { + offset_x = offsetof(IntVector3, x), + offset_y = offsetof(IntVector3, y), + offset_z = offsetof(IntVector3, z) + }; + }; + + template <> + struct VectorWrapperInfo { + enum { dimensions = 3 }; + typedef float scalar_type; + + enum { + offset_x = offsetof(MixedDataVector3, x), + offset_y = offsetof(MixedDataVector3, y), + offset_z = offsetof(MixedDataVector3, z) + }; + }; + + template <> + struct VectorWrapperInfo { + enum { dimensions = 3 }; + typedef float scalar_type; + + enum { + offset_x = offsetof(PaddedVector3, x), + offset_y = offsetof(PaddedVector3, y), + offset_z = offsetof(PaddedVector3, z) + }; + }; + + typedef Vec svec1; + typedef Vec svec2; + typedef Vec svec3; + typedef Vec ivec1; + typedef Vec ivec2; + typedef Vec ivec3; + typedef Vec mvec3; + typedef Vec pvec3; + + static_assert(not implem::HasOffsetXEnum::value, "Should return false"); + static_assert(sizeof(svec1) == sizeof(float), "Wrong size"); + static_assert(sizeof(svec2) == sizeof(SimpleVector2), "Wrong size"); + static_assert(sizeof(svec3) == sizeof(SimpleVector3), "Wrong size"); + static_assert(sizeof(ivec1) == sizeof(IntVector1), "Wrong size"); + static_assert(sizeof(ivec2) == sizeof(IntVector2), "Wrong size"); + static_assert(sizeof(ivec3) == sizeof(IntVector3), "Wrong size"); + static_assert(sizeof(mvec3) == sizeof(MixedDataVector3), "Wrong size"); + static_assert(sizeof(pvec3) == sizeof(PaddedVector3), "Wrong size"); +} //namespace vwr + +#endif diff --git a/test/unit/test_conversions.cpp b/test/unit/test_conversions.cpp new file mode 100644 index 0000000..9e858d9 --- /dev/null +++ b/test/unit/test_conversions.cpp @@ -0,0 +1,11 @@ +#include "sample_vectors.hpp" +#include + +TEST(vwr, conversion) { + using namespace vwr; + + { + svec1 s(10.0f); + EXPECT_EQ(s.x(), 10.0f); + } +}