Initial commit
This commit is contained in:
74
tests/.gitignore
vendored
Normal file
74
tests/.gitignore
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
# This file is used to ignore files which are generated
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
*~
|
||||
*.autosave
|
||||
*.a
|
||||
*.core
|
||||
*.moc
|
||||
*.o
|
||||
*.obj
|
||||
*.orig
|
||||
*.rej
|
||||
*.so
|
||||
*.so.*
|
||||
*_pch.h.cpp
|
||||
*_resource.rc
|
||||
*.qm
|
||||
.#*
|
||||
*.*#
|
||||
core
|
||||
!core/
|
||||
tags
|
||||
.DS_Store
|
||||
.directory
|
||||
*.debug
|
||||
Makefile*
|
||||
*.prl
|
||||
*.app
|
||||
moc_*.cpp
|
||||
ui_*.h
|
||||
qrc_*.cpp
|
||||
Thumbs.db
|
||||
*.res
|
||||
*.rc
|
||||
/.qmake.cache
|
||||
/.qmake.stash
|
||||
|
||||
# qtcreator generated files
|
||||
*.pro.user*
|
||||
CMakeLists.txt.user*
|
||||
|
||||
# xemacs temporary files
|
||||
*.flc
|
||||
|
||||
# Vim temporary files
|
||||
.*.swp
|
||||
|
||||
# Visual Studio generated files
|
||||
*.ib_pdb_index
|
||||
*.idb
|
||||
*.ilk
|
||||
*.pdb
|
||||
*.sln
|
||||
*.suo
|
||||
*.vcproj
|
||||
*vcproj.*.*.user
|
||||
*.ncb
|
||||
*.sdf
|
||||
*.opensdf
|
||||
*.vcxproj
|
||||
*vcxproj.*
|
||||
|
||||
# MinGW generated files
|
||||
*.Debug
|
||||
*.Release
|
||||
|
||||
# Python byte code
|
||||
*.pyc
|
||||
|
||||
# Binaries
|
||||
# --------
|
||||
*.dll
|
||||
*.exe
|
||||
|
||||
27
tests/CMakeLists.txt
Normal file
27
tests/CMakeLists.txt
Normal file
@@ -0,0 +1,27 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(adapter LANGUAGES CXX)
|
||||
|
||||
enable_testing()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(googletest
|
||||
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||
GIT_TAG main)
|
||||
|
||||
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
FetchContent_MakeAvailable(googletest)
|
||||
|
||||
enable_testing()
|
||||
|
||||
include_directories(..)
|
||||
|
||||
add_executable(adapter main.cpp tst_adapter.cpp
|
||||
mocks/usbdevicemock.h)
|
||||
add_test(NAME adapter COMMAND adapter)
|
||||
|
||||
target_link_libraries(adapter PRIVATE gmock gtest noolite)
|
||||
7
tests/main.cpp
Normal file
7
tests/main.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
16
tests/mocks/usbdevicemock.h
Normal file
16
tests/mocks/usbdevicemock.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef USBDEVICEMOCK_H
|
||||
#define USBDEVICEMOCK_H
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include "interfaces/iusbdevice.h"
|
||||
|
||||
class UsbDeviceMock : public noolitelib::IUsbDevice
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD(void, openDevice, (uint16_t, uint16_t), (override));
|
||||
MOCK_METHOD(void, close, (), (override));
|
||||
MOCK_METHOD(bool, sendDataToDevice, (unsigned char *, uint16_t, std::chrono::milliseconds), (override));
|
||||
};
|
||||
|
||||
#endif // USBDEVICEMOCK_H
|
||||
20
tests/tst_adapter.cpp
Normal file
20
tests/tst_adapter.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "mocks/usbdevicemock.h"
|
||||
|
||||
#include "src/noolite.h"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
TEST(noolite, createAndDeleteAdapter)
|
||||
{
|
||||
UsbDeviceMock *usbDevice = new UsbDeviceMock();
|
||||
|
||||
EXPECT_CALL(*usbDevice, openDevice(0x16c0, 0x05df)).
|
||||
Times(1);
|
||||
EXPECT_CALL(*usbDevice, close()).
|
||||
Times(1);
|
||||
|
||||
noolitelib::Noolite *adapter = new noolitelib::Noolite(usbDevice);
|
||||
delete adapter;
|
||||
}
|
||||
Reference in New Issue
Block a user