changes based on comments

This commit is contained in:
Aaron Katz 2015-04-06 09:57:16 -07:00
parent 70645d5bc1
commit ea7b78ef1c
4 changed files with 32 additions and 20 deletions

View File

@ -1,8 +1,12 @@
#include "getcomputername.h" #include "getcomputername.h"
#include <unistd.h> #include <unistd.h>
int GetComputerName(char *name, size_t len) BOOL GetComputerName(LPTSTR name, LPDWORD len)
{ {
int host = gethostname(name, len); int host = gethostname(name, HOST_NAME_MAX);
return host; if(host == 0)
{
return TRUE;
}
return FALSE;
} }

View File

@ -4,6 +4,6 @@
PAL_BEGIN_EXTERNC PAL_BEGIN_EXTERNC
int GetComputerName(char * name, size_t len); BOOL GetComputerName(LPTSTR name, LPDWORD len);
PAL_END_EXTERNC PAL_END_EXTERNC

View File

@ -59,6 +59,9 @@
typedef char *PSTR; typedef char *PSTR;
typedef void *PVOID; typedef void *PVOID;
typedef PVOID HANDLE; typedef PVOID HANDLE;
typedef char TCHAR;
typedef TCHAR *LPTSTR;
typedef DWORD *LPDWORD;
#define NO_ERROR 0 #define NO_ERROR 0
#define INFINITE 0xFFFFFFFF #define INFINITE 0xFFFFFFFF
#define WINAPI #define WINAPI

View File

@ -2,22 +2,27 @@
#include "getcomputername.h" #include "getcomputername.h"
TEST(GetComputerName,simple) TEST(GetComputerName,simple)
{ {
char hostname[HOST_NAME_MAX];
char hostname[128]; TCHAR hostnameFunctionTest[HOST_NAME_MAX];
char hostnameFunctionTest[128]; DWORD hostSize = HOST_NAME_MAX;
int getComputerName = GetComputerName(hostnameFunctionTest, sizeof hostnameFunctionTest); BOOL getComputerName = GetComputerName(hostnameFunctionTest, &hostSize);
int host = gethostname(hostname, sizeof hostname); BOOL host = gethostname(hostname, sizeof hostname);
// first make sure that on this platform those types are of the same size if(host == 0)
{
ASSERT_TRUE(getComputerName == 0); host = TRUE;
ASSERT_TRUE(host == 0); }
else
// now compare the actual values {
for(int i =0; hostname[i] != '\0'; i++) host = FALSE;
{ }
ASSERT_EQ(hostnameFunctionTest[i],hostname[i]);
} std::string hostnameSting(hostname);
std::string hostnameStingTest(hostnameFunctionTest);
ASSERT_TRUE(getComputerName == TRUE);
ASSERT_EQ(host,TRUE);
ASSERT_EQ(hostnameSting,hostnameFunctionTest);
} }