Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #52 from forno/develop
Browse files Browse the repository at this point in the history
Upgrade v1.5.0
  • Loading branch information
forno authored Mar 28, 2017
2 parents b8965f5 + 8f26cfd commit 118abe5
Show file tree
Hide file tree
Showing 9 changed files with 314 additions and 112 deletions.
39 changes: 32 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8.12.1)
project(ics3 C CXX)

set(PROJECT_VER_MAJOR 1)
set(PROJECT_VER_MINOR 4)
set(PROJECT_VER_MINOR 5)
set(PROJECT_VER_PATCH 0)
set(PROJECT_VER "${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}.${PROJECT_VER_PATCH}")
set(PROJECT_APIVER "${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}")
Expand All @@ -11,7 +11,7 @@ if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose: RelWithDebInfo Release Debug MinSizeRel None")
endif()

option(BUILD_SHARED_LIBS "Build shared (ON) or static (OFF) libraries" ON)
option(BUILD_SHARED_LIBS "Build shared (ON) or static (OFF) libraries" OFF)
option(ENABLE_TEST "Enable test program building" OFF)

set(MY_DIR ${ics3_SOURCE_DIR})
Expand Down Expand Up @@ -69,17 +69,42 @@ if(ENABLE_TEST)
find_package(Threads)

include_directories(${GTEST_INCLUDE_DIRS})
add_executable(integrate test/integrate.cpp)
target_link_libraries(integrate ics3 ${GTEST_BOTH_LIBRARIES})
add_executable(angle test/angle.cpp)
add_executable(baudrate test/baudrate.cpp)
add_executable(eepparam test/eepparam.cpp)
add_executable(id test/id.cpp)
add_executable(parameter test/parameter.cpp)
add_executable(ics3Test test/ics3.cpp)
target_link_libraries(angle ics3 ${GTEST_BOTH_LIBRARIES})
target_link_libraries(baudrate ics3 ${GTEST_BOTH_LIBRARIES})
target_link_libraries(eepparam ics3 ${GTEST_BOTH_LIBRARIES})
target_link_libraries(id ics3 ${GTEST_BOTH_LIBRARIES})
target_link_libraries(parameter ics3 ${GTEST_BOTH_LIBRARIES})
target_link_libraries(ics3Test ics3 ${GTEST_BOTH_LIBRARIES})
if(THREADS_HAVE_PTHREAD_ARG)
target_compile_options(PUBLIC integrate "-pthread")
target_compile_options(PUBLIC angle "-pthread")
target_compile_options(PUBLIC baudrate "-pthread")
target_compile_options(PUBLIC eepparam "-pthread")
target_compile_options(PUBLIC id "-pthread")
target_compile_options(PUBLIC parameter "-pthread")
target_compile_options(PUBLIC ics3Test "-pthread")
endif()
if(CMAKE_THREAD_LIBS_INIT)
target_link_libraries(integrate "${CMAKE_THREAD_LIBS_INIT}")
target_link_libraries(angle "${CMAKE_THREAD_LIBS_INIT}")
target_link_libraries(baudrate "${CMAKE_THREAD_LIBS_INIT}")
target_link_libraries(eepparam "${CMAKE_THREAD_LIBS_INIT}")
target_link_libraries(id "${CMAKE_THREAD_LIBS_INIT}")
target_link_libraries(parameter "${CMAKE_THREAD_LIBS_INIT}")
target_link_libraries(ics3Test "${CMAKE_THREAD_LIBS_INIT}")
endif()

enable_testing()
add_test(AllTestInIntegrate ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/integrate)
add_test(AngleTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/angle)
add_test(BaudrateTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/baudrate)
add_test(EepParamTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/eepparam)
add_test(IDTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/id)
add_test(ParameterTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/parameter)
add_test(ICS3Test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ics3Test)
endif()

install(TARGETS ics3 DESTINATION lib RUNTIME DESTINATION bin)
Expand Down
2 changes: 1 addition & 1 deletion script/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if [ $inputCheck -gt 1 ]; then
if [ $INTCHECK -gt 1 ]; then
echo "Invalid argument"
return 1
fi
fi
else
onePID=$1
fi
Expand Down
6 changes: 2 additions & 4 deletions src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <cstring> // for memset
#include <fcntl.h> // for open FLAGS
#include <sstream> // for error massage
#include <stdexcept>
#include <unordered_map> // for cashe
#include <fcntl.h> // for open FLAGS
#include <unistd.h> // for tty checks

#include "core.hpp"
Expand Down Expand Up @@ -133,8 +132,7 @@ void ics::Core::closeThis() const noexcept

termios ics::Core::getTermios() noexcept
{
termios newTio;
std::memset(&newTio, 0, sizeof(newTio));
termios newTio {};
newTio.c_iflag = 0;
newTio.c_oflag = 0;
newTio.c_cflag = CS8 | CREAD | CLOCAL | PARENB;
Expand Down
71 changes: 71 additions & 0 deletions test/angle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* BSD 2-Clause License
Copyright (c) 2016, Doi Yusuke
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ics3/ics"

#include <gtest/gtest.h>

TEST(AngleConstexprTest, CreateWithGetRaw) {
// constexpr test
constexpr auto defDeg = ics::Angle::newDegree();
constexpr auto defRad = ics::Angle::newRadian();
static_assert(defDeg == 0, "Angle default cast error");
static_assert(defRad.get() == 0, "Angle default get() error");
static_assert(defDeg.getRaw() == 7500, "Angle default must is 7500");
static_assert(defDeg.getRaw() == defRad.getRaw(), "Angle have different default");
constexpr auto degree1 = ics::Angle::newDegree(90);
constexpr auto radian1 = ics::Angle::newRadian(ics::Angle::PI / 2);
static_assert(degree1.getRaw() == radian1.getRaw(), "difference: 90 deg <-> pi/2 rad");
constexpr auto degree2 = ics::Angle::newDegree(30);
constexpr auto radian2 = ics::Angle::newRadian(ics::Angle::PI / 6);
static_assert(degree2.getRaw() == radian2.getRaw(), "difference: 30 deg <-> pi/6 rad");
constexpr auto degree_cast = ics::Angle::newDegree(50);
constexpr auto cast1 = static_cast<double>(degree_cast);
constexpr double cast2 {degree_cast};
static_assert(cast1 == cast2, "difference: angle cast to doubles. miss? impossible lol");
}

TEST(AngleCreateTest, NewFactoryWithGetAndGetRaw) {
// runtime test
auto degree = ics::Angle::newDegree();
auto radian = ics::Angle::newRadian();
EXPECT_EQ(degree.get(), radian.get());
EXPECT_EQ(degree.getRaw(), radian.getRaw());
EXPECT_THROW(ics::Angle::newDegree(136), std::out_of_range);
}

TEST(AngleMethodTest, SetWithGetRaw) {
auto degree = ics::Angle::newDegree(0);
auto radian = ics::Angle::newRadian(0);
degree.set(90);
radian.set(ics::Angle::PI / 2);
EXPECT_EQ(degree.getRaw(), radian.getRaw());
degree.set(-60);
radian.set(-ics::Angle::PI / 3);
EXPECT_EQ(degree.getRaw(), radian.getRaw());
EXPECT_THROW(degree.set(150), std::out_of_range);
EXPECT_THROW(radian.set(ics::Angle::PI), std::out_of_range);
}
37 changes: 37 additions & 0 deletions test/baudrate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* BSD 2-Clause License
Copyright (c) 2016, Doi Yusuke
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ics3/ics"

#include <gtest/gtest.h>

TEST(BaudrateContexprTest, Baudrate115200) {
constexpr auto baudrate115200 = ics::Baudrate::RATE115200();
static_assert(baudrate115200 == 10, "Baudrate: not equal 10");
static_assert(baudrate115200.get() == 10, "Baudrate: romdata error");
static_assert(baudrate115200.getSpeed() == B115200, "Baudrate: getSpeed method error");
static_assert(static_cast<uint8_t>(baudrate115200) == 10, "cast to Baudrate::type(uint8_t)");
}
61 changes: 61 additions & 0 deletions test/eepparam.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* BSD 2-Clause License
Copyright (c) 2016, Doi Yusuke
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ics3/ics"

#include <gtest/gtest.h>

TEST(EepParamConstexprTest, EepParam) {
constexpr auto current = ics::EepParam::current();
static_assert(63 == current.get(), "current error");
constexpr auto stretch = ics::EepParam::stretch(244);
static_assert(244 == stretch.get(), "strech error");
}

TEST(EepParamCreateTest, Correct) {
auto speed = ics::EepParam::speed();
EXPECT_EQ(speed.get(), 127);
auto speed2 = ics::EepParam::newEepParam(speed, 60);
EXPECT_EQ(speed2.get(), 60);
}

TEST(EepParamCreateTest, Invalid) {
EXPECT_THROW(ics::EepParam::flag(10), std::invalid_argument);
auto speed = ics::EepParam::speed();
EXPECT_THROW(ics::EepParam::newEepParam(speed, 130), std::out_of_range);
}

TEST(EepParamMethodSetTest, Correct) {
// runtime test
auto speed = ics::EepParam::speed();
speed.set(100);
EXPECT_EQ(100, speed.get());
}

TEST(EepParamMethodSetTest, Invalid) {
auto speed = ics::EepParam::speed();
EXPECT_THROW(speed.set(200), std::out_of_range);
}
103 changes: 3 additions & 100 deletions test/integrate.cpp → test/ics3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ics3/ics"

#include <chrono>
#include <iostream>
#include <thread>

#include "ics3/ics"

#include <gtest/gtest.h>

void testIcsMove(ics::ICS3&, const ics::ID&);
Expand All @@ -40,104 +40,7 @@ void testIcsID(ics::ICS3&);
template<typename Iter>
void dump(const Iter& begin, const Iter& end) noexcept;

TEST(AllTestInIntegrate, Angle) {
// constexpr test
constexpr auto defDeg = ics::Angle::newDegree();
constexpr auto defRad = ics::Angle::newRadian();
static_assert(defDeg == 0, "Angle default cast error");
static_assert(defRad.get() == 0, "Angle default get() error");
static_assert(defDeg.getRaw() == 7500, "Angle default must is 7500");
static_assert(defDeg.getRaw() == defRad.getRaw(), "Angle have different default");
constexpr auto degree1 = ics::Angle::newDegree(90);
constexpr auto radian1 = ics::Angle::newRadian(ics::Angle::PI / 2);
static_assert(degree1.getRaw() == radian1.getRaw(), "difference: 90 deg <-> pi/2 rad");
constexpr auto degree2 = ics::Angle::newDegree(30);
constexpr auto radian2 = ics::Angle::newRadian(ics::Angle::PI / 6);
static_assert(degree2.getRaw() == radian2.getRaw(), "difference: 30 deg <-> pi/6 rad");
constexpr auto degree_cast = ics::Angle::newDegree(50);
constexpr auto cast1 = static_cast<double>(degree_cast);
constexpr double cast2 {degree_cast};
static_assert(cast1 == cast2, "difference: angle cast to doubles. miss? impossible lol");
EXPECT_THROW(ics::Angle::newDegree(136), std::out_of_range);

// runtime test
auto degree = ics::Angle::newDegree(0);
auto radian = ics::Angle::newRadian(0);
EXPECT_EQ(degree.getRaw(), radian.getRaw());
degree.set(90);
radian.set(ics::Angle::PI / 2);
EXPECT_EQ(degree.getRaw(), radian.getRaw());
degree.set(-60);
radian.set(-ics::Angle::PI / 3);
EXPECT_EQ(degree.getRaw(), radian.getRaw());
EXPECT_THROW(degree.set(150), std::out_of_range);
EXPECT_THROW(radian.set(ics::Angle::PI), std::out_of_range);
}

TEST(AllTestInIntegrate, Baudrate) {
// constexpr test
constexpr auto baudrate115200 = ics::Baudrate::RATE115200();
static_assert(baudrate115200 == 10, "Baudrate: not equal 10");
static_assert(baudrate115200.get() == 10, "Baudrate: romdata error");
static_assert(baudrate115200.getSpeed() == B115200, "Baudrate: getSpeed method error");
static_assert(static_cast<uint8_t>(baudrate115200) == 10, "cast to Baudrate::type(uint8_t)");
}

TEST(AllTestInIntegrate, EepParam) {
// constexpr test
constexpr auto current = ics::EepParam::current();
static_assert(63 == current.get(), "current error");
constexpr auto stretch = ics::EepParam::stretch(244);
static_assert(244 == stretch.get(), "strech error");
EXPECT_THROW(ics::EepParam::flag(10), std::invalid_argument);

// runtime test
auto speed = ics::EepParam::speed();
EXPECT_EQ(127, speed.get());
speed.set(100);
EXPECT_EQ(100, speed.get());
auto speed2 = ics::EepParam::newEepParam(speed, 60);
EXPECT_EQ(60, speed2.get());
EXPECT_THROW(speed.set(200), std::out_of_range);
EXPECT_THROW(ics::EepParam::newEepParam(speed2, 130), std::out_of_range);
}

TEST(AllTestInIntegrate, ID) {
constexpr ics::ID id {0};
static_assert(id == 0, "id 0 error");
static_assert(id.get() == 0, "id 0 error by get");
constexpr ics::ID id31 {31};
static_assert(id31 == 31, "id 31 error");
static_assert(id31.get() == 31, "id 31 error by get");
EXPECT_THROW(ics::ID {32}, std::invalid_argument);
EXPECT_THROW(ics::ID {static_cast<ics::ID::type>(-1)}, std::invalid_argument);
}

TEST(AllTestInIntegrate, Parameter) {
// constexpr test
constexpr auto stretch = ics::Parameter::stretch();
static_assert(30 == stretch.get(), "stretch error");
static_assert(30 == stretch, "stretch error by cast");
static_assert(0x01 == stretch.getSubcommand(), "stretch error by subcommand");
constexpr auto speed = ics::Parameter::speed(100);
static_assert(100 == speed.get(), "speed error");
static_assert(100 == speed, "speed error by cast");
static_assert(0x02 == speed.getSubcommand(), "speed error by subcommand");
EXPECT_THROW(ics::Parameter::temperature(0), std::out_of_range);

// runtime test
auto current = ics::Parameter::current();
EXPECT_EQ(63, current.get());
EXPECT_EQ(0x03, current.getSubcommand());
current.set(30);
EXPECT_EQ(30, current);
current = 10;
EXPECT_EQ(10, current);
EXPECT_THROW(current.set(70), std::out_of_range);
EXPECT_THROW(current = 64;, std::out_of_range);
}

TEST(AllTestInIntegrate, ICS3) {
TEST(ICS3MethodTest, All) {
constexpr auto path = "/dev/ttyUSB0";
constexpr auto baudrate = ics::Baudrate::RATE115200();
constexpr ics::ID id {0};
Expand Down
Loading

0 comments on commit 118abe5

Please sign in to comment.