Add types & test
This commit is contained in:
parent
a5bdeaf41f
commit
48cf2bf9cb
4
.gitmodules
vendored
4
.gitmodules
vendored
|
@ -1,5 +1,5 @@
|
|||
[submodule "tests/gtest"]
|
||||
path = tests/gtest
|
||||
[submodule "test/gtest"]
|
||||
path = test/gtest
|
||||
url = https://github.com/google/googletest.git
|
||||
[submodule "third_party/glog"]
|
||||
path = third_party/glog
|
||||
|
|
|
@ -71,6 +71,7 @@ set(MYNTEYE_NAME ${PROJECT_NAME})
|
|||
set(MYNTEYE_PUBLIC_H
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/mynteye/global.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/include/mynteye/mynteye.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/mynteye/types.h
|
||||
)
|
||||
|
||||
if(OS_WIN)
|
||||
|
@ -90,6 +91,7 @@ endif()
|
|||
|
||||
set(MYNTEYE_SRCS
|
||||
${UVC_SRC}
|
||||
src/public/types.cc
|
||||
)
|
||||
|
||||
set(MYNTEYE_LINKLIBS
|
||||
|
|
11
Makefile
11
Makefile
|
@ -62,10 +62,13 @@ build: third_party
|
|||
|
||||
# test
|
||||
|
||||
test: submodules
|
||||
test: install
|
||||
@$(call echo,Make $@)
|
||||
@$(call echo,Make gtest,33)
|
||||
@$(call cmake_build,./tests/gtest/_build)
|
||||
@$(call cmake_build,./test/gtest/_build)
|
||||
@$(call echo,Make test,33)
|
||||
@$(call cmake_build,./test/_build)
|
||||
@./test/_output/bin/mynteye_test
|
||||
|
||||
.PHONY: test
|
||||
|
||||
|
@ -94,11 +97,13 @@ clean:
|
|||
@$(call rm,./_install/)
|
||||
@$(call rm,./samples/_build/)
|
||||
@$(call rm,./samples/_output/)
|
||||
@$(call rm,./test/_build/)
|
||||
@$(call rm,./test/_output/)
|
||||
@$(MAKE) cleanlog
|
||||
|
||||
cleanall: clean
|
||||
@$(call rm,./doc/_output/)
|
||||
@$(call rm,./tests/gtest/_build/)
|
||||
@$(call rm,./test/gtest/_build/)
|
||||
@$(call rm,./third_party/glog/_build/)
|
||||
@$(FIND) . -type f -name ".DS_Store" -print0 | xargs -0 rm -f
|
||||
|
||||
|
|
157
include/mynteye/types.h
Normal file
157
include/mynteye/types.h
Normal file
|
@ -0,0 +1,157 @@
|
|||
#ifndef MYNTEYE_TYPES_H_ // NOLINT
|
||||
#define MYNTEYE_TYPES_H_
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <iostream>
|
||||
#include <type_traits>
|
||||
|
||||
#include "mynteye/mynteye.h"
|
||||
|
||||
MYNTEYE_BEGIN_NAMESPACE
|
||||
|
||||
/**
|
||||
* @ingroup enumerations
|
||||
* @brief Streams define different type of data.
|
||||
*/
|
||||
enum class Stream : std::uint8_t {
|
||||
/** Left stream */
|
||||
LEFT,
|
||||
/** Right stream */
|
||||
RIGHT,
|
||||
/** Left stream, rectified */
|
||||
LEFT_RECTIFIED,
|
||||
/** Right stream, rectified */
|
||||
RIGHT_RECTIFIED,
|
||||
/** Disparity stream */
|
||||
DISPARITY,
|
||||
/** Disparity stream, normalized */
|
||||
DISPARITY_NORMALIZED,
|
||||
/** Depth stream */
|
||||
DEPTH,
|
||||
/** Point cloud stream */
|
||||
POINTS,
|
||||
/** Last guard */
|
||||
LAST
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup enumerations
|
||||
* @brief Capabilities define the full set of functionality that the device
|
||||
* might provide.
|
||||
*/
|
||||
enum class Capabilities : std::uint8_t {
|
||||
/** Provices stereo stream */
|
||||
STEREO,
|
||||
/** Provices color stream */
|
||||
COLOR,
|
||||
/** Provices depth stream */
|
||||
DEPTH,
|
||||
/** Provices point cloud stream */
|
||||
POINTS,
|
||||
/** Provices fisheye stream */
|
||||
FISHEYE,
|
||||
/** Provices IMU (accelerometer, gyroscope) data */
|
||||
IMU,
|
||||
/** Last guard */
|
||||
LAST
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup enumerations
|
||||
* @brief Camera info fields are read-only strings that can be queried from the
|
||||
* device.
|
||||
*/
|
||||
enum class Info : std::uint8_t {
|
||||
/** Device name */
|
||||
DEVICE_NAME,
|
||||
/** Serial number */
|
||||
SERIAL_NUMBER,
|
||||
/** Firmware version */
|
||||
FIRMWARE_VERSION,
|
||||
/** Hardware version */
|
||||
HARDWARE_VERSION,
|
||||
/** Spec version */
|
||||
SPEC_VERSION,
|
||||
/** Lens type */
|
||||
LENS_TYPE,
|
||||
/** IMU type */
|
||||
IMU_TYPE,
|
||||
/** Nominal baseline */
|
||||
NOMINAL_BASELINE,
|
||||
/** Last guard */
|
||||
LAST,
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup enumerations
|
||||
* Camera control options define general configuration controls.
|
||||
*/
|
||||
enum class Option : std::uint8_t {
|
||||
/** Image gain, setting it if manual-exposure */
|
||||
GAIN,
|
||||
/** Image brightness, setting it if manual-exposure */
|
||||
BRIGHTNESS,
|
||||
/** Image contrast */
|
||||
CONTRAST,
|
||||
/** Image frame rate */
|
||||
FRAME_RATE,
|
||||
/** IMU frequency */
|
||||
IMU_FREQUENCY,
|
||||
/**
|
||||
* Exposure mode
|
||||
*
|
||||
* 0: enable auto-exposure
|
||||
* 1: disable auto-exposure (manual-exposure)
|
||||
*/
|
||||
EXPOSURE_MODE,
|
||||
/** Max gain, setting it if auto-exposure */
|
||||
MAX_GAIN,
|
||||
/** Max exposure time, setting it if auto-exposure */
|
||||
MAX_EXPOSURE_TIME,
|
||||
/** Desired brightness */
|
||||
DESIRED_BRIGHTNESS,
|
||||
/** IR control */
|
||||
IR_CONTROL,
|
||||
/**
|
||||
* HDR mode
|
||||
*
|
||||
* 0: 10-bit
|
||||
* 1: 12-bit
|
||||
*/
|
||||
HDR_MODE,
|
||||
/** Zero drift calibration */
|
||||
ZERO_DRIFT_CALIBRATION,
|
||||
/** Erase chip */
|
||||
ERASE_CHIP,
|
||||
/** Last guard */
|
||||
LAST,
|
||||
};
|
||||
|
||||
#define MYNTEYE_ENUM_HELPERS(TYPE) \
|
||||
const char *to_string(const TYPE &value); \
|
||||
inline bool is_valid(const TYPE &value) { \
|
||||
using utype = std::underlying_type<TYPE>::type; \
|
||||
utype val = static_cast<utype>(value); \
|
||||
utype max = static_cast<utype>(TYPE::LAST); \
|
||||
return /*val >= 0 &&*/ val < max; \
|
||||
} \
|
||||
inline std::ostream &operator<<(std::ostream &os, const TYPE &value) { \
|
||||
using utype = std::underlying_type<TYPE>::type; \
|
||||
if (is_valid(value)) \
|
||||
return os << to_string(value); \
|
||||
else \
|
||||
return os << static_cast<utype>(value); \
|
||||
}
|
||||
|
||||
MYNTEYE_ENUM_HELPERS(Stream)
|
||||
MYNTEYE_ENUM_HELPERS(Capabilities)
|
||||
MYNTEYE_ENUM_HELPERS(Info)
|
||||
MYNTEYE_ENUM_HELPERS(Option)
|
||||
|
||||
#undef MYNTEYE_ENUM_HELPERS
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
|
||||
#endif // MYNTEYE_TYPES_H_ NOLINT
|
90
src/public/types.cc
Normal file
90
src/public/types.cc
Normal file
|
@ -0,0 +1,90 @@
|
|||
#include "mynteye/types.h"
|
||||
|
||||
#include <glog/logging.h>
|
||||
|
||||
MYNTEYE_BEGIN_NAMESPACE
|
||||
|
||||
const char *to_string(const Stream &value) {
|
||||
#define CASE(X) \
|
||||
case Stream::X: \
|
||||
return "Stream::" #X;
|
||||
switch (value) {
|
||||
CASE(LEFT)
|
||||
CASE(RIGHT)
|
||||
CASE(LEFT_RECTIFIED)
|
||||
CASE(RIGHT_RECTIFIED)
|
||||
CASE(DISPARITY)
|
||||
CASE(DISPARITY_NORMALIZED)
|
||||
CASE(DEPTH)
|
||||
CASE(POINTS)
|
||||
default:
|
||||
CHECK(is_valid(value));
|
||||
return "Stream::UNKNOWN";
|
||||
}
|
||||
#undef CASE
|
||||
}
|
||||
|
||||
const char *to_string(const Capabilities &value) {
|
||||
#define CASE(X) \
|
||||
case Capabilities::X: \
|
||||
return "Capabilities::" #X;
|
||||
switch (value) {
|
||||
CASE(STEREO)
|
||||
CASE(COLOR)
|
||||
CASE(DEPTH)
|
||||
CASE(POINTS)
|
||||
CASE(FISHEYE)
|
||||
CASE(IMU)
|
||||
default:
|
||||
CHECK(is_valid(value));
|
||||
return "Capabilities::UNKNOWN";
|
||||
}
|
||||
#undef CASE
|
||||
}
|
||||
|
||||
const char *to_string(const Info &value) {
|
||||
#define CASE(X) \
|
||||
case Info::X: \
|
||||
return "Info::" #X;
|
||||
switch (value) {
|
||||
CASE(DEVICE_NAME)
|
||||
CASE(SERIAL_NUMBER)
|
||||
CASE(FIRMWARE_VERSION)
|
||||
CASE(HARDWARE_VERSION)
|
||||
CASE(SPEC_VERSION)
|
||||
CASE(LENS_TYPE)
|
||||
CASE(IMU_TYPE)
|
||||
CASE(NOMINAL_BASELINE)
|
||||
default:
|
||||
CHECK(is_valid(value));
|
||||
return "Info::UNKNOWN";
|
||||
}
|
||||
#undef CASE
|
||||
}
|
||||
|
||||
const char *to_string(const Option &value) {
|
||||
#define CASE(X) \
|
||||
case Option::X: \
|
||||
return "Option::" #X;
|
||||
switch (value) {
|
||||
CASE(GAIN)
|
||||
CASE(BRIGHTNESS)
|
||||
CASE(CONTRAST)
|
||||
CASE(FRAME_RATE)
|
||||
CASE(IMU_FREQUENCY)
|
||||
CASE(EXPOSURE_MODE)
|
||||
CASE(MAX_GAIN)
|
||||
CASE(MAX_EXPOSURE_TIME)
|
||||
CASE(DESIRED_BRIGHTNESS)
|
||||
CASE(IR_CONTROL)
|
||||
CASE(HDR_MODE)
|
||||
CASE(ZERO_DRIFT_CALIBRATION)
|
||||
CASE(ERASE_CHIP)
|
||||
default:
|
||||
CHECK(is_valid(value));
|
||||
return "Option::UNKNOWN";
|
||||
}
|
||||
#undef CASE
|
||||
}
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
88
test/CMakeLists.txt
Normal file
88
test/CMakeLists.txt
Normal file
|
@ -0,0 +1,88 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
project(mynteye_test VERSION 2.0.0 LANGUAGES C CXX)
|
||||
|
||||
get_filename_component(PRO_DIR ${PROJECT_SOURCE_DIR} DIRECTORY)
|
||||
|
||||
# flags
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
|
||||
|
||||
include(${PRO_DIR}/cmake/DetectCXX11.cmake)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
|
||||
|
||||
string(STRIP "${CMAKE_C_FLAGS}" CMAKE_C_FLAGS)
|
||||
string(STRIP "${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS)
|
||||
message(STATUS "C_FLAGS: ${CMAKE_C_FLAGS}")
|
||||
message(STATUS "CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
|
||||
|
||||
# packages
|
||||
|
||||
LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/third_party/glog/_build)
|
||||
find_package(glog REQUIRED)
|
||||
message(STATUS "Found glog: ${glog_VERSION}")
|
||||
|
||||
LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/_install/lib/cmake)
|
||||
find_package(mynteye REQUIRED)
|
||||
message(STATUS "Found mynteye: ${mynteye_VERSION}")
|
||||
|
||||
LIST(APPEND CMAKE_MODULE_PATH ${PRO_DIR}/cmake)
|
||||
|
||||
## gtest
|
||||
|
||||
set(TEST_DIR ${PROJECT_SOURCE_DIR})
|
||||
set(GMOCK_DIR ${TEST_DIR}/gtest/googlemock)
|
||||
set(GTEST_DIR ${TEST_DIR}/gtest/googletest)
|
||||
|
||||
set(GMOCK_LIB_DIR ${TEST_DIR}/gtest/_build/googlemock)
|
||||
set(GTEST_LIB_DIR ${GMOCK_LIB_DIR}/gtest)
|
||||
if(OS_WIN AND NOT MINGW)
|
||||
set(GTEST_LIB_DIR ${GTEST_LIB_DIR}/Release)
|
||||
endif()
|
||||
|
||||
set(GTEST_LIBS
|
||||
${GTEST_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
|
||||
#${GTEST_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest_main${CMAKE_STATIC_LIBRARY_SUFFIX}
|
||||
)
|
||||
message(STATUS "Found gtest libs: ${GTEST_LIBS}")
|
||||
|
||||
# targets
|
||||
|
||||
include(${PRO_DIR}/cmake/Common.cmake)
|
||||
|
||||
set(OUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/_output")
|
||||
|
||||
set_outdir(
|
||||
"${OUT_DIR}/lib"
|
||||
"${OUT_DIR}/lib"
|
||||
"${OUT_DIR}/bin"
|
||||
)
|
||||
|
||||
include_directories(
|
||||
${GTEST_DIR}/include
|
||||
)
|
||||
|
||||
file(GLOB TEST_PUBLIC_SRC "public/*.cc")
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
gtest_main.cc
|
||||
${TEST_PUBLIC_SRC}
|
||||
)
|
||||
target_link_libraries(${PROJECT_NAME} ${GTEST_LIBS} mynteye)
|
||||
|
||||
if(OS_WIN)
|
||||
target_compile_definitions(${PROJECT_NAME}
|
||||
PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES
|
||||
)
|
||||
endif()
|
||||
|
||||
#find_package(Threads REQUIRED)
|
||||
#if(THREADS_HAVE_PTHREAD_ARG)
|
||||
# target_compile_options(PUBLIC ${PROJECT_NAME} "-pthread")
|
||||
#endif()
|
||||
#if(CMAKE_THREAD_LIBS_INIT)
|
||||
# target_link_libraries(${PROJECT_NAME} "${CMAKE_THREAD_LIBS_INIT}")
|
||||
#endif()
|
1
test/gtest
Submodule
1
test/gtest
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 7888184f28509dba839e3683409443e0b5bb8948
|
34
test/gtest_main.cc
Normal file
34
test/gtest_main.cc
Normal file
|
@ -0,0 +1,34 @@
|
|||
#include "gtest/gtest.h"
|
||||
#include <stdio.h>
|
||||
#include "glog/logging.h"
|
||||
|
||||
struct glog_init {
|
||||
glog_init(int /*argc*/, char *argv[]) {
|
||||
// FLAGS_logtostderr = true;
|
||||
FLAGS_alsologtostderr = true;
|
||||
FLAGS_colorlogtostderr = true;
|
||||
|
||||
FLAGS_log_dir = ".";
|
||||
FLAGS_max_log_size = 1024;
|
||||
FLAGS_stop_logging_if_full_disk = true;
|
||||
|
||||
// FLAGS_v = 2;
|
||||
|
||||
google::InitGoogleLogging(argv[0]);
|
||||
|
||||
VLOG(2) << __func__;
|
||||
}
|
||||
|
||||
~glog_init() {
|
||||
VLOG(2) << __func__;
|
||||
google::ShutdownGoogleLogging();
|
||||
}
|
||||
};
|
||||
|
||||
GTEST_API_ int main(int argc, char **argv) {
|
||||
glog_init _(argc, argv);
|
||||
|
||||
printf("Running main() from gtest_main.cc\n");
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
57
test/public/types_test.cc
Normal file
57
test/public/types_test.cc
Normal file
|
@ -0,0 +1,57 @@
|
|||
#include "gtest/gtest.h"
|
||||
|
||||
#include "mynteye/types.h"
|
||||
|
||||
MYNTEYE_USE_NAMESPACE
|
||||
|
||||
TEST(Stream, VerifyToString) {
|
||||
EXPECT_STREQ("Stream::LEFT", to_string(Stream::LEFT));
|
||||
EXPECT_STREQ("Stream::RIGHT", to_string(Stream::RIGHT));
|
||||
EXPECT_STREQ("Stream::LEFT_RECTIFIED", to_string(Stream::LEFT_RECTIFIED));
|
||||
EXPECT_STREQ("Stream::RIGHT_RECTIFIED", to_string(Stream::RIGHT_RECTIFIED));
|
||||
EXPECT_STREQ("Stream::DISPARITY", to_string(Stream::DISPARITY));
|
||||
EXPECT_STREQ(
|
||||
"Stream::DISPARITY_NORMALIZED", to_string(Stream::DISPARITY_NORMALIZED));
|
||||
EXPECT_STREQ("Stream::DEPTH", to_string(Stream::DEPTH));
|
||||
EXPECT_STREQ("Stream::POINTS", to_string(Stream::POINTS));
|
||||
}
|
||||
|
||||
TEST(Capabilities, VerifyToString) {
|
||||
EXPECT_STREQ("Capabilities::STEREO", to_string(Capabilities::STEREO));
|
||||
EXPECT_STREQ("Capabilities::COLOR", to_string(Capabilities::COLOR));
|
||||
EXPECT_STREQ("Capabilities::DEPTH", to_string(Capabilities::DEPTH));
|
||||
EXPECT_STREQ("Capabilities::POINTS", to_string(Capabilities::POINTS));
|
||||
EXPECT_STREQ("Capabilities::FISHEYE", to_string(Capabilities::FISHEYE));
|
||||
EXPECT_STREQ("Capabilities::IMU", to_string(Capabilities::IMU));
|
||||
}
|
||||
|
||||
TEST(Info, VerifyToString) {
|
||||
EXPECT_STREQ("Info::DEVICE_NAME", to_string(Info::DEVICE_NAME));
|
||||
EXPECT_STREQ("Info::SERIAL_NUMBER", to_string(Info::SERIAL_NUMBER));
|
||||
EXPECT_STREQ("Info::FIRMWARE_VERSION", to_string(Info::FIRMWARE_VERSION));
|
||||
EXPECT_STREQ("Info::HARDWARE_VERSION", to_string(Info::HARDWARE_VERSION));
|
||||
EXPECT_STREQ("Info::SPEC_VERSION", to_string(Info::SPEC_VERSION));
|
||||
EXPECT_STREQ("Info::LENS_TYPE", to_string(Info::LENS_TYPE));
|
||||
EXPECT_STREQ("Info::IMU_TYPE", to_string(Info::IMU_TYPE));
|
||||
EXPECT_STREQ("Info::NOMINAL_BASELINE", to_string(Info::NOMINAL_BASELINE));
|
||||
}
|
||||
|
||||
TEST(Option, VerifyToString) {
|
||||
EXPECT_STREQ("Option::GAIN", to_string(Option::GAIN));
|
||||
EXPECT_STREQ("Option::BRIGHTNESS", to_string(Option::BRIGHTNESS));
|
||||
EXPECT_STREQ("Option::CONTRAST", to_string(Option::CONTRAST));
|
||||
EXPECT_STREQ("Option::FRAME_RATE", to_string(Option::FRAME_RATE));
|
||||
EXPECT_STREQ("Option::IMU_FREQUENCY", to_string(Option::IMU_FREQUENCY));
|
||||
EXPECT_STREQ("Option::EXPOSURE_MODE", to_string(Option::EXPOSURE_MODE));
|
||||
EXPECT_STREQ("Option::MAX_GAIN", to_string(Option::MAX_GAIN));
|
||||
EXPECT_STREQ(
|
||||
"Option::MAX_EXPOSURE_TIME", to_string(Option::MAX_EXPOSURE_TIME));
|
||||
EXPECT_STREQ(
|
||||
"Option::DESIRED_BRIGHTNESS", to_string(Option::DESIRED_BRIGHTNESS));
|
||||
EXPECT_STREQ("Option::IR_CONTROL", to_string(Option::IR_CONTROL));
|
||||
EXPECT_STREQ("Option::HDR_MODE", to_string(Option::HDR_MODE));
|
||||
EXPECT_STREQ(
|
||||
"Option::ZERO_DRIFT_CALIBRATION",
|
||||
to_string(Option::ZERO_DRIFT_CALIBRATION));
|
||||
EXPECT_STREQ("Option::ERASE_CHIP", to_string(Option::ERASE_CHIP));
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
Subproject commit 9bda90b7e5e08c4c37a832d0cea218aed6af6470
|
Loading…
Reference in New Issue
Block a user