2015-04-03 10:22:05 -07:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
#include "getcomputername.h"
|
|
|
|
|
|
|
|
|
|
TEST(GetComputerName,simple)
|
2015-04-06 09:57:16 -07:00
|
|
|
{
|
|
|
|
|
char hostname[HOST_NAME_MAX];
|
2015-04-09 15:16:37 -07:00
|
|
|
std::string hostnameFunctionTest;
|
2015-04-06 09:57:16 -07:00
|
|
|
DWORD hostSize = HOST_NAME_MAX;
|
2015-04-09 15:16:37 -07:00
|
|
|
BOOL getComputerName = GetComputerName(&hostnameFunctionTest[0], &hostSize);
|
2015-04-06 09:57:16 -07:00
|
|
|
BOOL host = gethostname(hostname, sizeof hostname);
|
2015-04-03 10:22:05 -07:00
|
|
|
|
2015-04-06 09:57:16 -07:00
|
|
|
if(host == 0)
|
|
|
|
|
{
|
2015-04-09 15:16:37 -07:00
|
|
|
host = TRUE;
|
2015-04-06 09:57:16 -07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-04-09 15:16:37 -07:00
|
|
|
host = FALSE;
|
2015-04-06 09:57:16 -07:00
|
|
|
}
|
|
|
|
|
|
2015-04-09 15:16:37 -07:00
|
|
|
std::string hostnameString(hostname);
|
|
|
|
|
std::string hostnameStringTest(&hostnameFunctionTest[0]);
|
2015-04-06 09:57:16 -07:00
|
|
|
|
|
|
|
|
ASSERT_TRUE(getComputerName == TRUE);
|
|
|
|
|
ASSERT_EQ(host,TRUE);
|
2015-04-09 15:16:37 -07:00
|
|
|
ASSERT_EQ(hostnameString,hostnameStringTest);
|
2015-04-03 10:22:05 -07:00
|
|
|
}
|