@@ -1,41 +0,0 @@ | |||
| |||
Microsoft Visual Studio Solution File, Format Version 12.00 | |||
# Visual Studio Version 16 | |||
VisualStudioVersion = 16.0.30804.86 | |||
MinimumVisualStudioVersion = 10.0.40219.1 | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "A", "A\A.vcxproj", "{53093C19-B40F-47A8-9392-A223E414830E}" | |||
EndProject | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTest1", "UnitTest1\UnitTest1.vcxproj", "{F2E902DE-0C36-42A7-BF5D-2325F9D270C8}" | |||
EndProject | |||
Global | |||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
Debug|x64 = Debug|x64 | |||
Debug|x86 = Debug|x86 | |||
Release|x64 = Release|x64 | |||
Release|x86 = Release|x86 | |||
EndGlobalSection | |||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | |||
{53093C19-B40F-47A8-9392-A223E414830E}.Debug|x64.ActiveCfg = Debug|x64 | |||
{53093C19-B40F-47A8-9392-A223E414830E}.Debug|x64.Build.0 = Debug|x64 | |||
{53093C19-B40F-47A8-9392-A223E414830E}.Debug|x86.ActiveCfg = Debug|Win32 | |||
{53093C19-B40F-47A8-9392-A223E414830E}.Debug|x86.Build.0 = Debug|Win32 | |||
{53093C19-B40F-47A8-9392-A223E414830E}.Release|x64.ActiveCfg = Release|x64 | |||
{53093C19-B40F-47A8-9392-A223E414830E}.Release|x64.Build.0 = Release|x64 | |||
{53093C19-B40F-47A8-9392-A223E414830E}.Release|x86.ActiveCfg = Release|Win32 | |||
{53093C19-B40F-47A8-9392-A223E414830E}.Release|x86.Build.0 = Release|Win32 | |||
{F2E902DE-0C36-42A7-BF5D-2325F9D270C8}.Debug|x64.ActiveCfg = Debug|x64 | |||
{F2E902DE-0C36-42A7-BF5D-2325F9D270C8}.Debug|x64.Build.0 = Debug|x64 | |||
{F2E902DE-0C36-42A7-BF5D-2325F9D270C8}.Debug|x86.ActiveCfg = Debug|Win32 | |||
{F2E902DE-0C36-42A7-BF5D-2325F9D270C8}.Debug|x86.Build.0 = Debug|Win32 | |||
{F2E902DE-0C36-42A7-BF5D-2325F9D270C8}.Release|x64.ActiveCfg = Release|x64 | |||
{F2E902DE-0C36-42A7-BF5D-2325F9D270C8}.Release|x64.Build.0 = Release|x64 | |||
{F2E902DE-0C36-42A7-BF5D-2325F9D270C8}.Release|x86.ActiveCfg = Release|Win32 | |||
{F2E902DE-0C36-42A7-BF5D-2325F9D270C8}.Release|x86.Build.0 = Release|Win32 | |||
EndGlobalSection | |||
GlobalSection(SolutionProperties) = preSolution | |||
HideSolutionNode = FALSE | |||
EndGlobalSection | |||
GlobalSection(ExtensibilityGlobals) = postSolution | |||
SolutionGuid = {B7DA30AA-170D-4E63-A28E-AD3D6C3C05C2} | |||
EndGlobalSection | |||
EndGlobal |
@@ -1,150 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<ItemGroup Label="ProjectConfigurations"> | |||
<ProjectConfiguration Include="Debug|Win32"> | |||
<Configuration>Debug</Configuration> | |||
<Platform>Win32</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Release|Win32"> | |||
<Configuration>Release</Configuration> | |||
<Platform>Win32</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Debug|x64"> | |||
<Configuration>Debug</Configuration> | |||
<Platform>x64</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Release|x64"> | |||
<Configuration>Release</Configuration> | |||
<Platform>x64</Platform> | |||
</ProjectConfiguration> | |||
</ItemGroup> | |||
<PropertyGroup Label="Globals"> | |||
<VCProjectVersion>16.0</VCProjectVersion> | |||
<Keyword>Win32Proj</Keyword> | |||
<ProjectGuid>{53093c19-b40f-47a8-9392-a223e414830e}</ProjectGuid> | |||
<RootNamespace>A</RootNamespace> | |||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> | |||
</PropertyGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | |||
<ConfigurationType>StaticLibrary</ConfigurationType> | |||
<UseDebugLibraries>true</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<CharacterSet>Unicode</CharacterSet> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | |||
<ConfigurationType>Application</ConfigurationType> | |||
<UseDebugLibraries>false</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<WholeProgramOptimization>true</WholeProgramOptimization> | |||
<CharacterSet>Unicode</CharacterSet> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | |||
<ConfigurationType>Application</ConfigurationType> | |||
<UseDebugLibraries>true</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<CharacterSet>Unicode</CharacterSet> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | |||
<ConfigurationType>Application</ConfigurationType> | |||
<UseDebugLibraries>false</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<WholeProgramOptimization>true</WholeProgramOptimization> | |||
<CharacterSet>Unicode</CharacterSet> | |||
</PropertyGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | |||
<ImportGroup Label="ExtensionSettings"> | |||
</ImportGroup> | |||
<ImportGroup Label="Shared"> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<PropertyGroup Label="UserMacros" /> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<LinkIncremental>true</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<LinkIncremental>false</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<LinkIncremental>true</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<LinkIncremental>false</LinkIncremental> | |||
</PropertyGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<ClCompile> | |||
<WarningLevel>Level3</WarningLevel> | |||
<SDLCheck>true</SDLCheck> | |||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<ConformanceMode>true</ConformanceMode> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Console</SubSystem> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<ClCompile> | |||
<WarningLevel>Level3</WarningLevel> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<IntrinsicFunctions>true</IntrinsicFunctions> | |||
<SDLCheck>true</SDLCheck> | |||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<ConformanceMode>true</ConformanceMode> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Console</SubSystem> | |||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | |||
<OptimizeReferences>true</OptimizeReferences> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<ClCompile> | |||
<WarningLevel>Level3</WarningLevel> | |||
<SDLCheck>true</SDLCheck> | |||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<ConformanceMode>true</ConformanceMode> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Console</SubSystem> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<ClCompile> | |||
<WarningLevel>Level3</WarningLevel> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<IntrinsicFunctions>true</IntrinsicFunctions> | |||
<SDLCheck>true</SDLCheck> | |||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<ConformanceMode>true</ConformanceMode> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Console</SubSystem> | |||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | |||
<OptimizeReferences>true</OptimizeReferences> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemGroup> | |||
<ClInclude Include="add.h" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClCompile Include="add.cpp" /> | |||
</ItemGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | |||
<ImportGroup Label="ExtensionTargets"> | |||
</ImportGroup> | |||
</Project> |
@@ -1,27 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<ItemGroup> | |||
<Filter Include="源文件"> | |||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | |||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | |||
</Filter> | |||
<Filter Include="头文件"> | |||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | |||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions> | |||
</Filter> | |||
<Filter Include="资源文件"> | |||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | |||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | |||
</Filter> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClInclude Include="add.h"> | |||
<Filter>头文件</Filter> | |||
</ClInclude> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClCompile Include="add.cpp"> | |||
<Filter>源文件</Filter> | |||
</ClCompile> | |||
</ItemGroup> | |||
</Project> |
@@ -1,4 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<PropertyGroup /> | |||
</Project> |
@@ -1,5 +0,0 @@ | |||
#include "add.h" | |||
long long add(int x, int y) | |||
{ | |||
return (long long)x + (long long)y; | |||
} |
@@ -1,3 +0,0 @@ | |||
#pragma once | |||
#include <stdio.h> | |||
long long add(int x, int y); |
@@ -1,33 +0,0 @@ | |||
#include "pch.h" | |||
#include "CppUnitTest.h" | |||
#include<Windows.h> | |||
#include <atlstr.h> | |||
#include"../A/add.h" | |||
#define FilePath "..//ex1.ini" | |||
using namespace Microsoft::VisualStudio::CppUnitTestFramework; | |||
namespace UnitTest1 | |||
{ | |||
TEST_CLASS(UnitTest1) | |||
{ | |||
public: | |||
int j = 0; | |||
char str[50][10] = { 0 };//保存ini文件里 节的名字 | |||
int count = CalcCount(50, str);//保存ini文件里 节的个数 | |||
unsigned short i; | |||
TEST_METHOD(TestMethode1) | |||
{ | |||
int nReal;//保存运算结果 | |||
CString na, nb, nExpect; //b保存不同的键值 | |||
for (j = 0; j < count; j++) | |||
{ | |||
GetPrivateProfileString(str[j], "na", " ", na.GetBuffer(20), 20, FilePath); | |||
GetPrivateProfileString(str[j], "nb", " ", nb.GetBuffer(20), 20, FilePath); | |||
GetPrivateProfileString(str[j], "nExpect", " ", nExpect.GetBuffer(20), 20, FilePath); | |||
nReal = add(_ttoi(na), _ttoi(nb)); //_ttoi是CString转为整型 | |||
Assert::AreEqual(nReal, _ttoi(nExpect)); | |||
} | |||
} | |||
}; | |||
} |
@@ -1,180 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<ItemGroup Label="ProjectConfigurations"> | |||
<ProjectConfiguration Include="Debug|Win32"> | |||
<Configuration>Debug</Configuration> | |||
<Platform>Win32</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Release|Win32"> | |||
<Configuration>Release</Configuration> | |||
<Platform>Win32</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Debug|x64"> | |||
<Configuration>Debug</Configuration> | |||
<Platform>x64</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Release|x64"> | |||
<Configuration>Release</Configuration> | |||
<Platform>x64</Platform> | |||
</ProjectConfiguration> | |||
</ItemGroup> | |||
<PropertyGroup Label="Globals"> | |||
<VCProjectVersion>16.0</VCProjectVersion> | |||
<ProjectGuid>{F2E902DE-0C36-42A7-BF5D-2325F9D270C8}</ProjectGuid> | |||
<Keyword>Win32Proj</Keyword> | |||
<RootNamespace>UnitTest1</RootNamespace> | |||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> | |||
<ProjectSubType>NativeUnitTestProject</ProjectSubType> | |||
</PropertyGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | |||
<ConfigurationType>DynamicLibrary</ConfigurationType> | |||
<UseDebugLibraries>true</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<CharacterSet>MultiByte</CharacterSet> | |||
<UseOfMfc>false</UseOfMfc> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | |||
<ConfigurationType>DynamicLibrary</ConfigurationType> | |||
<UseDebugLibraries>false</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<WholeProgramOptimization>true</WholeProgramOptimization> | |||
<CharacterSet>Unicode</CharacterSet> | |||
<UseOfMfc>false</UseOfMfc> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | |||
<ConfigurationType>DynamicLibrary</ConfigurationType> | |||
<UseDebugLibraries>true</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<CharacterSet>Unicode</CharacterSet> | |||
<UseOfMfc>false</UseOfMfc> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | |||
<ConfigurationType>DynamicLibrary</ConfigurationType> | |||
<UseDebugLibraries>false</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<WholeProgramOptimization>true</WholeProgramOptimization> | |||
<CharacterSet>Unicode</CharacterSet> | |||
<UseOfMfc>false</UseOfMfc> | |||
</PropertyGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | |||
<ImportGroup Label="ExtensionSettings"> | |||
</ImportGroup> | |||
<ImportGroup Label="Shared"> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<PropertyGroup Label="UserMacros" /> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<LinkIncremental>true</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<LinkIncremental>true</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<LinkIncremental>false</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<LinkIncremental>false</LinkIncremental> | |||
</PropertyGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<ClCompile> | |||
<PrecompiledHeader>Use</PrecompiledHeader> | |||
<WarningLevel>Level3</WarningLevel> | |||
<SDLCheck>true</SDLCheck> | |||
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<UseFullPaths>true</UseFullPaths> | |||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Windows</SubSystem> | |||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
<AdditionalDependencies>..\A\Debug\add.obj;%(AdditionalDependencies)</AdditionalDependencies> | |||
<GenerateDebugInformation>DebugFull</GenerateDebugInformation> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<ClCompile> | |||
<PrecompiledHeader>Use</PrecompiledHeader> | |||
<WarningLevel>Level3</WarningLevel> | |||
<SDLCheck>true</SDLCheck> | |||
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<UseFullPaths>true</UseFullPaths> | |||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Windows</SubSystem> | |||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<ClCompile> | |||
<PrecompiledHeader>Use</PrecompiledHeader> | |||
<WarningLevel>Level3</WarningLevel> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<IntrinsicFunctions>true</IntrinsicFunctions> | |||
<SDLCheck>true</SDLCheck> | |||
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<UseFullPaths>true</UseFullPaths> | |||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Windows</SubSystem> | |||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | |||
<OptimizeReferences>true</OptimizeReferences> | |||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<ClCompile> | |||
<PrecompiledHeader>Use</PrecompiledHeader> | |||
<WarningLevel>Level3</WarningLevel> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<IntrinsicFunctions>true</IntrinsicFunctions> | |||
<SDLCheck>true</SDLCheck> | |||
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<UseFullPaths>true</UseFullPaths> | |||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Windows</SubSystem> | |||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | |||
<OptimizeReferences>true</OptimizeReferences> | |||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemGroup> | |||
<ClCompile Include="pch.cpp"> | |||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> | |||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader> | |||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> | |||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader> | |||
</ClCompile> | |||
<ClCompile Include="UnitTest1.cpp" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClInclude Include="pch.h" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\A\A.vcxproj"> | |||
<Project>{53093c19-b40f-47a8-9392-a223e414830e}</Project> | |||
</ProjectReference> | |||
</ItemGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | |||
<ImportGroup Label="ExtensionTargets"> | |||
</ImportGroup> | |||
</Project> |
@@ -1,30 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<ItemGroup> | |||
<Filter Include="源文件"> | |||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | |||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | |||
</Filter> | |||
<Filter Include="头文件"> | |||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | |||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions> | |||
</Filter> | |||
<Filter Include="资源文件"> | |||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | |||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | |||
</Filter> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClCompile Include="UnitTest1.cpp"> | |||
<Filter>源文件</Filter> | |||
</ClCompile> | |||
<ClCompile Include="pch.cpp"> | |||
<Filter>源文件</Filter> | |||
</ClCompile> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClInclude Include="pch.h"> | |||
<Filter>头文件</Filter> | |||
</ClInclude> | |||
</ItemGroup> | |||
</Project> |
@@ -1,4 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<PropertyGroup /> | |||
</Project> |
@@ -1,45 +0,0 @@ | |||
// pch.cpp: 与预编译标头对应的源文件 | |||
#include "pch.h" | |||
#include <stdio.h> | |||
#include<Windows.h> | |||
int CalcCount(int n, char(*str)[10]) | |||
{ | |||
TCHAR chSectionNames[2048] = { 0 };//定义一个数组,保存读取节的名字 | |||
char* pSectionName; //保存找到的某个节名字符串的首地址 | |||
int i = 0; //i指向数组chSectionNames的某个位置,从0开始,顺序后移 | |||
int j = 0; //j用来保存下一个节名字符串的首地址相对于当前i的位置偏移量 | |||
int k = 0; //临时变量,用于给str数组赋值 | |||
int m = 0; //临时变量,用于给str数组赋值 | |||
int count = 0; //统计节的个数 | |||
GetPrivateProfileSectionNames(chSectionNames, 2048, "..//ex1.ini");//获取文件中的节名,每个节名以"\0"分割,保存在chSectionNames中 | |||
//要加头文件 | |||
for (i = 0; i < 2048; i++, j++)//对chSectionName中保存的内容进行拆分 | |||
{ | |||
if (chSectionNames[0] == '\0')//如果第一个字符就是0,则说明ini中一个节也没有, | |||
{ | |||
break; | |||
} | |||
if (chSectionNames[i] == '\0') | |||
{ | |||
count++; | |||
pSectionName = &chSectionNames[i - j]; //找到一个0,则说明从这个字符往前,减掉j个偏移量, | |||
//就是一个节名的首地址 | |||
j = -1; //找到一个节名后,j的值要还原,以统计下一个节名地址的偏移量 | |||
//赋成-1是因为节名字符串的最后一个字符0是终止符,不能作为节名 | |||
for (m = 0; m <= strlen(pSectionName); m++)//把找到的节名保存到str中 | |||
{ | |||
str[k][m] = *(pSectionName + m); | |||
} | |||
//str[k][++m] = '\0';//手动给节名加上\0,表示这个节名结束 | |||
k++;//变量自加,用来保存下一个节名 | |||
//在获取节名的时候可以获取该节中键的值,前提是我们知道该节中有哪些键。 | |||
if (chSectionNames[i + 1] == 0) | |||
{ | |||
break; //当两个相邻的字符都是0时,则所有的节名都已找到,循环终止 | |||
} | |||
} | |||
} | |||
return count;//返回节名的个数 | |||
} | |||
// 当使用预编译的头时,需要使用此源文件,编译才能成功。 |
@@ -1,12 +0,0 @@ | |||
// pch.h: 这是预编译标头文件。 | |||
// 下方列出的文件仅编译一次,提高了将来生成的生成性能。 | |||
// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 | |||
// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 | |||
// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 | |||
#ifndef PCH_H | |||
#define PCH_H | |||
int CalcCount(int n, char(*str)[10]); | |||
// 添加要在此处预编译的标头 | |||
#endif //PCH_H |
@@ -1,9 +0,0 @@ | |||
[TestMethod1] | |||
na=12 | |||
nb=4 | |||
nExpect=16 | |||
[TestMethod2] | |||
na=3 | |||
nb=7 | |||
nExpect=10 | |||
@@ -1,122 +0,0 @@ | |||
# add函数说明文档 | |||
## 一、工程说明 | |||
- 本工程的配置类型是一个静态库文件,目的是生成一个可被其他工程调用的静态库,静态库的函数功能是:输入两个int类型的数,返回两数之和。 | |||
## 二、头文件 add.h ,放的是add函数的声明 | |||
```C | |||
#pragma once | |||
#include <stdio.h> | |||
/* | |||
**函数名: add | |||
**参数:int ,int | |||
**返回值:long long | |||
**函数功能:传入两个int类型的参数,对其进行加法运算并返回一个 long long类型的数值,目的是防止两个int类型相加的和超过int的范围,所以这里返回值不用int。 | |||
*/ | |||
long long add(int x, int y); | |||
``` | |||
## 三、源文件 add.cpp ,放的是add函数的定义 | |||
```C | |||
#include "add.h" | |||
long long add(int x, int y) | |||
{ | |||
return (long long)x + (long long)y;//在运算前进行强转 | |||
} | |||
``` | |||
## 四、单元测试 | |||
- 手动创建ini文件并添加测试样例,之后在单元测试的源文件里对ini文件进行读取解析 ,完成以后获取单元测试的结果,保证代码覆盖率在80%以上。其中对ini文件的读取另封装了函数,见下面的源码。 | |||
1. ini文件内容 exl.ini | |||
``` | |||
[TestMethod1] #测试样例1 | |||
na=12 #函数第一个入数 | |||
nb=4 #函数第二个入参 | |||
nExpect=16 #两个入参相加的正确结果 | |||
[TestMethod2] | |||
na=3 | |||
nb=7 | |||
nExpect=10 | |||
``` | |||
2. 读取ini文件的函数 int CalcCount(int n, char(*str)[10]) | |||
```C | |||
/* | |||
**函数功能:获取一个ini文件里有多少个节,并通过二维指针数组将节名带出来。 | |||
* 函数名:CalcCount() | |||
* 入参:int n --------节的个数 | |||
* char (*str)[10] --------二维数组指针,10是节名的长度,可以根据需求修改 | |||
*返回值:int --------返回节的个数 | |||
*/ | |||
int CalcCount(int n, char(*str)[10]) | |||
int CalcCount(int n, char(*str)[10]) | |||
{ | |||
TCHAR chSectionNames[2048] = { 0 };//定义一个数组,保存读取节的名字 | |||
char* pSectionName; //保存找到的某个节名字符串的首地址 | |||
int i = 0; //i指向数组chSectionNames的某个位置,从0开始,顺序后移 | |||
int j = 0; //j用来保存下一个节名字符串的首地址相对于当前i的位置偏移量 | |||
int k = 0; //临时变量,用于给str数组赋值 | |||
int m = 0; //临时变量,用于给str数组赋值 | |||
int count = 0; //统计节的个数 | |||
GetPrivateProfileSectionNames(chSectionNames, 2048, "..//ex1.ini");//获取文件中的节名,每个节名以"\0"分割,保存在chSectionNames中 | |||
//要加头文件 | |||
for (i = 0; i < 2048; i++, j++)//对chSectionName中保存的内容进行拆分 | |||
{ | |||
if (chSectionNames[0] == '\0')//如果第一个字符就是0,则说明ini中一个节也没有, | |||
{ | |||
break; | |||
} | |||
if (chSectionNames[i] == '\0') | |||
{ | |||
count++; | |||
pSectionName = &chSectionNames[i - j]; //找到一个0,则说明从这个字符往前,减掉j个偏移量, | |||
//就是一个节名的首地址 | |||
j = -1; //找到一个节名后,j的值要还原,以统计下一个节名地址的偏移量 | |||
//赋成-1是因为节名字符串的最后一个字符0是终止符,不能作为节名 | |||
for (m = 0; m <= strlen(pSectionName); m++)//把找到的节名保存到str中 | |||
{ | |||
str[k][m] = *(pSectionName + m); | |||
} | |||
k++;//变量自加,用来保存下一个节名 | |||
//在获取节名的时候可以获取该节中键的值,前提是我们知道该节中有哪些键。 | |||
if (chSectionNames[i + 1] == 0) | |||
{ | |||
break; //当两个相邻的字符都是0时,则所有的节名都已找到,循环终止 | |||
} | |||
} | |||
} | |||
return count;//返回节名的个数 | |||
} | |||
``` | |||
3. 单元测试源码 UNITest1.cpp | |||
```C | |||
#include "pch.h" | |||
#include "CppUnitTest.h" | |||
#include<Windows.h> | |||
#include <atlstr.h> | |||
#include"../A/add.h" | |||
#define FilePath "../ex1.ini" | |||
using namespace Microsoft::VisualStudio::CppUnitTestFramework; | |||
namespace UnitTest1 | |||
{ | |||
TEST_CLASS(UnitTest1) | |||
{ | |||
public: | |||
int j = 0;//循环变量,用来访问ini文件中的 节 | |||
char str[50][10] = { 0 };//存放ini文件里 节的名字 | |||
int count = CalcCount(50, str);//保存ini文件里 节的个数 | |||
TEST_METHOD(TestMethode1) | |||
{ | |||
int nReal;//保存运算结果 | |||
CString na, nb, nExpect; //保存测试样例中的键值 | |||
for (j = 0; j < count; j++)//遍历读取测试样例 | |||
{ | |||
GetPrivateProfileString(str[j], "na", " ", na.GetBuffer(20), 20, FilePath);//读取第一个参数,保存在na里 | |||
GetPrivateProfileString(str[j], "nb", " ", nb.GetBuffer(20), 20, FilePath);//读取第二个参数,保存在nb里 | |||
GetPrivateProfileString(str[j], "nExpect", " ", nExpect.GetBuffer(20), 20, FilePath);//读取正确的值,保存在nExpect里 | |||
nReal = add(_ttoi(na), _ttoi(nb)); //_ttoi是CString转为整型,把运算结果给nReal | |||
Assert::AreEqual(nReal, _ttoi(nExpect));\\对比运算结果和正确结果 | |||
} | |||
} | |||
}; | |||
} | |||
``` | |||
4. 附加测试结果 | |||
 |
@@ -1,41 +0,0 @@ | |||
| |||
Microsoft Visual Studio Solution File, Format Version 12.00 | |||
# Visual Studio Version 16 | |||
VisualStudioVersion = 16.0.30804.86 | |||
MinimumVisualStudioVersion = 10.0.40219.1 | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FourOperator", "FourOperator\FourOperator.vcxproj", "{84D3E0B3-C22A-4F07-9329-8220A2F2EABD}" | |||
EndProject | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTest1", "UnitTest1\UnitTest1.vcxproj", "{B68018EC-3312-470A-898A-89F46F36C582}" | |||
EndProject | |||
Global | |||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
Debug|x64 = Debug|x64 | |||
Debug|x86 = Debug|x86 | |||
Release|x64 = Release|x64 | |||
Release|x86 = Release|x86 | |||
EndGlobalSection | |||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | |||
{84D3E0B3-C22A-4F07-9329-8220A2F2EABD}.Debug|x64.ActiveCfg = Debug|x64 | |||
{84D3E0B3-C22A-4F07-9329-8220A2F2EABD}.Debug|x64.Build.0 = Debug|x64 | |||
{84D3E0B3-C22A-4F07-9329-8220A2F2EABD}.Debug|x86.ActiveCfg = Debug|Win32 | |||
{84D3E0B3-C22A-4F07-9329-8220A2F2EABD}.Debug|x86.Build.0 = Debug|Win32 | |||
{84D3E0B3-C22A-4F07-9329-8220A2F2EABD}.Release|x64.ActiveCfg = Release|x64 | |||
{84D3E0B3-C22A-4F07-9329-8220A2F2EABD}.Release|x64.Build.0 = Release|x64 | |||
{84D3E0B3-C22A-4F07-9329-8220A2F2EABD}.Release|x86.ActiveCfg = Release|Win32 | |||
{84D3E0B3-C22A-4F07-9329-8220A2F2EABD}.Release|x86.Build.0 = Release|Win32 | |||
{B68018EC-3312-470A-898A-89F46F36C582}.Debug|x64.ActiveCfg = Debug|x64 | |||
{B68018EC-3312-470A-898A-89F46F36C582}.Debug|x64.Build.0 = Debug|x64 | |||
{B68018EC-3312-470A-898A-89F46F36C582}.Debug|x86.ActiveCfg = Debug|Win32 | |||
{B68018EC-3312-470A-898A-89F46F36C582}.Debug|x86.Build.0 = Debug|Win32 | |||
{B68018EC-3312-470A-898A-89F46F36C582}.Release|x64.ActiveCfg = Release|x64 | |||
{B68018EC-3312-470A-898A-89F46F36C582}.Release|x64.Build.0 = Release|x64 | |||
{B68018EC-3312-470A-898A-89F46F36C582}.Release|x86.ActiveCfg = Release|Win32 | |||
{B68018EC-3312-470A-898A-89F46F36C582}.Release|x86.Build.0 = Release|Win32 | |||
EndGlobalSection | |||
GlobalSection(SolutionProperties) = preSolution | |||
HideSolutionNode = FALSE | |||
EndGlobalSection | |||
GlobalSection(ExtensibilityGlobals) = postSolution | |||
SolutionGuid = {D74B31F8-B3E0-4D9E-8BFC-F0959A7F9337} | |||
EndGlobalSection | |||
EndGlobal |
@@ -1,156 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<ItemGroup Label="ProjectConfigurations"> | |||
<ProjectConfiguration Include="Debug|Win32"> | |||
<Configuration>Debug</Configuration> | |||
<Platform>Win32</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Release|Win32"> | |||
<Configuration>Release</Configuration> | |||
<Platform>Win32</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Debug|x64"> | |||
<Configuration>Debug</Configuration> | |||
<Platform>x64</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Release|x64"> | |||
<Configuration>Release</Configuration> | |||
<Platform>x64</Platform> | |||
</ProjectConfiguration> | |||
</ItemGroup> | |||
<PropertyGroup Label="Globals"> | |||
<VCProjectVersion>16.0</VCProjectVersion> | |||
<Keyword>Win32Proj</Keyword> | |||
<ProjectGuid>{84d3e0b3-c22a-4f07-9329-8220a2f2eabd}</ProjectGuid> | |||
<RootNamespace>FourOperator</RootNamespace> | |||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> | |||
</PropertyGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | |||
<ConfigurationType>Application</ConfigurationType> | |||
<UseDebugLibraries>true</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<CharacterSet>MultiByte</CharacterSet> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | |||
<ConfigurationType>Application</ConfigurationType> | |||
<UseDebugLibraries>false</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<WholeProgramOptimization>true</WholeProgramOptimization> | |||
<CharacterSet>Unicode</CharacterSet> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | |||
<ConfigurationType>Application</ConfigurationType> | |||
<UseDebugLibraries>true</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<CharacterSet>Unicode</CharacterSet> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | |||
<ConfigurationType>Application</ConfigurationType> | |||
<UseDebugLibraries>false</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<WholeProgramOptimization>true</WholeProgramOptimization> | |||
<CharacterSet>Unicode</CharacterSet> | |||
</PropertyGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | |||
<ImportGroup Label="ExtensionSettings"> | |||
</ImportGroup> | |||
<ImportGroup Label="Shared"> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<PropertyGroup Label="UserMacros" /> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<LinkIncremental>true</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<LinkIncremental>false</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<LinkIncremental>true</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<LinkIncremental>false</LinkIncremental> | |||
</PropertyGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<ClCompile> | |||
<WarningLevel>Level3</WarningLevel> | |||
<SDLCheck>true</SDLCheck> | |||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<ConformanceMode>true</ConformanceMode> | |||
<AdditionalIncludeDirectories>..\..\add\A\A;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Console</SubSystem> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
<AdditionalLibraryDirectories>..\..\..\add\A\Debug</AdditionalLibraryDirectories> | |||
<AdditionalDependencies>A.lib;%(AdditionalDependencies)</AdditionalDependencies> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<ClCompile> | |||
<WarningLevel>Level3</WarningLevel> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<IntrinsicFunctions>true</IntrinsicFunctions> | |||
<SDLCheck>true</SDLCheck> | |||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<ConformanceMode>true</ConformanceMode> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Console</SubSystem> | |||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | |||
<OptimizeReferences>true</OptimizeReferences> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<ClCompile> | |||
<WarningLevel>Level3</WarningLevel> | |||
<SDLCheck>true</SDLCheck> | |||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<ConformanceMode>true</ConformanceMode> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Console</SubSystem> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<ClCompile> | |||
<WarningLevel>Level3</WarningLevel> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<IntrinsicFunctions>true</IntrinsicFunctions> | |||
<SDLCheck>true</SDLCheck> | |||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<ConformanceMode>true</ConformanceMode> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Console</SubSystem> | |||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | |||
<OptimizeReferences>true</OptimizeReferences> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemGroup> | |||
<ClCompile Include="dev.cpp" /> | |||
<ClCompile Include="main.cpp" /> | |||
<ClCompile Include="Opera_api.cpp" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClInclude Include="dev.h" /> | |||
<ClInclude Include="Opera_api.h" /> | |||
</ItemGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | |||
<ImportGroup Label="ExtensionTargets"> | |||
</ImportGroup> | |||
</Project> |
@@ -1,36 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<ItemGroup> | |||
<Filter Include="源文件"> | |||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | |||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | |||
</Filter> | |||
<Filter Include="头文件"> | |||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | |||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions> | |||
</Filter> | |||
<Filter Include="资源文件"> | |||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | |||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | |||
</Filter> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClInclude Include="Opera_api.h"> | |||
<Filter>头文件</Filter> | |||
</ClInclude> | |||
<ClInclude Include="dev.h"> | |||
<Filter>头文件</Filter> | |||
</ClInclude> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClCompile Include="main.cpp"> | |||
<Filter>源文件</Filter> | |||
</ClCompile> | |||
<ClCompile Include="Opera_api.cpp"> | |||
<Filter>源文件</Filter> | |||
</ClCompile> | |||
<ClCompile Include="dev.cpp"> | |||
<Filter>源文件</Filter> | |||
</ClCompile> | |||
</ItemGroup> | |||
</Project> |
@@ -1,4 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<PropertyGroup /> | |||
</Project> |
@@ -1,35 +0,0 @@ | |||
#pragma once | |||
#include "Opera_api.h" | |||
#include"../../../add/A/A/add.h" | |||
//封装的加法函数 | |||
long long add_api(int x, int y) | |||
{ | |||
long long res = add(x, y); | |||
printf("%d + %d = %lld\n", x, y, res); | |||
return res; | |||
} | |||
//.封装的减法函数 | |||
int sub_api(int x, int y) | |||
{ | |||
printf("%d - %d = %d\n", x, y, x - y); | |||
return x - y; | |||
} | |||
//封装的乘法函数 | |||
long long mul_api(int x, int y) | |||
{ | |||
long long res; | |||
HMODULE hdll = LoadLibrary("../../../mul/C/Debug/C.dll"); | |||
if (hdll != NULL) | |||
{ | |||
MulFunc MUL1 = (MulFunc)GetProcAddress(hdll, (char*)(1)); | |||
if (MUL1 != NULL) | |||
{ | |||
res = MUL1(x,y); | |||
return res; | |||
} | |||
FreeLibrary(hdll); | |||
} | |||
} | |||
@@ -1,10 +0,0 @@ | |||
#pragma once | |||
#include"sub.h" | |||
#include<Windows.h> | |||
#include <stdio.h> | |||
#pragma comment(lib,"./B.lib") | |||
typedef int(WINAPI* MulFunc)(int x, int y); | |||
long long mul_api(int x, int y); | |||
int sub_api(int x, int y); | |||
long long add_api(int x, int y); |
@@ -1,15 +0,0 @@ | |||
#include "dev.h" | |||
//封装的除法函数 | |||
int dev(int x, int y) | |||
{ | |||
if (y == 0) | |||
{ | |||
printf("除数不能为0!\n"); | |||
return 0; | |||
} | |||
else | |||
{ | |||
printf("%d / %d = %d\n", x, y, x / y); | |||
return x / y; | |||
} | |||
} |
@@ -1,7 +0,0 @@ | |||
#pragma once | |||
#pragma once | |||
#include"sub.h" | |||
#include<Windows.h> | |||
#include <stdio.h> | |||
int dev(int x, int y); |
@@ -1,13 +0,0 @@ | |||
#include "Opera_api.h" | |||
#include "dev.h" | |||
int main() | |||
{ | |||
int a = 2147483647, b = 2; | |||
add_api(a, b);//调用 加法接口add_api | |||
sub_api(a, b);//调用 减法接口sub_api | |||
mul_api(a, b); //调用 乘法接口mul_api | |||
dev(a, b);//调用 除法接口dev_api | |||
return 0; | |||
} |
@@ -1,13 +0,0 @@ | |||
#ifndef _SUB_H_ | |||
#define _SUB_H_ | |||
#ifdef sub_EXPORTS | |||
#define sub_EXPORTS _declspec(dllexport) | |||
#else | |||
#define sub_EXPORTS _declspec(dllimport) | |||
#endif | |||
sub_EXPORTS int sub(int x, int y); | |||
#endif | |||
@@ -1,140 +0,0 @@ | |||
#pragma once | |||
#include "pch.h" | |||
#include "CppUnitTest.h" | |||
#include"../FourOperator/dev.h" | |||
#include<Windows.h> | |||
#include <atlstr.h> | |||
#include <stdio.h> | |||
#define FilePath "..//ex1.ini" | |||
using namespace Microsoft::VisualStudio::CppUnitTestFramework; | |||
namespace UnitTest1 | |||
{ | |||
TEST_CLASS(UnitTest1) | |||
{ | |||
public: | |||
#if 1 | |||
int j = 0; | |||
char str[50][10] = { 0 };//保存ini文件里 节的名字 | |||
int count = CalcCount(50, str);//保存ini文件里 节的个数 | |||
unsigned short i; | |||
TEST_METHOD(TestMethode1) | |||
{ | |||
int nReal;//保存运算结果 | |||
CString na, nb, nExpect; //b保存不同的键值 | |||
for (j = 0; j < count; j++) | |||
{ | |||
GetPrivateProfileString(str[j], "na", " ", na.GetBuffer(20), 20, FilePath); | |||
GetPrivateProfileString(str[j], "nb", " ", nb.GetBuffer(20), 20, FilePath); | |||
GetPrivateProfileString(str[j], "nExpect", " ", nExpect.GetBuffer(20), 20, FilePath); | |||
nReal = dev(_ttoi(na), _ttoi(nb)); //_ttoi是CString转为整型 | |||
Assert::AreEqual(nReal, _ttoi(nExpect)); | |||
} | |||
} | |||
}; | |||
} | |||
#endif | |||
#if 0 | |||
TEST_METHOD(a) | |||
{ | |||
int nReal; | |||
CString na, nb, nExpect; | |||
//这一段程序是往 ex1.ini 文件中写入测试样例 | |||
//WritePrivateProfileString(_T("a"), _T("na"), _T("6"), _T("../ex1.ini")); | |||
//WritePrivateProfileString(_T("a"), _T("nb"), _T("2"), _T("../ex1.ini")); | |||
//WritePrivateProfileString(_T("a"), _T("QExpect"), _T("3"), _T("../ex1.ini")); | |||
//这一段程序是从 ex1.ini 文件读取测试样例 | |||
GetPrivateProfileString(_T("a"), _T("na"), _T(" "), na.GetBuffer(20), 20, _T(FilePath)); | |||
GetPrivateProfileString(_T("a"), _T("nb"), _T(" "), nb.GetBuffer(20), 20, _T(FilePath)); | |||
GetPrivateProfileString(_T("a"), _T("nExpect"), _T(" "), nExpect.GetBuffer(20), 20, _T(FilePath)); | |||
nReal = dev(_ttoi(na), _ttoi(nb)); | |||
Assert::AreEqual(nReal, _ttoi(nExpect)); | |||
} | |||
TEST_METHOD(b) | |||
{ | |||
int nReal; | |||
CString na, nb, nExpect; | |||
GetPrivateProfileString(_T("b"), _T("na"), _T(" "), na.GetBuffer(20), 20, _T(FilePath)); | |||
GetPrivateProfileString(_T("b"), _T("nb"), _T(" "), nb.GetBuffer(20), 20, _T(FilePath)); | |||
GetPrivateProfileString(_T("b"), _T("nExpect"), _T(" "), nExpect.GetBuffer(20), 20, _T(FilePath)); | |||
nReal = dev(_ttoi(na), _ttoi(nb)); | |||
Assert::AreEqual(nReal, _ttoi(nExpect)); | |||
} | |||
TEST_METHOD(c) | |||
{ | |||
int nReal; | |||
CString na, nb, nExpect; | |||
GetPrivateProfileString(_T("c"), _T("na"), _T(" "), na.GetBuffer(20), 20, _T(FilePath)); | |||
GetPrivateProfileString(_T("c"), _T("nb"), _T(" "), nb.GetBuffer(20), 20, _T(FilePath)); | |||
GetPrivateProfileString(_T("c"), _T("nExpect"), _T(" "), nExpect.GetBuffer(20), 20, _T(FilePath)); | |||
nReal = dev(_ttoi(na), _ttoi(nb)); | |||
Assert::AreEqual(nReal, _ttoi(nExpect)); | |||
} | |||
TEST_METHOD(TestMethod3) | |||
{ | |||
int nReal; | |||
CString na, nb, nExpect; | |||
GetPrivateProfileString("d", "na", " ", na.GetBuffer(20), 20, FilePath); | |||
GetPrivateProfileString("d", "nb", " ", nb.GetBuffer(20), 20, FilePath); | |||
GetPrivateProfileString("d", "nExpect", " ", nExpect.GetBuffer(20), 20, FilePath); | |||
nReal = dev(_ttoi(na), _ttoi(nb)); | |||
Assert::AreEqual(nReal, _ttoi(nExpect)); | |||
} | |||
#endif | |||
@@ -1,174 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<ItemGroup Label="ProjectConfigurations"> | |||
<ProjectConfiguration Include="Debug|Win32"> | |||
<Configuration>Debug</Configuration> | |||
<Platform>Win32</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Release|Win32"> | |||
<Configuration>Release</Configuration> | |||
<Platform>Win32</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Debug|x64"> | |||
<Configuration>Debug</Configuration> | |||
<Platform>x64</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Release|x64"> | |||
<Configuration>Release</Configuration> | |||
<Platform>x64</Platform> | |||
</ProjectConfiguration> | |||
</ItemGroup> | |||
<PropertyGroup Label="Globals"> | |||
<VCProjectVersion>16.0</VCProjectVersion> | |||
<ProjectGuid>{B68018EC-3312-470A-898A-89F46F36C582}</ProjectGuid> | |||
<Keyword>Win32Proj</Keyword> | |||
<RootNamespace>UnitTest1</RootNamespace> | |||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> | |||
<ProjectSubType>NativeUnitTestProject</ProjectSubType> | |||
</PropertyGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | |||
<ConfigurationType>DynamicLibrary</ConfigurationType> | |||
<UseDebugLibraries>true</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<UseOfMfc>false</UseOfMfc> | |||
<CharacterSet>MultiByte</CharacterSet> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | |||
<ConfigurationType>DynamicLibrary</ConfigurationType> | |||
<UseDebugLibraries>false</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<WholeProgramOptimization>true</WholeProgramOptimization> | |||
<CharacterSet>Unicode</CharacterSet> | |||
<UseOfMfc>false</UseOfMfc> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | |||
<ConfigurationType>DynamicLibrary</ConfigurationType> | |||
<UseDebugLibraries>true</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<CharacterSet>Unicode</CharacterSet> | |||
<UseOfMfc>false</UseOfMfc> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | |||
<ConfigurationType>DynamicLibrary</ConfigurationType> | |||
<UseDebugLibraries>false</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<WholeProgramOptimization>true</WholeProgramOptimization> | |||
<CharacterSet>Unicode</CharacterSet> | |||
<UseOfMfc>false</UseOfMfc> | |||
</PropertyGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | |||
<ImportGroup Label="ExtensionSettings"> | |||
</ImportGroup> | |||
<ImportGroup Label="Shared"> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<PropertyGroup Label="UserMacros" /> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<LinkIncremental>true</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<LinkIncremental>true</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<LinkIncremental>false</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<LinkIncremental>false</LinkIncremental> | |||
</PropertyGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<ClCompile> | |||
<PrecompiledHeader>Use</PrecompiledHeader> | |||
<WarningLevel>Level3</WarningLevel> | |||
<SDLCheck>true</SDLCheck> | |||
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
<PreprocessorDefinitions>WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<UseFullPaths>true</UseFullPaths> | |||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Windows</SubSystem> | |||
<GenerateDebugInformation>DebugFull</GenerateDebugInformation> | |||
<AdditionalDependencies>..\FourOperator\Debug\dev.obj</AdditionalDependencies> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<ClCompile> | |||
<PrecompiledHeader>Use</PrecompiledHeader> | |||
<WarningLevel>Level3</WarningLevel> | |||
<SDLCheck>true</SDLCheck> | |||
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<UseFullPaths>true</UseFullPaths> | |||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Windows</SubSystem> | |||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<ClCompile> | |||
<PrecompiledHeader>Use</PrecompiledHeader> | |||
<WarningLevel>Level3</WarningLevel> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<IntrinsicFunctions>true</IntrinsicFunctions> | |||
<SDLCheck>true</SDLCheck> | |||
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<UseFullPaths>true</UseFullPaths> | |||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Windows</SubSystem> | |||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | |||
<OptimizeReferences>true</OptimizeReferences> | |||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<ClCompile> | |||
<PrecompiledHeader>Use</PrecompiledHeader> | |||
<WarningLevel>Level3</WarningLevel> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<IntrinsicFunctions>true</IntrinsicFunctions> | |||
<SDLCheck>true</SDLCheck> | |||
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<UseFullPaths>true</UseFullPaths> | |||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Windows</SubSystem> | |||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | |||
<OptimizeReferences>true</OptimizeReferences> | |||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemGroup> | |||
<ClCompile Include="pch.cpp"> | |||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> | |||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader> | |||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> | |||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader> | |||
</ClCompile> | |||
<ClCompile Include="UnitTest1.cpp" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClInclude Include="pch.h" /> | |||
</ItemGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | |||
<ImportGroup Label="ExtensionTargets"> | |||
</ImportGroup> | |||
</Project> |
@@ -1,30 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<ItemGroup> | |||
<Filter Include="源文件"> | |||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | |||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | |||
</Filter> | |||
<Filter Include="头文件"> | |||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | |||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions> | |||
</Filter> | |||
<Filter Include="资源文件"> | |||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | |||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | |||
</Filter> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClCompile Include="UnitTest1.cpp"> | |||
<Filter>源文件</Filter> | |||
</ClCompile> | |||
<ClCompile Include="pch.cpp"> | |||
<Filter>源文件</Filter> | |||
</ClCompile> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClInclude Include="pch.h"> | |||
<Filter>头文件</Filter> | |||
</ClInclude> | |||
</ItemGroup> | |||
</Project> |
@@ -1,4 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<PropertyGroup /> | |||
</Project> |
@@ -1,44 +0,0 @@ | |||
// pch.cpp: 与预编译标头对应的源文件 | |||
#pragma once | |||
#include "pch.h" | |||
int CalcCount(int n, char(*str)[10]) | |||
{ | |||
TCHAR chSectionNames[2048] = { 0 };//定义一个数组,保存读取节的名字 | |||
char* pSectionName; //保存找到的某个节名字符串的首地址 | |||
int i = 0; //i指向数组chSectionNames的某个位置,从0开始,顺序后移 | |||
int j = 0; //j用来保存下一个节名字符串的首地址相对于当前i的位置偏移量 | |||
int k = 0; //临时变量,用于给str数组赋值 | |||
int m = 0; //临时变量,用于给str数组赋值 | |||
int count = 0; //统计节的个数 | |||
GetPrivateProfileSectionNames(chSectionNames, 2048, "..//ex1.ini");//获取文件中的节名,每个节名以"\0"分割,保存在chSectionNames中 | |||
//要加头文件 | |||
for (i = 0; i < 2048; i++, j++)//对chSectionName中保存的内容进行拆分 | |||
{ | |||
if (chSectionNames[0] == '\0')//如果第一个字符就是0,则说明ini中一个节也没有, | |||
{ | |||
break; | |||
} | |||
if (chSectionNames[i] == '\0') | |||
{ | |||
count++; | |||
pSectionName = &chSectionNames[i - j]; //找到一个0,则说明从这个字符往前,减掉j个偏移量, | |||
//就是一个节名的首地址 | |||
j = -1; //找到一个节名后,j的值要还原,以统计下一个节名地址的偏移量 | |||
//赋成-1是因为节名字符串的最后一个字符0是终止符,不能作为节名 | |||
for (m = 0; m <= strlen(pSectionName); m++)//把找到的节名保存到str中 | |||
{ | |||
str[k][m] = *(pSectionName + m); | |||
} | |||
//str[k][++m] = '\0';//手动给节名加上\0,表示这个节名结束 | |||
k++;//变量自加,用来保存下一个节名 | |||
//在获取节名的时候可以获取该节中键的值,前提是我们知道该节中有哪些键。 | |||
if (chSectionNames[i + 1] == 0) | |||
{ | |||
break; //当两个相邻的字符都是0时,则所有的节名都已找到,循环终止 | |||
} | |||
} | |||
} | |||
return count;//返回节名的个数 | |||
} | |||
// 当使用预编译的头时,需要使用此源文件,编译才能成功。 |
@@ -1,14 +0,0 @@ | |||
// pch.h: 这是预编译标头文件。 | |||
// 下方列出的文件仅编译一次,提高了将来生成的生成性能。 | |||
// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 | |||
// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 | |||
// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 | |||
#ifndef PCH_H | |||
#define PCH_H | |||
#include <stdio.h> | |||
#include<Windows.h> | |||
// 添加要在此处预编译的标头 | |||
int CalcCount(int n, char(*str)[10]); | |||
#endif //PCH_H |
@@ -1,21 +0,0 @@ | |||
[a] | |||
na=6 | |||
nb=2 | |||
nExpect=3 | |||
[b] | |||
na=4 | |||
nb=2 | |||
nExpect=2 | |||
[c] | |||
na=3 | |||
nb=0 | |||
nExpect=0 | |||
[d] | |||
na=100 | |||
nb=10 | |||
nExpect=10 | |||
[e] | |||
na=100 | |||
nb=10 | |||
nExpect=10 | |||
@@ -1,229 +0,0 @@ | |||
# dev函数说明文档 | |||
## 一、工程说明 | |||
- 本工程的配置类型是一个exe可执行文件,工程内存在四个函数接口,分别为加、减、乘、除。加法函数接口是调用add静态库实现;减法函数接口是采用在工程中配置加载sub动态库的方式实现;乘法接口以运行时加载动态库mul的方式实现;除法接口调用本身函数的方式实现。 | |||
## 二、工程文件 | |||
1. 除法函数 | |||
- 头文件 dev.h ,放的是dev的声明 | |||
```C | |||
#pragma once | |||
#include<Windows.h> | |||
#include <stdio.h> | |||
/* | |||
**函数名: dev | |||
**参数:int ,int | |||
**返回值:int | |||
**函数功能:传入两个int类型的参数,对其进行除法运算并返回两数之商。 | |||
*/ | |||
int dev(int x, int y); | |||
``` | |||
- 源文件 dev.cpp ,放的是dev函数的定义 | |||
```C | |||
#include "dev.h" | |||
int dev(int x, int y) | |||
{ | |||
if (y == 0) | |||
{ | |||
printf("除数不能为0!\n"); | |||
return 0; | |||
} | |||
else | |||
{ | |||
printf("%d / %d = %d\n", x, y, x / y); | |||
return x / y; | |||
} | |||
} | |||
``` | |||
2. 加、减、乘、接口 | |||
- 头文件 Oper_api.h ,放的是add_api,sub_api,mul_api接口声明 | |||
```C | |||
#pragma once | |||
#include"sub.h" | |||
#include<Windows.h> | |||
#include <stdio.h> | |||
#pragma comment(lib,"./B.lib") | |||
typedef int(WINAPI* MulFunc)(int x, int y); | |||
/* | |||
**函数名: add_api | |||
**参数:int ,int | |||
**返回值:long long | |||
**函数功能:传入两个int类型的参数,调用静态库add函数的方式实现。 | |||
*/ | |||
long long add_api(int x, int y); | |||
/* | |||
**函数名: sub_api | |||
**参数:int ,int | |||
**返回值:int | |||
**函数功能:传入两个int类型的参数,调用动态库sub函数的方式实现。 | |||
*/ | |||
int sub_api(int x, int y); | |||
/* | |||
**函数名: mul_api | |||
**参数:int ,int | |||
**返回值:long long | |||
**函数功能:传入两个int类型的参数,运行时加载动态库mul,实现乘法运算。 | |||
*/ | |||
void mul_api(int x, int y); | |||
``` | |||
- 源文件 Oper_api.cpp ,放的是add_api,sub_api,mul_api接口定义 | |||
```C | |||
#pragma once | |||
#include "Opera_api.h" | |||
#include"add.h" | |||
//函数接口add_api的实现 | |||
long long add_api(int x, int y) | |||
{ | |||
long long res = add(x, y); | |||
printf("%d + %d = %lld\n", x, y, res); | |||
return res; | |||
} | |||
//函数接口sub_api的实现 | |||
int sub_api(int x, int y) | |||
{ | |||
printf("%d - %d = %d\n", x, y, x - y); | |||
return x - y; | |||
} | |||
//函数接口mul_api的实现 | |||
long long mul_api(int x, int y) | |||
{ | |||
HMODULE hdll = LoadLibrary("../../C/Debug/C.dll"); | |||
if (hdll != NULL) | |||
{ | |||
MulFunc MUL1 = (MulFunc)GetProcAddress(hdll, (char*)(1)); | |||
if (MUL1 != NULL) | |||
{ | |||
printf("%d * %d = %lld\n", x, y, MUL1(x, y)); | |||
return MUL1(x, y); | |||
} | |||
FreeLibrary(hdll); | |||
} | |||
} | |||
``` | |||
3. 调用函数 main.c ,对接口进行调用 | |||
```C | |||
#include "Opera_api.h" | |||
#include "dev.h" | |||
int main() | |||
{ | |||
int a = 2147483647, b = 2; | |||
add_api(a, b);//调用 加法接口add_api | |||
sub_api(a, b);//调用 减法接口sub_api | |||
mul_api(a, b); //调用 乘法接口mul_api | |||
dev(a, b);//调用 除法接口dev_api | |||
return 0; | |||
} | |||
``` | |||
4. 运行结果如下: | |||
 | |||
## 三、单元测试 | |||
- 手动创建ini文件并添加测试样例,之后在单元测试的源文件里对ini文件进行读取解析 ,完成以后获取单元测试的结果,保证代码覆盖率在80%以上。其中对ini文件的读取另封装了函数,见下面的源码。 | |||
1. ini文件内容 exl.ini | |||
``` | |||
[TestMethod1] #测试样例1 | |||
na=10 #函数第一个入数 | |||
nb=2 #函数第二个入参 | |||
nExpect=5 #两个入参相除的正确结果 | |||
[TestMethod2] | |||
na=12 | |||
nb=3 | |||
nExpect=4 | |||
[TestMethod3] | |||
na=90 | |||
nb=3 | |||
nExpect=30 | |||
``` | |||
2. 读取ini文件的函数 int CalcCount(int n, char(*str)[10]) | |||
```C | |||
/* | |||
**函数功能:获取一个ini文件里有多少个节,并通过二维指针数组将节名带出来。 | |||
* 函数名:CalcCount() | |||
* 入参:int n --------节的个数 | |||
* char (*str)[10] --------二维数组指针,10是节名的长度,可以根据需求修改 | |||
*返回值:int --------返回节的个数 | |||
*/ | |||
int CalcCount(int n, char(*str)[10]) | |||
int CalcCount(int n, char(*str)[10]) | |||
{ | |||
TCHAR chSectionNames[2048] = { 0 };//定义一个数组,保存读取节的名字 | |||
char* pSectionName; //保存找到的某个节名字符串的首地址 | |||
int i = 0; //i指向数组chSectionNames的某个位置,从0开始,顺序后移 | |||
int j = 0; //j用来保存下一个节名字符串的首地址相对于当前i的位置偏移量 | |||
int k = 0; //临时变量,用于给str数组赋值 | |||
int m = 0; //临时变量,用于给str数组赋值 | |||
int count = 0; //统计节的个数 | |||
GetPrivateProfileSectionNames(chSectionNames, 2048, "..//ex1.ini");//获取文件中的节名,每个节名以"\0"分割,保存在chSectionNames中 | |||
//要加头文件 | |||
for (i = 0; i < 2048; i++, j++)//对chSectionName中保存的内容进行拆分 | |||
{ | |||
if (chSectionNames[0] == '\0')//如果第一个字符就是0,则说明ini中一个节也没有, | |||
{ | |||
break; | |||
} | |||
if (chSectionNames[i] == '\0') | |||
{ | |||
count++; | |||
pSectionName = &chSectionNames[i - j]; //找到一个0,则说明从这个字符往前,减掉j个偏移量, | |||
//就是一个节名的首地址 | |||
j = -1; //找到一个节名后,j的值要还原,以统计下一个节名地址的偏移量 | |||
//赋成-1是因为节名字符串的最后一个字符0是终止符,不能作为节名 | |||
for (m = 0; m <= strlen(pSectionName); m++)//把找到的节名保存到str中 | |||
{ | |||
str[k][m] = *(pSectionName + m); | |||
} | |||
k++;//变量自加,用来保存下一个节名 | |||
//在获取节名的时候可以获取该节中键的值,前提是我们知道该节中有哪些键。 | |||
if (chSectionNames[i + 1] == 0) | |||
{ | |||
break; //当两个相邻的字符都是0时,则所有的节名都已找到,循环终止 | |||
} | |||
} | |||
} | |||
return count;//返回节名的个数 | |||
} | |||
``` | |||
3. 单元测试源码 UNITest1.cpp | |||
```C | |||
#include "pch.h" | |||
#include "CppUnitTest.h" | |||
#include<Windows.h> | |||
#include <atlstr.h> | |||
#include"../FourOperator/dev.h" | |||
#define FilePath "../ex1.ini" | |||
using namespace Microsoft::VisualStudio::CppUnitTestFramework; | |||
namespace UnitTest1 | |||
{ | |||
TEST_CLASS(UnitTest1) | |||
{ | |||
public: | |||
int j = 0;//循环变量,用来访问ini文件中的 节 | |||
char str[50][10] = { 0 };//存放ini文件里 节的名字 | |||
int count = CalcCount(50, str);//保存ini文件里 节的个数 | |||
TEST_METHOD(TestMethode1) | |||
{ | |||
int nReal;//保存运算结果 | |||
CString na, nb, nExpect; //保存测试样例中的键值 | |||
for (j = 0; j < count; j++)//遍历读取测试样例 | |||
{ | |||
GetPrivateProfileString(str[j], "na", " ", na.GetBuffer(20), 20, FilePath);//读取第一个参数,保存在na里 | |||
GetPrivateProfileString(str[j], "nb", " ", nb.GetBuffer(20), 20, FilePath);//读取第二个参数,保存在nb里 | |||
GetPrivateProfileString(str[j], "nExpect", " ", nExpect.GetBuffer(20), 20, FilePath);//读取正确的值,保存在nExpect里 | |||
nReal = dev(_ttoi(na), _ttoi(nb)); //_ttoi是CString转为整型,把运算结果给nReal | |||
Assert::AreEqual(nReal, _ttoi(nExpect));//对比运算结果和正确结果 | |||
} | |||
} | |||
}; | |||
} | |||
``` | |||
4. 附加测试结果 | |||
 | |||
@@ -1,41 +0,0 @@ | |||
| |||
Microsoft Visual Studio Solution File, Format Version 12.00 | |||
# Visual Studio Version 16 | |||
VisualStudioVersion = 16.0.30804.86 | |||
MinimumVisualStudioVersion = 10.0.40219.1 | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "C", "C\C.vcxproj", "{00D1AA82-D340-4FF6-86FF-FFA68354D442}" | |||
EndProject | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTest1", "UnitTest1\UnitTest1.vcxproj", "{888C6BC4-668C-4C89-97CE-8108E4583F92}" | |||
EndProject | |||
Global | |||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
Debug|x64 = Debug|x64 | |||
Debug|x86 = Debug|x86 | |||
Release|x64 = Release|x64 | |||
Release|x86 = Release|x86 | |||
EndGlobalSection | |||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | |||
{00D1AA82-D340-4FF6-86FF-FFA68354D442}.Debug|x64.ActiveCfg = Debug|x64 | |||
{00D1AA82-D340-4FF6-86FF-FFA68354D442}.Debug|x64.Build.0 = Debug|x64 | |||
{00D1AA82-D340-4FF6-86FF-FFA68354D442}.Debug|x86.ActiveCfg = Debug|Win32 | |||
{00D1AA82-D340-4FF6-86FF-FFA68354D442}.Debug|x86.Build.0 = Debug|Win32 | |||
{00D1AA82-D340-4FF6-86FF-FFA68354D442}.Release|x64.ActiveCfg = Release|x64 | |||
{00D1AA82-D340-4FF6-86FF-FFA68354D442}.Release|x64.Build.0 = Release|x64 | |||
{00D1AA82-D340-4FF6-86FF-FFA68354D442}.Release|x86.ActiveCfg = Release|Win32 | |||
{00D1AA82-D340-4FF6-86FF-FFA68354D442}.Release|x86.Build.0 = Release|Win32 | |||
{888C6BC4-668C-4C89-97CE-8108E4583F92}.Debug|x64.ActiveCfg = Debug|x64 | |||
{888C6BC4-668C-4C89-97CE-8108E4583F92}.Debug|x64.Build.0 = Debug|x64 | |||
{888C6BC4-668C-4C89-97CE-8108E4583F92}.Debug|x86.ActiveCfg = Debug|Win32 | |||
{888C6BC4-668C-4C89-97CE-8108E4583F92}.Debug|x86.Build.0 = Debug|Win32 | |||
{888C6BC4-668C-4C89-97CE-8108E4583F92}.Release|x64.ActiveCfg = Release|x64 | |||
{888C6BC4-668C-4C89-97CE-8108E4583F92}.Release|x64.Build.0 = Release|x64 | |||
{888C6BC4-668C-4C89-97CE-8108E4583F92}.Release|x86.ActiveCfg = Release|Win32 | |||
{888C6BC4-668C-4C89-97CE-8108E4583F92}.Release|x86.Build.0 = Release|Win32 | |||
EndGlobalSection | |||
GlobalSection(SolutionProperties) = preSolution | |||
HideSolutionNode = FALSE | |||
EndGlobalSection | |||
GlobalSection(ExtensibilityGlobals) = postSolution | |||
SolutionGuid = {3DF6E949-2010-47F5-9C2B-9B17FE0C93F3} | |||
EndGlobalSection | |||
EndGlobal |
@@ -1,157 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<ItemGroup Label="ProjectConfigurations"> | |||
<ProjectConfiguration Include="Debug|Win32"> | |||
<Configuration>Debug</Configuration> | |||
<Platform>Win32</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Release|Win32"> | |||
<Configuration>Release</Configuration> | |||
<Platform>Win32</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Debug|x64"> | |||
<Configuration>Debug</Configuration> | |||
<Platform>x64</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Release|x64"> | |||
<Configuration>Release</Configuration> | |||
<Platform>x64</Platform> | |||
</ProjectConfiguration> | |||
</ItemGroup> | |||
<PropertyGroup Label="Globals"> | |||
<VCProjectVersion>16.0</VCProjectVersion> | |||
<Keyword>Win32Proj</Keyword> | |||
<ProjectGuid>{00d1aa82-d340-4ff6-86ff-ffa68354d442}</ProjectGuid> | |||
<RootNamespace>C</RootNamespace> | |||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> | |||
</PropertyGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | |||
<ConfigurationType>DynamicLibrary</ConfigurationType> | |||
<UseDebugLibraries>true</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<CharacterSet>Unicode</CharacterSet> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | |||
<ConfigurationType>Application</ConfigurationType> | |||
<UseDebugLibraries>false</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<WholeProgramOptimization>true</WholeProgramOptimization> | |||
<CharacterSet>Unicode</CharacterSet> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | |||
<ConfigurationType>Application</ConfigurationType> | |||
<UseDebugLibraries>true</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<CharacterSet>Unicode</CharacterSet> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | |||
<ConfigurationType>Application</ConfigurationType> | |||
<UseDebugLibraries>false</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<WholeProgramOptimization>true</WholeProgramOptimization> | |||
<CharacterSet>Unicode</CharacterSet> | |||
</PropertyGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | |||
<ImportGroup Label="ExtensionSettings"> | |||
</ImportGroup> | |||
<ImportGroup Label="Shared"> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<PropertyGroup Label="UserMacros" /> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<LinkIncremental>true</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<LinkIncremental>false</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<LinkIncremental>true</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<LinkIncremental>false</LinkIncremental> | |||
</PropertyGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<ClCompile> | |||
<WarningLevel>Level3</WarningLevel> | |||
<SDLCheck>true</SDLCheck> | |||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<ConformanceMode>true</ConformanceMode> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Console</SubSystem> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
<ModuleDefinitionFile>Source.def</ModuleDefinitionFile> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<ClCompile> | |||
<WarningLevel>Level3</WarningLevel> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<IntrinsicFunctions>true</IntrinsicFunctions> | |||
<SDLCheck>true</SDLCheck> | |||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<ConformanceMode>true</ConformanceMode> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Console</SubSystem> | |||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | |||
<OptimizeReferences>true</OptimizeReferences> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
<ModuleDefinitionFile>Source.def</ModuleDefinitionFile> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<ClCompile> | |||
<WarningLevel>Level3</WarningLevel> | |||
<SDLCheck>true</SDLCheck> | |||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<ConformanceMode>true</ConformanceMode> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Console</SubSystem> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
<ModuleDefinitionFile>Source.def</ModuleDefinitionFile> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<ClCompile> | |||
<WarningLevel>Level3</WarningLevel> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<IntrinsicFunctions>true</IntrinsicFunctions> | |||
<SDLCheck>true</SDLCheck> | |||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<ConformanceMode>true</ConformanceMode> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Console</SubSystem> | |||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | |||
<OptimizeReferences>true</OptimizeReferences> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
<ModuleDefinitionFile>Source.def</ModuleDefinitionFile> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemGroup> | |||
<ClInclude Include="mul.h" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClCompile Include="mul.cpp" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<None Include="Source.def" /> | |||
</ItemGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | |||
<ImportGroup Label="ExtensionTargets"> | |||
</ImportGroup> | |||
</Project> |
@@ -1,3 +0,0 @@ | |||
LIBRARY "Source" | |||
EXPORTS | |||
mul @1 |
@@ -1,11 +0,0 @@ | |||
#include "mul.h" | |||
#include <stdio.h> | |||
long long _stdcall mul(int x, int y) | |||
{ | |||
long long m = (long long)x; | |||
long long n = (long long)y; | |||
long long s = m * n; | |||
printf("%lld * %lld = %lld\n",m,n,s); | |||
return s; | |||
} |
@@ -1,2 +0,0 @@ | |||
#pragma once | |||
long long _stdcall mul(int x, int y);//这里暂时不太清楚为啥要加_stdcall,但是不加调用的时候会抛异常 |
@@ -1,36 +0,0 @@ | |||
#include "pch.h" | |||
#include "CppUnitTest.h" | |||
#include "../C/mul.h" | |||
#include <Windows.h> | |||
#include <atlstr.h> | |||
#define FilePath "..//ex1.ini" | |||
using namespace Microsoft::VisualStudio::CppUnitTestFramework; | |||
namespace UnitTest1 | |||
{ | |||
TEST_CLASS(UnitTest1) | |||
{ | |||
public: | |||
int j = 0; | |||
char str[50][10] = { 0 };//保存ini文件里 节的名字 | |||
int count = CalcCount(50, str);//保存ini文件里 节的个数 | |||
unsigned short i; | |||
TEST_METHOD(TestMethode1) | |||
{ | |||
int nReal;//保存运算结果 | |||
CString na, nb, nExpect; //b保存不同的键值 | |||
for (j = 0; j < count; j++) | |||
{ | |||
GetPrivateProfileString(str[j], "na", " ", na.GetBuffer(20), 20, FilePath); | |||
GetPrivateProfileString(str[j], "nb", " ", nb.GetBuffer(20), 20, FilePath); | |||
GetPrivateProfileString(str[j], "nExpect", " ", nExpect.GetBuffer(20), 20, FilePath); | |||
nReal = mul(_ttoi(na), _ttoi(nb)); //_ttoi是CString转为整型 | |||
Assert::AreEqual(nReal, _ttoi(nExpect)); | |||
} | |||
} | |||
}; | |||
} |
@@ -1,175 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<ItemGroup Label="ProjectConfigurations"> | |||
<ProjectConfiguration Include="Debug|Win32"> | |||
<Configuration>Debug</Configuration> | |||
<Platform>Win32</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Release|Win32"> | |||
<Configuration>Release</Configuration> | |||
<Platform>Win32</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Debug|x64"> | |||
<Configuration>Debug</Configuration> | |||
<Platform>x64</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Release|x64"> | |||
<Configuration>Release</Configuration> | |||
<Platform>x64</Platform> | |||
</ProjectConfiguration> | |||
</ItemGroup> | |||
<PropertyGroup Label="Globals"> | |||
<VCProjectVersion>16.0</VCProjectVersion> | |||
<ProjectGuid>{888C6BC4-668C-4C89-97CE-8108E4583F92}</ProjectGuid> | |||
<Keyword>Win32Proj</Keyword> | |||
<RootNamespace>UnitTest1</RootNamespace> | |||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> | |||
<ProjectSubType>NativeUnitTestProject</ProjectSubType> | |||
</PropertyGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | |||
<ConfigurationType>DynamicLibrary</ConfigurationType> | |||
<UseDebugLibraries>true</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<CharacterSet>MultiByte</CharacterSet> | |||
<UseOfMfc>false</UseOfMfc> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | |||
<ConfigurationType>DynamicLibrary</ConfigurationType> | |||
<UseDebugLibraries>false</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<WholeProgramOptimization>true</WholeProgramOptimization> | |||
<CharacterSet>Unicode</CharacterSet> | |||
<UseOfMfc>false</UseOfMfc> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | |||
<ConfigurationType>DynamicLibrary</ConfigurationType> | |||
<UseDebugLibraries>true</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<CharacterSet>Unicode</CharacterSet> | |||
<UseOfMfc>false</UseOfMfc> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | |||
<ConfigurationType>DynamicLibrary</ConfigurationType> | |||
<UseDebugLibraries>false</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<WholeProgramOptimization>true</WholeProgramOptimization> | |||
<CharacterSet>Unicode</CharacterSet> | |||
<UseOfMfc>false</UseOfMfc> | |||
</PropertyGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | |||
<ImportGroup Label="ExtensionSettings"> | |||
</ImportGroup> | |||
<ImportGroup Label="Shared"> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<PropertyGroup Label="UserMacros" /> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<LinkIncremental>true</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<LinkIncremental>true</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<LinkIncremental>false</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<LinkIncremental>false</LinkIncremental> | |||
</PropertyGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<ClCompile> | |||
<PrecompiledHeader>Use</PrecompiledHeader> | |||
<WarningLevel>Level3</WarningLevel> | |||
<SDLCheck>true</SDLCheck> | |||
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<UseFullPaths>true</UseFullPaths> | |||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Windows</SubSystem> | |||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
<AdditionalDependencies>..\C\Debug\mul.obj;%(AdditionalDependencies)</AdditionalDependencies> | |||
<GenerateDebugInformation>DebugFull</GenerateDebugInformation> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<ClCompile> | |||
<PrecompiledHeader>Use</PrecompiledHeader> | |||
<WarningLevel>Level3</WarningLevel> | |||
<SDLCheck>true</SDLCheck> | |||
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<UseFullPaths>true</UseFullPaths> | |||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Windows</SubSystem> | |||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<ClCompile> | |||
<PrecompiledHeader>Use</PrecompiledHeader> | |||
<WarningLevel>Level3</WarningLevel> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<IntrinsicFunctions>true</IntrinsicFunctions> | |||
<SDLCheck>true</SDLCheck> | |||
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<UseFullPaths>true</UseFullPaths> | |||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Windows</SubSystem> | |||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | |||
<OptimizeReferences>true</OptimizeReferences> | |||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<ClCompile> | |||
<PrecompiledHeader>Use</PrecompiledHeader> | |||
<WarningLevel>Level3</WarningLevel> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<IntrinsicFunctions>true</IntrinsicFunctions> | |||
<SDLCheck>true</SDLCheck> | |||
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<UseFullPaths>true</UseFullPaths> | |||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Windows</SubSystem> | |||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | |||
<OptimizeReferences>true</OptimizeReferences> | |||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemGroup> | |||
<ClCompile Include="pch.cpp"> | |||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> | |||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader> | |||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> | |||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader> | |||
</ClCompile> | |||
<ClCompile Include="UnitTest1.cpp" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClInclude Include="pch.h" /> | |||
</ItemGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | |||
<ImportGroup Label="ExtensionTargets"> | |||
</ImportGroup> | |||
</Project> |
@@ -1,45 +0,0 @@ | |||
/// pch.cpp: 与预编译标头对应的源文件 | |||
#include <stdio.h> | |||
#include "pch.h" | |||
#include<Windows.h> | |||
int CalcCount(int n, char(*str)[10]) | |||
{ | |||
TCHAR chSectionNames[2048] = { 0 };//定义一个数组,保存读取节的名字 | |||
char* pSectionName; //保存找到的某个节名字符串的首地址 | |||
int i = 0; //i指向数组chSectionNames的某个位置,从0开始,顺序后移 | |||
int j = 0; //j用来保存下一个节名字符串的首地址相对于当前i的位置偏移量 | |||
int k = 0; //临时变量,用于给str数组赋值 | |||
int m = 0; //临时变量,用于给str数组赋值 | |||
int count = 0; //统计节的个数 | |||
GetPrivateProfileSectionNames(chSectionNames, 2048, "..//ex1.ini");//获取文件中的节名,每个节名以"\0"分割,保存在chSectionNames中 | |||
//要加头文件 | |||
for (i = 0; i < 2048; i++, j++)//对chSectionName中保存的内容进行拆分 | |||
{ | |||
if (chSectionNames[0] == '\0')//如果第一个字符就是0,则说明ini中一个节也没有, | |||
{ | |||
break; | |||
} | |||
if (chSectionNames[i] == '\0') | |||
{ | |||
count++; | |||
pSectionName = &chSectionNames[i - j]; //找到一个0,则说明从这个字符往前,减掉j个偏移量, | |||
//就是一个节名的首地址 | |||
j = -1; //找到一个节名后,j的值要还原,以统计下一个节名地址的偏移量 | |||
//赋成-1是因为节名字符串的最后一个字符0是终止符,不能作为节名 | |||
for (m = 0; m <= strlen(pSectionName); m++)//把找到的节名保存到str中 | |||
{ | |||
str[k][m] = *(pSectionName + m); | |||
} | |||
//str[k][++m] = '\0';//手动给节名加上\0,表示这个节名结束 | |||
k++;//变量自加,用来保存下一个节名 | |||
//在获取节名的时候可以获取该节中键的值,前提是我们知道该节中有哪些键。 | |||
if (chSectionNames[i + 1] == 0) | |||
{ | |||
break; //当两个相邻的字符都是0时,则所有的节名都已找到,循环终止 | |||
} | |||
} | |||
} | |||
return count;//返回节名的个数 | |||
} | |||
// 当使用预编译的头时,需要使用此源文件,编译才能成功。 |
@@ -1,12 +0,0 @@ | |||
// pch.h: 这是预编译标头文件。 | |||
// 下方列出的文件仅编译一次,提高了将来生成的生成性能。 | |||
// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 | |||
// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 | |||
// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 | |||
#ifndef PCH_H | |||
#define PCH_H | |||
int CalcCount(int n, char(*str)[10]); | |||
// 添加要在此处预编译的标头 | |||
#endif //PCH_H |
@@ -1,14 +0,0 @@ | |||
[TestMethod1] | |||
na=4 | |||
nb=4 | |||
nExpect=16 | |||
[TestMethod2] | |||
na=3 | |||
nb=7 | |||
nExpect=21 | |||
[TestMethod3] | |||
na=3 | |||
nb=5 | |||
nExpect=15 | |||
@@ -1,132 +0,0 @@ | |||
# mul函数说明文档 | |||
## 一、工程说明 | |||
- 本工程的配置类型是一个动态库文件,使用的方法是生成.def文件,目的是生成一个可被其他工程调用动态库,动态库的函数功能是:输入两个int类型的数,返回两数之积。 | |||
## 二、头文件 mul.h ,放的是mul函数的声明 | |||
```C | |||
/* | |||
**函数名: mul | |||
**参数:int ,int | |||
**返回值:long long | |||
**函数功能:传入两个int类型的参数,对其进行乘法运算并返回两数之积,因为两个int型数相乘结果可能会超出int范围,所以返回值用long long。 | |||
*/ | |||
#pragma once | |||
long long _stdcall mul(int x, int y);//这里暂时不太清楚为啥要加_stdcall,但是不加调用的时候会抛异常# | |||
``` | |||
## 三、源文件 mul.cpp ,放的是mul函数的定义 | |||
```C | |||
#include "mul.h" | |||
long long _stdcall mul(int x, int y) | |||
{ | |||
return (long long)x * (long long)y; | |||
} | |||
``` | |||
## 四、def文件内容 Source.def | |||
``` | |||
LIBRARY "Source" | |||
EXPORTS | |||
mul @1 | |||
``` | |||
## 五、单元测试 | |||
- 手动创建ini文件并添加测试样例,之后在单元测试的源文件里对ini文件进行读取解析 ,完成以后获取单元测试的结果,保证代码覆盖率在80%以上。其中对ini文件的读取另封装了函数,见下面的源码。 | |||
1. ini文件内容 exl.ini | |||
``` | |||
[TestMethod1] #测试样例1 | |||
na=10 #函数第一个入数 | |||
nb=4 #函数第二个入参 | |||
nExpect=40 #两个入参相乘的正确结果 | |||
[TestMethod2] | |||
na=3 | |||
nb=7 | |||
nExpect=21 | |||
[TestMethod3] | |||
na=3 | |||
nb=5 | |||
nExpect=15 | |||
``` | |||
2. 读取ini文件的函数 int CalcCount(int n, char(*str)[10]) | |||
```C | |||
/* | |||
**函数功能:获取一个ini文件里有多少个节,并通过二维指针数组将节名带出来。 | |||
* 函数名:CalcCount() | |||
* 入参:int n --------节的个数 | |||
* char (*str)[10] --------二维数组指针,10是节名的长度,可以根据需求修改 | |||
*返回值:int --------返回节的个数 | |||
*/ | |||
int CalcCount(int n, char(*str)[10]) | |||
int CalcCount(int n, char(*str)[10]) | |||
{ | |||
TCHAR chSectionNames[2048] = { 0 };//定义一个数组,保存读取节的名字 | |||
char* pSectionName; //保存找到的某个节名字符串的首地址 | |||
int i = 0; //i指向数组chSectionNames的某个位置,从0开始,顺序后移 | |||
int j = 0; //j用来保存下一个节名字符串的首地址相对于当前i的位置偏移量 | |||
int k = 0; //临时变量,用于给str数组赋值 | |||
int m = 0; //临时变量,用于给str数组赋值 | |||
int count = 0; //统计节的个数 | |||
GetPrivateProfileSectionNames(chSectionNames, 2048, "..//ex1.ini");//获取文件中的节名,每个节名以"\0"分割,保存在chSectionNames中 | |||
//要加头文件 | |||
for (i = 0; i < 2048; i++, j++)//对chSectionName中保存的内容进行拆分 | |||
{ | |||
if (chSectionNames[0] == '\0')//如果第一个字符就是0,则说明ini中一个节也没有, | |||
{ | |||
break; | |||
} | |||
if (chSectionNames[i] == '\0') | |||
{ | |||
count++; | |||
pSectionName = &chSectionNames[i - j]; //找到一个0,则说明从这个字符往前,减掉j个偏移量, | |||
//就是一个节名的首地址 | |||
j = -1; //找到一个节名后,j的值要还原,以统计下一个节名地址的偏移量 | |||
//赋成-1是因为节名字符串的最后一个字符0是终止符,不能作为节名 | |||
for (m = 0; m <= strlen(pSectionName); m++)//把找到的节名保存到str中 | |||
{ | |||
str[k][m] = *(pSectionName + m); | |||
} | |||
k++;//变量自加,用来保存下一个节名 | |||
//在获取节名的时候可以获取该节中键的值,前提是我们知道该节中有哪些键。 | |||
if (chSectionNames[i + 1] == 0) | |||
{ | |||
break; //当两个相邻的字符都是0时,则所有的节名都已找到,循环终止 | |||
} | |||
} | |||
} | |||
return count;//返回节名的个数 | |||
} | |||
``` | |||
3. 单元测试源码 UNITest1.cpp | |||
```C | |||
#include "pch.h" | |||
#include "CppUnitTest.h" | |||
#include<Windows.h> | |||
#include <atlstr.h> | |||
#include "../C/mul.h" | |||
#define FilePath "../ex1.ini" | |||
using namespace Microsoft::VisualStudio::CppUnitTestFramework; | |||
namespace UnitTest1 | |||
{ | |||
TEST_CLASS(UnitTest1) | |||
{ | |||
public: | |||
int j = 0;//循环变量,用来访问ini文件中的 节 | |||
char str[50][10] = { 0 };//存放ini文件里 节的名字 | |||
int count = CalcCount(50, str);//保存ini文件里 节的个数 | |||
TEST_METHOD(TestMethode1) | |||
{ | |||
int nReal;//保存运算结果 | |||
CString na, nb, nExpect; //保存测试样例中的键值 | |||
for (j = 0; j < count; j++)//遍历读取测试样例 | |||
{ | |||
GetPrivateProfileString(str[j], "na", " ", na.GetBuffer(20), 20, FilePath);//读取第一个参数,保存在na里 | |||
GetPrivateProfileString(str[j], "nb", " ", nb.GetBuffer(20), 20, FilePath);//读取第二个参数,保存在nb里 | |||
GetPrivateProfileString(str[j], "nExpect", " ", nExpect.GetBuffer(20), 20, FilePath);//读取正确的值,保存在nExpect里 | |||
nReal = mul(_ttoi(na), _ttoi(nb)); //_ttoi是CString转为整型,把运算结果给nReal | |||
Assert::AreEqual(nReal, _ttoi(nExpect));//对比运算结果和正确结果 | |||
} | |||
} | |||
}; | |||
} | |||
``` | |||
4. 附加测试结果 | |||
 |
@@ -1,41 +0,0 @@ | |||
| |||
Microsoft Visual Studio Solution File, Format Version 12.00 | |||
# Visual Studio Version 16 | |||
VisualStudioVersion = 16.0.30804.86 | |||
MinimumVisualStudioVersion = 10.0.40219.1 | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "B", "B\B.vcxproj", "{C9C2CED7-109C-41F8-A522-2BE7855A0D71}" | |||
EndProject | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTest1", "UnitTest1\UnitTest1.vcxproj", "{6F4C0F3A-8892-4407-B3F3-E22C659148C1}" | |||
EndProject | |||
Global | |||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
Debug|x64 = Debug|x64 | |||
Debug|x86 = Debug|x86 | |||
Release|x64 = Release|x64 | |||
Release|x86 = Release|x86 | |||
EndGlobalSection | |||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | |||
{C9C2CED7-109C-41F8-A522-2BE7855A0D71}.Debug|x64.ActiveCfg = Debug|x64 | |||
{C9C2CED7-109C-41F8-A522-2BE7855A0D71}.Debug|x64.Build.0 = Debug|x64 | |||
{C9C2CED7-109C-41F8-A522-2BE7855A0D71}.Debug|x86.ActiveCfg = Debug|Win32 | |||
{C9C2CED7-109C-41F8-A522-2BE7855A0D71}.Debug|x86.Build.0 = Debug|Win32 | |||
{C9C2CED7-109C-41F8-A522-2BE7855A0D71}.Release|x64.ActiveCfg = Release|x64 | |||
{C9C2CED7-109C-41F8-A522-2BE7855A0D71}.Release|x64.Build.0 = Release|x64 | |||
{C9C2CED7-109C-41F8-A522-2BE7855A0D71}.Release|x86.ActiveCfg = Release|Win32 | |||
{C9C2CED7-109C-41F8-A522-2BE7855A0D71}.Release|x86.Build.0 = Release|Win32 | |||
{6F4C0F3A-8892-4407-B3F3-E22C659148C1}.Debug|x64.ActiveCfg = Debug|x64 | |||
{6F4C0F3A-8892-4407-B3F3-E22C659148C1}.Debug|x64.Build.0 = Debug|x64 | |||
{6F4C0F3A-8892-4407-B3F3-E22C659148C1}.Debug|x86.ActiveCfg = Debug|Win32 | |||
{6F4C0F3A-8892-4407-B3F3-E22C659148C1}.Debug|x86.Build.0 = Debug|Win32 | |||
{6F4C0F3A-8892-4407-B3F3-E22C659148C1}.Release|x64.ActiveCfg = Release|x64 | |||
{6F4C0F3A-8892-4407-B3F3-E22C659148C1}.Release|x64.Build.0 = Release|x64 | |||
{6F4C0F3A-8892-4407-B3F3-E22C659148C1}.Release|x86.ActiveCfg = Release|Win32 | |||
{6F4C0F3A-8892-4407-B3F3-E22C659148C1}.Release|x86.Build.0 = Release|Win32 | |||
EndGlobalSection | |||
GlobalSection(SolutionProperties) = preSolution | |||
HideSolutionNode = FALSE | |||
EndGlobalSection | |||
GlobalSection(ExtensibilityGlobals) = postSolution | |||
SolutionGuid = {B0E8A81B-EFF0-4230-AA65-F9B19FF65BF3} | |||
EndGlobalSection | |||
EndGlobal |
@@ -1,150 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<ItemGroup Label="ProjectConfigurations"> | |||
<ProjectConfiguration Include="Debug|Win32"> | |||
<Configuration>Debug</Configuration> | |||
<Platform>Win32</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Release|Win32"> | |||
<Configuration>Release</Configuration> | |||
<Platform>Win32</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Debug|x64"> | |||
<Configuration>Debug</Configuration> | |||
<Platform>x64</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Release|x64"> | |||
<Configuration>Release</Configuration> | |||
<Platform>x64</Platform> | |||
</ProjectConfiguration> | |||
</ItemGroup> | |||
<PropertyGroup Label="Globals"> | |||
<VCProjectVersion>16.0</VCProjectVersion> | |||
<Keyword>Win32Proj</Keyword> | |||
<ProjectGuid>{c9c2ced7-109c-41f8-a522-2be7855a0d71}</ProjectGuid> | |||
<RootNamespace>B</RootNamespace> | |||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> | |||
</PropertyGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | |||
<ConfigurationType>DynamicLibrary</ConfigurationType> | |||
<UseDebugLibraries>true</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<CharacterSet>Unicode</CharacterSet> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | |||
<ConfigurationType>Application</ConfigurationType> | |||
<UseDebugLibraries>false</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<WholeProgramOptimization>true</WholeProgramOptimization> | |||
<CharacterSet>Unicode</CharacterSet> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | |||
<ConfigurationType>Application</ConfigurationType> | |||
<UseDebugLibraries>true</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<CharacterSet>Unicode</CharacterSet> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | |||
<ConfigurationType>Application</ConfigurationType> | |||
<UseDebugLibraries>false</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<WholeProgramOptimization>true</WholeProgramOptimization> | |||
<CharacterSet>Unicode</CharacterSet> | |||
</PropertyGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | |||
<ImportGroup Label="ExtensionSettings"> | |||
</ImportGroup> | |||
<ImportGroup Label="Shared"> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<PropertyGroup Label="UserMacros" /> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<LinkIncremental>true</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<LinkIncremental>false</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<LinkIncremental>true</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<LinkIncremental>false</LinkIncremental> | |||
</PropertyGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<ClCompile> | |||
<WarningLevel>Level3</WarningLevel> | |||
<SDLCheck>true</SDLCheck> | |||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;sub_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<ConformanceMode>true</ConformanceMode> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Console</SubSystem> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<ClCompile> | |||
<WarningLevel>Level3</WarningLevel> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<IntrinsicFunctions>true</IntrinsicFunctions> | |||
<SDLCheck>true</SDLCheck> | |||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<ConformanceMode>true</ConformanceMode> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Console</SubSystem> | |||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | |||
<OptimizeReferences>true</OptimizeReferences> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<ClCompile> | |||
<WarningLevel>Level3</WarningLevel> | |||
<SDLCheck>true</SDLCheck> | |||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<ConformanceMode>true</ConformanceMode> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Console</SubSystem> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<ClCompile> | |||
<WarningLevel>Level3</WarningLevel> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<IntrinsicFunctions>true</IntrinsicFunctions> | |||
<SDLCheck>true</SDLCheck> | |||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<ConformanceMode>true</ConformanceMode> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Console</SubSystem> | |||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | |||
<OptimizeReferences>true</OptimizeReferences> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemGroup> | |||
<ClInclude Include="sub.h" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClCompile Include="sub.cpp" /> | |||
</ItemGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | |||
<ImportGroup Label="ExtensionTargets"> | |||
</ImportGroup> | |||
</Project> |
@@ -1,27 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<ItemGroup> | |||
<Filter Include="源文件"> | |||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | |||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | |||
</Filter> | |||
<Filter Include="头文件"> | |||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | |||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions> | |||
</Filter> | |||
<Filter Include="资源文件"> | |||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | |||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | |||
</Filter> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClInclude Include="sub.h"> | |||
<Filter>头文件</Filter> | |||
</ClInclude> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClCompile Include="sub.cpp"> | |||
<Filter>源文件</Filter> | |||
</ClCompile> | |||
</ItemGroup> | |||
</Project> |
@@ -1,4 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<PropertyGroup /> | |||
</Project> |
@@ -1,5 +0,0 @@ | |||
#include"sub.h" | |||
int sub(int x, int y) | |||
{ | |||
return x - y; | |||
} |
@@ -1,13 +0,0 @@ | |||
#ifndef _SUB_H_ | |||
#define _SUB_H_ | |||
#ifdef sub_EXPORTS | |||
#define sub_EXPORTS _declspec(dllexport) | |||
#else | |||
#define sub_EXPORTS _declspec(dllimport) | |||
#endif | |||
sub_EXPORTS int sub(int x, int y); | |||
#endif | |||
@@ -1,35 +0,0 @@ | |||
#include "pch.h" | |||
#include "CppUnitTest.h" | |||
#include<Windows.h> | |||
#include <atlstr.h> | |||
#include "../B/sub.h" | |||
#define FilePath "..//ex1.ini" | |||
using namespace Microsoft::VisualStudio::CppUnitTestFramework; | |||
namespace UnitTest1 | |||
{ | |||
TEST_CLASS(UnitTest1) | |||
{ | |||
public: | |||
int j = 0; | |||
char str[50][10] = { 0 };//保存ini文件里 节的名字 | |||
int count = CalcCount(50, str);//保存ini文件里 节的个数 | |||
unsigned short i; | |||
TEST_METHOD(TestMethode1) | |||
{ | |||
int nReal;//保存运算结果 | |||
CString na, nb, nExpect; //b保存不同的键值 | |||
for (j = 0; j < count; j++)//循环读取节,键值,并作对比。 | |||
{ | |||
GetPrivateProfileString(str[j], "na", " ", na.GetBuffer(20), 20, FilePath); | |||
GetPrivateProfileString(str[j], "nb", " ", nb.GetBuffer(20), 20, FilePath); | |||
GetPrivateProfileString(str[j], "nExpect", " ", nExpect.GetBuffer(20), 20, FilePath); | |||
nReal = sub(_ttoi(na), _ttoi(nb)); //_ttoi是CString转为整型 | |||
Assert::AreEqual(nReal, _ttoi(nExpect)); | |||
} | |||
} | |||
}; | |||
} |
@@ -1,175 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<ItemGroup Label="ProjectConfigurations"> | |||
<ProjectConfiguration Include="Debug|Win32"> | |||
<Configuration>Debug</Configuration> | |||
<Platform>Win32</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Release|Win32"> | |||
<Configuration>Release</Configuration> | |||
<Platform>Win32</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Debug|x64"> | |||
<Configuration>Debug</Configuration> | |||
<Platform>x64</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Release|x64"> | |||
<Configuration>Release</Configuration> | |||
<Platform>x64</Platform> | |||
</ProjectConfiguration> | |||
</ItemGroup> | |||
<PropertyGroup Label="Globals"> | |||
<VCProjectVersion>16.0</VCProjectVersion> | |||
<ProjectGuid>{6F4C0F3A-8892-4407-B3F3-E22C659148C1}</ProjectGuid> | |||
<Keyword>Win32Proj</Keyword> | |||
<RootNamespace>UnitTest1</RootNamespace> | |||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> | |||
<ProjectSubType>NativeUnitTestProject</ProjectSubType> | |||
</PropertyGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | |||
<ConfigurationType>DynamicLibrary</ConfigurationType> | |||
<UseDebugLibraries>true</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<CharacterSet>MultiByte</CharacterSet> | |||
<UseOfMfc>false</UseOfMfc> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | |||
<ConfigurationType>DynamicLibrary</ConfigurationType> | |||
<UseDebugLibraries>false</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<WholeProgramOptimization>true</WholeProgramOptimization> | |||
<CharacterSet>Unicode</CharacterSet> | |||
<UseOfMfc>false</UseOfMfc> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | |||
<ConfigurationType>DynamicLibrary</ConfigurationType> | |||
<UseDebugLibraries>true</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<CharacterSet>Unicode</CharacterSet> | |||
<UseOfMfc>false</UseOfMfc> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | |||
<ConfigurationType>DynamicLibrary</ConfigurationType> | |||
<UseDebugLibraries>false</UseDebugLibraries> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<WholeProgramOptimization>true</WholeProgramOptimization> | |||
<CharacterSet>Unicode</CharacterSet> | |||
<UseOfMfc>false</UseOfMfc> | |||
</PropertyGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | |||
<ImportGroup Label="ExtensionSettings"> | |||
</ImportGroup> | |||
<ImportGroup Label="Shared"> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<PropertyGroup Label="UserMacros" /> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<LinkIncremental>true</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<LinkIncremental>true</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<LinkIncremental>false</LinkIncremental> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<LinkIncremental>false</LinkIncremental> | |||
</PropertyGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<ClCompile> | |||
<PrecompiledHeader>Use</PrecompiledHeader> | |||
<WarningLevel>Level3</WarningLevel> | |||
<SDLCheck>true</SDLCheck> | |||
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<UseFullPaths>true</UseFullPaths> | |||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Windows</SubSystem> | |||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
<AdditionalDependencies>..\B\Debug\sub.obj;%(AdditionalDependencies)</AdditionalDependencies> | |||
<GenerateDebugInformation>DebugFull</GenerateDebugInformation> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
<ClCompile> | |||
<PrecompiledHeader>Use</PrecompiledHeader> | |||
<WarningLevel>Level3</WarningLevel> | |||
<SDLCheck>true</SDLCheck> | |||
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<UseFullPaths>true</UseFullPaths> | |||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Windows</SubSystem> | |||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<ClCompile> | |||
<PrecompiledHeader>Use</PrecompiledHeader> | |||
<WarningLevel>Level3</WarningLevel> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<IntrinsicFunctions>true</IntrinsicFunctions> | |||
<SDLCheck>true</SDLCheck> | |||
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<UseFullPaths>true</UseFullPaths> | |||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Windows</SubSystem> | |||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | |||
<OptimizeReferences>true</OptimizeReferences> | |||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||
<ClCompile> | |||
<PrecompiledHeader>Use</PrecompiledHeader> | |||
<WarningLevel>Level3</WarningLevel> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<IntrinsicFunctions>true</IntrinsicFunctions> | |||
<SDLCheck>true</SDLCheck> | |||
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<UseFullPaths>true</UseFullPaths> | |||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Windows</SubSystem> | |||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | |||
<OptimizeReferences>true</OptimizeReferences> | |||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemGroup> | |||
<ClCompile Include="pch.cpp"> | |||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> | |||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader> | |||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> | |||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader> | |||
</ClCompile> | |||
<ClCompile Include="UnitTest1.cpp" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClInclude Include="pch.h" /> | |||
</ItemGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | |||
<ImportGroup Label="ExtensionTargets"> | |||
</ImportGroup> | |||
</Project> |
@@ -1,30 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<ItemGroup> | |||
<Filter Include="源文件"> | |||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | |||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | |||
</Filter> | |||
<Filter Include="头文件"> | |||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | |||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions> | |||
</Filter> | |||
<Filter Include="资源文件"> | |||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | |||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | |||
</Filter> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClCompile Include="UnitTest1.cpp"> | |||
<Filter>源文件</Filter> | |||
</ClCompile> | |||
<ClCompile Include="pch.cpp"> | |||
<Filter>源文件</Filter> | |||
</ClCompile> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClInclude Include="pch.h"> | |||
<Filter>头文件</Filter> | |||
</ClInclude> | |||
</ItemGroup> | |||
</Project> |
@@ -1,4 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<PropertyGroup /> | |||
</Project> |
@@ -1,45 +0,0 @@ | |||
// pch.cpp: 与预编译标头对应的源文件 | |||
#include "pch.h" | |||
#include <stdio.h> | |||
#include<Windows.h> | |||
int CalcCount(int n, char(*str)[10]) | |||
{ | |||
TCHAR chSectionNames[2048] = { 0 };//定义一个数组,保存读取节的名字 | |||
char* pSectionName; //保存找到的某个节名字符串的首地址 | |||
int i = 0; //i指向数组chSectionNames的某个位置,从0开始,顺序后移 | |||
int j = 0; //j用来保存下一个节名字符串的首地址相对于当前i的位置偏移量 | |||
int k = 0; //临时变量,用于给str数组赋值 | |||
int m = 0; //临时变量,用于给str数组赋值 | |||
int count = 0; //统计节的个数 | |||
GetPrivateProfileSectionNames(chSectionNames, 2048, "..//ex1.ini");//获取文件中的节名,每个节名以"\0"分割,保存在chSectionNames中 | |||
//要加头文件 | |||
for (i = 0; i < 2048; i++, j++)//对chSectionName中保存的内容进行拆分 | |||
{ | |||
if (chSectionNames[0] == '\0')//如果第一个字符就是0,则说明ini中一个节也没有, | |||
{ | |||
break; | |||
} | |||
if (chSectionNames[i] == '\0') | |||
{ | |||
count++; | |||
pSectionName = &chSectionNames[i - j]; //找到一个0,则说明从这个字符往前,减掉j个偏移量, | |||
//就是一个节名的首地址 | |||
j = -1; //找到一个节名后,j的值要还原,以统计下一个节名地址的偏移量 | |||
//赋成-1是因为节名字符串的最后一个字符0是终止符,不能作为节名 | |||
for (m = 0; m <= strlen(pSectionName); m++)//把找到的节名保存到str中 | |||
{ | |||
str[k][m] = *(pSectionName + m); | |||
} | |||
//str[k][++m] = '\0';//手动给节名加上\0,表示这个节名结束 | |||
k++;//变量自加,用来保存下一个节名 | |||
//在获取节名的时候可以获取该节中键的值,前提是我们知道该节中有哪些键。 | |||
if (chSectionNames[i + 1] == 0) | |||
{ | |||
break; //当两个相邻的字符都是0时,则所有的节名都已找到,循环终止 | |||
} | |||
} | |||
} | |||
return count;//返回节名的个数 | |||
} | |||
// 当使用预编译的头时,需要使用此源文件,编译才能成功。 |
@@ -1,12 +0,0 @@ | |||
// pch.h: 这是预编译标头文件。 | |||
// 下方列出的文件仅编译一次,提高了将来生成的生成性能。 | |||
// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 | |||
// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 | |||
// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 | |||
#ifndef PCH_H | |||
#define PCH_H | |||
int CalcCount(int n, char(*str)[10]); | |||
// 添加要在此处预编译的标头 | |||
#endif //PCH_H |
@@ -1,9 +0,0 @@ | |||
[TestMethod1] | |||
na=12 | |||
nb=4 | |||
nExpect=8 | |||
[TestMethod2] | |||
na=7 | |||
nb=3 | |||
nExpect=4 | |||
@@ -1,129 +0,0 @@ | |||
# sub函数说明文档 | |||
## 一、工程说明 | |||
- 本工程的配置类型是一个动态库文件,目的是生成一个可被其他工程调用动态库,动态库的函数功能是:输入两个int类型的数,返回两数之差。 | |||
## 二、头文件 sub.h ,放的是sub函数声明 | |||
```C | |||
#ifndef _SUB_H_ | |||
#define _SUB_H_ | |||
#ifdef sub_EXPORTS | |||
#define sub_EXPORTS _declspec(dllexport) | |||
#else | |||
#define sub_EXPORTS _declspec(dllimport) | |||
#endif | |||
/* | |||
**函数名: sub | |||
**参数:int ,int | |||
**返回值:int | |||
**函数功能:传入两个int类型的参数,对其进行减法运算并返回差值。 | |||
*/ | |||
sub_EXPORTS int sub(int x, int y); | |||
#endif | |||
``` | |||
## 三、源文件 sub.cpp ,放的是sub函数的另一 | |||
```C | |||
#include"sub.h" | |||
int sub(int x, int y) | |||
{ | |||
return x - y; | |||
} | |||
``` | |||
## 四、单元测试 | |||
- 手动创建ini文件并添加测试样例,之后在单元测试的源文件里对ini文件进行读取解析 ,完成以后获取单元测试的结果,保证代码覆盖率在80%以上。其中对ini文件的读取另封装了函数,见下面的源码。 | |||
1. ini文件内容 exl.ini | |||
``` | |||
[TestMethod1] #测试样例1 | |||
na=10 #函数第一个入数 | |||
nb=4 #函数第二个入参 | |||
nExpect=6 #两个入参相减的正确结果 | |||
[TestMethod2] | |||
na=7 | |||
nb=3 | |||
nExpect=4 | |||
``` | |||
2. 读取ini文件的函数 int CalcCount(int n, char(*str)[10]) | |||
```C | |||
/* | |||
**函数功能:获取一个ini文件里有多少个节,并通过二维指针数组将节名带出来。 | |||
* 函数名:CalcCount() | |||
* 入参:int n --------节的个数 | |||
* char (*str)[10] --------二维数组指针,10是节名的长度,可以根据需求修改 | |||
*返回值:int --------返回节的个数 | |||
*/ | |||
int CalcCount(int n, char(*str)[10]) | |||
int CalcCount(int n, char(*str)[10]) | |||
{ | |||
TCHAR chSectionNames[2048] = { 0 };//定义一个数组,保存读取节的名字 | |||
char* pSectionName; //保存找到的某个节名字符串的首地址 | |||
int i = 0; //i指向数组chSectionNames的某个位置,从0开始,顺序后移 | |||
int j = 0; //j用来保存下一个节名字符串的首地址相对于当前i的位置偏移量 | |||
int k = 0; //临时变量,用于给str数组赋值 | |||
int m = 0; //临时变量,用于给str数组赋值 | |||
int count = 0; //统计节的个数 | |||
GetPrivateProfileSectionNames(chSectionNames, 2048, "..//ex1.ini");//获取文件中的节名,每个节名以"\0"分割,保存在chSectionNames中 | |||
//要加头文件 | |||
for (i = 0; i < 2048; i++, j++)//对chSectionName中保存的内容进行拆分 | |||
{ | |||
if (chSectionNames[0] == '\0')//如果第一个字符就是0,则说明ini中一个节也没有, | |||
{ | |||
break; | |||
} | |||
if (chSectionNames[i] == '\0') | |||
{ | |||
count++; | |||
pSectionName = &chSectionNames[i - j]; //找到一个0,则说明从这个字符往前,减掉j个偏移量, | |||
//就是一个节名的首地址 | |||
j = -1; //找到一个节名后,j的值要还原,以统计下一个节名地址的偏移量 | |||
//赋成-1是因为节名字符串的最后一个字符0是终止符,不能作为节名 | |||
for (m = 0; m <= strlen(pSectionName); m++)//把找到的节名保存到str中 | |||
{ | |||
str[k][m] = *(pSectionName + m); | |||
} | |||
k++;//变量自加,用来保存下一个节名 | |||
//在获取节名的时候可以获取该节中键的值,前提是我们知道该节中有哪些键。 | |||
if (chSectionNames[i + 1] == 0) | |||
{ | |||
break; //当两个相邻的字符都是0时,则所有的节名都已找到,循环终止 | |||
} | |||
} | |||
} | |||
return count;//返回节名的个数 | |||
} | |||
``` | |||
3. 单元测试源码 UNITest1.cpp | |||
```C | |||
#include "pch.h" | |||
#include "CppUnitTest.h" | |||
#include<Windows.h> | |||
#include <atlstr.h> | |||
#include "../B/sub.h" | |||
#define FilePath "../ex1.ini" | |||
using namespace Microsoft::VisualStudio::CppUnitTestFramework; | |||
namespace UnitTest1 | |||
{ | |||
TEST_CLASS(UnitTest1) | |||
{ | |||
public: | |||
int j = 0;//循环变量,用来访问ini文件中的 节 | |||
char str[50][10] = { 0 };//存放ini文件里 节的名字 | |||
int count = CalcCount(50, str);//保存ini文件里 节的个数 | |||
TEST_METHOD(TestMethode1) | |||
{ | |||
int nReal;//保存运算结果 | |||
CString na, nb, nExpect; //保存测试样例中的键值 | |||
for (j = 0; j < count; j++)//遍历读取测试样例 | |||
{ | |||
GetPrivateProfileString(str[j], "na", " ", na.GetBuffer(20), 20, FilePath);//读取第一个参数,保存在na里 | |||
GetPrivateProfileString(str[j], "nb", " ", nb.GetBuffer(20), 20, FilePath);//读取第二个参数,保存在nb里 | |||
GetPrivateProfileString(str[j], "nExpect", " ", nExpect.GetBuffer(20), 20, FilePath);//读取正确的值,保存在nExpect里 | |||
nReal = sub(_ttoi(na), _ttoi(nb)); //_ttoi是CString转为整型,把运算结果给nReal | |||
Assert::AreEqual(nReal, _ttoi(nExpect));//对比运算结果和正确结果 | |||
} | |||
} | |||
}; | |||
} | |||
``` | |||
4. 附加测试结果 | |||
 |