changes based on comments
This commit is contained in:
parent
70645d5bc1
commit
ea7b78ef1c
@ -1,8 +1,12 @@
|
||||
#include "getcomputername.h"
|
||||
#include <unistd.h>
|
||||
|
||||
int GetComputerName(char *name, size_t len)
|
||||
BOOL GetComputerName(LPTSTR name, LPDWORD len)
|
||||
{
|
||||
int host = gethostname(name, len);
|
||||
return host;
|
||||
int host = gethostname(name, HOST_NAME_MAX);
|
||||
if(host == 0)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -4,6 +4,6 @@
|
||||
|
||||
PAL_BEGIN_EXTERNC
|
||||
|
||||
int GetComputerName(char * name, size_t len);
|
||||
BOOL GetComputerName(LPTSTR name, LPDWORD len);
|
||||
|
||||
PAL_END_EXTERNC
|
@ -59,6 +59,9 @@
|
||||
typedef char *PSTR;
|
||||
typedef void *PVOID;
|
||||
typedef PVOID HANDLE;
|
||||
typedef char TCHAR;
|
||||
typedef TCHAR *LPTSTR;
|
||||
typedef DWORD *LPDWORD;
|
||||
#define NO_ERROR 0
|
||||
#define INFINITE 0xFFFFFFFF
|
||||
#define WINAPI
|
||||
|
@ -2,22 +2,27 @@
|
||||
#include "getcomputername.h"
|
||||
|
||||
TEST(GetComputerName,simple)
|
||||
{
|
||||
|
||||
char hostname[128];
|
||||
char hostnameFunctionTest[128];
|
||||
{
|
||||
char hostname[HOST_NAME_MAX];
|
||||
TCHAR hostnameFunctionTest[HOST_NAME_MAX];
|
||||
DWORD hostSize = HOST_NAME_MAX;
|
||||
|
||||
int getComputerName = GetComputerName(hostnameFunctionTest, sizeof hostnameFunctionTest);
|
||||
int host = gethostname(hostname, sizeof hostname);
|
||||
BOOL getComputerName = GetComputerName(hostnameFunctionTest, &hostSize);
|
||||
BOOL host = gethostname(hostname, sizeof hostname);
|
||||
|
||||
// first make sure that on this platform those types are of the same size
|
||||
|
||||
ASSERT_TRUE(getComputerName == 0);
|
||||
ASSERT_TRUE(host == 0);
|
||||
|
||||
// now compare the actual values
|
||||
for(int i =0; hostname[i] != '\0'; i++)
|
||||
{
|
||||
ASSERT_EQ(hostnameFunctionTest[i],hostname[i]);
|
||||
}
|
||||
if(host == 0)
|
||||
{
|
||||
host = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
host = FALSE;
|
||||
}
|
||||
|
||||
std::string hostnameSting(hostname);
|
||||
std::string hostnameStingTest(hostnameFunctionTest);
|
||||
|
||||
ASSERT_TRUE(getComputerName == TRUE);
|
||||
ASSERT_EQ(host,TRUE);
|
||||
ASSERT_EQ(hostnameSting,hostnameFunctionTest);
|
||||
}
|
Loading…
Reference in New Issue
Block a user