forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-getfullyqualifiedname.cpp
More file actions
41 lines (36 loc) · 1.06 KB
/
Copy pathtest-getfullyqualifiedname.cpp
File metadata and controls
41 lines (36 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! @file test-getfullyqualifiedname.cpp
//! @author George Fleming <v-geflem@microsoft.com>
//! @brief Unit tests for GetFullyQualifiedName
#include <gtest/gtest.h>
#include "getcomputername.h"
#include "getfullyqualifiedname.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <string>
TEST(GetFullyQualifiedNameTest, ValidateLinuxGetFullyQualifiedDomainName)
{
char *hostname = GetComputerName();
ASSERT_STRNE(NULL, hostname);
// this might be fail
errno = 0;
char *actual = GetFullyQualifiedName();
int fqdnErrno = errno;
struct addrinfo hints, *info;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_CANONNAME;
errno = 0;
if (getaddrinfo(hostname, "http", &hints, &info) != 0)
{
// test that getaddrinfo failed the same way
EXPECT_EQ(fqdnErrno, errno);
goto exit;
}
// Compare canonical name to FQDN
EXPECT_STREQ(info->ai_canonname, actual);
freeaddrinfo(info);
exit:
free(hostname);
}