stub for companion storage tests
This commit is contained in:
@@ -326,6 +326,10 @@ set(simu_SRCS simulator.cpp )
|
|||||||
add_executable(${SIMULATOR_NAME} MACOSX_BUNDLE ${WIN_EXECUTABLE_TYPE} ${simu_SRCS} ${icon_RC})
|
add_executable(${SIMULATOR_NAME} MACOSX_BUNDLE ${WIN_EXECUTABLE_TYPE} ${simu_SRCS} ${icon_RC})
|
||||||
target_link_libraries(${SIMULATOR_NAME} PRIVATE ${CPN_COMMON_LIB})
|
target_link_libraries(${SIMULATOR_NAME} PRIVATE ${CPN_COMMON_LIB})
|
||||||
|
|
||||||
|
if(NOT MSVC)
|
||||||
|
add_subdirectory(tests)
|
||||||
|
endif()
|
||||||
|
|
||||||
############# Install ####################
|
############# Install ####################
|
||||||
|
|
||||||
# Generate list of simulator plugins, used by all platforms
|
# Generate list of simulator plugins, used by all platforms
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
set(GTEST_ROOT /usr CACHE STRING "Base path to Google Test headers and source.")
|
||||||
|
|
||||||
|
find_path(GTEST_INCDIR gtest/gtest.h HINTS "${GTEST_ROOT}/include" DOC "Path to Google Test header files folder ('gtest/gtest.h').")
|
||||||
|
find_path(GTEST_SRCDIR src/gtest-all.cc HINTS "${GTEST_ROOT}" "${GTEST_ROOT}/src/gtest" DOC "Path of Google Test 'src' folder.")
|
||||||
|
|
||||||
|
if(GTEST_INCDIR AND GTEST_SRCDIR AND Qt5Widgets_FOUND)
|
||||||
|
add_library(gtests-cpn-lib STATIC EXCLUDE_FROM_ALL ${GTEST_SRCDIR}/src/gtest-all.cc )
|
||||||
|
target_include_directories(gtests-cpn-lib PUBLIC ${GTEST_INCDIR} ${GTEST_INCDIR}/gtest ${GTEST_SRCDIR})
|
||||||
|
add_definitions(-DGTESTS)
|
||||||
|
set(TESTS_PATH ${COMPANION_SRC_DIRECTORY}/tests)
|
||||||
|
configure_file(${TESTS_PATH}/location.h.in ${CMAKE_CURRENT_BINARY_DIR}/location.h @ONLY)
|
||||||
|
|
||||||
|
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
target_include_directories(gtests-cpn-lib PUBLIC ${WIN_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(gtests-cpn-lib PRIVATE ${WIN_LINK_LIBRARIES})
|
||||||
|
endif(WIN32)
|
||||||
|
|
||||||
|
file(GLOB TEST_SRC_FILES ${TESTS_PATH}/*.cpp)
|
||||||
|
|
||||||
|
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
|
||||||
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 ${WARNING_FLAGS}")
|
||||||
|
|
||||||
|
use_cxx11() # ensure gnu++11 in CXX_FLAGS with CMake < 3.1
|
||||||
|
|
||||||
|
add_executable(gtests-cpn EXCLUDE_FROM_ALL ${TEST_SRC_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/location.h)
|
||||||
|
add_dependencies(gtests-cpn gtests-cpn-lib)
|
||||||
|
target_link_libraries(gtests-cpn gtests-cpn-lib pthread Qt5::Core Qt5::Widgets ${CPN_COMMON_LIB})
|
||||||
|
message(STATUS "Added optional gtests-cpn target")
|
||||||
|
else()
|
||||||
|
message(WARNING "WARNING: gtests target will not be available (check that GTEST_INCDIR, GTEST_SRCDIR, and Qt5Widgets are configured).")
|
||||||
|
endif()
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#include "gtests.h"
|
||||||
|
#include "location.h"
|
||||||
|
#include "storage/storage.h"
|
||||||
|
|
||||||
|
TEST(Conversions, test_conversion)
|
||||||
|
{
|
||||||
|
QString error;
|
||||||
|
RadioData simuData;
|
||||||
|
Storage store = Storage(TESTS_PATH "/eeprom_22_x9d+.bin");
|
||||||
|
|
||||||
|
EXPECT_EQ(true, store.load(simuData));
|
||||||
|
qDebug() << store.error();
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,149 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) OpenTX
|
||||||
|
*
|
||||||
|
* Based on code named
|
||||||
|
* th9x - http://code.google.com/p/th9x
|
||||||
|
* er9x - http://code.google.com/p/er9x
|
||||||
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||||
|
*
|
||||||
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License version 2 as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <memory>
|
||||||
|
#include "gtests.h"
|
||||||
|
|
||||||
|
#include "storage.h"
|
||||||
|
#include "opentxinterface.h"
|
||||||
|
#include "customdebug.h"
|
||||||
|
|
||||||
|
|
||||||
|
using ::testing::TestEventListener;
|
||||||
|
using ::testing::EmptyTestEventListener;
|
||||||
|
using ::testing::Test;
|
||||||
|
using ::testing::TestCase;
|
||||||
|
using ::testing::TestEventListeners;
|
||||||
|
using ::testing::TestInfo;
|
||||||
|
using ::testing::TestPartResult;
|
||||||
|
using ::testing::UnitTest;
|
||||||
|
using ::testing::InitGoogleTest;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
void printColorCode(int color)
|
||||||
|
{
|
||||||
|
#if !GTEST_OS_WINDOWS
|
||||||
|
if (isatty(fileno(stdout)))
|
||||||
|
fprintf(stdout, "\033[0;%dm", color);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces gtest's PrettyUnitTestResultPrinter with something less verbose.
|
||||||
|
* Uses the default printer if/when the messages might be interesting,
|
||||||
|
* e.g. for full error info or tests summary.
|
||||||
|
*/
|
||||||
|
class TersePrinter : public EmptyTestEventListener {
|
||||||
|
public:
|
||||||
|
explicit TersePrinter(TestEventListener * prettyPrinter)
|
||||||
|
: prettyPrinter(prettyPrinter), currentTestInfo(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void OnTestProgramStart(const UnitTest & unit_test)
|
||||||
|
{
|
||||||
|
prettyPrinter->OnTestProgramStart(unit_test);
|
||||||
|
}
|
||||||
|
void OnTestIterationStart(const UnitTest & unit_test, int iteration)
|
||||||
|
{
|
||||||
|
printColorCode(36);
|
||||||
|
fprintf(stdout, "############ ");
|
||||||
|
fprintf(stdout, "Running %d test(s) from %d test case(s), iteration: %d.\n", unit_test.test_to_run_count(), unit_test.test_case_to_run_count(), iteration + 1);
|
||||||
|
printColorCode(0);
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
void OnTestCaseStart(const TestCase & test_case)
|
||||||
|
{
|
||||||
|
prettyPrinter->OnTestCaseStart(test_case);
|
||||||
|
}
|
||||||
|
void OnTestStart(const TestInfo & test_info)
|
||||||
|
{
|
||||||
|
currentTestInfo = &test_info;
|
||||||
|
}
|
||||||
|
void OnTestPartResult(const TestPartResult & test_part_result)
|
||||||
|
{
|
||||||
|
if (test_part_result.failed()) {
|
||||||
|
prettyPrinter->OnTestStart(*currentTestInfo);
|
||||||
|
prettyPrinter->OnTestPartResult(test_part_result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void OnTestEnd(const TestInfo & test_info)
|
||||||
|
{
|
||||||
|
currentTestInfo = NULL;
|
||||||
|
if (test_info.result()->Failed()) {
|
||||||
|
prettyPrinter->OnTestEnd(test_info);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printColorCode(32);
|
||||||
|
fprintf(stdout, "+");
|
||||||
|
printColorCode(0);
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void OnTestCaseEnd(const TestCase & test_case)
|
||||||
|
{
|
||||||
|
fprintf(stdout, "\n");
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
void OnTestIterationEnd(const UnitTest & unit_test, int iteration)
|
||||||
|
{
|
||||||
|
prettyPrinter->OnTestIterationEnd(unit_test, iteration);
|
||||||
|
}
|
||||||
|
void OnTestProgramEnd(const UnitTest & unit_test)
|
||||||
|
{
|
||||||
|
prettyPrinter->OnTestProgramEnd(unit_test);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
// gtest's default unit test result printer.
|
||||||
|
std::unique_ptr<TestEventListener> prettyPrinter;
|
||||||
|
// The currently running TestInfo, if any.
|
||||||
|
const TestInfo * currentTestInfo;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
QCoreApplication app(argc, argv);
|
||||||
|
|
||||||
|
CustomDebug::setFilterRules();
|
||||||
|
registerStorageFactories();
|
||||||
|
registerOpenTxFirmwares();
|
||||||
|
|
||||||
|
InitGoogleTest(&argc, argv);
|
||||||
|
|
||||||
|
// use --verbose option to revert to gtest's default output format
|
||||||
|
bool verbose = false;
|
||||||
|
if (argc > 1 && !strcmp(argv[1], "--verbose"))
|
||||||
|
verbose = true;
|
||||||
|
|
||||||
|
if (!verbose) {
|
||||||
|
TestEventListeners & listeners = UnitTest::GetInstance()->listeners();
|
||||||
|
TestEventListener * defaultPrinter = listeners.Release(listeners.default_result_printer());
|
||||||
|
listeners.Append(new TersePrinter(defaultPrinter));
|
||||||
|
}
|
||||||
|
|
||||||
|
return RUN_ALL_TESTS();
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) OpenTX
|
||||||
|
*
|
||||||
|
* Based on code named
|
||||||
|
* th9x - http://code.google.com/p/th9x
|
||||||
|
* er9x - http://code.google.com/p/er9x
|
||||||
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||||
|
*
|
||||||
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License version 2 as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _GTESTS_H_
|
||||||
|
#define _GTESTS_H_
|
||||||
|
|
||||||
|
#include <QtCore/QString>
|
||||||
|
#include <math.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
// #if defined(PCBTARANIS) || defined(PCBHORUS)
|
||||||
|
// #define RADIO_RESET() \
|
||||||
|
// g_eeGeneral.switchConfig = 0x00007bff
|
||||||
|
// #else
|
||||||
|
// #define RADIO_RESET()
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// inline void SYSTEM_RESET()
|
||||||
|
// {
|
||||||
|
// #if defined(EEPROM)
|
||||||
|
// memset(modelHeaders, 0, sizeof(modelHeaders));
|
||||||
|
// #endif
|
||||||
|
// generalDefault();
|
||||||
|
// g_eeGeneral.templateSetup = 0;
|
||||||
|
// for (int i=0; i<NUM_SWITCHES; i++) {
|
||||||
|
// simuSetSwitch(i, -1);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// inline void MODEL_RESET()
|
||||||
|
// {
|
||||||
|
// memset(&g_model, 0, sizeof(g_model));
|
||||||
|
// memset(&anaInValues, 0, sizeof(anaInValues));
|
||||||
|
// extern uint8_t s_mixer_first_run_done;
|
||||||
|
// s_mixer_first_run_done = false;
|
||||||
|
// lastFlightMode = 255;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// inline void MIXER_RESET()
|
||||||
|
// {
|
||||||
|
// memset(channelOutputs, 0, sizeof(channelOutputs));
|
||||||
|
// memset(chans, 0, sizeof(chans));
|
||||||
|
// memset(ex_chans, 0, sizeof(ex_chans));
|
||||||
|
// memset(act, 0, sizeof(act));
|
||||||
|
// memset(swOn, 0, sizeof(swOn));
|
||||||
|
// mixerCurrentFlightMode = lastFlightMode = 0;
|
||||||
|
// lastAct = 0;
|
||||||
|
// logicalSwitchesReset();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// inline void TELEMETRY_RESET()
|
||||||
|
// {
|
||||||
|
// telemetryData.clear();
|
||||||
|
// telemetryData.rssi.set(100);
|
||||||
|
// for (int i=0; i<MAX_TELEMETRY_SENSORS; i++) {
|
||||||
|
// telemetryItems[i].clear();
|
||||||
|
// }
|
||||||
|
// memclear(g_model.telemetrySensors, sizeof(g_model.telemetrySensors));
|
||||||
|
// }
|
||||||
|
|
||||||
|
class OpenTxTest : public testing::Test
|
||||||
|
{
|
||||||
|
protected: // You should make the members protected s.t. they can be
|
||||||
|
// accessed from sub-classes.
|
||||||
|
|
||||||
|
// virtual void SetUp() will be called before each test is run. You
|
||||||
|
// should define it if you need to initialize the varaibles.
|
||||||
|
// Otherwise, this can be skipped.
|
||||||
|
virtual void SetUp()
|
||||||
|
{
|
||||||
|
// SYSTEM_RESET();
|
||||||
|
// MODEL_RESET();
|
||||||
|
// MIXER_RESET();
|
||||||
|
// modelDefault(0);
|
||||||
|
// RADIO_RESET();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _GTESTS_H_
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
#define TESTS_PATH "@TESTS_PATH@"
|
||||||
Reference in New Issue
Block a user