Skip to content

Commit f2529d4

Browse files
committed
Added tests with the support for Linux and Windows
1 parent a99bfce commit f2529d4

File tree

6 files changed

+192
-1
lines changed

6 files changed

+192
-1
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ x64/
3737
x86/
3838
Debug/
3939
Release/
40-
FileBroadcaster
40+
packages/

FileBroadcaster.sln

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.27703.2047
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FileBroadcaster", "src\FileBroadcaster.vcxproj", "{CB24E1BF-BA1E-405A-809C-7EA285F3AF1E}"
77
EndProject
8+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tests", "tests\tests.vcxproj", "{6E714D4E-EAB6-43B3-AD29-FB75743CA1BD}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|x64 = Debug|x64
@@ -21,6 +23,14 @@ Global
2123
{CB24E1BF-BA1E-405A-809C-7EA285F3AF1E}.Release|x64.Build.0 = Release|x64
2224
{CB24E1BF-BA1E-405A-809C-7EA285F3AF1E}.Release|x86.ActiveCfg = Release|Win32
2325
{CB24E1BF-BA1E-405A-809C-7EA285F3AF1E}.Release|x86.Build.0 = Release|Win32
26+
{6E714D4E-EAB6-43B3-AD29-FB75743CA1BD}.Debug|x64.ActiveCfg = Debug|x64
27+
{6E714D4E-EAB6-43B3-AD29-FB75743CA1BD}.Debug|x64.Build.0 = Debug|x64
28+
{6E714D4E-EAB6-43B3-AD29-FB75743CA1BD}.Debug|x86.ActiveCfg = Debug|Win32
29+
{6E714D4E-EAB6-43B3-AD29-FB75743CA1BD}.Debug|x86.Build.0 = Debug|Win32
30+
{6E714D4E-EAB6-43B3-AD29-FB75743CA1BD}.Release|x64.ActiveCfg = Release|x64
31+
{6E714D4E-EAB6-43B3-AD29-FB75743CA1BD}.Release|x64.Build.0 = Release|x64
32+
{6E714D4E-EAB6-43B3-AD29-FB75743CA1BD}.Release|x86.ActiveCfg = Release|Win32
33+
{6E714D4E-EAB6-43B3-AD29-FB75743CA1BD}.Release|x86.Build.0 = Release|Win32
2434
EndGlobalSection
2535
GlobalSection(SolutionProperties) = preSolution
2636
HideSolutionNode = FALSE

Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@ all:
33
-std=c++14 -pthread \
44
-Ilib/cxxopts/include \
55
-o FileBroadcaster
6+
7+
tests:
8+
g++ tests/Tests.cpp \
9+
-std=c++14 -pthread \
10+
-Ilib/cxxopts/include \
11+
-lgtest \
12+
-o GTests

tests/Tests.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <gtest/gtest.h>
2+
3+
#include "../src/Utils.hpp"
4+
5+
class BytesConverter : public ::testing::TestWithParam<std::tuple<size_t, int>> {
6+
public:
7+
size_t value;
8+
int count;
9+
10+
protected:
11+
void SetUp() override {
12+
std::tie(value, count) = GetParam();
13+
}
14+
};
15+
16+
INSTANTIATE_TEST_CASE_P(
17+
CombinationsTest, BytesConverter,
18+
::testing::Combine(
19+
::testing::Values(0U, 1U, 2U, 1000U, 65535U, 2147483647U),
20+
::testing::Values(4, 8, 16)));
21+
22+
TEST_P(BytesConverter, getIntFromBytes) {
23+
char buffer[16] = { 0 };
24+
25+
Utils::writeBytesFromNumber(buffer, value, count);
26+
27+
size_t result = Utils::getNumberFromBytes(buffer, count);
28+
29+
EXPECT_EQ(result, value);
30+
}
31+
32+
int main(int argc, char** argv) {
33+
testing::InitGoogleTest(&argc, argv);
34+
return RUN_ALL_TESTS();
35+
}

tests/packages.config

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn" version="1.8.0" targetFramework="native" />
4+
</packages>

tests/tests.vcxproj

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<ProjectGuid>{6e714d4e-eab6-43b3-ad29-fb75743ca1bd}</ProjectGuid>
23+
<Keyword>Win32Proj</Keyword>
24+
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
25+
<ConfigurationType>Application</ConfigurationType>
26+
<PlatformToolset>v141</PlatformToolset>
27+
<CharacterSet>Unicode</CharacterSet>
28+
</PropertyGroup>
29+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
30+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
31+
<ImportGroup Label="ExtensionSettings" />
32+
<ImportGroup Label="Shared" />
33+
<ImportGroup Label="PropertySheets" />
34+
<PropertyGroup Label="UserMacros" />
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
36+
<Microsoft-googletest-v140-windesktop-msvcstl-static-rt-dyn-Disable-gtest_main>true</Microsoft-googletest-v140-windesktop-msvcstl-static-rt-dyn-Disable-gtest_main>
37+
</PropertyGroup>
38+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
39+
<Microsoft-googletest-v140-windesktop-msvcstl-static-rt-dyn-Disable-gtest_main>true</Microsoft-googletest-v140-windesktop-msvcstl-static-rt-dyn-Disable-gtest_main>
40+
</PropertyGroup>
41+
<ItemGroup>
42+
<ClCompile Include="test.cpp" />
43+
</ItemGroup>
44+
<ItemGroup>
45+
<ProjectReference Include="..\src\FileBroadcaster.vcxproj">
46+
<Project>{cb24e1bf-ba1e-405a-809c-7ea285f3af1e}</Project>
47+
</ProjectReference>
48+
</ItemGroup>
49+
<ItemGroup>
50+
<None Include="packages.config">
51+
<SubType>Designer</SubType>
52+
</None>
53+
</ItemGroup>
54+
<ItemDefinitionGroup />
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
56+
<ImportGroup Label="ExtensionTargets">
57+
<Import Project="..\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.0\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets" Condition="Exists('..\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.0\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets')" />
58+
</ImportGroup>
59+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
60+
<ClCompile>
61+
<PrecompiledHeader>Use</PrecompiledHeader>
62+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
63+
<Optimization>Disabled</Optimization>
64+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
65+
<MinimalRebuild>true</MinimalRebuild>
66+
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
67+
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
68+
<WarningLevel>Level3</WarningLevel>
69+
</ClCompile>
70+
<Link>
71+
<GenerateDebugInformation>true</GenerateDebugInformation>
72+
<SubSystem>Console</SubSystem>
73+
</Link>
74+
</ItemDefinitionGroup>
75+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
76+
<ClCompile>
77+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
78+
<PrecompiledHeaderFile>
79+
</PrecompiledHeaderFile>
80+
<Optimization>Disabled</Optimization>
81+
<PreprocessorDefinitions>X64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
82+
<MinimalRebuild>true</MinimalRebuild>
83+
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
84+
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
85+
<WarningLevel>Level3</WarningLevel>
86+
<PrecompiledHeaderOutputFile />
87+
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)include;%(AdditionalIncludeDirectories);$(SolutionDir)/lib/cxxopts/include/</AdditionalIncludeDirectories>
88+
</ClCompile>
89+
<Link>
90+
<GenerateDebugInformation>true</GenerateDebugInformation>
91+
<SubSystem>Console</SubSystem>
92+
</Link>
93+
</ItemDefinitionGroup>
94+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
95+
<ClCompile>
96+
<PrecompiledHeader>Use</PrecompiledHeader>
97+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
98+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
99+
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
100+
<WarningLevel>Level3</WarningLevel>
101+
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
102+
</ClCompile>
103+
<Link>
104+
<GenerateDebugInformation>true</GenerateDebugInformation>
105+
<SubSystem>Console</SubSystem>
106+
<OptimizeReferences>true</OptimizeReferences>
107+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
108+
</Link>
109+
</ItemDefinitionGroup>
110+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
111+
<ClCompile>
112+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
113+
<PrecompiledHeaderFile>
114+
</PrecompiledHeaderFile>
115+
<PreprocessorDefinitions>X64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
116+
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
117+
<WarningLevel>Level3</WarningLevel>
118+
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
119+
<PrecompiledHeaderOutputFile />
120+
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)include;%(AdditionalIncludeDirectories);$(SolutionDir)/lib/cxxopts/include/</AdditionalIncludeDirectories>
121+
</ClCompile>
122+
<Link>
123+
<GenerateDebugInformation>true</GenerateDebugInformation>
124+
<SubSystem>Console</SubSystem>
125+
<OptimizeReferences>true</OptimizeReferences>
126+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
127+
</Link>
128+
</ItemDefinitionGroup>
129+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
130+
<PropertyGroup>
131+
<ErrorText>Данный проект ссылается на пакеты NuGet, отсутствующие на этом компьютере. Используйте восстановление пакетов NuGet, чтобы скачать их. Дополнительную информацию см. по адресу: http://go.microsoft.com/fwlink/?LinkID=322105. Отсутствует следующий файл: {0}.</ErrorText>
132+
</PropertyGroup>
133+
<Error Condition="!Exists('..\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.0\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.0\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets'))" />
134+
</Target>
135+
</Project>

0 commit comments

Comments
 (0)