瀏覽代碼

11

master
刘春山 4 年之前
父節點
當前提交
c55e356b67
共有 18 個文件被更改,包括 224 次插入103 次删除
  1. +1
    -1
      jia/UnitTest1/UnitTest1.vcxproj
  2. +64
    -24
      jia/UnitTest1/unittest1.cpp
  3. +1
    -2
      jia/chen/Source.def
  4. +9
    -6
      jia/chen/chen.cpp
  5. +3
    -4
      jia/chen/chen.h
  6. +3
    -1
      jia/chu/chu.vcxproj
  7. +6
    -0
      jia/chu/chu.vcxproj.filters
  8. +44
    -12
      jia/chu/main.cpp
  9. +18
    -0
      jia/chu/tof.cpp
  10. +8
    -0
      jia/chu/tof.h
  11. +7
    -7
      jia/ex1.ini
  12. +6
    -6
      jia/ex2.ini
  13. +18
    -18
      jia/ex3.ini
  14. +5
    -5
      jia/ex4.ini
  15. +5
    -9
      jia/jia/jia.cpp
  16. +2
    -2
      jia/jia/jia.h
  17. +22
    -4
      jia/jian/jian.cpp
  18. +2
    -2
      jia/jian/jian.h

+ 1
- 1
jia/UnitTest1/UnitTest1.vcxproj 查看文件

@@ -60,7 +60,7 @@
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>..\jia\Debug\jia.obj;..\jian\Debug\jian.obj;..\chen\Debug\chen.obj;..\chu\Debug\chu.obj;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>..\jia\Debug\jia.obj;..\jian\Debug\jian.obj;..\chen\Debug\chen.obj;..\chu\Debug\chu.obj;..\chu\Debug\tof.obj;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">


+ 64
- 24
jia/UnitTest1/unittest1.cpp 查看文件

@@ -5,6 +5,10 @@
#include"../jian/jian.h"
#include"../chen/chen.h"
#include"../chu/chu.h"
#include"../chu/tof.h"
#include <limits>
//#include "iostream"
//using namespace std;

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

@@ -18,25 +22,37 @@ namespace UnitTest1
TEST_METHOD(TestMethod1)
{
// TODO: ÔÚ´ËÊäÈë²âÊÔ´úÂë
int SUM = GetPrivateProfileInt("Len", "sum", 0, "../ex1.ini");
int SUM = GetPrivateProfileInt("Len", "sum", 0, "..//ex1.ini");
{
for (int i = 1; i <= SUM; i++)
{
char SUMStr[8];
char TestStr[8] = { "Test" };
_itoa_s(i, SUMStr, 8);
char SUMStr[10];
char TestStr[10] = { "Test" };
_itoa_s(i, SUMStr, 10);
strcat_s(TestStr, SUMStr);
int num1 = GetPrivateProfileInt("TestStr", "number1", 0, "ex1.ini");
int num2 = GetPrivateProfileInt("TestStr", "number2", 0, "ex1.ini");
int output = GetPrivateProfileInt("TestStr", "output", 0, "ex1.ini");

Assert::AreEqual(output, add(num1, num2));
//string str(TestStr);
int num1 = GetPrivateProfileInt(TestStr, "number1", 0, "..//ex1.ini");
int num2 = GetPrivateProfileInt(TestStr, "number2", 0, "..//ex1.ini");
int c = 0;
bool ret1 = Add(num1, num2, &c);
if (ret1 == 1)
{
int output = GetPrivateProfileInt(TestStr, "output", 0, "..//ex1.ini");
Assert::AreEqual(output, c);
}
else
{
LPTSTR Output = (LPTSTR)malloc(255);
GetPrivateProfileString(TestStr, "output", "", Output, 255, "..//ex1.ini");
string s(Output);
Assert::AreEqual(tof(s), Add(num1, num2, &c));
}
}
}
}
TEST_METHOD(TestMethod2)
{
int SUB = GetPrivateProfileInt("Len", "sum", 0, "../ex2.ini");
int SUB = GetPrivateProfileInt("Len", "sum", 0, "..//ex2.ini");
{
for (int j = 1; j <= SUB; j++)
{
@@ -44,17 +60,29 @@ namespace UnitTest1
char TestStr[8] = { "Test" };
_itoa_s(j, SUBStr, 8);
strcat_s(TestStr, SUBStr);
int num1 = GetPrivateProfileInt("TestStr", "number1", 0, "ex2.ini");
int num2 = GetPrivateProfileInt("TestStr", "number2", 0, "ex2.ini");
int output = GetPrivateProfileInt("TestStr", "output", 0, "ex2.ini");

Assert::AreEqual(output, sub(num1, num2));
int num1 = GetPrivateProfileInt(TestStr, "number1", 0, "..//ex2.ini");
int num2 = GetPrivateProfileInt(TestStr, "number2", 0, "..//ex2.ini");
int d = 0;
bool ret2 = Sub(num1, num2, &d);
if (ret2 == 1)
{
int output = GetPrivateProfileInt(TestStr, "output", 0, "..//ex2.ini");
Assert::AreEqual(output, d);
}
else
{
LPTSTR Output = (LPTSTR)malloc(255);
GetPrivateProfileString(TestStr, "output", "", Output, 255, "..//ex2.ini");
string s(Output);
Assert::AreEqual(tof(s), Sub(num1, num2, &d));
}
}
}
}
TEST_METHOD(TestMethod3)
{
int MUL = GetPrivateProfileInt("Len", "sum", 0, "../ex3.ini");
int MUL = GetPrivateProfileInt("Len", "sum", 0, "..//ex3.ini");
{
for (int i = 1; i <= MUL; i++)
{
@@ -62,17 +90,29 @@ namespace UnitTest1
char TestStr[8] = { "Test" };
_itoa_s(i, MULStr, 8);
strcat_s(TestStr, MULStr);
int num1 = GetPrivateProfileInt("TestStr", "number1", 0, "ex3.ini");
int num2 = GetPrivateProfileInt("TestStr", "number2", 0, "ex3.ini");
int output = GetPrivateProfileInt("TestStr", "output", 0, "ex3.ini");
int num1 = GetPrivateProfileInt(TestStr, "number1", 0, "..//ex3.ini");
int num2 = GetPrivateProfileInt(TestStr, "number2", 0, "..//ex3.ini");
int e = 0;
bool ret3 = chen(num1, num2, &e);
if (ret3 == 1)
{
int output = GetPrivateProfileInt(TestStr, "output", 0, "..//ex3.ini");
Assert::AreEqual(output, e);
}
else
{
LPTSTR Output = (LPTSTR)malloc(255);
GetPrivateProfileString(TestStr, "output", "", Output, 255, "..//ex3.ini");
string s(Output);
Assert::AreEqual(tof(s), chen(num1, num2, &e));
}

Assert::AreEqual(output, mul(num1, num2));
}
}
}
TEST_METHOD(TestMethod4)
{
int DIV = GetPrivateProfileInt("Len", "sum", 0, "../ex4.ini");
int DIV = GetPrivateProfileInt("Len", "sum", 0, "..//ex4.ini");
{
for (int i = 1; i <= DIV; i++)
{
@@ -80,9 +120,9 @@ namespace UnitTest1
char TestStr[8] = { "Test" };
_itoa_s(i, DIVStr, 8);
strcat_s(TestStr, DIVStr);
int num1 = GetPrivateProfileInt("TestStr", "number1", 0, "ex4.ini");
int num2 = GetPrivateProfileInt("TestStr", "number2", 0, "ex4.ini");
int output = GetPrivateProfileInt("TestStr", "output", 0, "ex4.ini");
int num1 = GetPrivateProfileInt(TestStr, "number1", 0, "..//ex4.ini");
int num2 = GetPrivateProfileInt(TestStr, "number2", 0, "..//ex4.ini");
int output = GetPrivateProfileInt(TestStr, "output", 0, "../ex4.ini");

Assert::AreEqual(output, chu(num1, num2));
}


+ 1
- 2
jia/chen/Source.def 查看文件

@@ -1,4 +1,3 @@
LIBRARY CHEN
LIBRARY chen
EXPORTS
mul
chen

+ 9
- 6
jia/chen/chen.cpp 查看文件

@@ -1,8 +1,15 @@
#include "chen.h"
#include <limits>
bool chen(int a, int b, int *e)

bool chen(int a, int b, int *e)
{
if( (a>0 && b>0 && a >( INT_MAX / b ))||( a<0 && b<0 && a < (INT_MAX / b)) ||( a>0 && b<0 && a < (INT_MIN / b)) ||( a<0 && b>0 && a >( INT_MIN /b) ))
if ((a>0 && b>0 && a >(INT_MAX / b)) || (a<0 && b<0 && a < (INT_MAX / b)))
{

return false;
}

else if ((a > 0 && b < 0 && b != -1 && (INT_MIN / a) > b || (a < 0 && b > 0 && a != -1 && (INT_MIN / a) < b)))
{

return false;
@@ -15,8 +22,4 @@ bool chen(int a, int b, int *e)
}

}
int mul(int a, int b)
{

return a * b;
}

+ 3
- 4
jia/chen/chen.h 查看文件

@@ -1,8 +1,7 @@
#ifndef MUL_H
#define MUL_H
#ifndef CHEN_H
#define CHEN_H


int mul(int a, int b);
bool chen(int a, int b, int *e);
bool chen(int a, int b, int *e);

#endif

+ 3
- 1
jia/chu/chu.vcxproj 查看文件

@@ -20,7 +20,7 @@
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
@@ -81,9 +81,11 @@
<ItemGroup>
<ClCompile Include="chu.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="tof.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="chu.h" />
<ClInclude Include="tof.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">


+ 6
- 0
jia/chu/chu.vcxproj.filters 查看文件

@@ -21,10 +21,16 @@
<ClCompile Include="chu.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="tof.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="chu.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="tof.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
</Project>

+ 44
- 12
jia/chu/main.cpp 查看文件

@@ -4,47 +4,79 @@
#include "../jian/jian.h"
//#pragma comment(lib,"jian.lib")
#include "chu.h"
#include "Windows.h"
#include "windows.h"
#include "../chen/chen.h"
#include <iostream>
#include "tof.h"
using namespace std;

typedef int(*PMUL)(int a, int b);
typedef bool(*QCHEN)(int a, int b,int *e);

int main()
{
int a, b;
int c = 0;
int d = 0;
int e = 0;

/*char f = 0;
char *d = &f;*/
printf("请输入两个整数\n");
scanf("%d%d", &a, &b);

bool ret1 = Add(a, b,&c);
if ( ret1 == 0)
{
printf("两个整数相加结果溢出!\n");
}
else
{

printf("ret1=%d a+b=%d\n",ret1,c);
printf("两个整数的相加结果是;%d\n", c);

}
//printf("两个整数的相减结果是;%d\n,%d", Sub(a, b, d));
bool ret2 = Sub(a, b, &d);
printf("ret2=%d a-b=%d\n", ret2,d);
if (ret2 == 0)
{
printf("两个整数相减结果溢出!\n ");
}
else
{
printf("两个整数的相减结果是;%d\n", d);
}

HMODULE hDLL = LoadLibrary(L"../Debug/chen.dll");
HMODULE hDLL =LoadLibrary ("../Debug/chen.dll");
if (hDLL == NULL)
{
printf("加载DLL文件失败\n");
return 0;

}
PMUL pMul = (PMUL)GetProcAddress(hDLL, "mul");
// PMUL pMul = (PMUL)GetProcAddress(hDLL, "mul");
QCHEN qChen = (QCHEN)GetProcAddress(hDLL, "chen");

bool ret3 = chen(a, b, &e);
printf("ret3=%d a*b=%d\n", ret3, e);

printf("a/b=%d\n", chu(a, b));
if (ret3 == 0)
{
printf("两个整数相乘结果溢出!\n ");

FreeLibrary(hDLL);

}
else
{
printf("两个整数的相乘结果是;%d\n", e);
}

printf("两个整数的相除结果是;%d\n", chu(a,b));

system("pause");
FreeLibrary(hDLL);

}

+ 18
- 0
jia/chu/tof.cpp 查看文件

@@ -0,0 +1,18 @@
#include "tof.h"

bool tof(string a)
{
string b = "false";
if (a == b)
{
return false;

}
else
{
return true;

}


}

+ 8
- 0
jia/chu/tof.h 查看文件

@@ -0,0 +1,8 @@
#ifndef TOF_H
#define TOF_H
#include <iostream>
using namespace std;

bool tof(string a);

#endif

+ 7
- 7
jia/ex1.ini 查看文件

@@ -2,7 +2,7 @@
sum=8

[Test1]
number1=1
number1 =1
number2=2
output=3

@@ -22,9 +22,9 @@ number2=-2
output=-3

[Test5]
number1=1000
number2=20000
output=21000
number1=2000000000
number2=2000000000
output=false

[Test6]
number1=-1000
@@ -37,6 +37,6 @@ number2=-10
output=2990

[Test8]
number1=100000
number2=5000000
output=5100000
number1=-1000000000
number2=-2000000000
output=false

+ 6
- 6
jia/ex2.ini 查看文件

@@ -22,9 +22,9 @@ number2=-11
output=2

[Test5]
number1=10000
number2=2000
output=8000
number1=-1000000000
number2=2000000000
output=false

[Test6]
number1=-1
@@ -37,6 +37,6 @@ number2=-10000
output=10300

[Test8]
number1=10000
number2=500000
output=-490000
number1=2000000000
number2=-2000000000
output=false

+ 18
- 18
jia/ex3.ini 查看文件

@@ -12,31 +12,31 @@ number2=2
output=-2

[Test3]
number1=1
number2=-5
output=-5
number1=1000000
number2=50000
output=false

[Test4]
number1=-9
number2=-11
output=99
number1=-9000000
number2=-11000
output=false

[Test5]
number1=100
number2=200
output=20000
number1=9
number2=9
output=81

[Test6]
number1=-10000
number2=200
output=-2000000
number1=-100000
number2=200000
output=false

[Test7]
number1=300
number2=-1
output=-300
number1=1000000
number2=-20000
output=false

[Test8]
number1=-11
number2=-11
output=121
number1=2
number2=2
output=4

+ 5
- 5
jia/ex4.ini 查看文件

@@ -3,8 +3,8 @@ sum=8

[Test1]
number1=100
number2=0
output=0
number2=1
output=100

[Test2]
number1=-2
@@ -29,12 +29,12 @@ output=-1
[Test6]
number1=-10000
number2=200
output=-500
output=-50

[Test7]
number1=300
number2=-1
output=-300
number2=0
output=false

[Test8]
number1=0


+ 5
- 9
jia/jia/jia.cpp 查看文件

@@ -1,23 +1,19 @@
#include "jia.h"
#include <limits>
bool Add(int a, int b, int *c)

bool Add(int a, int b, int *c)
{
if (a>0&&b>0&&a > INT_MAX - b ||a<0&&b<0&& a < INT_MIN - b)
{
if ((a > 0 && b > 0 && a > (INT_MAX - b)) || (a < 0 && b < 0 && a < (INT_MIN - b)))

{
return false;
}
else
{
*c = a + b;
return true;
}
}
int add(int a, int b)
{
return a + b;

}



+ 2
- 2
jia/jia/jia.h 查看文件

@@ -1,6 +1,6 @@
#ifndef ADD_H
#define ADD_H

bool Add(int a, int b, int *c);
int add(int a, int b);
bool Add(int a, int b,int *c);
//int add(int a,int b);
#endif

+ 22
- 4
jia/jian/jian.cpp 查看文件

@@ -1,5 +1,23 @@
#include "jian.h"
#include <limits>

//char Sub(int a, int b, char *d)
//{
// if ((a>0 && b<0 && a >(INT_MAX + b)) || (a<0 && b>0 && a < (INT_MIN + b)))
// {
// char *c = { "overflow" };
// *d = c[0];
// return d[0];
// }
// else
// {
// d[0] = (a - b) + '0';
// return d[0];
//
// }
//
//}

bool Sub(int a, int b, int *d)
{
if ((a>0 &&b<0 && a >( INT_MAX + b)) ||( a<0 && b>0 && a < (INT_MIN + b)))
@@ -15,7 +33,7 @@ bool Sub(int a, int b, int *d)
}

}
int sub(int a, int b)
{
return a - b;
}
//int sub(int a, int b)
//{
// return a - b;
//}

+ 2
- 2
jia/jian/jian.h 查看文件

@@ -5,7 +5,7 @@
#else
#define DLLAPI _declspec(dllimport)
#endif
int DLLAPI sub(int a, int b);
//int DLLAPI sub(int a, int b);
bool DLLAPI Sub(int a, int b, int *d);
//char DLLAPI Sub(int a, int b, char *d);
#endif

Loading…
取消
儲存