diff --git a/add/.vs/add/v16/.suo b/add/.vs/add/v16/.suo new file mode 100644 index 0000000..27f989d Binary files /dev/null and b/add/.vs/add/v16/.suo differ diff --git a/add/UnitTest1/UnitTest1.cpp b/add/UnitTest1/UnitTest1.cpp new file mode 100644 index 0000000..f93fbff --- /dev/null +++ b/add/UnitTest1/UnitTest1.cpp @@ -0,0 +1,33 @@ +#include "pch.h" +#include "CppUnitTest.h" +#include +#include +#include"../add/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) + { + long long 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(_ttoi64(na), _ttoi64(nb)); //_ttoi是CString转为整型 + Assert::AreEqual(nReal, _ttoi64(nExpect)); + } + + } + }; +} diff --git a/add/UnitTest1/UnitTest1.vcxproj b/add/UnitTest1/UnitTest1.vcxproj new file mode 100644 index 0000000..67437bc --- /dev/null +++ b/add/UnitTest1/UnitTest1.vcxproj @@ -0,0 +1,180 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {34F2D7FA-8879-401C-9F95-A57B90C33DC5} + Win32Proj + UnitTest1 + 10.0 + NativeUnitTestProject + + + + DynamicLibrary + true + v142 + MultiByte + false + + + DynamicLibrary + false + v142 + true + Unicode + false + + + DynamicLibrary + true + v142 + Unicode + false + + + DynamicLibrary + false + v142 + true + Unicode + false + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + Use + Level3 + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + ..\add\Debug\add.obj;%(AdditionalDependencies) + DebugFull + + + + + Use + Level3 + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + _DEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Use + Level3 + true + true + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + true + true + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Use + Level3 + true + true + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + NDEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + true + true + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Create + Create + Create + Create + + + + + + + + + {b2461a9c-6d35-4906-bce4-723b1e669c20} + + + + + + \ No newline at end of file diff --git a/add/UnitTest1/UnitTest1.vcxproj.filters b/add/UnitTest1/UnitTest1.vcxproj.filters new file mode 100644 index 0000000..83a287b --- /dev/null +++ b/add/UnitTest1/UnitTest1.vcxproj.filters @@ -0,0 +1,30 @@ +锘 + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 婧愭枃浠 + + + 婧愭枃浠 + + + + + 澶存枃浠 + + + \ No newline at end of file diff --git a/add/UnitTest1/UnitTest1.vcxproj.user b/add/UnitTest1/UnitTest1.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/add/UnitTest1/UnitTest1.vcxproj.user @@ -0,0 +1,4 @@ +锘 + + + \ No newline at end of file diff --git a/add/UnitTest1/pch.cpp b/add/UnitTest1/pch.cpp new file mode 100644 index 0000000..d2bdc54 --- /dev/null +++ b/add/UnitTest1/pch.cpp @@ -0,0 +1,45 @@ +锘// pch.cpp: 涓庨缂栬瘧鏍囧ご瀵瑰簲鐨勬簮鏂囦欢 + +#include "pch.h" +#include +#include +int CalcCount(int n, char(*str)[10]) +{ + TCHAR chSectionNames[2048] = { 0 };//瀹氫箟涓涓暟缁勶紝淇濆瓨璇诲彇鑺傜殑鍚嶅瓧 + char* pSectionName; //淇濆瓨鎵惧埌鐨勬煇涓妭鍚嶅瓧绗︿覆鐨勯鍦板潃 + int i = 0; //i鎸囧悜鏁扮粍chSectionNames鐨勬煇涓綅缃紝浠0寮濮嬶紝椤哄簭鍚庣Щ + int j = 0; //j鐢ㄦ潵淇濆瓨涓嬩竴涓妭鍚嶅瓧绗︿覆鐨勯鍦板潃鐩稿浜庡綋鍓峣鐨勪綅缃亸绉婚噺 + 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++)//瀵筩hSectionName涓繚瀛樼殑鍐呭杩涜鎷嗗垎 + { + if (chSectionNames[0] == '\0')//濡傛灉绗竴涓瓧绗﹀氨鏄0锛屽垯璇存槑ini涓竴涓妭涔熸病鏈夛紝 + { + break; + } + if (chSectionNames[i] == '\0') + { + count++; + pSectionName = &chSectionNames[i - j]; //鎵惧埌涓涓0锛屽垯璇存槑浠庤繖涓瓧绗﹀線鍓嶏紝鍑忔帀j涓亸绉婚噺锛 + //灏辨槸涓涓妭鍚嶇殑棣栧湴鍧 + j = -1; //鎵惧埌涓涓妭鍚嶅悗锛宩鐨勫艰杩樺師锛屼互缁熻涓嬩竴涓妭鍚嶅湴鍧鐨勫亸绉婚噺 + //璧嬫垚-1鏄洜涓鸿妭鍚嶅瓧绗︿覆鐨勬渶鍚庝竴涓瓧绗0鏄粓姝㈢锛屼笉鑳戒綔涓鸿妭鍚 + for (m = 0; m <= strlen(pSectionName); m++)//鎶婃壘鍒扮殑鑺傚悕淇濆瓨鍒皊tr涓 + { + str[k][m] = *(pSectionName + m); + } + //str[k][++m] = '\0';//鎵嬪姩缁欒妭鍚嶅姞涓奬0,琛ㄧず杩欎釜鑺傚悕缁撴潫 + k++;//鍙橀噺鑷姞锛岀敤鏉ヤ繚瀛樹笅涓涓妭鍚 + //鍦ㄨ幏鍙栬妭鍚嶇殑鏃跺欏彲浠ヨ幏鍙栬鑺備腑閿殑鍊硷紝鍓嶆彁鏄垜浠煡閬撹鑺備腑鏈夊摢浜涢敭銆 + if (chSectionNames[i + 1] == 0) + { + break; //褰撲袱涓浉閭荤殑瀛楃閮芥槸0鏃讹紝鍒欐墍鏈夌殑鑺傚悕閮藉凡鎵惧埌锛屽惊鐜粓姝 + } + } + } + return count;//杩斿洖鑺傚悕鐨勪釜鏁 +} +// 褰撲娇鐢ㄩ缂栬瘧鐨勫ご鏃讹紝闇瑕佷娇鐢ㄦ婧愭枃浠讹紝缂栬瘧鎵嶈兘鎴愬姛銆 diff --git a/add/UnitTest1/pch.h b/add/UnitTest1/pch.h new file mode 100644 index 0000000..90cc566 --- /dev/null +++ b/add/UnitTest1/pch.h @@ -0,0 +1,12 @@ +锘// pch.h: 杩欐槸棰勭紪璇戞爣澶存枃浠躲 +// 涓嬫柟鍒楀嚭鐨勬枃浠朵粎缂栬瘧涓娆★紝鎻愰珮浜嗗皢鏉ョ敓鎴愮殑鐢熸垚鎬ц兘銆 +// 杩欒繕灏嗗奖鍝 IntelliSense 鎬ц兘锛屽寘鎷唬鐮佸畬鎴愬拰璁稿浠g爜娴忚鍔熻兘銆 +// 浣嗘槸锛屽鏋滄澶勫垪鍑虹殑鏂囦欢涓殑浠讳綍涓涓湪鐢熸垚涔嬮棿鏈夋洿鏂帮紝瀹冧滑鍏ㄩ儴閮藉皢琚噸鏂扮紪璇戙 +// 璇峰嬁鍦ㄦ澶勬坊鍔犺棰戠箒鏇存柊鐨勬枃浠讹紝杩欏皢浣垮緱鎬ц兘浼樺娍鏃犳晥銆 + +#ifndef PCH_H +#define PCH_H +int CalcCount(int n, char(*str)[10]); +// 娣诲姞瑕佸湪姝ゅ棰勭紪璇戠殑鏍囧ご + +#endif //PCH_H diff --git a/add/add.sln b/add/add.sln new file mode 100644 index 0000000..42cc8b7 --- /dev/null +++ b/add/add.sln @@ -0,0 +1,41 @@ +锘 +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}") = "add", "add\add.vcxproj", "{B2461A9C-6D35-4906-BCE4-723B1E669C20}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTest1", "UnitTest1\UnitTest1.vcxproj", "{34F2D7FA-8879-401C-9F95-A57B90C33DC5}" +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 + {B2461A9C-6D35-4906-BCE4-723B1E669C20}.Debug|x64.ActiveCfg = Debug|x64 + {B2461A9C-6D35-4906-BCE4-723B1E669C20}.Debug|x64.Build.0 = Debug|x64 + {B2461A9C-6D35-4906-BCE4-723B1E669C20}.Debug|x86.ActiveCfg = Debug|Win32 + {B2461A9C-6D35-4906-BCE4-723B1E669C20}.Debug|x86.Build.0 = Debug|Win32 + {B2461A9C-6D35-4906-BCE4-723B1E669C20}.Release|x64.ActiveCfg = Release|x64 + {B2461A9C-6D35-4906-BCE4-723B1E669C20}.Release|x64.Build.0 = Release|x64 + {B2461A9C-6D35-4906-BCE4-723B1E669C20}.Release|x86.ActiveCfg = Release|Win32 + {B2461A9C-6D35-4906-BCE4-723B1E669C20}.Release|x86.Build.0 = Release|Win32 + {34F2D7FA-8879-401C-9F95-A57B90C33DC5}.Debug|x64.ActiveCfg = Debug|x64 + {34F2D7FA-8879-401C-9F95-A57B90C33DC5}.Debug|x64.Build.0 = Debug|x64 + {34F2D7FA-8879-401C-9F95-A57B90C33DC5}.Debug|x86.ActiveCfg = Debug|Win32 + {34F2D7FA-8879-401C-9F95-A57B90C33DC5}.Debug|x86.Build.0 = Debug|Win32 + {34F2D7FA-8879-401C-9F95-A57B90C33DC5}.Release|x64.ActiveCfg = Release|x64 + {34F2D7FA-8879-401C-9F95-A57B90C33DC5}.Release|x64.Build.0 = Release|x64 + {34F2D7FA-8879-401C-9F95-A57B90C33DC5}.Release|x86.ActiveCfg = Release|Win32 + {34F2D7FA-8879-401C-9F95-A57B90C33DC5}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1938ABFD-AFB2-4663-807D-7FAF14CB344A} + EndGlobalSection +EndGlobal diff --git a/add/add/add.cpp b/add/add/add.cpp new file mode 100644 index 0000000..ff0665e --- /dev/null +++ b/add/add/add.cpp @@ -0,0 +1,5 @@ +#include "add.h" +long long add(int x, int y) +{ + return (long long)x + (long long)y;; +} diff --git a/add/add/add.h b/add/add/add.h new file mode 100644 index 0000000..9c057a4 --- /dev/null +++ b/add/add/add.h @@ -0,0 +1,4 @@ +#pragma once +#pragma once +#include +long long add(int x, int y); diff --git a/add/add/add.vcxproj b/add/add/add.vcxproj new file mode 100644 index 0000000..3d0181f --- /dev/null +++ b/add/add/add.vcxproj @@ -0,0 +1,150 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {b2461a9c-6d35-4906-bce4-723b1e669c20} + add + 10.0 + + + + StaticLibrary + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + \ No newline at end of file diff --git a/add/add/add.vcxproj.filters b/add/add/add.vcxproj.filters new file mode 100644 index 0000000..f8947b4 --- /dev/null +++ b/add/add/add.vcxproj.filters @@ -0,0 +1,27 @@ +锘 + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 澶存枃浠 + + + + + 婧愭枃浠 + + + \ No newline at end of file diff --git a/add/add/add.vcxproj.user b/add/add/add.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/add/add/add.vcxproj.user @@ -0,0 +1,4 @@ +锘 + + + \ No newline at end of file diff --git a/add/ex1.ini b/add/ex1.ini new file mode 100644 index 0000000..1000ccc --- /dev/null +++ b/add/ex1.ini @@ -0,0 +1,24 @@ +[TestMethod1] +na=12 +nb=4 +nExpect=16 +[TestMethod2] +na=3 +nb=7 +nExpect=10 +[TestMethod3] +na=2147483647 +nb=10 +nExpect=2147483657 +[TestMethod4] +na=2147483647 +nb=1000 +nExpect=2147484647 +[TestMethod5] +na=2147483647 +nb=10000 +nExpect=2147493647 + + + + diff --git a/add/readme.md b/add/readme.md new file mode 100644 index 0000000..bac2f3d --- /dev/null +++ b/add/readme.md @@ -0,0 +1,120 @@ +# add鍑芥暟璇存槑鏂囨。 +## 涓銆佸伐绋嬭鏄 +- 鏈伐绋嬬殑閰嶇疆绫诲瀷鏄竴涓潤鎬佸簱鏂囦欢锛岀洰鐨勬槸鐢熸垚涓涓彲琚叾浠栧伐绋嬭皟鐢ㄧ殑闈欐佸簱锛岄潤鎬佸簱鐨勫嚱鏁板姛鑳芥槸锛氳緭鍏ヤ袱涓猧nt绫诲瀷鐨勬暟锛岃繑鍥炰袱鏁颁箣鍜屻 +## 浜屻佸ご鏂囦欢 add.h 锛屾斁鐨勬槸add鍑芥暟鐨勫0鏄 +```C +#pragma once +#include +/* +**鍑芥暟鍚嶏細 add +**鍙傛暟锛歩nt 锛宨nt +**杩斿洖鍊硷細long long +**鍑芥暟鍔熻兘锛氫紶鍏ヤ袱涓猧nt绫诲瀷鐨勫弬鏁帮紝瀵瑰叾杩涜鍔犳硶杩愮畻骞惰繑鍥炰竴涓 long long绫诲瀷鐨勬暟鍊硷紝鐩殑鏄槻姝袱涓猧nt绫诲瀷鐩稿姞鐨勫拰瓒呰繃int鐨勮寖鍥达紝鎵浠ヨ繖閲岃繑鍥炲间笉鐢╥nt銆 +*/ + 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鏂囦欢骞舵坊鍔犳祴璇曟牱渚嬶紝涔嬪悗鍦ㄥ崟鍏冩祴璇曠殑婧愭枃浠堕噷瀵筰ni鏂囦欢杩涜璇诲彇瑙f瀽 锛屽畬鎴愪互鍚庤幏鍙栧崟鍏冩祴璇曠殑缁撴灉锛屼繚璇佷唬鐮佽鐩栫巼鍦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 +/* +**鍑芥暟鍔熻兘锛氳幏鍙栦竴涓猧ni鏂囦欢閲屾湁澶氬皯涓妭锛屽苟閫氳繃浜岀淮鎸囬拡鏁扮粍灏嗚妭鍚嶅甫鍑烘潵銆 +* 鍑芥暟鍚嶏細CalcCount锛堬級 +* 鍏ュ弬锛歩nt 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鐢ㄦ潵淇濆瓨涓嬩竴涓妭鍚嶅瓧绗︿覆鐨勯鍦板潃鐩稿浜庡綋鍓峣鐨勪綅缃亸绉婚噺 + 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++)//瀵筩hSectionName涓繚瀛樼殑鍐呭杩涜鎷嗗垎 + { + if (chSectionNames[0] == '\0')//濡傛灉绗竴涓瓧绗﹀氨鏄0锛屽垯璇存槑ini涓竴涓妭涔熸病鏈夛紝 + { + break; + } + if (chSectionNames[i] == '\0') + { + count++; + pSectionName = &chSectionNames[i - j]; //鎵惧埌涓涓0锛屽垯璇存槑浠庤繖涓瓧绗﹀線鍓嶏紝鍑忔帀j涓亸绉婚噺锛 + //灏辨槸涓涓妭鍚嶇殑棣栧湴鍧 + j = -1; //鎵惧埌涓涓妭鍚嶅悗锛宩鐨勫艰杩樺師锛屼互缁熻涓嬩竴涓妭鍚嶅湴鍧鐨勫亸绉婚噺 + //璧嬫垚-1鏄洜涓鸿妭鍚嶅瓧绗︿覆鐨勬渶鍚庝竴涓瓧绗0鏄粓姝㈢锛屼笉鑳戒綔涓鸿妭鍚 + for (m = 0; m <= strlen(pSectionName); m++)//鎶婃壘鍒扮殑鑺傚悕淇濆瓨鍒皊tr涓 + { + 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 +#include +#include"../A/add.h" +#define FilePath "../ex1.ini" +using namespace Microsoft::VisualStudio::CppUnitTestFramework; + +namespace UnitTest1 +{ + TEST_CLASS(UnitTest1) + { + public: + int j = 0;//寰幆鍙橀噺锛岀敤鏉ヨ闂甶ni鏂囦欢涓殑 鑺 + 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);//璇诲彇绗竴涓弬鏁帮紝淇濆瓨鍦╪a閲 + GetPrivateProfileString(str[j], "nb", " ", nb.GetBuffer(20), 20, FilePath);//璇诲彇绗簩涓弬鏁帮紝淇濆瓨鍦╪b閲 + GetPrivateProfileString(str[j], "nExpect", " ", nExpect.GetBuffer(20), 20, FilePath);//璇诲彇姝g‘鐨勫硷紝淇濆瓨鍦╪Expect閲 + nReal = add(_ttoi(na), _ttoi(nb)); //_ttoi鏄疌String杞负鏁村瀷锛屾妸杩愮畻缁撴灉缁檔Real + Assert::AreEqual(nReal, _ttoi(nExpect));\\瀵规瘮杩愮畻缁撴灉鍜屾纭粨鏋 + } + + } + }; +} +``` \ No newline at end of file diff --git a/dev/.vs/dev/v16/.suo b/dev/.vs/dev/v16/.suo new file mode 100644 index 0000000..0a2b0e7 Binary files /dev/null and b/dev/.vs/dev/v16/.suo differ diff --git a/dev/UnitTest1/UnitTest1.cpp b/dev/UnitTest1/UnitTest1.cpp new file mode 100644 index 0000000..d9be101 --- /dev/null +++ b/dev/UnitTest1/UnitTest1.cpp @@ -0,0 +1,86 @@ +#pragma once +#include "pch.h" +#include "CppUnitTest.h" +#include"../dev/dev.h" +#include +#include +#include + +#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 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/UnitTest1/UnitTest1.vcxproj b/dev/UnitTest1/UnitTest1.vcxproj new file mode 100644 index 0000000..74a5b86 --- /dev/null +++ b/dev/UnitTest1/UnitTest1.vcxproj @@ -0,0 +1,175 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {17E5808D-4540-4B67-898F-18D1CB5B82A0} + Win32Proj + UnitTest1 + 10.0 + NativeUnitTestProject + + + + DynamicLibrary + true + v142 + MultiByte + false + + + DynamicLibrary + false + v142 + true + Unicode + false + + + DynamicLibrary + true + v142 + Unicode + false + + + DynamicLibrary + false + v142 + true + Unicode + false + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + Use + Level3 + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + ..\dev\Debug\dev.obj;%(AdditionalDependencies) + DebugFull + + + + + Use + Level3 + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + _DEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Use + Level3 + true + true + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + true + true + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Use + Level3 + true + true + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + NDEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + true + true + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Create + Create + Create + Create + + + + + + + + + + \ No newline at end of file diff --git a/dev/UnitTest1/UnitTest1.vcxproj.filters b/dev/UnitTest1/UnitTest1.vcxproj.filters new file mode 100644 index 0000000..83a287b --- /dev/null +++ b/dev/UnitTest1/UnitTest1.vcxproj.filters @@ -0,0 +1,30 @@ +锘 + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 婧愭枃浠 + + + 婧愭枃浠 + + + + + 澶存枃浠 + + + \ No newline at end of file diff --git a/dev/UnitTest1/UnitTest1.vcxproj.user b/dev/UnitTest1/UnitTest1.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/dev/UnitTest1/UnitTest1.vcxproj.user @@ -0,0 +1,4 @@ +锘 + + + \ No newline at end of file diff --git a/dev/UnitTest1/pch.cpp b/dev/UnitTest1/pch.cpp new file mode 100644 index 0000000..96ad9c7 --- /dev/null +++ b/dev/UnitTest1/pch.cpp @@ -0,0 +1,44 @@ +锘// 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鐢ㄦ潵淇濆瓨涓嬩竴涓妭鍚嶅瓧绗︿覆鐨勯鍦板潃鐩稿浜庡綋鍓峣鐨勪綅缃亸绉婚噺 + 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++)//瀵筩hSectionName涓繚瀛樼殑鍐呭杩涜鎷嗗垎 + { + if (chSectionNames[0] == '\0')//濡傛灉绗竴涓瓧绗﹀氨鏄0锛屽垯璇存槑ini涓竴涓妭涔熸病鏈夛紝 + { + break; + } + if (chSectionNames[i] == '\0') + { + count++; + pSectionName = &chSectionNames[i - j]; //鎵惧埌涓涓0锛屽垯璇存槑浠庤繖涓瓧绗﹀線鍓嶏紝鍑忔帀j涓亸绉婚噺锛 + //灏辨槸涓涓妭鍚嶇殑棣栧湴鍧 + j = -1; //鎵惧埌涓涓妭鍚嶅悗锛宩鐨勫艰杩樺師锛屼互缁熻涓嬩竴涓妭鍚嶅湴鍧鐨勫亸绉婚噺 + //璧嬫垚-1鏄洜涓鸿妭鍚嶅瓧绗︿覆鐨勬渶鍚庝竴涓瓧绗0鏄粓姝㈢锛屼笉鑳戒綔涓鸿妭鍚 + for (m = 0; m <= strlen(pSectionName); m++)//鎶婃壘鍒扮殑鑺傚悕淇濆瓨鍒皊tr涓 + { + str[k][m] = *(pSectionName + m); + } + //str[k][++m] = '\0';//鎵嬪姩缁欒妭鍚嶅姞涓奬0,琛ㄧず杩欎釜鑺傚悕缁撴潫 + k++;//鍙橀噺鑷姞锛岀敤鏉ヤ繚瀛樹笅涓涓妭鍚 + //鍦ㄨ幏鍙栬妭鍚嶇殑鏃跺欏彲浠ヨ幏鍙栬鑺備腑閿殑鍊硷紝鍓嶆彁鏄垜浠煡閬撹鑺備腑鏈夊摢浜涢敭銆 + if (chSectionNames[i + 1] == 0) + { + break; //褰撲袱涓浉閭荤殑瀛楃閮芥槸0鏃讹紝鍒欐墍鏈夌殑鑺傚悕閮藉凡鎵惧埌锛屽惊鐜粓姝 + } + } + } + return count;//杩斿洖鑺傚悕鐨勪釜鏁 +} + +// 褰撲娇鐢ㄩ缂栬瘧鐨勫ご鏃讹紝闇瑕佷娇鐢ㄦ婧愭枃浠讹紝缂栬瘧鎵嶈兘鎴愬姛銆 diff --git a/dev/UnitTest1/pch.h b/dev/UnitTest1/pch.h new file mode 100644 index 0000000..f455103 --- /dev/null +++ b/dev/UnitTest1/pch.h @@ -0,0 +1,14 @@ +锘// pch.h: 杩欐槸棰勭紪璇戞爣澶存枃浠躲 +// 涓嬫柟鍒楀嚭鐨勬枃浠朵粎缂栬瘧涓娆★紝鎻愰珮浜嗗皢鏉ョ敓鎴愮殑鐢熸垚鎬ц兘銆 +// 杩欒繕灏嗗奖鍝 IntelliSense 鎬ц兘锛屽寘鎷唬鐮佸畬鎴愬拰璁稿浠g爜娴忚鍔熻兘銆 +// 浣嗘槸锛屽鏋滄澶勫垪鍑虹殑鏂囦欢涓殑浠讳綍涓涓湪鐢熸垚涔嬮棿鏈夋洿鏂帮紝瀹冧滑鍏ㄩ儴閮藉皢琚噸鏂扮紪璇戙 +// 璇峰嬁鍦ㄦ澶勬坊鍔犺棰戠箒鏇存柊鐨勬枃浠讹紝杩欏皢浣垮緱鎬ц兘浼樺娍鏃犳晥銆 + +#ifndef PCH_H +#define PCH_H +#include + +#include +// 娣诲姞瑕佸湪姝ゅ棰勭紪璇戠殑鏍囧ご +int CalcCount(int n, char(*str)[10]); +#endif //PCH_H diff --git a/dev/dev.sln b/dev/dev.sln new file mode 100644 index 0000000..77a68cd --- /dev/null +++ b/dev/dev.sln @@ -0,0 +1,41 @@ +锘 +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}") = "dev", "dev\dev.vcxproj", "{373F16B2-9E44-42AE-9CB5-F50C1D469625}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTest1", "UnitTest1\UnitTest1.vcxproj", "{17E5808D-4540-4B67-898F-18D1CB5B82A0}" +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 + {373F16B2-9E44-42AE-9CB5-F50C1D469625}.Debug|x64.ActiveCfg = Debug|x64 + {373F16B2-9E44-42AE-9CB5-F50C1D469625}.Debug|x64.Build.0 = Debug|x64 + {373F16B2-9E44-42AE-9CB5-F50C1D469625}.Debug|x86.ActiveCfg = Debug|Win32 + {373F16B2-9E44-42AE-9CB5-F50C1D469625}.Debug|x86.Build.0 = Debug|Win32 + {373F16B2-9E44-42AE-9CB5-F50C1D469625}.Release|x64.ActiveCfg = Release|x64 + {373F16B2-9E44-42AE-9CB5-F50C1D469625}.Release|x64.Build.0 = Release|x64 + {373F16B2-9E44-42AE-9CB5-F50C1D469625}.Release|x86.ActiveCfg = Release|Win32 + {373F16B2-9E44-42AE-9CB5-F50C1D469625}.Release|x86.Build.0 = Release|Win32 + {17E5808D-4540-4B67-898F-18D1CB5B82A0}.Debug|x64.ActiveCfg = Debug|x64 + {17E5808D-4540-4B67-898F-18D1CB5B82A0}.Debug|x64.Build.0 = Debug|x64 + {17E5808D-4540-4B67-898F-18D1CB5B82A0}.Debug|x86.ActiveCfg = Debug|Win32 + {17E5808D-4540-4B67-898F-18D1CB5B82A0}.Debug|x86.Build.0 = Debug|Win32 + {17E5808D-4540-4B67-898F-18D1CB5B82A0}.Release|x64.ActiveCfg = Release|x64 + {17E5808D-4540-4B67-898F-18D1CB5B82A0}.Release|x64.Build.0 = Release|x64 + {17E5808D-4540-4B67-898F-18D1CB5B82A0}.Release|x86.ActiveCfg = Release|Win32 + {17E5808D-4540-4B67-898F-18D1CB5B82A0}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A53B4729-E877-4464-9628-FC58CAE67389} + EndGlobalSection +EndGlobal diff --git a/dev/dev/Opera_api.cpp b/dev/dev/Opera_api.cpp new file mode 100644 index 0000000..c778d1b --- /dev/null +++ b/dev/dev/Opera_api.cpp @@ -0,0 +1,35 @@ +#pragma once +#include "Opera_api.h" +#include"../../add/add/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/Debug/mul.dll"); + if (hdll != NULL) + { + MulFunc MUL1 = (MulFunc)GetProcAddress(hdll, (char*)(1)); + if (MUL1 != NULL) + { + res = MUL1(x, y); + return res; + } + FreeLibrary(hdll); + } +} + + + diff --git a/dev/dev/Opera_api.h b/dev/dev/Opera_api.h new file mode 100644 index 0000000..a296aa3 --- /dev/null +++ b/dev/dev/Opera_api.h @@ -0,0 +1,10 @@ +#pragma once +#include"./sub.h" +#include +#include +#pragma comment(lib,"./sub.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); diff --git a/dev/dev/dev.cpp b/dev/dev/dev.cpp new file mode 100644 index 0000000..c939cd1 --- /dev/null +++ b/dev/dev/dev.cpp @@ -0,0 +1,15 @@ +#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; + } +} \ No newline at end of file diff --git a/dev/dev/dev.h b/dev/dev/dev.h new file mode 100644 index 0000000..8bbaaf1 --- /dev/null +++ b/dev/dev/dev.h @@ -0,0 +1,5 @@ +#pragma once +#include +#include + +int dev(int x, int y); \ No newline at end of file diff --git a/dev/dev/dev.vcxproj b/dev/dev/dev.vcxproj new file mode 100644 index 0000000..d09f2ea --- /dev/null +++ b/dev/dev/dev.vcxproj @@ -0,0 +1,156 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {373f16b2-9e44-42ae-9cb5-f50c1d469625} + dev + 10.0 + + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + ..\..\add\add + + + Console + DebugFull + ..\..\add\Debug;%(AdditionalLibraryDirectories) + add.lib;%(AdditionalDependencies) + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/dev/dev/dev.vcxproj.filters b/dev/dev/dev.vcxproj.filters new file mode 100644 index 0000000..d1ca5af --- /dev/null +++ b/dev/dev/dev.vcxproj.filters @@ -0,0 +1,36 @@ +锘 + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 澶存枃浠 + + + 澶存枃浠 + + + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + \ No newline at end of file diff --git a/dev/dev/dev.vcxproj.user b/dev/dev/dev.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/dev/dev/dev.vcxproj.user @@ -0,0 +1,4 @@ +锘 + + + \ No newline at end of file diff --git a/dev/dev/main.cpp b/dev/dev/main.cpp new file mode 100644 index 0000000..2e6c127 --- /dev/null +++ b/dev/dev/main.cpp @@ -0,0 +1,13 @@ + +#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; +} \ No newline at end of file diff --git a/dev/dev/sub.dll b/dev/dev/sub.dll new file mode 100644 index 0000000..0092c64 Binary files /dev/null and b/dev/dev/sub.dll differ diff --git a/dev/dev/sub.h b/dev/dev/sub.h new file mode 100644 index 0000000..135a4cf --- /dev/null +++ b/dev/dev/sub.h @@ -0,0 +1,13 @@ +#ifndef _SUB_H_ +#define _SUB_H_ + +#ifdef sub_EXPORTS +#define sub_EXPORTS _declspec(dllexport) +#else +#define sub_EXPORTS _declspec(dllimport) +#endif + +sub_EXPORTS long long sub(int x, int y); + +#endif + diff --git a/dev/dev/sub.lib b/dev/dev/sub.lib new file mode 100644 index 0000000..aa4e126 Binary files /dev/null and b/dev/dev/sub.lib differ diff --git a/dev/ex1.ini b/dev/ex1.ini new file mode 100644 index 0000000..7b9ddd4 --- /dev/null +++ b/dev/ex1.ini @@ -0,0 +1,21 @@ +[TestMethod1] +na=6 +nb=2 +nExpect=3 +[TestMethod2] +na=4 +nb=2 +nExpect=2 +[TestMethod3] +na=3 +nb=0 +nExpect=0 +[TestMethod4] +na=100 +nb=10 +nExpect=10 +[TestMethod5] +na=100 +nb=10 +nExpect=10 + diff --git a/dev/readme.md b/dev/readme.md new file mode 100644 index 0000000..2bd8b0c --- /dev/null +++ b/dev/readme.md @@ -0,0 +1,228 @@ +# dev鍑芥暟璇存槑鏂囨。 +## 涓銆佸伐绋嬭鏄 +- 鏈伐绋嬬殑閰嶇疆绫诲瀷鏄竴涓猠xe鍙墽琛屾枃浠讹紝宸ョ▼鍐呭瓨鍦ㄥ洓涓嚱鏁版帴鍙o紝鍒嗗埆涓哄姞銆佸噺銆佷箻銆侀櫎銆傚姞娉曞嚱鏁版帴鍙f槸璋冪敤add闈欐佸簱瀹炵幇锛涘噺娉曞嚱鏁版帴鍙f槸閲囩敤鍦ㄥ伐绋嬩腑閰嶇疆鍔犺浇sub鍔ㄦ佸簱鐨勬柟寮忓疄鐜帮紱涔樻硶鎺ュ彛浠ヨ繍琛屾椂鍔犺浇鍔ㄦ佸簱mul鐨勬柟寮忓疄鐜帮紱闄ゆ硶鎺ュ彛璋冪敤鏈韩鍑芥暟鐨勬柟寮忓疄鐜般 +## 浜屻佸伐绋嬫枃浠 +1. 闄ゆ硶鍑芥暟 + - 澶存枃浠 dev.h 锛屾斁鐨勬槸dev鐨勫0鏄 + ```C + #pragma once + #include + #include + /* + **鍑芥暟鍚嶏細 dev + **鍙傛暟锛歩nt 锛宨nt + **杩斿洖鍊硷細int + **鍑芥暟鍔熻兘锛氫紶鍏ヤ袱涓猧nt绫诲瀷鐨勫弬鏁帮紝瀵瑰叾杩涜闄ゆ硶杩愮畻骞惰繑鍥炰袱鏁颁箣鍟嗐 + */ + 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 + #include + #pragma comment(lib,"./B.lib") + typedef int(WINAPI* MulFunc)(int x, int y); + + /* + **鍑芥暟鍚嶏細 add_api + **鍙傛暟锛歩nt 锛宨nt + **杩斿洖鍊硷細long long + **鍑芥暟鍔熻兘锛氫紶鍏ヤ袱涓猧nt绫诲瀷鐨勫弬鏁帮紝璋冪敤闈欐佸簱add鍑芥暟鐨勬柟寮忓疄鐜般 + */ + long long add_api(int x, int y); + + /* + **鍑芥暟鍚嶏細 sub_api + **鍙傛暟锛歩nt 锛宨nt + **杩斿洖鍊硷細int + **鍑芥暟鍔熻兘锛氫紶鍏ヤ袱涓猧nt绫诲瀷鐨勫弬鏁帮紝璋冪敤鍔ㄦ佸簱sub鍑芥暟鐨勬柟寮忓疄鐜般 + */ + int sub_api(int x, int y); + + /* + **鍑芥暟鍚嶏細 mul_api + **鍙傛暟锛歩nt 锛宨nt + **杩斿洖鍊硷細long long + **鍑芥暟鍔熻兘锛氫紶鍏ヤ袱涓猧nt绫诲瀷鐨勫弬鏁帮紝杩愯鏃跺姞杞藉姩鎬佸簱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. 杩愯缁撴灉濡備笅锛 + ![](./pic/main.jpg) + ## 涓夈佸崟鍏冩祴璇 + - 鎵嬪姩鍒涘缓ini鏂囦欢骞舵坊鍔犳祴璇曟牱渚嬶紝涔嬪悗鍦ㄥ崟鍏冩祴璇曠殑婧愭枃浠堕噷瀵筰ni鏂囦欢杩涜璇诲彇瑙f瀽 锛屽畬鎴愪互鍚庤幏鍙栧崟鍏冩祴璇曠殑缁撴灉锛屼繚璇佷唬鐮佽鐩栫巼鍦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 +/* +**鍑芥暟鍔熻兘锛氳幏鍙栦竴涓猧ni鏂囦欢閲屾湁澶氬皯涓妭锛屽苟閫氳繃浜岀淮鎸囬拡鏁扮粍灏嗚妭鍚嶅甫鍑烘潵銆 +* 鍑芥暟鍚嶏細CalcCount锛堬級 +* 鍏ュ弬锛歩nt 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鐢ㄦ潵淇濆瓨涓嬩竴涓妭鍚嶅瓧绗︿覆鐨勯鍦板潃鐩稿浜庡綋鍓峣鐨勪綅缃亸绉婚噺 + 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++)//瀵筩hSectionName涓繚瀛樼殑鍐呭杩涜鎷嗗垎 + { + if (chSectionNames[0] == '\0')//濡傛灉绗竴涓瓧绗﹀氨鏄0锛屽垯璇存槑ini涓竴涓妭涔熸病鏈夛紝 + { + break; + } + if (chSectionNames[i] == '\0') + { + count++; + pSectionName = &chSectionNames[i - j]; //鎵惧埌涓涓0锛屽垯璇存槑浠庤繖涓瓧绗﹀線鍓嶏紝鍑忔帀j涓亸绉婚噺锛 + //灏辨槸涓涓妭鍚嶇殑棣栧湴鍧 + j = -1; //鎵惧埌涓涓妭鍚嶅悗锛宩鐨勫艰杩樺師锛屼互缁熻涓嬩竴涓妭鍚嶅湴鍧鐨勫亸绉婚噺 + //璧嬫垚-1鏄洜涓鸿妭鍚嶅瓧绗︿覆鐨勬渶鍚庝竴涓瓧绗0鏄粓姝㈢锛屼笉鑳戒綔涓鸿妭鍚 + for (m = 0; m <= strlen(pSectionName); m++)//鎶婃壘鍒扮殑鑺傚悕淇濆瓨鍒皊tr涓 + { + 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 +#include +#include"../FourOperator/dev.h" +#define FilePath "../ex1.ini" +using namespace Microsoft::VisualStudio::CppUnitTestFramework; + +namespace UnitTest1 +{ + TEST_CLASS(UnitTest1) + { + public: + int j = 0;//寰幆鍙橀噺锛岀敤鏉ヨ闂甶ni鏂囦欢涓殑 鑺 + 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);//璇诲彇绗竴涓弬鏁帮紝淇濆瓨鍦╪a閲 + GetPrivateProfileString(str[j], "nb", " ", nb.GetBuffer(20), 20, FilePath);//璇诲彇绗簩涓弬鏁帮紝淇濆瓨鍦╪b閲 + GetPrivateProfileString(str[j], "nExpect", " ", nExpect.GetBuffer(20), 20, FilePath);//璇诲彇姝g‘鐨勫硷紝淇濆瓨鍦╪Expect閲 + nReal = dev(_ttoi(na), _ttoi(nb)); //_ttoi鏄疌String杞负鏁村瀷锛屾妸杩愮畻缁撴灉缁檔Real + Assert::AreEqual(nReal, _ttoi(nExpect));//瀵规瘮杩愮畻缁撴灉鍜屾纭粨鏋 + } + + } + }; +} +``` + + diff --git a/mul/.vs/mul/v16/.suo b/mul/.vs/mul/v16/.suo new file mode 100644 index 0000000..72f7efe Binary files /dev/null and b/mul/.vs/mul/v16/.suo differ diff --git a/mul/UnitTest1/UnitTest1.cpp b/mul/UnitTest1/UnitTest1.cpp new file mode 100644 index 0000000..9eeae95 --- /dev/null +++ b/mul/UnitTest1/UnitTest1.cpp @@ -0,0 +1,36 @@ +#include "pch.h" +#include "CppUnitTest.h" +#include "../mul/mul.h" +#include +#include + +#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) + { + long long 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(_ttoi64(na), _ttoi64(nb)); //_ttoi是CString转为整型 + Assert::AreEqual(nReal, _ttoi64(nExpect)); + } + + } + + }; +} diff --git a/mul/UnitTest1/UnitTest1.vcxproj b/mul/UnitTest1/UnitTest1.vcxproj new file mode 100644 index 0000000..b5d66a3 --- /dev/null +++ b/mul/UnitTest1/UnitTest1.vcxproj @@ -0,0 +1,175 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {9349997F-BBA9-466B-87AB-033AF11E021A} + Win32Proj + UnitTest1 + 10.0 + NativeUnitTestProject + + + + DynamicLibrary + true + v142 + MultiByte + false + + + DynamicLibrary + false + v142 + true + Unicode + false + + + DynamicLibrary + true + v142 + Unicode + false + + + DynamicLibrary + false + v142 + true + Unicode + false + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + Use + Level3 + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + ..\mul\Debug\mul.obj;%(AdditionalDependencies) + DebugFull + + + + + Use + Level3 + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + _DEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Use + Level3 + true + true + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + true + true + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Use + Level3 + true + true + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + NDEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + true + true + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Create + Create + Create + Create + + + + + + + + + + \ No newline at end of file diff --git a/mul/UnitTest1/UnitTest1.vcxproj.filters b/mul/UnitTest1/UnitTest1.vcxproj.filters new file mode 100644 index 0000000..83a287b --- /dev/null +++ b/mul/UnitTest1/UnitTest1.vcxproj.filters @@ -0,0 +1,30 @@ +锘 + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 婧愭枃浠 + + + 婧愭枃浠 + + + + + 澶存枃浠 + + + \ No newline at end of file diff --git a/mul/UnitTest1/UnitTest1.vcxproj.user b/mul/UnitTest1/UnitTest1.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/mul/UnitTest1/UnitTest1.vcxproj.user @@ -0,0 +1,4 @@ +锘 + + + \ No newline at end of file diff --git a/mul/UnitTest1/pch.cpp b/mul/UnitTest1/pch.cpp new file mode 100644 index 0000000..eb28fa4 --- /dev/null +++ b/mul/UnitTest1/pch.cpp @@ -0,0 +1,45 @@ +锘/// pch.cpp: 涓庨缂栬瘧鏍囧ご瀵瑰簲鐨勬簮鏂囦欢 +#include +#include "pch.h" +#include +int CalcCount(int n, char(*str)[10]) +{ + TCHAR chSectionNames[2048] = { 0 };//瀹氫箟涓涓暟缁勶紝淇濆瓨璇诲彇鑺傜殑鍚嶅瓧 + char* pSectionName; //淇濆瓨鎵惧埌鐨勬煇涓妭鍚嶅瓧绗︿覆鐨勯鍦板潃 + int i = 0; //i鎸囧悜鏁扮粍chSectionNames鐨勬煇涓綅缃紝浠0寮濮嬶紝椤哄簭鍚庣Щ + int j = 0; //j鐢ㄦ潵淇濆瓨涓嬩竴涓妭鍚嶅瓧绗︿覆鐨勯鍦板潃鐩稿浜庡綋鍓峣鐨勪綅缃亸绉婚噺 + 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++)//瀵筩hSectionName涓繚瀛樼殑鍐呭杩涜鎷嗗垎 + { + if (chSectionNames[0] == '\0')//濡傛灉绗竴涓瓧绗﹀氨鏄0锛屽垯璇存槑ini涓竴涓妭涔熸病鏈夛紝 + { + break; + } + if (chSectionNames[i] == '\0') + { + count++; + pSectionName = &chSectionNames[i - j]; //鎵惧埌涓涓0锛屽垯璇存槑浠庤繖涓瓧绗﹀線鍓嶏紝鍑忔帀j涓亸绉婚噺锛 + //灏辨槸涓涓妭鍚嶇殑棣栧湴鍧 + j = -1; //鎵惧埌涓涓妭鍚嶅悗锛宩鐨勫艰杩樺師锛屼互缁熻涓嬩竴涓妭鍚嶅湴鍧鐨勫亸绉婚噺 + //璧嬫垚-1鏄洜涓鸿妭鍚嶅瓧绗︿覆鐨勬渶鍚庝竴涓瓧绗0鏄粓姝㈢锛屼笉鑳戒綔涓鸿妭鍚 + for (m = 0; m <= strlen(pSectionName); m++)//鎶婃壘鍒扮殑鑺傚悕淇濆瓨鍒皊tr涓 + { + str[k][m] = *(pSectionName + m); + } + //str[k][++m] = '\0';//鎵嬪姩缁欒妭鍚嶅姞涓奬0,琛ㄧず杩欎釜鑺傚悕缁撴潫 + k++;//鍙橀噺鑷姞锛岀敤鏉ヤ繚瀛樹笅涓涓妭鍚 + //鍦ㄨ幏鍙栬妭鍚嶇殑鏃跺欏彲浠ヨ幏鍙栬鑺備腑閿殑鍊硷紝鍓嶆彁鏄垜浠煡閬撹鑺備腑鏈夊摢浜涢敭銆 + if (chSectionNames[i + 1] == 0) + { + break; //褰撲袱涓浉閭荤殑瀛楃閮芥槸0鏃讹紝鍒欐墍鏈夌殑鑺傚悕閮藉凡鎵惧埌锛屽惊鐜粓姝 + } + } + } + return count;//杩斿洖鑺傚悕鐨勪釜鏁 +} + +// 褰撲娇鐢ㄩ缂栬瘧鐨勫ご鏃讹紝闇瑕佷娇鐢ㄦ婧愭枃浠讹紝缂栬瘧鎵嶈兘鎴愬姛銆 diff --git a/mul/UnitTest1/pch.h b/mul/UnitTest1/pch.h new file mode 100644 index 0000000..90cc566 --- /dev/null +++ b/mul/UnitTest1/pch.h @@ -0,0 +1,12 @@ +锘// pch.h: 杩欐槸棰勭紪璇戞爣澶存枃浠躲 +// 涓嬫柟鍒楀嚭鐨勬枃浠朵粎缂栬瘧涓娆★紝鎻愰珮浜嗗皢鏉ョ敓鎴愮殑鐢熸垚鎬ц兘銆 +// 杩欒繕灏嗗奖鍝 IntelliSense 鎬ц兘锛屽寘鎷唬鐮佸畬鎴愬拰璁稿浠g爜娴忚鍔熻兘銆 +// 浣嗘槸锛屽鏋滄澶勫垪鍑虹殑鏂囦欢涓殑浠讳綍涓涓湪鐢熸垚涔嬮棿鏈夋洿鏂帮紝瀹冧滑鍏ㄩ儴閮藉皢琚噸鏂扮紪璇戙 +// 璇峰嬁鍦ㄦ澶勬坊鍔犺棰戠箒鏇存柊鐨勬枃浠讹紝杩欏皢浣垮緱鎬ц兘浼樺娍鏃犳晥銆 + +#ifndef PCH_H +#define PCH_H +int CalcCount(int n, char(*str)[10]); +// 娣诲姞瑕佸湪姝ゅ棰勭紪璇戠殑鏍囧ご + +#endif //PCH_H diff --git a/mul/ex1.ini b/mul/ex1.ini new file mode 100644 index 0000000..01b2205 --- /dev/null +++ b/mul/ex1.ini @@ -0,0 +1,22 @@ +[TestMethod1] +na=4 +nb=4 +nExpect=16 +[TestMethod2] +na=3 +nb=7 +nExpect=21 +[TestMethod3] +na=3 +nb=5 +nExpect=15 +[TestMethod4] +na=2147483647 +nb=2 +nExpect=4294967294 +[TestMethod5] +na=2147483647 +nb=10 +nExpect=21474836470 + + diff --git a/mul/mul.sln b/mul/mul.sln new file mode 100644 index 0000000..de1862c --- /dev/null +++ b/mul/mul.sln @@ -0,0 +1,41 @@ +锘 +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}") = "mul", "mul\mul.vcxproj", "{5F45D6E6-F22E-4144-AD99-F5A8F1C89852}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTest1", "UnitTest1\UnitTest1.vcxproj", "{9349997F-BBA9-466B-87AB-033AF11E021A}" +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 + {5F45D6E6-F22E-4144-AD99-F5A8F1C89852}.Debug|x64.ActiveCfg = Debug|x64 + {5F45D6E6-F22E-4144-AD99-F5A8F1C89852}.Debug|x64.Build.0 = Debug|x64 + {5F45D6E6-F22E-4144-AD99-F5A8F1C89852}.Debug|x86.ActiveCfg = Debug|Win32 + {5F45D6E6-F22E-4144-AD99-F5A8F1C89852}.Debug|x86.Build.0 = Debug|Win32 + {5F45D6E6-F22E-4144-AD99-F5A8F1C89852}.Release|x64.ActiveCfg = Release|x64 + {5F45D6E6-F22E-4144-AD99-F5A8F1C89852}.Release|x64.Build.0 = Release|x64 + {5F45D6E6-F22E-4144-AD99-F5A8F1C89852}.Release|x86.ActiveCfg = Release|Win32 + {5F45D6E6-F22E-4144-AD99-F5A8F1C89852}.Release|x86.Build.0 = Release|Win32 + {9349997F-BBA9-466B-87AB-033AF11E021A}.Debug|x64.ActiveCfg = Debug|x64 + {9349997F-BBA9-466B-87AB-033AF11E021A}.Debug|x64.Build.0 = Debug|x64 + {9349997F-BBA9-466B-87AB-033AF11E021A}.Debug|x86.ActiveCfg = Debug|Win32 + {9349997F-BBA9-466B-87AB-033AF11E021A}.Debug|x86.Build.0 = Debug|Win32 + {9349997F-BBA9-466B-87AB-033AF11E021A}.Release|x64.ActiveCfg = Release|x64 + {9349997F-BBA9-466B-87AB-033AF11E021A}.Release|x64.Build.0 = Release|x64 + {9349997F-BBA9-466B-87AB-033AF11E021A}.Release|x86.ActiveCfg = Release|Win32 + {9349997F-BBA9-466B-87AB-033AF11E021A}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {25E2EB02-6E3D-4816-9848-035C68239F09} + EndGlobalSection +EndGlobal diff --git a/mul/mul/Source.def b/mul/mul/Source.def new file mode 100644 index 0000000..3387fa3 --- /dev/null +++ b/mul/mul/Source.def @@ -0,0 +1,3 @@ +LIBRARY "Source" +EXPORTS +mul @1 diff --git a/mul/mul/mul.cpp b/mul/mul/mul.cpp new file mode 100644 index 0000000..8e0cfca --- /dev/null +++ b/mul/mul/mul.cpp @@ -0,0 +1,11 @@ + +#include "mul.h" +#include +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; +} \ No newline at end of file diff --git a/mul/mul/mul.h b/mul/mul/mul.h new file mode 100644 index 0000000..c7e3e4c --- /dev/null +++ b/mul/mul/mul.h @@ -0,0 +1,2 @@ +#pragma once +long long _stdcall mul(int x, int y); diff --git a/mul/mul/mul.vcxproj b/mul/mul/mul.vcxproj new file mode 100644 index 0000000..be00127 --- /dev/null +++ b/mul/mul/mul.vcxproj @@ -0,0 +1,157 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {5f45d6e6-f22e-4144-ad99-f5a8f1c89852} + mul + 10.0 + + + + DynamicLibrary + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + Source.def + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + Source.def + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + Source.def + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + Source.def + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mul/mul/mul.vcxproj.filters b/mul/mul/mul.vcxproj.filters new file mode 100644 index 0000000..0fe02ca --- /dev/null +++ b/mul/mul/mul.vcxproj.filters @@ -0,0 +1,32 @@ +锘 + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 澶存枃浠 + + + + + 婧愭枃浠 + + + + + 婧愭枃浠 + + + \ No newline at end of file diff --git a/mul/mul/mul.vcxproj.user b/mul/mul/mul.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/mul/mul/mul.vcxproj.user @@ -0,0 +1,4 @@ +锘 + + + \ No newline at end of file diff --git a/mul/readme.md b/mul/readme.md new file mode 100644 index 0000000..d8db606 --- /dev/null +++ b/mul/readme.md @@ -0,0 +1,131 @@ +# mul鍑芥暟璇存槑鏂囨。 +## 涓銆佸伐绋嬭鏄 +- 鏈伐绋嬬殑閰嶇疆绫诲瀷鏄竴涓姩鎬佸簱鏂囦欢锛屼娇鐢ㄧ殑鏂规硶鏄敓鎴.def鏂囦欢锛岀洰鐨勬槸鐢熸垚涓涓彲琚叾浠栧伐绋嬭皟鐢ㄥ姩鎬佸簱锛屽姩鎬佸簱鐨勫嚱鏁板姛鑳芥槸锛氳緭鍏ヤ袱涓猧nt绫诲瀷鐨勬暟锛岃繑鍥炰袱鏁颁箣绉 +## 浜屻佸ご鏂囦欢 mul.h 锛屾斁鐨勬槸mul鍑芥暟鐨勫0鏄 +```C +/* +**鍑芥暟鍚嶏細 mul +**鍙傛暟锛歩nt 锛宨nt +**杩斿洖鍊硷細long long +**鍑芥暟鍔熻兘锛氫紶鍏ヤ袱涓猧nt绫诲瀷鐨勫弬鏁帮紝瀵瑰叾杩涜涔樻硶杩愮畻骞惰繑鍥炰袱鏁颁箣绉紝鍥犱负涓や釜int鍨嬫暟鐩镐箻缁撴灉鍙兘浼氳秴鍑篿nt鑼冨洿锛屾墍浠ヨ繑鍥炲肩敤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; +} +``` +## 鍥涖乨ef鏂囦欢鍐呭 Source.def + ``` + LIBRARY "Source" + EXPORTS + mul @1 + + ``` +## 浜斻佸崟鍏冩祴璇 +- 鎵嬪姩鍒涘缓ini鏂囦欢骞舵坊鍔犳祴璇曟牱渚嬶紝涔嬪悗鍦ㄥ崟鍏冩祴璇曠殑婧愭枃浠堕噷瀵筰ni鏂囦欢杩涜璇诲彇瑙f瀽 锛屽畬鎴愪互鍚庤幏鍙栧崟鍏冩祴璇曠殑缁撴灉锛屼繚璇佷唬鐮佽鐩栫巼鍦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 +/* +**鍑芥暟鍔熻兘锛氳幏鍙栦竴涓猧ni鏂囦欢閲屾湁澶氬皯涓妭锛屽苟閫氳繃浜岀淮鎸囬拡鏁扮粍灏嗚妭鍚嶅甫鍑烘潵銆 +* 鍑芥暟鍚嶏細CalcCount锛堬級 +* 鍏ュ弬锛歩nt 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鐢ㄦ潵淇濆瓨涓嬩竴涓妭鍚嶅瓧绗︿覆鐨勯鍦板潃鐩稿浜庡綋鍓峣鐨勪綅缃亸绉婚噺 + 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++)//瀵筩hSectionName涓繚瀛樼殑鍐呭杩涜鎷嗗垎 + { + if (chSectionNames[0] == '\0')//濡傛灉绗竴涓瓧绗﹀氨鏄0锛屽垯璇存槑ini涓竴涓妭涔熸病鏈夛紝 + { + break; + } + if (chSectionNames[i] == '\0') + { + count++; + pSectionName = &chSectionNames[i - j]; //鎵惧埌涓涓0锛屽垯璇存槑浠庤繖涓瓧绗﹀線鍓嶏紝鍑忔帀j涓亸绉婚噺锛 + //灏辨槸涓涓妭鍚嶇殑棣栧湴鍧 + j = -1; //鎵惧埌涓涓妭鍚嶅悗锛宩鐨勫艰杩樺師锛屼互缁熻涓嬩竴涓妭鍚嶅湴鍧鐨勫亸绉婚噺 + //璧嬫垚-1鏄洜涓鸿妭鍚嶅瓧绗︿覆鐨勬渶鍚庝竴涓瓧绗0鏄粓姝㈢锛屼笉鑳戒綔涓鸿妭鍚 + for (m = 0; m <= strlen(pSectionName); m++)//鎶婃壘鍒扮殑鑺傚悕淇濆瓨鍒皊tr涓 + { + 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 +#include +#include "../C/mul.h" +#define FilePath "../ex1.ini" +using namespace Microsoft::VisualStudio::CppUnitTestFramework; + +namespace UnitTest1 +{ + TEST_CLASS(UnitTest1) + { + public: + int j = 0;//寰幆鍙橀噺锛岀敤鏉ヨ闂甶ni鏂囦欢涓殑 鑺 + 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);//璇诲彇绗竴涓弬鏁帮紝淇濆瓨鍦╪a閲 + GetPrivateProfileString(str[j], "nb", " ", nb.GetBuffer(20), 20, FilePath);//璇诲彇绗簩涓弬鏁帮紝淇濆瓨鍦╪b閲 + GetPrivateProfileString(str[j], "nExpect", " ", nExpect.GetBuffer(20), 20, FilePath);//璇诲彇姝g‘鐨勫硷紝淇濆瓨鍦╪Expect閲 + nReal = mul(_ttoi(na), _ttoi(nb)); //_ttoi鏄疌String杞负鏁村瀷锛屾妸杩愮畻缁撴灉缁檔Real + Assert::AreEqual(nReal, _ttoi(nExpect));//瀵规瘮杩愮畻缁撴灉鍜屾纭粨鏋 + } + + } + }; +} +``` + diff --git a/sub/.vs/sub/v16/.suo b/sub/.vs/sub/v16/.suo new file mode 100644 index 0000000..6df4bda Binary files /dev/null and b/sub/.vs/sub/v16/.suo differ diff --git a/sub/UnitTest1/UnitTest1.cpp b/sub/UnitTest1/UnitTest1.cpp new file mode 100644 index 0000000..a6e1e18 --- /dev/null +++ b/sub/UnitTest1/UnitTest1.cpp @@ -0,0 +1,35 @@ +#include "pch.h" +#include "CppUnitTest.h" +#include +#include +#include "../sub/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) + { + long long 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(_ttoi64(na), _ttoi64(nb)); //_ttoi是CString转为整型 + Assert::AreEqual(nReal, _ttoi64(nExpect)); + } + + } + }; +} diff --git a/sub/UnitTest1/UnitTest1.vcxproj b/sub/UnitTest1/UnitTest1.vcxproj new file mode 100644 index 0000000..30118c4 --- /dev/null +++ b/sub/UnitTest1/UnitTest1.vcxproj @@ -0,0 +1,175 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {41EA5A08-F53D-45F8-B927-8B35B73BE84B} + Win32Proj + UnitTest1 + 10.0 + NativeUnitTestProject + + + + DynamicLibrary + true + v142 + MultiByte + false + + + DynamicLibrary + false + v142 + true + Unicode + false + + + DynamicLibrary + true + v142 + Unicode + false + + + DynamicLibrary + false + v142 + true + Unicode + false + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + Use + Level3 + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + ..\sub\Debug\sub.obj;%(AdditionalDependencies) + DebugFull + + + + + Use + Level3 + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + _DEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Use + Level3 + true + true + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + true + true + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Use + Level3 + true + true + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + NDEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + true + true + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Create + Create + Create + Create + + + + + + + + + + \ No newline at end of file diff --git a/sub/UnitTest1/UnitTest1.vcxproj.filters b/sub/UnitTest1/UnitTest1.vcxproj.filters new file mode 100644 index 0000000..83a287b --- /dev/null +++ b/sub/UnitTest1/UnitTest1.vcxproj.filters @@ -0,0 +1,30 @@ +锘 + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 婧愭枃浠 + + + 婧愭枃浠 + + + + + 澶存枃浠 + + + \ No newline at end of file diff --git a/sub/UnitTest1/UnitTest1.vcxproj.user b/sub/UnitTest1/UnitTest1.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/sub/UnitTest1/UnitTest1.vcxproj.user @@ -0,0 +1,4 @@ +锘 + + + \ No newline at end of file diff --git a/sub/UnitTest1/pch.cpp b/sub/UnitTest1/pch.cpp new file mode 100644 index 0000000..d2bdc54 --- /dev/null +++ b/sub/UnitTest1/pch.cpp @@ -0,0 +1,45 @@ +锘// pch.cpp: 涓庨缂栬瘧鏍囧ご瀵瑰簲鐨勬簮鏂囦欢 + +#include "pch.h" +#include +#include +int CalcCount(int n, char(*str)[10]) +{ + TCHAR chSectionNames[2048] = { 0 };//瀹氫箟涓涓暟缁勶紝淇濆瓨璇诲彇鑺傜殑鍚嶅瓧 + char* pSectionName; //淇濆瓨鎵惧埌鐨勬煇涓妭鍚嶅瓧绗︿覆鐨勯鍦板潃 + int i = 0; //i鎸囧悜鏁扮粍chSectionNames鐨勬煇涓綅缃紝浠0寮濮嬶紝椤哄簭鍚庣Щ + int j = 0; //j鐢ㄦ潵淇濆瓨涓嬩竴涓妭鍚嶅瓧绗︿覆鐨勯鍦板潃鐩稿浜庡綋鍓峣鐨勪綅缃亸绉婚噺 + 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++)//瀵筩hSectionName涓繚瀛樼殑鍐呭杩涜鎷嗗垎 + { + if (chSectionNames[0] == '\0')//濡傛灉绗竴涓瓧绗﹀氨鏄0锛屽垯璇存槑ini涓竴涓妭涔熸病鏈夛紝 + { + break; + } + if (chSectionNames[i] == '\0') + { + count++; + pSectionName = &chSectionNames[i - j]; //鎵惧埌涓涓0锛屽垯璇存槑浠庤繖涓瓧绗﹀線鍓嶏紝鍑忔帀j涓亸绉婚噺锛 + //灏辨槸涓涓妭鍚嶇殑棣栧湴鍧 + j = -1; //鎵惧埌涓涓妭鍚嶅悗锛宩鐨勫艰杩樺師锛屼互缁熻涓嬩竴涓妭鍚嶅湴鍧鐨勫亸绉婚噺 + //璧嬫垚-1鏄洜涓鸿妭鍚嶅瓧绗︿覆鐨勬渶鍚庝竴涓瓧绗0鏄粓姝㈢锛屼笉鑳戒綔涓鸿妭鍚 + for (m = 0; m <= strlen(pSectionName); m++)//鎶婃壘鍒扮殑鑺傚悕淇濆瓨鍒皊tr涓 + { + str[k][m] = *(pSectionName + m); + } + //str[k][++m] = '\0';//鎵嬪姩缁欒妭鍚嶅姞涓奬0,琛ㄧず杩欎釜鑺傚悕缁撴潫 + k++;//鍙橀噺鑷姞锛岀敤鏉ヤ繚瀛樹笅涓涓妭鍚 + //鍦ㄨ幏鍙栬妭鍚嶇殑鏃跺欏彲浠ヨ幏鍙栬鑺備腑閿殑鍊硷紝鍓嶆彁鏄垜浠煡閬撹鑺備腑鏈夊摢浜涢敭銆 + if (chSectionNames[i + 1] == 0) + { + break; //褰撲袱涓浉閭荤殑瀛楃閮芥槸0鏃讹紝鍒欐墍鏈夌殑鑺傚悕閮藉凡鎵惧埌锛屽惊鐜粓姝 + } + } + } + return count;//杩斿洖鑺傚悕鐨勪釜鏁 +} +// 褰撲娇鐢ㄩ缂栬瘧鐨勫ご鏃讹紝闇瑕佷娇鐢ㄦ婧愭枃浠讹紝缂栬瘧鎵嶈兘鎴愬姛銆 diff --git a/sub/UnitTest1/pch.h b/sub/UnitTest1/pch.h new file mode 100644 index 0000000..90cc566 --- /dev/null +++ b/sub/UnitTest1/pch.h @@ -0,0 +1,12 @@ +锘// pch.h: 杩欐槸棰勭紪璇戞爣澶存枃浠躲 +// 涓嬫柟鍒楀嚭鐨勬枃浠朵粎缂栬瘧涓娆★紝鎻愰珮浜嗗皢鏉ョ敓鎴愮殑鐢熸垚鎬ц兘銆 +// 杩欒繕灏嗗奖鍝 IntelliSense 鎬ц兘锛屽寘鎷唬鐮佸畬鎴愬拰璁稿浠g爜娴忚鍔熻兘銆 +// 浣嗘槸锛屽鏋滄澶勫垪鍑虹殑鏂囦欢涓殑浠讳綍涓涓湪鐢熸垚涔嬮棿鏈夋洿鏂帮紝瀹冧滑鍏ㄩ儴閮藉皢琚噸鏂扮紪璇戙 +// 璇峰嬁鍦ㄦ澶勬坊鍔犺棰戠箒鏇存柊鐨勬枃浠讹紝杩欏皢浣垮緱鎬ц兘浼樺娍鏃犳晥銆 + +#ifndef PCH_H +#define PCH_H +int CalcCount(int n, char(*str)[10]); +// 娣诲姞瑕佸湪姝ゅ棰勭紪璇戠殑鏍囧ご + +#endif //PCH_H diff --git a/sub/ex1.ini b/sub/ex1.ini new file mode 100644 index 0000000..257cf31 --- /dev/null +++ b/sub/ex1.ini @@ -0,0 +1,22 @@ +[TestMethod1] +na=12 +nb=4 +nExpect=8 +[TestMethod2] +na=7 +nb=3 +nExpect=4 +[TestMethod3] +na=-1 +nb=2147483647 +nExpect=-2147483648 +[TestMethod4] +na=-2 +nb=2147483647 +nExpect=-2147483649 +[TestMethod5] +na=-1000 +nb=2147483647 +nExpect=-2147484647 + + diff --git a/sub/readme.md b/sub/readme.md new file mode 100644 index 0000000..184ccac --- /dev/null +++ b/sub/readme.md @@ -0,0 +1,127 @@ +# sub鍑芥暟璇存槑鏂囨。 +## 涓銆佸伐绋嬭鏄 +- 鏈伐绋嬬殑閰嶇疆绫诲瀷鏄竴涓姩鎬佸簱鏂囦欢锛岀洰鐨勬槸鐢熸垚涓涓彲琚叾浠栧伐绋嬭皟鐢ㄥ姩鎬佸簱锛屽姩鎬佸簱鐨勫嚱鏁板姛鑳芥槸锛氳緭鍏ヤ袱涓猧nt绫诲瀷鐨勬暟锛岃繑鍥炰袱鏁颁箣宸 +## 浜屻佸ご鏂囦欢 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 +**鍙傛暟锛歩nt 锛宨nt +**杩斿洖鍊硷細int +**鍑芥暟鍔熻兘锛氫紶鍏ヤ袱涓猧nt绫诲瀷鐨勫弬鏁帮紝瀵瑰叾杩涜鍑忔硶杩愮畻骞惰繑鍥炲樊鍊笺 +*/ +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鏂囦欢骞舵坊鍔犳祴璇曟牱渚嬶紝涔嬪悗鍦ㄥ崟鍏冩祴璇曠殑婧愭枃浠堕噷瀵筰ni鏂囦欢杩涜璇诲彇瑙f瀽 锛屽畬鎴愪互鍚庤幏鍙栧崟鍏冩祴璇曠殑缁撴灉锛屼繚璇佷唬鐮佽鐩栫巼鍦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 +/* +**鍑芥暟鍔熻兘锛氳幏鍙栦竴涓猧ni鏂囦欢閲屾湁澶氬皯涓妭锛屽苟閫氳繃浜岀淮鎸囬拡鏁扮粍灏嗚妭鍚嶅甫鍑烘潵銆 +* 鍑芥暟鍚嶏細CalcCount锛堬級 +* 鍏ュ弬锛歩nt 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鐢ㄦ潵淇濆瓨涓嬩竴涓妭鍚嶅瓧绗︿覆鐨勯鍦板潃鐩稿浜庡綋鍓峣鐨勪綅缃亸绉婚噺 + 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++)//瀵筩hSectionName涓繚瀛樼殑鍐呭杩涜鎷嗗垎 + { + if (chSectionNames[0] == '\0')//濡傛灉绗竴涓瓧绗﹀氨鏄0锛屽垯璇存槑ini涓竴涓妭涔熸病鏈夛紝 + { + break; + } + if (chSectionNames[i] == '\0') + { + count++; + pSectionName = &chSectionNames[i - j]; //鎵惧埌涓涓0锛屽垯璇存槑浠庤繖涓瓧绗﹀線鍓嶏紝鍑忔帀j涓亸绉婚噺锛 + //灏辨槸涓涓妭鍚嶇殑棣栧湴鍧 + j = -1; //鎵惧埌涓涓妭鍚嶅悗锛宩鐨勫艰杩樺師锛屼互缁熻涓嬩竴涓妭鍚嶅湴鍧鐨勫亸绉婚噺 + //璧嬫垚-1鏄洜涓鸿妭鍚嶅瓧绗︿覆鐨勬渶鍚庝竴涓瓧绗0鏄粓姝㈢锛屼笉鑳戒綔涓鸿妭鍚 + for (m = 0; m <= strlen(pSectionName); m++)//鎶婃壘鍒扮殑鑺傚悕淇濆瓨鍒皊tr涓 + { + 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 +#include +#include "../B/sub.h" +#define FilePath "../ex1.ini" +using namespace Microsoft::VisualStudio::CppUnitTestFramework; + +namespace UnitTest1 +{ + TEST_CLASS(UnitTest1) + { + public: + int j = 0;//寰幆鍙橀噺锛岀敤鏉ヨ闂甶ni鏂囦欢涓殑 鑺 + char str[50][10] = { 0 };//瀛樻斁ini鏂囦欢閲 鑺傜殑鍚嶅瓧 + int count = CalcCount(50, str);//淇濆瓨ini鏂囦欢閲 鑺傜殑涓暟 + TEST_METHOD(TestMethode1) + { + long long nReal;//淇濆瓨杩愮畻缁撴灉 + CString na, nb, nExpect; //淇濆瓨娴嬭瘯鏍蜂緥涓殑閿 + for (j = 0; j < count; j++)//閬嶅巻璇诲彇娴嬭瘯鏍蜂緥 + { + GetPrivateProfileString(str[j], "na", " ", na.GetBuffer(20), 20, FilePath);//璇诲彇绗竴涓弬鏁帮紝淇濆瓨鍦╪a閲 + GetPrivateProfileString(str[j], "nb", " ", nb.GetBuffer(20), 20, FilePath);//璇诲彇绗簩涓弬鏁帮紝淇濆瓨鍦╪b閲 + GetPrivateProfileString(str[j], "nExpect", " ", nExpect.GetBuffer(20), 20, FilePath);//璇诲彇姝g‘鐨勫硷紝淇濆瓨鍦╪Expect閲 + nReal = sub(_ttoi64(na), _tto64(nb)); //_ttoi鏄疌String杞负鏁村瀷锛屾妸杩愮畻缁撴灉缁檔Real + Assert::AreEqual(nReal, _ttoi64(nExpect));//瀵规瘮杩愮畻缁撴灉鍜屾纭粨鏋 + } + + } + }; +} +``` diff --git a/sub/sub.sln b/sub/sub.sln new file mode 100644 index 0000000..87587cc --- /dev/null +++ b/sub/sub.sln @@ -0,0 +1,41 @@ +锘 +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}") = "sub", "sub\sub.vcxproj", "{1C0469B3-B257-478F-8CCE-E00E9A8ED7B0}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTest1", "UnitTest1\UnitTest1.vcxproj", "{41EA5A08-F53D-45F8-B927-8B35B73BE84B}" +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 + {1C0469B3-B257-478F-8CCE-E00E9A8ED7B0}.Debug|x64.ActiveCfg = Debug|x64 + {1C0469B3-B257-478F-8CCE-E00E9A8ED7B0}.Debug|x64.Build.0 = Debug|x64 + {1C0469B3-B257-478F-8CCE-E00E9A8ED7B0}.Debug|x86.ActiveCfg = Debug|Win32 + {1C0469B3-B257-478F-8CCE-E00E9A8ED7B0}.Debug|x86.Build.0 = Debug|Win32 + {1C0469B3-B257-478F-8CCE-E00E9A8ED7B0}.Release|x64.ActiveCfg = Release|x64 + {1C0469B3-B257-478F-8CCE-E00E9A8ED7B0}.Release|x64.Build.0 = Release|x64 + {1C0469B3-B257-478F-8CCE-E00E9A8ED7B0}.Release|x86.ActiveCfg = Release|Win32 + {1C0469B3-B257-478F-8CCE-E00E9A8ED7B0}.Release|x86.Build.0 = Release|Win32 + {41EA5A08-F53D-45F8-B927-8B35B73BE84B}.Debug|x64.ActiveCfg = Debug|x64 + {41EA5A08-F53D-45F8-B927-8B35B73BE84B}.Debug|x64.Build.0 = Debug|x64 + {41EA5A08-F53D-45F8-B927-8B35B73BE84B}.Debug|x86.ActiveCfg = Debug|Win32 + {41EA5A08-F53D-45F8-B927-8B35B73BE84B}.Debug|x86.Build.0 = Debug|Win32 + {41EA5A08-F53D-45F8-B927-8B35B73BE84B}.Release|x64.ActiveCfg = Release|x64 + {41EA5A08-F53D-45F8-B927-8B35B73BE84B}.Release|x64.Build.0 = Release|x64 + {41EA5A08-F53D-45F8-B927-8B35B73BE84B}.Release|x86.ActiveCfg = Release|Win32 + {41EA5A08-F53D-45F8-B927-8B35B73BE84B}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1E62416C-4140-4806-91B8-6FDC6ECE9356} + EndGlobalSection +EndGlobal diff --git a/sub/sub/sub.cpp b/sub/sub/sub.cpp new file mode 100644 index 0000000..b68c3e1 --- /dev/null +++ b/sub/sub/sub.cpp @@ -0,0 +1,5 @@ +#include"sub.h" + long long sub(int x, int y) +{ + return (long long)x -(long long) y; +} \ No newline at end of file diff --git a/sub/sub/sub.h b/sub/sub/sub.h new file mode 100644 index 0000000..993f557 --- /dev/null +++ b/sub/sub/sub.h @@ -0,0 +1,12 @@ +#ifndef _SUB_H_ +#define _SUB_H_ + +#ifdef DLL_EXPORTS +#define SUB_API _declspec(dllexport) +#else +#define SUB_API _declspec(dllimport) +#endif + +SUB_API long long sub(int x, int y); +#endif + diff --git a/sub/sub/sub.vcxproj b/sub/sub/sub.vcxproj new file mode 100644 index 0000000..467a95c --- /dev/null +++ b/sub/sub/sub.vcxproj @@ -0,0 +1,150 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {1c0469b3-b257-478f-8cce-e00e9a8ed7b0} + sub + 10.0 + + + + DynamicLibrary + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + \ No newline at end of file diff --git a/sub/sub/sub.vcxproj.filters b/sub/sub/sub.vcxproj.filters new file mode 100644 index 0000000..755deeb --- /dev/null +++ b/sub/sub/sub.vcxproj.filters @@ -0,0 +1,27 @@ +锘 + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 澶存枃浠 + + + + + 婧愭枃浠 + + + \ No newline at end of file diff --git a/sub/sub/sub.vcxproj.user b/sub/sub/sub.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/sub/sub/sub.vcxproj.user @@ -0,0 +1,4 @@ +锘 + + + \ No newline at end of file