在构建此代码以进行测试时,我遇到了错误代码C2144。
我实际上正在构建一个本机C ++ DLL应用程序来获取电池信息: 这是BatteryInfromation.cpp文件的代码:
// BATTERY INFORMATION.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "StatusCodes.h"
SYSTEM_POWER_STATUS SYS;
STATUS battery_info_init(void )
{
if ( GetSystemPowerStatus( &SYS ) )
return SUCCESS;
return FALIURE;
}
STATUS ChargingState( )
{
if ( battery_info_init( ) )
{
switch ( SYS.ACLineStatus )
{
case 1:
return ONCHARGING; break;
case 0:
return ONBATTERY; break;
case 128:
return NOBATTERY; break;
case 255:
return UNKNOWNSTATUS; break;
default:
return FALIURE; break;
}
}
else
return FALIURE;
}
这是我的宏定义代码:
#pragma once
#include "stdafx.h"
/* Status Code: Contains the Status Codes returned by the BATTERYINFORMATION.cpp*/
typedef unsigned char STATUS
# define ONBATTERY 0x64
# define ONCHARGING 0x65
# define HIGHBATTERY 0x66
# define LOWBATTERY 0x67
# define CRITICALBATTERY 0x68
# define NOBATTERY 0x80
# define UNKNOWNSTATUS 0xFF
# define SUCCESS 0x01
# define FALIURE 0x00
# define MEDIUMBATTERY 0x69
以下是单元测试文件的代码:
#include "stdafx.h"
#include "CppUnitTest.h"
#include "E:\UNIVERSAL ARDUINO CONTROLLER\CODE\SYSTEM PROFILE\BATTERY INFORMATION\BATTERY INFORMATION\StatusCodes.h"
#include "E:\UNIVERSAL ARDUINO CONTROLLER\CODE\SYSTEM PROFILE\BATTERY INFORMATION\BATTERY INFORMATION\BATTERY INFORMATION.cpp"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace Battery_Information_Functions_Test
{
TEST_CLASS(BatteryInformationTests)
{
public:
TEST_METHOD( Battery_Information_Initialization )
{
Assert::AreEqual<int>( ChargingState() , SUCCESS , L"GetSystemPowerStatus() failed to initialize " );
}
TEST_METHOD(ChargingState_in_AC)
{
Assert::AreEqual<int>( ChargingState( ) , ONCHARGING , L"Function not returning ONCHARGING STATE " );
}
TEST_METHOD( ChargingState_in_DC )
{
Assert::AreEqual<int>( ChargingState() ,(int) ONBATTERY , L"Function not returning ONBATTERY STATE" );
}
TEST_METHOD( ChargingState_in_UnknownStatus )
{
if(ChargingState() != ONBATTERY && ChargingState() != ONCHARGING )
Assert::Fail( L"Function not able to get the information associated with charging" );
}
};
}
这是我开始写作的一小部分。如果有人能帮助我,那将会有很大的帮助。 在此先感谢:)