-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* used namespace direct * deleted version stuff
- Loading branch information
Myron Franze
authored
Jun 17, 2020
1 parent
64b7a60
commit 326327d
Showing
18 changed files
with
780 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
cmake_minimum_required (VERSION 3.16) | ||
|
||
SET(CMAKE_CXX_STANDARD 20) | ||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Werror=pedantic -Wextra") | ||
|
||
SET(PRJ_NAME "siguni") | ||
project(${PRJ_NAME}) | ||
|
||
find_package(GTest QUIET) | ||
|
||
if(${GTest_FOUND}) | ||
add_subdirectory(gtest) | ||
endif() | ||
|
||
|
||
add_library(${PRJ_NAME} | ||
|
||
unit | ||
signal | ||
protocol | ||
managerbase | ||
|
||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
SET(LIB_NAME "sigunit-test") | ||
project (${LIB_NAME}) | ||
|
||
add_executable( ${LIB_NAME} | ||
test.cpp | ||
signal_test.cpp | ||
unit_test.cpp | ||
siguni_test.cpp | ||
) | ||
|
||
target_link_libraries( ${LIB_NAME} | ||
gtest | ||
pthread | ||
siguni | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* SPDX-License-Identifier: GPLv3-or-later */ | ||
/* Copyright (c) 2020 Project WomoLIN */ | ||
/* Author Myron Franze <[email protected]> */ | ||
|
||
#include "../signal.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
|
||
namespace siguni::gtest | ||
{ | ||
|
||
class CSerialTest : public ::testing::Test { }; | ||
|
||
|
||
class CSignalSetResetTest : public interface::ISignalSetReset | ||
{ | ||
public: | ||
CSignalSetResetTest() = default ; | ||
~CSignalSetResetTest() = default; | ||
void UpdateUnitSignalSetReset( std::string & attKey, std::string & attValue ) override final | ||
{ | ||
key = attKey; | ||
value = attValue; | ||
}; | ||
std::string key; | ||
std::string value { "UNKNOWN" }; | ||
|
||
}; | ||
|
||
|
||
TEST_F( CSerialTest, ISignalSetReset ) { | ||
|
||
std::string key { "KEY" }; | ||
std::string val { "GET" }; | ||
|
||
auto test = CSignalSetResetTest(); | ||
|
||
test.UpdateUnitSignalSetReset( key, val ); | ||
|
||
ASSERT_STREQ( test.key.c_str() , "KEY" ); | ||
ASSERT_STREQ( test.value.c_str(), "GET" ); | ||
|
||
} | ||
|
||
class CSignalGetVoltageTest : public interface::ISignalGetVoltage | ||
{ | ||
public: | ||
CSignalGetVoltageTest() = default ; | ||
~CSignalGetVoltageTest() = default; | ||
void UpdateUnitSignalGetVoltage( std::string & attKey, std::string & attGetVoltage ) override final | ||
{ | ||
key = attKey; | ||
voltage = attGetVoltage; | ||
}; | ||
std::string key; | ||
std::string voltage; | ||
}; | ||
|
||
|
||
TEST_F( CSerialTest, ISignalGetVoltage ) { | ||
|
||
std::string key {"KEY"}; | ||
std::string voltage {"VOLTAGE"}; | ||
|
||
auto test = CSignalGetVoltageTest(); | ||
|
||
test.UpdateUnitSignalGetVoltage( key, voltage ); | ||
|
||
ASSERT_STREQ( test.key.c_str() , "KEY" ); | ||
ASSERT_STREQ( test.voltage.c_str() , "VOLTAGE"); | ||
|
||
} | ||
|
||
|
||
class CSignalGetVersionTest : public interface::ISignalGetVersion | ||
{ | ||
public: | ||
CSignalGetVersionTest() = default ; | ||
~CSignalGetVersionTest() = default; | ||
void UpdateUnitSignalGetVersion( std::string & attKey, std::string & attVersion ) override final | ||
{ | ||
key = attKey; | ||
fw = attVersion; | ||
}; | ||
std::string key; | ||
std::string fw; | ||
}; | ||
|
||
|
||
TEST_F( CSerialTest, ISignalGetVersion ) { | ||
|
||
std::string key {"KEY"}; | ||
std::string fw {"FW"}; | ||
|
||
auto test = CSignalGetVersionTest(); | ||
|
||
test.UpdateUnitSignalGetVersion( key, fw ); | ||
|
||
ASSERT_STREQ( test.key.c_str() , "KEY" ); | ||
ASSERT_STREQ( test.fw.c_str() , "FW"); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
class CSignalAddUnitIntTest : public CSignalAddUnit<int> | ||
{ | ||
public: | ||
CSignalAddUnitIntTest() { unitsPointer = &units ; } ; | ||
~CSignalAddUnitIntTest() = default; | ||
const std::vector<int*>* unitsPointer; // pointer to access unit array | ||
}; | ||
|
||
TEST_F( CSerialTest, CSignalAddUnitInt ) { | ||
|
||
int val1 {1}; | ||
int val2 {2}; | ||
|
||
auto test = CSignalAddUnitIntTest(); | ||
|
||
ASSERT_TRUE( (*test.unitsPointer).empty() ) << "no values added, array must be empty"; | ||
test.AddUnit( &val1 ); | ||
ASSERT_EQ( 1, (*test.unitsPointer).size() ) << "added one value, array must be have one value"; | ||
|
||
test.AddUnit( &val2 ); // add second value to array | ||
|
||
val1 = 10; // change initialize value from value 1 | ||
val2 = 20; // change initialize value from value 2 | ||
|
||
ASSERT_EQ( 10, *(*test.unitsPointer).at(0) ) << "value 1 must be 10, changed variable var1 changed"; | ||
ASSERT_EQ( 20, *(*test.unitsPointer).at(1) ) << "value 1 must be 20, changed variable var2 changed"; | ||
|
||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* SPDX-License-Identifier: GPLv3-or-later */ | ||
/* Copyright (c) 2020 Project WomoLIN */ | ||
/* Author Myron Franze <[email protected]> */ | ||
|
||
#include "../unit.h" | ||
#include "../signal.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
namespace siguni::gtest | ||
{ | ||
|
||
|
||
class CSiguniTest : public ::testing::Test { }; | ||
|
||
|
||
|
||
class CUnitSignalSetReset : public interface::ISignalSetReset | ||
{ | ||
void UpdateUnitSignalSetReset( std::string & /*attKey*/, std::string & /*attValue*/ ) override {}; | ||
}; | ||
|
||
|
||
class CRelayOutput : public interface::IUnitOutput | ||
{ | ||
public: | ||
CRelayOutput() = default ; | ||
~CRelayOutput() = default; | ||
|
||
void Set( std::string & attSetOutput ) override final { set = attSetOutput; }; | ||
|
||
std::string set; | ||
}; | ||
|
||
|
||
TEST_F( CSiguniTest, CUnitOutput ) { | ||
|
||
auto signal_setReset_1 = CSignalSetReset(); | ||
|
||
auto unit_setReset_1 = CUnitSignalSetReset(); | ||
|
||
signal_setReset_1.AddUnit( &unit_setReset_1 ); | ||
|
||
std::string key {}; | ||
std::string val {}; | ||
|
||
signal_setReset_1.UpdateUnit( key, val ); | ||
|
||
// TODO | ||
//std::cout << key << std::endl; | ||
//std::cout << val << std::endl; | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* SPDX-License-Identifier: GPLv3-or-later */ | ||
/* Copyright (c) 2020 Project WomoLIN */ | ||
/* Author Myron Franze <[email protected]> */ | ||
|
||
#include <gtest/gtest.h> | ||
|
||
int main(int argc, char **argv) { | ||
::testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* SPDX-License-Identifier: GPLv3-or-later */ | ||
/* Copyright (c) 2020 Project WomoLIN */ | ||
/* Author Myron Franze <[email protected]> */ | ||
|
||
#include "../unit.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
namespace siguni::gtest | ||
{ | ||
|
||
class CUnitTest : public ::testing::Test { }; | ||
|
||
|
||
class CUnitOutputTest : public interface::IUnitOutput | ||
{ | ||
public: | ||
CUnitOutputTest() = default ; | ||
~CUnitOutputTest() = default; | ||
|
||
void Set( std::string & attSetOutput ) override final { setCommand = attSetOutput; }; | ||
|
||
std::string setCommand; | ||
}; | ||
|
||
TEST_F( CUnitTest, IUnitOutput ) { | ||
|
||
auto test = CUnitOutputTest(); | ||
|
||
std::string setCommand { "SET" }; | ||
|
||
test.Set( setCommand ); | ||
ASSERT_STREQ( test.setCommand.c_str() , "SET" ); | ||
|
||
setCommand = "RESET"; | ||
|
||
test.Set( setCommand ); | ||
ASSERT_STREQ( test.setCommand.c_str() , "RESET" ); | ||
} | ||
|
||
class CUnitInputTest : public interface::IUnitInput | ||
{ | ||
public: | ||
CUnitInputTest() = default ; | ||
~CUnitInputTest() = default; | ||
|
||
void Get( std::string & attStatus ) override final { attStatus = "SET"; }; | ||
}; | ||
|
||
TEST_F( CUnitTest, IUnitInput ) { | ||
|
||
auto test = CUnitInputTest(); | ||
|
||
std::string status_string {"UNKNOWN"}; | ||
|
||
test.Get( status_string ); | ||
ASSERT_STREQ( status_string.c_str() , "SET" ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* SPDX-License-Identifier: GPLv3-or-later */ | ||
/* Copyright (c) 2019 Project WomoLIN */ | ||
/* Author Myron Franze <[email protected]> */ | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
|
||
namespace siguni::interface | ||
{ | ||
class IControlbus | ||
{ | ||
public: | ||
virtual ~IControlbus() = default; | ||
|
||
virtual int WriteData( const std::string & attMessage ) = 0; | ||
virtual int ReadData( std::string & attMessage ) = 0; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* SPDX-License-Identifier: GPLv3-or-later */ | ||
/* Copyright (c) 2020 Project WomoLIN */ | ||
/* Author Myron Franze <[email protected]> */ | ||
|
||
#pragma once | ||
|
||
#include "iunit.h" | ||
|
||
namespace siguni::interface | ||
{ | ||
|
||
class IInputHwBoardVersion : public siguni::interface::IUnitInput | ||
{ | ||
public: | ||
virtual ~IInputHwBoardVersion() = default; | ||
|
||
void Get( std::string & attGetInput ) override = 0; | ||
}; | ||
|
||
class IInputDriverVersion : public siguni::interface::IUnitInput | ||
{ | ||
public: | ||
virtual ~IInputDriverVersion() = default; | ||
|
||
void Get( std::string & attGetInput ) override = 0; | ||
}; | ||
|
||
} | ||
|
Oops, something went wrong.