PROFINET IO Controller Stack 1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
Loading...
Searching...
No Matches
test_platform.cpp
Go to the documentation of this file.
1
3
4#include <gtest/gtest.h>
5
6#include <array>
7#include <cstdint>
8#include <cstdlib>
9#include <filesystem>
10#include <string>
11
12#include "profinet/exceptions.h"
13#include "profinet/util.h"
14
15#ifndef PROFINET_TEST_INTERFACE
16#define PROFINET_TEST_INTERFACE ""
17#endif
18
19namespace
20{
24[[nodiscard]] std::string GetTestInterface()
25{
27}
28} // namespace
29
31TEST(PlatformTests, GetInterfaceMacRejectsEmptyInterface)
32{
34}
35
37TEST(PlatformTests, GetInterfaceMacRejectsUnknownInterface)
38{
39 EXPECT_THROW(profinet::GetInterfaceMac("this-interface-does-not-exist"), profinet::SocketError);
40}
41
43TEST(PlatformTests, GetInterfaceMacReturnsSixByteAddress)
44{
45 const std::string interface = GetTestInterface();
46
47 if (interface.empty())
48 {
49 GTEST_SKIP() << "Set PROFINET_TEST_INTERFACE to run live interface tests";
50 }
51
53
54 EXPECT_EQ(mac.size(), static_cast<std::size_t>(profinet::macAddressLength));
55}
56
58TEST(PlatformTests, MacAddressProviderUsesPortableInterfaceLookup)
59{
60 const std::string interface = GetTestInterface();
61
62 if (interface.empty())
63 {
64 GTEST_SKIP() << "Set PROFINET_TEST_INTERFACE to run live interface tests";
65 }
66
68
69 EXPECT_EQ(provider.GetMac(interface), profinet::GetInterfaceMac(interface));
70}
71
73TEST(PlatformTests, GetExecutableDirectoryReturnsExistingAbsoluteDirectory)
74{
75 const std::filesystem::path directory = profinet::GetExecutableDirectory();
76
77 ASSERT_TRUE(directory.is_absolute());
78 EXPECT_TRUE(std::filesystem::exists(directory));
79 EXPECT_TRUE(std::filesystem::is_directory(directory));
80}
81
83TEST(PlatformTests, GetExecutableDirectoryIsStable)
84{
86}
Production implementation of IMacAddressProvider.
Definition util.h:169
MacAddress GetMac(const std::string &interface) override
Get the MAC address of a network interface.
Definition util.cpp:266
Socket operation error.
Definition exceptions.h:663
Declares exceptions and error types used by the PROFINET IO controller stack.
MacAddress GetInterfaceMac(const std::string &interface)
Get the MAC address assigned to a network interface.
std::array< std::uint8_t, macAddressLength > MacAddress
A 6-byte Ethernet MAC address.
Definition util.h:48
std::filesystem::path GetExecutableDirectory()
Retrieves the absolute directory path of the currently running executable.
constexpr int macAddressLength
Constant lenght of a mac address.
Definition util.h:37
#define PROFINET_TEST_INTERFACE
TEST(PlatformTests, GetInterfaceMacRejectsEmptyInterface)
Declares Linux Ethernet, addressing, timing, and utility helpers used by the PROFINET stack.