Skip to content

Commit

Permalink
modify test case
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminyangguang520 authored and litz-a committed Jan 18, 2016
1 parent ff4533d commit 9b052b1
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 92 deletions.
25 changes: 13 additions & 12 deletions GLDUserInfoUtils/GLDDiskInfoUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 4,7 @@
namespace GlodonDiskInfo
{

QString GLDDiskInfo::getSystemVolumeName()
QString getSystemVolumeName()
{
WCHAR str[MAX_PATH];
char sysDiskName[MAX_PATH * 2 1];
Expand All @@ -13,7 13,7 @@ namespace GlodonDiskInfo
return QString(sysDiskName[0]);
}

QString GLDDiskInfo::getCurrentVolumeName()
QString getCurrentVolumeName()
{
/* Path of Module */
WCHAR szModulePath[MAX_PATH];
Expand All @@ -26,7 26,7 @@ namespace GlodonDiskInfo
return QString(curDiskName[0]);
}

QString GLDDiskInfo::getPhysicalDriveSerialNumber()
QString getPhysicalDriveSerialNumber()
{
DWORD dwResult = NO_ERROR;
UINT nDriveNumber = 0;
Expand Down Expand Up @@ -98,13 98,12 @@ namespace GlodonDiskInfo
return QString::fromStdWString(intermediate).trimmed();
}

QVector<DiskInfomation> GLDDiskInfo::getAllVolumeInfo()
QVector<DiskInfomation> getAllVolumeInfo()
{
QVector<DiskInfomation> diskInfoVect;
QVector<QString> drvNameVct;
qulonglong dwDrvNum = getVolumeNum();

if (getAllVolumeName(dwDrvNum, drvNameVct))
if (getAllVolumeName(drvNameVct))
{
QVector<QString>::const_iterator iter = drvNameVct.begin();
for (; iter != drvNameVct.end(); iter)
Expand Down Expand Up @@ -153,7 152,7 @@ namespace GlodonDiskInfo
return diskInfoVect;
}

ulong GLDDiskInfo::getVolumeNum()
ulong getVolumeNum()
{
ulong diskCount = 0;
DWORD DiskInfo = GetLogicalDrives();
Expand All @@ -172,8 171,10 @@ namespace GlodonDiskInfo
}

//n个driver,以A:\null的形式存放的话,需4n个字符的数组,猜想,实际获得4n+1个字符的数组,可见末尾是以nullnull结束字符数组
bool GLDDiskInfo::getAllVolumeName(ulong dwDrvNum, QVector<QString> & volumeNameVct)
bool getAllVolumeName(QVector<QString> & volumeNameVct)
{
ulong dwDrvNum = getVolumeNum();

//通过GetLogicalDriveStrings()函数获取所有驱动器字符串信息长度。
DWORD dwLength = GetLogicalDriveStringsA(0,NULL);

Expand All @@ -199,7 200,7 @@ namespace GlodonDiskInfo
return true;
}

QString GLDDiskInfo::getVolumeTypeItem(const QString& dir)
QString getVolumeTypeItem(const QString& dir)
{
UINT uiType = GetDriveTypeA(dir.toStdString().c_str());
switch (uiType)
Expand All @@ -221,7 222,7 @@ namespace GlodonDiskInfo
}
}

FS GLDDiskInfo::getFileSystemType(const QString &dir)
FS getFileSystemType(const QString &dir)
{
//对于光驱信息的需排除之
QString temp = dir[0];
Expand Down Expand Up @@ -250,7 251,7 @@ namespace GlodonDiskInfo
}
}

bool GLDDiskInfo::getVolumeSpace(const QString& dir, qulonglong& ri64FreeBytesToCaller, qulonglong& ri64TotalBytes)
bool getVolumeSpace(const QString& dir, qulonglong& ri64FreeBytesToCaller, qulonglong& ri64TotalBytes)
{
typedef bool (WINAPI *PGETDISKFREESPACEEX)(LPCSTR,
PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
Expand Down Expand Up @@ -294,7 295,7 @@ namespace GlodonDiskInfo
return fResult;
}

bool GLDDiskInfo::getDiskSpaceInfo(qulonglong& ri64FreeBytesToCaller, qulonglong& ri64TotalBytes)
bool getDiskSpaceInfo(qulonglong& ri64FreeBytesToCaller, qulonglong& ri64TotalBytes)
{
ri64FreeBytesToCaller = 0;
ri64TotalBytes = 0;
Expand Down
135 changes: 67 additions & 68 deletions GLDUserInfoUtils/GLDDiskInfoUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,74 34,73 @@ namespace GlodonDiskInfo

}DiskInfomation;

class GLDDiskInfo
{
public:

/**
* @brief 获取系统盘符
* @return
*/
QString getSystemVolumeName();

/**
* @brief 获取当前盘符
* @return
*/
QString getCurrentVolumeName();

/**
* @brief 获取硬盘序列号
* @return
*/
QString getPhysicalDriveSerialNumber();

/**
* @brief 获取分区个数
* @return
*/
ulong getVolumeNum();

/**
* @brief 获取所有分区信息
* @return
*/
QVector<DiskInfomation> getAllVolumeInfo();

/**
* @brief 获取分区格式
* @param dir 分区名
* @return
*/
FS getFileSystemType(const QString& dir);

/**
* @brief 获取分区类型
* @param dir 分区名
* @return
*/
QString getVolumeTypeItem(const QString& dir);

/**
* @brief 获取分区空间信息
* @param dir 分区名
* @param ri64FreeBytesToCaller 可用空间
* @param ri64TotalBytes 分区总空间
* @return
*/
bool getVolumeSpace(const QString& dir, qulonglong& ri64FreeBytesToCaller, qulonglong& ri64TotalBytes);

/**
* @brief 获取硬盘空间信息
* @param ri64FreeBytesToCaller 硬盘可用空间
* @param ri64TotalBytes 硬盘总空间
* @return
*/
bool getDiskSpaceInfo(qulonglong& ri64FreeBytesToCaller, qulonglong& ri64TotalBytes);

private:
bool getAllVolumeName(ulong dwDrvNum, QVector<QString> & volumeNameVct);
};
/**
* @brief 获取系统盘符
* @return
*/
QString getSystemVolumeName();

/**
* @brief 获取当前盘符
* @return
*/
QString getCurrentVolumeName();

/**
* @brief 获取硬盘序列号
* @return
*/
QString getPhysicalDriveSerialNumber();

/**
* @brief 获取分区个数
* @return
*/
ulong getVolumeNum();

/**
* @brief 获取所有分区信息
* @return
*/
QVector<DiskInfomation> getAllVolumeInfo();

/**
* @brief 获取分区格式
* @param dir 分区名
* @return
*/
FS getFileSystemType(const QString& dir);

/**
* @brief 获取分区类型
* @param dir 分区名
* @return
*/
QString getVolumeTypeItem(const QString& dir);

/**
* @brief 获取分区空间信息
* @param dir 分区名
* @param ri64FreeBytesToCaller 可用空间
* @param ri64TotalBytes 分区总空间
* @return
*/
bool getVolumeSpace(const QString& dir, qulonglong& ri64FreeBytesToCaller, qulonglong& ri64TotalBytes);

/**
* @brief 获取硬盘空间信息
* @param ri64FreeBytesToCaller 硬盘可用空间
* @param ri64TotalBytes 硬盘总空间
* @return
*/
bool getDiskSpaceInfo(qulonglong& ri64FreeBytesToCaller, qulonglong& ri64TotalBytes);

/**
* @brief 获取所有分区的名字
* @param volumeNameVct 存放分区名的容器
* @return
*/
bool getAllVolumeName(QVector<QString> & volumeNameVct);
}

#endif // GLDDISKINFOUTILS_H
4 changes: 2 additions & 2 deletions GLDUserInfoUtils/GLDMemoryInfoUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 5,7 @@ namespace GlodonMemoryInfo
PhysMemInfo getPhysMemInfo()
{
PhysMemInfo memInfo;
MEMORYSTATUSEX mymem;
MEMORYSTATUSEX mymem;
mymem.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&mymem);
memset(&memInfo, 0, sizeof(memInfo));
Expand All @@ -18,7 18,7 @@ namespace GlodonMemoryInfo
VirMemInfo getVirMemInfo()
{
VirMemInfo memInfo;
MEMORYSTATUSEX mymem;
MEMORYSTATUSEX mymem;
mymem.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&mymem);
memset(&memInfo, 0, sizeof(memInfo));
Expand Down
8 changes: 8 additions & 0 deletions GLDUserInfoUtils/GLDMemoryInfoUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 19,16 @@ namespace GlodonMemoryInfo
qint64 m_availVirtual; // 可用虚拟内存数,单位M
} VirMemInfo;

/**
* @brief 获取物理内存信息
* @return
*/
PhysMemInfo getPhysMemInfo();

/**
* @brief 获取虚拟内存信息
* @return
*/
VirMemInfo getVirMemInfo();
}

Expand Down
30 changes: 20 additions & 10 deletions GLDUserInfoUtils/main.cpp
Original file line number Diff line number Diff line change
@@ -1,9 1,11 @@
#include <QCoreApplication>
#include "GLDCpuInfoUtils.h"
#include "GLDDiskInfoUtils.h"
#include "GLDMemoryInfoUtils.h"

using namespace GlodonDiskInfo;
using namespace GlodonCpuInfo;
using namespace GlodonMemoryInfo;

#include <QDebug>

Expand Down Expand Up @@ -33,40 35,39 @@ int main(int argc, char *argv[])
qDebug() << "cpuInfo is" << cpuInfo.m_processSpeed;


GLDDiskInfo disk;
DiskInfomation diskInfo;

FS fileSystem = disk.getFileSystemType("C:\\");
FS fileSystem = getFileSystemType("C:\\");
qDebug() << "FS is" << fileSystem;

QString voluName = disk.getSystemVolumeName();
QString voluName = getSystemVolumeName();
qDebug() << "system volume name is" << voluName;

QString currentVolName = disk.getCurrentVolumeName();
QString currentVolName = getCurrentVolumeName();
qDebug() << "current volume name is" << currentVolName;

QString serialNumber = disk.getPhysicalDriveSerialNumber();
QString serialNumber = getPhysicalDriveSerialNumber();
qDebug() << "serialNumber is" << serialNumber;

ulong volNumber = disk.getVolumeNum();
ulong volNumber = getVolumeNum();
qDebug() << "volNumber is" << volNumber;

QString volType = disk.getVolumeTypeItem("D:\\");
QString volType = getVolumeTypeItem("D:\\");
qDebug() << "volType is" << volType;

qulonglong ri64FreeBytesToCaller;
qulonglong ri64TotalBytes;
disk.getVolumeSpace("E:\\", ri64FreeBytesToCaller, ri64TotalBytes);
getVolumeSpace("E:\\", ri64FreeBytesToCaller, ri64TotalBytes);
qDebug() << "E volume's free space is" << ri64FreeBytesToCaller;
qDebug() << "E volume's totle space is" << ri64TotalBytes;

qulonglong diskFreeBytesToCaller;
qulonglong diskTotalBytes;
disk.getDiskSpaceInfo(diskFreeBytesToCaller, diskTotalBytes);
getDiskSpaceInfo(diskFreeBytesToCaller, diskTotalBytes);
qDebug() << "Disk free space is" << diskFreeBytesToCaller;
qDebug() << "Disk totle space is" << diskTotalBytes;

QVector<DiskInfomation> diskInfoVet = disk.getAllVolumeInfo();
QVector<DiskInfomation> diskInfoVet = getAllVolumeInfo();
foreach(DiskInfomation disk , diskInfoVet)
{
qDebug() << "disk name is" << disk.m_strDiskName;
Expand All @@ -77,5 78,14 @@ int main(int argc, char *argv[])
qDebug() << "free space is" << disk.m_dwFreeMBytes;
}

PhysMemInfo memInfo = getPhysMemInfo();
qDebug() << "memInfo's m_totalPhys is" << memInfo.m_totalPhys;
qDebug() << "memInfo's m_availPhys is " << memInfo.m_availPhys;
qDebug() << "memInfo's m_usedPhys is " << memInfo.m_usedPhys;

VirMemInfo virMemInfo = getVirMemInfo();
qDebug() << "virMemInfo's m_totalVirtual is" << virMemInfo.m_totalVirtual;
qDebug() << "virMemInfo's m_availVirtual is " << virMemInfo.m_availVirtual;

return a.exec();
}

0 comments on commit 9b052b1

Please sign in to comment.