进制转换TestCode



//BYTE 型取值范围:0x00~0xFF
//主要调用四个AIP,实现进制之间的相互转换。具体API 如下:
//First Section:API definition&describe

#ifndef CONVERT_TOOL_H
#define CONVERT_TOOL_H

/*** Include Files *******************************************************************************/
#include "CommonDef.h"

#ifdef __cplusplus
extern "C"
{
#endif
/*************************************************************************************************/
/*!
\brief ByteToBinaryString
Convert one byte data to binary string.

\param[in] byData - Assign a byte data.

\param[out] szBinaryString - Pointer to the binary string that specifies the converted data
you want to store.

\return Return ERR_OK if the function succeeds else nonzero error code.
*/
/*************************************************************************************************/
CONVERT_TOOL_API DWORD ByteToBinaryString(BYTE byData, char szBinaryString[8]);

/*************************************************************************************************/
/*!
\brief ByteToOctalString
Convert one byte data to octal string.

\param[in] byData - Assign a byte data.

\param[out] szBinaryString - Pointer to the octal string that specifies the converted data
you want to store.

\return Return ERR_OK if the function succeeds else nonzero error code.
*/
/*************************************************************************************************/
CONVERT_TOOL_API DWORD ByteToOctalString(BYTE byData, char szOctalString[3]);

/*************************************************************************************************/
/*!
\brief ByteToDecimalString
Convert one byte data to Decimal string.

\param[in] byData - Assign a byte data.

\param[out] szBinaryString - Pointer to the Decimal string that specifies the converted data
you want to store.

\return Return ERR_OK if the function succeeds else nonzero error code.
*/
/*************************************************************************************************/
CONVERT_TOOL_API DWORD ByteToDecimalString(BYTE byData, char szDecimalString[3]);

/*************************************************************************************************/
/*!
\brief ByteToHexString
Convert one byte data to hex string.

\param[in] byData - Assign a byte data.

\param[out] szBinaryString - Pointer to the hex string that specifies the converted data
you want to store.

\return Return ERR_OK if the function succeeds else nonzero error code.
*/
/*************************************************************************************************/
CONVERT_TOOL_API DWORD ByteToHexString(BYTE byData, char szHexString[2]);

#ifdef __cplusplus
}
#endif

#endif//CONVERT_TOOL_H
//

//这个部分主要是具体实现进制转换,加注一些描述,使人能清晰看到每个CASE所要测试的目的。
//Second Section:Covert and Test Case
//1)ByteToBinaryString.h and ByteToBinaryString.cpp
//1.1)ByteToBinaryString.h

#ifndef BYTETOBINARYSTRING_H
#define BYTETOBINARYSTRING_H

#include "ConvertTool.h"

#pragma comment(lib, "ConvertTool.lib")


#ifdef __cplusplus
extern "C"
{
#endif

void ByteToBinaryString_TestCase_Normal(CHAR* pszName, BYTE byInputData, char szExceptedData[8]);

/*************************************************************************************************/
/*!
\brief ByteToBinaryString_TestCase_01_00_00000000()

Convert byte(00) data to Binary string.ExecptedData is 00000000

*/
/*************************************************************************************************/
void ByteToBinaryString_TestCase_01_00_00000000();

/*************************************************************************************************/
/*!
\brief ByteToBinaryString_TestCase_02_01_00000001()

Convert byte(01) data to Binary string. ExecptedData is 00000001
*/
/*************************************************************************************************/
void ByteToBinaryString_TestCase_02_01_00000001();

/*************************************************************************************************/
/*!
\brief ByteToBinaryString_TestCase_03_A_00001010()

Convert byte(A) data to Binary string. ExecptedData is 00001010.

*/
/*************************************************************************************************/
void ByteToBinaryString_TestCase_03_0A_00001010();

/*************************************************************************************************/
/*!
\brief ByteToBinaryString_TestCase_04_37_00110111()

Convert byte(37) data to Binary string. ExecptedData is 00110111

*/
/*************************************************************************************************/
void ByteToBinaryString_TestCase_04_37_00110111();

/*************************************************************************************************/
/*!
\brief ByteToBinaryString_TestCase_05_63_01100011()

Convert byte(63) data to Binary string. ExecptedData is 01100011
*/
/*************************************************************************************************/
void ByteToBinaryString_TestCase_05_63_01100011();

/*************************************************************************************************/
/*!
\brief ByteToBinaryString_TestCase_06_6F_01101111()

Convert byte(6F) data to Binary string. ExecptedData is 01101111
*/
/*************************************************************************************************/
void ByteToBinaryString_TestCase_06_6F_01101111();

/*************************************************************************************************/
/*!
\brief ByteToBinaryString_TestCase_07_7D_01111101()

Convert byte(7D) data to Binary string. ExecptedData is 01111101

*/
/*************************************************************************************************/
void ByteToBinaryString_TestCase_07_7D_01111101();

/*************************************************************************************************/
/*!
\brief ByteToBinaryString_TestCase_08_C7_11000111()

Convert byte(C7) data to Binary string. ExecptedData is 11000111

*/
/*************************************************************************************************/
void ByteToBinaryString_TestCase_08_C7_11000111();

/*************************************************************************************************/
/*!
\brief ByteToBinaryString_TestCase_09_DF_11011111()

Convert byte(DF) data to Binary string. ExecptedData is 11011111

*/
/*************************************************************************************************/
void ByteToBinaryString_TestCase_09_DF_11011111();

/*************************************************************************************************/
/*!
\brief ByteToBinaryString_TestCase_10_FF_11111111()

\The boundary of the return value is the maximum test

Convert byte(FF) data to Binary string. ExecptedData is 11111111

*/
/*************************************************************************************************/
void ByteToBinaryString_TestCase_10_FF_11111111();

/*************************************************************************************************/
/*!
\brief ByteToBinaryString_TestCase_11_E0_11100000()

0xE0=0xFF-0x1F

Convert byte(E0) data to Binary string. ExecptedData is 11100000

*/
/*************************************************************************************************/
void ByteToBinaryString_TestCase_11_E0_11100000();

/*************************************************************************************************/
/*!
\brief ByteToBinaryString_TestCase_12_FE_11111110()

0xFE=0x00+0xFE

Convert byte(FE) data to Binary string. ExecptedData is 11111110

*/
/*************************************************************************************************/
void ByteToBinaryString_TestCase_12_FE_11111110();

/*************************************************************************************************/
/*!
\brief ByteToBinaryString_TestCase_13_FF_11111111()

0xFE=0xFF+0x00

\The boundary of the return value is the maximum test

Convert byte(FF) data to Binary string. ExecptedData is 11111111


*/
/*************************************************************************************************/
void ByteToBinaryString_TestCase_13_FF_11111111();

void ByteToBinaryString_RunTestCaes();

#ifdef __cplusplus
}
#endif

#endif//BYTETOBINARYSTRING_H

//
//1.2) ByteToBinaryString.cpp

#include<stdio.h>
#include "ByteToBinaryString.h"
#include "ConvertTool.h"

WORD g_nBinaryTotalRun = 0;
WORD g_nBinaryPass = 0;
WORD g_nBinaryFail = 0;

//以下此段,主要是根据返回值来实现实际值与期望值进行比对
void ByteToBinaryString_TestCase_Normal(CHAR* pszName, BYTE byInputData, char szExceptedData[8])
{
int result = 0;
DWORD dwRet = ERR_OK;
char szBinaryString[8] = {0};

++g_nBinaryTotalRun;

dwRet = ByteToBinaryString(byInputData, szBinaryString);

if (NULL != pszName)
{
printf("[%s] ", pszName);
}

if(dwRet == ERR_OK)
{
++g_nBinaryPass;

result = memcmp(szBinaryString, szExceptedData, 8);
if(result == 0)
{
printf("OK\n");
//printf("%s\n", szExceptedData);
}
else
{
++g_nBinaryFail;
printf("FAIL\n");
}
}
else
{
++g_nBinaryFail;
printf("ERROR!");
}

}
//以下为每个CASE 的输入值以及期望值
void ByteToBinaryString_TestCase_01_00_00000000()
{
ByteToBinaryString_TestCase_Normal("ByteToBinaryString_TestCase_01_00_00000000", 0x00, "00000000");
}

void ByteToBinaryString_TestCase_02_01_00000001()
{
ByteToBinaryString_TestCase_Normal("ByteToBinaryString_TestCase_02_01_00000001", 0x01, "00000001");
}

void ByteToBinaryString_TestCase_03_0A_00001010()
{
ByteToBinaryString_TestCase_Normal("ByteToBinaryString_TestCase_03_0A_00001010", 0x0A, "00001010");
}

void ByteToBinaryString_TestCase_04_37_00110111()
{
ByteToBinaryString_TestCase_Normal("ByteToBinaryString_TestCase_04_37_00110111", 0x37, "00110111");
}

void ByteToBinaryString_TestCase_05_63_01100011()
{
ByteToBinaryString_TestCase_Normal("ByteToBinaryString_TestCase_05_63_01100011", 0x63, "01100011");
}

void ByteToBinaryString_TestCase_06_6F_01101111()
{
ByteToBinaryString_TestCase_Normal("ByteToBinaryString_TestCase_06_6F_01101111", 0x63, "01100011");
}

void ByteToBinaryString_TestCase_07_7D_01111101()
{
ByteToBinaryString_TestCase_Normal("ByteToBinaryString_TestCase_07_7D_01111101", 0x7D, "01111101");
}

void ByteToBinaryString_TestCase_08_C7_11000111()
{
ByteToBinaryString_TestCase_Normal("ByteToBinaryString_TestCase_08_C7_11000111", 0xC7, "11000111");
}

void ByteToBinaryString_TestCase_09_DF_11011111()
{
ByteToBinaryString_TestCase_Normal("ByteToBinaryString_TestCase_09_DF_11011111", 0xDF, "11011111");
}

void ByteToBinaryString_TestCase_10_FF_11111111()
{
ByteToBinaryString_TestCase_Normal("ByteToBinaryString_TestCase_10_FF_11111111", 0xFF, "11111111");
}

void ByteToBinaryString_TestCase_11_E0_11100000()
{
ByteToBinaryString_TestCase_Normal("ByteToBinaryString_TestCase_11_E0_11100000", 0xFF-0x1F, "11100000");
}

void ByteToBinaryString_TestCase_12_FE_11111110()
{
ByteToBinaryString_TestCase_Normal("ByteToBinaryString_TestCase_12_FE_11111110", 0x00+0xFE, "11111110");
}

void ByteToBinaryString_TestCase_13_FF_11111111()
{
ByteToBinaryString_TestCase_Normal("ByteToBinaryString_TestCase_13_FF_11111111", 0xFF+0x00, "11111111");
}


void ByteToBinaryString_RunTestCaes()
{
g_nBinaryTotalRun = 0;
g_nBinaryPass = 0;
g_nBinaryFail = 0;

printf("---------------ByteToBinaryString_RunTestCaes------------------\n");

ByteToBinaryString_TestCase_01_00_00000000();
ByteToBinaryString_TestCase_02_01_00000001();
ByteToBinaryString_TestCase_03_0A_00001010();
ByteToBinaryString_TestCase_04_37_00110111();
ByteToBinaryString_TestCase_05_63_01100011();
ByteToBinaryString_TestCase_06_6F_01101111();
ByteToBinaryString_TestCase_07_7D_01111101();
ByteToBinaryString_TestCase_08_C7_11000111();
ByteToBinaryString_TestCase_09_DF_11011111();
ByteToBinaryString_TestCase_10_FF_11111111();
ByteToBinaryString_TestCase_11_E0_11100000();
ByteToBinaryString_TestCase_12_FE_11111110();
ByteToBinaryString_TestCase_13_FF_11111111();

printf("Total:%d Pass:%d Fail:%d\n", g_nBinaryTotalRun, g_nBinaryPass, g_nBinaryFail);

printf("---------------------------------------------------------------\n");
}

//1.3)ByteToOctalString.h and ByteToOctalString.cpp
//1.3.1)ByteToOctalString.h

#ifndef BYTETOOCTALSTRING_H
#define BYTETOOCTALSTRING_H
#include "ConvertTool.h"
#pragma comment(lib, "ConvertTool.lib")

#ifdef __cplusplus
extern "C"
{
#endif

void ByteToOctalString_TestCase_Normal(CHAR *pszName, BYTE byData, char szOctalString[3]);
/*************************************************************************************************/
/*!
\brief ByteToOctalString_TestCase_01_00_000()

Convert byte(00) data to Octal string. ExecptedData is 000

*/
/*************************************************************************************************/
void ByteToOctalString_TestCase_01_00_000();

/*************************************************************************************************/
/*!
\brief ByteToOctalString_TestCase_02_34_064()

Convert byte(34) data to Octal string. ExecptedData is 064

*/
/*************************************************************************************************/
void ByteToOctalString_TestCase_02_34_064();

/*************************************************************************************************/
/*!
\brief ByteToOctalString_TestCase_03_3C_074()

Convert byte(3C) data to Octal string. ExecptedData is 074

*/
/*************************************************************************************************/
void ByteToOctalString_TestCase_03_3C_074();

/*************************************************************************************************/
/*!
\brief ByteToOctalString_TestCase_04_44_104()

Convert byte(44) data to Octal string. ExecptedData is 104

*/
/*************************************************************************************************/
void ByteToOctalString_TestCase_04_44_104();

/*************************************************************************************************/
/*!
\brief ByteToOctalString_TestCase_05_4A_112()

Convert byte(4A) data to Octal string. ExecptedData is 112

*/
/*************************************************************************************************/
void ByteToOctalString_TestCase_05_4A_112();

/*************************************************************************************************/
/*!
\brief ByteToOctalString_TestCase_06_6C_154()

Convert byte(6C) data to Octal string. ExecptedData is 154

*/
/*************************************************************************************************/
void ByteToOctalString_TestCase_06_6C_154();

/*************************************************************************************************/
/*!
\brief ByteToOctalString_TestCase_07_80_200()

Convert byte(80) data to Octal string. ExecptedData is 200

*/
/*************************************************************************************************/
void ByteToOctalString_TestCase_07_80_200();

/*************************************************************************************************/
/*!
\brief ByteToOctalString_TestCase_08_99_231()

Convert byte(99) data to Octal string. ExecptedData is 231

*/
/*************************************************************************************************/
void ByteToOctalString_TestCase_08_99_231();

/*************************************************************************************************/
/*!
\brief ByteToOctalString_TestCase_09_AC_254()

Convert byte(AC) data to Octal string. ExecptedData is 254

*/
/*************************************************************************************************/
void ByteToOctalString_TestCase_09_AC_254();

/*************************************************************************************************/
/*!
\brief ByteToOctalString_TestCase_10_EF_357()

Convert byte(EF) data to Octal string. ExecptedData is 357

*/
/*************************************************************************************************/
void ByteToOctalString_TestCase_10_EF_357();

/*************************************************************************************************/
/*!
\brief ByteToOctalString_TestCase_11_E0_340()

E0=0xFF-0x1F

Convert byte(E0) data to Octal string. ExecptedData is 340

*/
/*************************************************************************************************/
void ByteToOctalString_TestCase_11_E0_340();

/*************************************************************************************************/
/*!
\brief ByteToOctalString_TestCase_12_FF_377()

FF=0xFF+0x00

\The boundary of the return value is the maximum test

Convert byte(FF) data to Octal string. ExecptedData is 377

*/
/*************************************************************************************************/
void ByteToOctalString_TestCase_12_FF_377();

/*************************************************************************************************/
/*!
\brief ByteToOctalString_TestCase_13_FF_377()

\The boundary of the return value is the maximum test

Convert byte(FF) data to Octal string. ExecptedData is 377

*/
/*************************************************************************************************/
void ByteToOctalString_TestCase_13_FF_377();

/*************************************************************************************************/

void ByteToOctalString_RunTestCaes();

#ifdef __cplusplus
}
#endif

#endif//BYTETOOCTALSTRING_H

//1.3.2)ByteToOctalString.cpp

#include<stdio.h>
#include "ByteToOctalString.h"
#include "ConvertTool.h"

WORD g_nOctalTotalRun = 0;
WORD g_nOctalpass = 0;
WORD g_nOctalFail = 0;

void ByteToOctalString_TestCase_Normal(CHAR *pszName, BYTE byData, char szOctalString[3])
{
int result = 0;

DWORD dwRet = ERR_OK;

char _szOctalString[3] = {0};

++g_nOctalTotalRun;

dwRet = ByteToOctalString(byData, _szOctalString);

if (NULL != pszName)
{
printf("[%s] ", pszName);
}

if(dwRet == ERR_OK)
{
++g_nOctalpass;

result = memcmp(_szOctalString, szOctalString, 3);

if(result == 0)
{
printf("OK\n" );
//printf("%s\n", szOctalString);
}
else
{
++g_nOctalFail;
printf("FAIL\n");
}
}
else
{
++g_nOctalFail;
printf("ERROR!");
}

}

void ByteToOctalString_TestCase_01_00_000()
{
ByteToOctalString_TestCase_Normal("ByteToOctalString_TestCase_01_00_000", 0x00, "000");
}

void ByteToOctalString_TestCase_02_34_064()
{
ByteToOctalString_TestCase_Normal("ByteToOctalString_TestCase_02_34_064", 0x34, "064");
}

void ByteToOctalString_TestCase_03_3C_074()
{
ByteToOctalString_TestCase_Normal("ByteToOctalString_TestCase_03_3C_074", 0x3C, "074");
}

void ByteToOctalString_TestCase_04_44_104()
{
ByteToOctalString_TestCase_Normal("ByteToOctalString_TestCase_04_44_104", 0x44, "104");
}

void ByteToOctalString_TestCase_05_4A_112()
{
ByteToOctalString_TestCase_Normal("ByteToOctalString_TestCase_05_4A_112", 0x4A, "112");
}

void ByteToOctalString_TestCase_06_6C_154()
{
ByteToOctalString_TestCase_Normal("ByteToOctalString_TestCase_06_6C_154", 0x6C, "154");
}

void ByteToOctalString_TestCase_07_80_200()
{
ByteToOctalString_TestCase_Normal("ByteToOctalString_TestCase_07_80_200", 0x80, "200");
}

void ByteToOctalString_TestCase_08_99_231()
{
ByteToOctalString_TestCase_Normal("ByteToOctalString_TestCase_08_99_231", 0x99, "231");
}

void ByteToOctalString_TestCase_09_AC_254()
{
ByteToOctalString_TestCase_Normal("ByteToOctalString_TestCase_09_AC_254", 0xAC, "254");
}

void ByteToOctalString_TestCase_10_EF_357()
{
ByteToOctalString_TestCase_Normal("ByteToOctalString_TestCase_10_EF_357", 0xEF, "357");
}

void ByteToOctalString_TestCase_11_E0_340()
{
ByteToOctalString_TestCase_Normal("ByteToOctalString_TestCase_11_E0_340", 0xFF-0x1F, "340");
}

void ByteToOctalString_TestCase_12_FF_377()
{
ByteToOctalString_TestCase_Normal("ByteToOctalString_TestCase_12_FF_377", 0xFF+0x00, "377");
}

void ByteToOctalString_TestCase_13_FF_377()
{
ByteToOctalString_TestCase_Normal("ByteToOctalString_TestCase_13_FF_377", 0xFF, "377");
}

void ByteToOctalString_RunTestCaes()
{
g_nOctalTotalRun = 0;
g_nOctalpass = 0;
g_nOctalFail = 0;

printf("-----------------ByteToOctalString_RunTestCaes------------------\n");

ByteToOctalString_TestCase_01_00_000();
ByteToOctalString_TestCase_02_34_064();
ByteToOctalString_TestCase_03_3C_074();
ByteToOctalString_TestCase_04_44_104();
ByteToOctalString_TestCase_05_4A_112();
ByteToOctalString_TestCase_06_6C_154();
ByteToOctalString_TestCase_07_80_200();
ByteToOctalString_TestCase_08_99_231();
ByteToOctalString_TestCase_09_AC_254();
ByteToOctalString_TestCase_10_EF_357();
ByteToOctalString_TestCase_11_E0_340();
ByteToOctalString_TestCase_12_FF_377();
ByteToOctalString_TestCase_13_FF_377();

printf("Total:%d Pass:%d Fail:%d\n", g_nOctalTotalRun, g_nOctalpass, g_nOctalFail);

printf("---------------------------------------------------------------\n");
}
//1.4)ByteToDecimalString.h and ByteToDecimalString.cpp
//1.4.1)ByteToDecimalString.h

#ifndef BYTETODECIMALSTRING_H
#define BYTETODECIMALSTRING_H
#include "ConvertTool.h"
#pragma comment(lib, "ConvertTool.lib")

#ifdef __cplusplus
extern "C"
{
#endif

void ByteToDecimalString_TestCase_Normal(CHAR* pszName, BYTE byData, char szDecimalString[3]);

/*************************************************************************************************/
/*!
\brief ByteToDecimalString_TestCase_01_00_000()

Convert byte(00) data to Decimal string. ExecptedData is 00000000

*/
/*************************************************************************************************/
void ByteToDecimalString_TestCase_01_00_000();

/*************************************************************************************************/
/*!
\brief ByteToDecimalString_TestCase_02_22_034()

Convert byte(22) data to Decimal string. ExecptedData is 034

*/
/*************************************************************************************************/
void ByteToDecimalString_TestCase_02_22_034();

/*************************************************************************************************/
/*!
\brief ByteToDecimalString_TestCase_03_45_069()

Convert byte(45) data to Decimal string. ExecptedData is 069

*/
/*************************************************************************************************/
void ByteToDecimalString_TestCase_03_45_069();

/*************************************************************************************************/
/*!
\brief ByteToDecimalString_TestCase_04_5A_090()

Convert byte(5A) data to Decimal string. ExecptedData is 090

*/
/*************************************************************************************************/
void ByteToDecimalString_TestCase_04_5A_090();

/*************************************************************************************************/
/*!
\brief ByteToDecimalString_TestCase_05_4C_076()

Convert byte(4C) data to Decimal string. ExecptedData is 076

*/
/*************************************************************************************************/
void ByteToDecimalString_TestCase_05_4C_076();

/*************************************************************************************************/
/*!
\brief ByteToDecimalString_TestCase_06_61_097()

Convert byte(61) data to Decimal string. ExecptedData is 097

*/
/*************************************************************************************************/
void ByteToDecimalString_TestCase_06_61_097();

/*************************************************************************************************/
/*!
\brief ByteToDecimalString_TestCase_07_74_116()

Convert byte(74) data to Decimal string. ExecptedData is 116

*/
/*************************************************************************************************/
void ByteToDecimalString_TestCase_07_74_116();

/*************************************************************************************************/
/*!
\brief ByteToDecimalString_TestCase_08_76_118()

Convert byte(76) data to Decimal string. ExecptedData is 118

*/
/*************************************************************************************************/
void ByteToDecimalString_TestCase_08_76_118();

/*************************************************************************************************/
/*!
\brief ByteToDecimalString_TestCase_09_7A_122()

Convert byte(7A) data to Decimal string. ExecptedData is 112

*/
/*************************************************************************************************/
void ByteToDecimalString_TestCase_09_7A_122();
/*************************************************************************************************/
/*!
\brief ByteToDecimalString_TestCase_10_80_128()

Convert byte(80) data to Decimal string. ExecptedData is 128

*/
/*************************************************************************************************/
void ByteToDecimalString_TestCase_10_80_128();

/*************************************************************************************************/
/*!
\brief ByteToDecimalString_TestCase_11_CB_203()

Convert byte(CB) data to Decimal string. ExecptedData is 203

*/
/*************************************************************************************************/
void ByteToDecimalString_TestCase_11_CB_203();

/*************************************************************************************************/
/*!
\brief ByteToDecimalString_TestCase_12_FE_254()

Convert byte(FE) data to Decimal string. ExecptedData is 254


*/
/*************************************************************************************************/
void ByteToDecimalString_TestCase_12_FE_254();

/*************************************************************************************************/
/*!
\brief ByteToDecimalString_TestCase_13_7F_127()

0x7F=0xFF-0x80

Convert byte(7F) data to Decimal string. ExecptedData is 127

*/
/*************************************************************************************************/
void ByteToDecimalString_TestCase_13_7F_127();

/*************************************************************************************************/
/*!
\brief ByteToDecimalString_TestCase_14_FF_255()

0xFF=0xFF+0x00

\The boundary of the return value is the maximum test

Convert byte(FF) data to Decimal string. ExecptedData is 255

*/
/*************************************************************************************************/
void ByteToDecimalString_TestCase_14_FF_255();

/*************************************************************************************************/
/*!
\brief ByteToDecimalString_TestCase_15_FF_255()

\The boundary of the return value is the maximum test

Convert byte(0xFF) data to Decimal string. ExecptedData is 255

*/
/*************************************************************************************************/
void ByteToDecimalString_TestCase_15_FF_255();

/*************************************************************************************************/

void ByteToDecimalString_RunTestCaes();

#ifdef __cplusplus
}
#endif
#endif//BYTETODECIMALSTRING_H

//1.4.2)ByteToDecimalString.cpp

#include<stdio.h>
#include "ByteToDecimalString.h"
#include "ConvertTool.h"

WORD g_nDecimalTotalRun = 0;
WORD g_nDecimalPass = 0;
WORD g_nDecimalFail = 0;

void ByteToDecimalString_TestCase_Normal(CHAR* pszName,BYTE byData, char szDecimalString[3])
{

int result = 0;

DWORD dwRet = ERR_OK;

char _szDecimalString[3] = {0};

++g_nDecimalTotalRun;

dwRet = ByteToDecimalString(byData, _szDecimalString);

if (NULL != pszName)
{
printf("[%s] ", pszName);
}

if(dwRet == ERR_OK)
{
++g_nDecimalPass;

result = memcmp(_szDecimalString, szDecimalString, 3);


if(result == 0)
{
printf("OK\n");
//printf("%s\n", szDecimalString);
}
else
{
++g_nDecimalFail;
printf("FAIL\n");
}
}
else
{
++g_nDecimalFail;
printf("ERROR!");
}

}
void ByteToDecimalString_TestCase_01_00_000()
{
ByteToDecimalString_TestCase_Normal("ByteToDecimalString_TestCase_01_00_000", 0x00, "000");
}

void ByteToDecimalString_TestCase_02_22_034()
{
ByteToDecimalString_TestCase_Normal("ByteToDecimalString_TestCase_02_22_034", 0x22, "034");
}

void ByteToDecimalString_TestCase_03_45_069()
{
ByteToDecimalString_TestCase_Normal("ByteToDecimalString_TestCase_03_45_069", 0x45, "069");
}

void ByteToDecimalString_TestCase_04_5A_090()
{
ByteToDecimalString_TestCase_Normal("ByteToDecimalString_TestCase_04_5A_090", 0x5A, "090");
}

void ByteToDecimalString_TestCase_05_4C_076()
{
ByteToDecimalString_TestCase_Normal("ByteToDecimalString_TestCase_05_4C_076", 0x4C, "076");
}

void ByteToDecimalString_TestCase_06_61_097()
{
ByteToDecimalString_TestCase_Normal("ByteToDecimalString_TestCase_06_61_097", 0x61, "097");
}

void ByteToDecimalString_TestCase_07_74_116()
{
ByteToDecimalString_TestCase_Normal("ByteToDecimalString_TestCase_07_74_116", 0x74, "116");
}

void ByteToDecimalString_TestCase_08_76_118()
{
ByteToDecimalString_TestCase_Normal("ByteToDecimalString_TestCase_08_76_118", 0x76, "118");
}

void ByteToDecimalString_TestCase_09_7A_122()
{
ByteToDecimalString_TestCase_Normal("ByteToDecimalString_TestCase_09_7A_122", 0x7A, "122");
}

void ByteToDecimalString_TestCase_10_80_128()
{
ByteToDecimalString_TestCase_Normal("ByteToDecimalString_TestCase_10_80_128", 0x80, "128");
}

void ByteToDecimalString_TestCase_11_CB_203()
{
ByteToDecimalString_TestCase_Normal("ByteToDecimalString_TestCase_11_CB_203", 0xCB, "203");
}

void ByteToDecimalString_TestCase_12_FE_254()
{
ByteToDecimalString_TestCase_Normal("ByteToDecimalString_TestCase_12_FE_254", 0xFE, "254");
}

void ByteToDecimalString_TestCase_13_7F_127()
{
ByteToDecimalString_TestCase_Normal("ByteToDecimalString_TestCase_13_7F_127", 0xFF-0x80, "127");

}

void ByteToDecimalString_TestCase_14_FF_255()
{
ByteToDecimalString_TestCase_Normal("ByteToDecimalString_TestCase_14_FF_255", 0xFF+0x00, "255");
}

void ByteToDecimalString_TestCase_15_FF_255()
{
ByteToDecimalString_TestCase_Normal("ByteToDecimalString_TestCase_15_FF_255", 0xFF, "255");
}

void ByteToDecimalString_RunTestCaes()
{
g_nDecimalTotalRun = 0;
g_nDecimalPass = 0;
g_nDecimalFail = 0;

printf("---------------ByteToDecimalString_RunTestCaes------------------\n");

ByteToDecimalString_TestCase_01_00_000();
ByteToDecimalString_TestCase_02_22_034();
ByteToDecimalString_TestCase_03_45_069();
ByteToDecimalString_TestCase_04_5A_090();
ByteToDecimalString_TestCase_05_4C_076();
ByteToDecimalString_TestCase_06_61_097();
ByteToDecimalString_TestCase_07_74_116();
ByteToDecimalString_TestCase_08_76_118();
ByteToDecimalString_TestCase_09_7A_122();
ByteToDecimalString_TestCase_10_80_128();
ByteToDecimalString_TestCase_11_CB_203();
ByteToDecimalString_TestCase_12_FE_254();
ByteToDecimalString_TestCase_13_7F_127();
ByteToDecimalString_TestCase_14_FF_255();
ByteToDecimalString_TestCase_15_FF_255();
printf("Total:%d Pass:%d Fail:%d\n", g_nDecimalTotalRun, g_nDecimalPass, g_nDecimalFail);

printf("---------------------------------------------------------------\n");
}

//1.5)ByteToHexString.h and ByteToHexString.cpp
//1.5.1)ByteToHexString.h

#ifndef BYTETOHEXSTRING_H
#define BYTETOHEXSTRING_H
#include "ConvertTool.h"
#pragma comment(lib, "ConvertTool.lib")

#ifdef __cplusplus
extern "C"
{
#endif

void ByteToHexString_TestCase_Normal(CHAR* pszName,BYTE byData, char szHexString[2]);

/*************************************************************************************************/
/*!
\brief ByteToHexString_TestCase_01_00_00()

Convert byte(00) data to Hex string. ExecptedData is 00

*/
/*************************************************************************************************/
void ByteToHexString_TestCase_01_00_00();

/*************************************************************************************************/
/*!
\brief ByteToHexString_TestCase_02_31_31()

Convert byte(31) data to Hex string. ExecptedData is 31

*/
/*************************************************************************************************/
void ByteToHexString_TestCase_02_31_31();

/*************************************************************************************************/
/*!
\brief ByteToHexString_TestCase_03_45_45()

Convert byte(45) data to Hex string. ExecptedData is 45

*/
/*************************************************************************************************/
void ByteToHexString_TestCase_03_45_45();

/*************************************************************************************************/
/*!
\brief ByteToHexString_TestCase_04_5C_5C()

Convert byte(5C) data to Hex string. ExecptedData is 5C

*/
/*************************************************************************************************/
void ByteToHexString_TestCase_04_5C_5C();

/*************************************************************************************************/
/*!
\brief ByteToHexString_TestCase_05_62_62()

Convert byte(62) data to Hex string. ExecptedData is 62

*/
/*************************************************************************************************/
void ByteToHexString_TestCase_05_62_62();

/*************************************************************************************************/
/*!
\brief ByteToHexString_TestCase_06_66_66()

Convert byte(66) data to Hex string. ExecptedData is 66

*/
/*************************************************************************************************/
void ByteToHexString_TestCase_06_66_66();

/*************************************************************************************************/
/*!
\brief ByteToHexString_TestCase_07_70_70()

Convert byte(70) data to Hex string. ExecptedData is 70

*/
/*************************************************************************************************/
void ByteToHexString_TestCase_07_70_70();

/*************************************************************************************************/
/*!
\brief ByteToHexString_TestCase_08_7D_7D()

Convert byte(7D) data to Hex string. ExecptedData is 7D

*/
/*************************************************************************************************/
void ByteToHexString_TestCase_08_7D_7D();

/*************************************************************************************************/
/*!
\brief ByteToHexString_TestCase_09_80_80()

Convert byte(80) data to Hex string. ExecptedData is 80

*/
/*************************************************************************************************/
void ByteToHexString_TestCase_09_80_80();

/*************************************************************************************************/
/*!
\brief ByteToHexString_TestCase_10_AB_AB()

Convert byte(AB) data to Hex string. ExecptedData is AB

*/
/*************************************************************************************************/
void ByteToHexString_TestCase_10_AB_AB();

/*************************************************************************************************/
/*!
\brief ByteToHexString_TestCase_11_CD_CD()

Convert byte(CD) data to Hex string. ExecptedData is CD

*/
/*************************************************************************************************/
void ByteToHexString_TestCase_11_CD_CD();

/*************************************************************************************************/
/*!
\brief ByteToHexString_TestCase_12_FE_FE()

Convert byte(FE) data to Hex string. ExecptedData is FE

*/
/*************************************************************************************************/
void ByteToHexString_TestCase_12_FE_FE();

/*************************************************************************************************/
/*!
\brief ByteToHexString_TestCase_13_C6_C6()

C6=0xFF-0x39

Convert byte(C6) data to Hex string. ExecptedData is C6

*/
/*************************************************************************************************/
void ByteToHexString_TestCase_13_C6_C6();

/*************************************************************************************************/
/*!
\brief ByteToHexString_TestCase_14_FF_FF()

\The boundary of the return value is the maximum test

Convert byte(FF) data to Hex string. ExecptedData is FF

*/
/*************************************************************************************************/
void ByteToHexString_TestCase_14_FF_FF();

/*************************************************************************************************/
/*!
\brief ByteToHexString_TestCase_15_FF_FF()

FF=0x00+0xFF

\The boundary of the return value is the maximum test

Convert byte(FF) data to Hex string. ExecptedData is FF
*/
/*************************************************************************************************/
void ByteToHexString_TestCase_15_FF_FF();

/*************************************************************************************************/
void ByteToHexString_RunTestCaes();

#ifdef __cplusplus
}
#endif
#endif//BYTETOHEXSTRING_H

//1.5.2)ByteToHexString.cpp

#include<stdio.h>
#include "ByteToHexString.h"
#include "ConvertTool.h"

WORD g_nHexTotalRun = 0;
WORD g_nHexPass = 0;
WORD g_nHexFail = 0;

void ByteToHexString_TestCase_Normal(CHAR* pszName,BYTE byData, char szHexString[2])
{
int result = 0;

DWORD dwRet = ERR_OK;

char _szHexString[2] = {0};

++g_nHexTotalRun;

dwRet = ByteToHexString(byData, _szHexString);

if (NULL != pszName)
{
printf("[%s] ", pszName);
}

if(dwRet == ERR_OK)
{
++g_nHexPass;
result = memcmp(_szHexString, szHexString, 2);

if(result == 0)
{
printf("OK\n");
//printf("%s\n", szHexString);
}
else
{
++g_nHexFail;
printf("FAIL\n");
}
}
else
{
++g_nHexFail;
printf("ERROR!");
}

}
void ByteToHexString_TestCase_01_00_00()
{
ByteToHexString_TestCase_Normal("ByteToHexString_TestCase_01_00_00", 0x00, "00");

}

void ByteToHexString_TestCase_02_31_31()
{
ByteToHexString_TestCase_Normal("ByteToHexString_TestCase_02_31_31", 0x31, "31");
}

void ByteToHexString_TestCase_03_45_45()
{
ByteToHexString_TestCase_Normal("ByteToHexString_TestCase_03_45_45", 0x45, "45");
}

void ByteToHexString_TestCase_04_5C_5C()
{
ByteToHexString_TestCase_Normal("ByteToHexString_TestCase_04_5C_5C", 0x5C, "5C");
}

void ByteToHexString_TestCase_05_62_62()
{
ByteToHexString_TestCase_Normal("ByteToHexString_TestCase_05_62_62", 0x62, "62");
}

void ByteToHexString_TestCase_06_66_66()
{
ByteToHexString_TestCase_Normal("ByteToHexString_TestCase_06_66_66", 0x66, "66");
}

void ByteToHexString_TestCase_07_70_70()
{
ByteToHexString_TestCase_Normal("ByteToHexString_TestCase_07_70_70", 0x70, "70");
}

void ByteToHexString_TestCase_08_7D_7D()
{
ByteToHexString_TestCase_Normal("ByteToHexString_TestCase_08_7D_7D", 0x7D, "7D");
}

void ByteToHexString_TestCase_09_80_80()
{
ByteToHexString_TestCase_Normal("ByteToHexString_TestCase_09_80_80", 0x80, "80");
}

void ByteToHexString_TestCase_10_AB_AB()
{
ByteToHexString_TestCase_Normal("ByteToHexString_TestCase_10_AB_AB", 0xAB, "AB");
}

void ByteToHexString_TestCase_11_CD_CD()
{
ByteToHexString_TestCase_Normal("ByteToHexString_TestCase_11_CD_CD", 0xCD, "CD");
}

void ByteToHexString_TestCase_12_FE_FE()
{
ByteToHexString_TestCase_Normal("ByteToHexString_TestCase_12_FE_FE", 0xFE, "FE");
}

void ByteToHexString_TestCase_13_C6_C6()
{
ByteToHexString_TestCase_Normal("ByteToHexString_TestCase_13_C6_C6", 0xFF-0x39, "C6");
}

void ByteToHexString_TestCase_14_FF_FF()
{
ByteToHexString_TestCase_Normal("ByteToHexString_TestCase_14_FF_FF", 0xFF, "FF" );
}

void ByteToHexString_TestCase_15_FF_FF()
{
ByteToHexString_TestCase_Normal("ByteToHexString_TestCase_15_FF_FF", 0x00+0xFF, "FF");
}

void ByteToHexString_RunTestCaes()
{
g_nHexTotalRun = 0;
g_nHexPass = 0;
g_nHexFail = 0;

printf("------------------ByteToHexString_RunTestCaes-----------------\n");

ByteToHexString_TestCase_01_00_00();
ByteToHexString_TestCase_02_31_31();
ByteToHexString_TestCase_03_45_45();
ByteToHexString_TestCase_04_5C_5C();
ByteToHexString_TestCase_05_62_62();
ByteToHexString_TestCase_06_66_66();
ByteToHexString_TestCase_07_70_70();
ByteToHexString_TestCase_08_7D_7D();
ByteToHexString_TestCase_09_80_80();
ByteToHexString_TestCase_10_AB_AB();
ByteToHexString_TestCase_11_CD_CD();
ByteToHexString_TestCase_12_FE_FE();
ByteToHexString_TestCase_13_C6_C6();
ByteToHexString_TestCase_14_FF_FF();
ByteToHexString_TestCase_15_FF_FF();
printf("Total:%d Pass:%d Fail:%d\n", g_nHexTotalRun, g_nHexPass, g_nHexFail);

printf("---------------------------------------------------------------\n");
}

//
// 以上Code:修改了几次,主要两次描述出来
//第一次修改前,此小CODE虽然可以运行出想要的结果,但在定义中没有作具体的描述,每个CASE测试的目的不明确。
//第二次修改,主要是因为每个Case名标注的不是那么清晰。
//针对以上两次修改,主要还是因为在写的时候,测试CASE的命名、输出、比对两字符长度时所用的函数、对CASE运行OK或者Fail 的统计等,考虑不是那么全面。
//一般测试流程(留着自己备用):1)接受任务;2)仔细阅读和理解拿到的资料(参考文档,或者.h文件。若有不懂或者不清楚的地方要及时提出);3)根据不同的API(UI界面)的功能才写测试文档,需要考虑参数以及返回值;4)TestCase Review;5)根据TestCase写测试代码或者有自动化测试代码。测试过程中发现Bug需及时上报并能将Bug重现(重现的步骤写的要详细(图文并茂));6)回滚测试,确认问题是否都已修复,确认所写的TestCasez是否都能测试通过;7)Test Report;8)工作的提交(包括Test document,Test code,Test report,Debug report)
//具体测试文档以附件形式上传。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值