From 36ce07093b68b07513149577c209ae7a57ab356b Mon Sep 17 00:00:00 2001
From: Gabriele Contini <contini.mailing@gmail.com>
Date: 周日, 15 3月 2020 16:26:21 +0800
Subject: [PATCH] Merge branch 'feature/pc_identifiers' into develop issues #2 #3 #14 #49

---
 test/library/os/network_test.cpp |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/test/library/os/network_test.cpp b/test/library/os/network_test.cpp
new file mode 100644
index 0000000..f5a7483
--- /dev/null
+++ b/test/library/os/network_test.cpp
@@ -0,0 +1,50 @@
+#define BOOST_TEST_MODULE network_test
+#include <string>
+#include <iostream>
+#include <boost/test/unit_test.hpp>
+
+#include <licensecc_properties.h>
+#include <licensecc_properties_test.h>
+#include "../../../src/library/base/StringUtils.h"
+#include "../../../src/library/os/network.hpp"
+#include "../../../src/library/os/execution_environment.hpp"
+
+namespace license {
+namespace os {
+namespace test {
+
+using namespace license::os;
+using namespace std;
+
+BOOST_AUTO_TEST_CASE(read_network_adapters) {
+	std::vector<license::os::OsAdapterInfo> adapters;
+	// we can suppose every test environment  other than docker has at least one network interface (it's hard to
+	// download this source code)
+	FUNCTION_RETURN result = getAdapterInfos(adapters);
+	ExecutionEnvironment exec_env;
+	if (result != FUNC_RET_OK && exec_env.is_docker()) {
+		BOOST_TEST_MESSAGE("detected docker environment, not having network interfaces is normal here");
+		return;
+	}
+	BOOST_CHECK_EQUAL(result, FUNC_RET_OK);
+	for (auto& it : adapters) {
+		cout << "Interface found: " << string(it.description) << endl;
+		BOOST_CHECK_GT(strlen(it.description), 0);
+		// lo mac address is always 0 but it has ip
+		// other interfaces may not be connected
+		if (string(it.description) == "lo") {
+			BOOST_FAIL("loopback adapters shouldn't appear");
+		} else {
+			// check mac address are not all zero
+			bool mac_is_0 = true;
+			for (int j = 0; j < 6; j++) {
+				mac_is_0 = mac_is_0 || (it.mac_address[j] != 0);
+			}
+			BOOST_CHECK_MESSAGE(mac_is_0, "Mac address for interface " << it.description << " is 0");
+		}
+	}
+}
+
+}  // namespace test
+}  // namespace os
+}  // namespace license

--
Gitblit v1.9.1