From 4bd7da9ff2eb06c11b1f54e2b8e2cfb44af56776 Mon Sep 17 00:00:00 2001 From: gcontini <1121667+gcontini@users.noreply.github.com> Date: 周六, 02 5月 2020 10:20:38 +0800 Subject: [PATCH] rename StringUtils in string_utls --- test/library/os/execution_environment_test.cpp | 27 ++++++++++++++++----------- 1 files changed, 16 insertions(+), 11 deletions(-) diff --git a/test/library/os/execution_environment_test.cpp b/test/library/os/execution_environment_test.cpp index dba290f..be9256c 100644 --- a/test/library/os/execution_environment_test.cpp +++ b/test/library/os/execution_environment_test.cpp @@ -1,11 +1,11 @@ -#define BOOST_TEST_MODULE network_test +#define BOOST_TEST_MODULE execution_environment_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/base/string_utils.h" #include "../../../src/library/os/network.hpp" #include "../../../src/library/os/execution_environment.hpp" @@ -16,28 +16,33 @@ using namespace license::os; using namespace std; -// To test if virtualization is detected correctly define an env variable VIRT_ENV +// To test if virtualization is detected correctly define an env variable VIRTUAL_ENV // otherwise the test is skipped BOOST_AUTO_TEST_CASE(test_virtualization) { const char *env = getenv("VIRTUAL_ENV"); - os::ExecutionEnvironment exec_env; bool docker = false; if (env != nullptr) { - LCC_API_VIRTUALIZATION_SUMMARY virt = exec_env.virtualization(); - if (strcmp(env, "CONTAINER") == 0 || (docker = (strcmp(env, "DOCKER") == 0))) { - BOOST_CHECK_MESSAGE(virt == LCC_API_VIRTUALIZATION_SUMMARY::CONTAINER, "container detected"); + string required_virtualization(env); + os::ExecutionEnvironment exec_env; + LCC_API_VIRTUALIZATION_SUMMARY detected_virt = exec_env.virtualization(); + if (required_virtualization == "CONTAINER" || (docker = (required_virtualization == "DOCKER"))) { + BOOST_CHECK_MESSAGE(detected_virt == LCC_API_VIRTUALIZATION_SUMMARY::CONTAINER, "container detected"); BOOST_CHECK_MESSAGE(exec_env.is_container(), "container detected"); if (docker) { BOOST_CHECK_MESSAGE(exec_env.is_docker(), "docker detected"); } - } else if (strcmp(env, "VM") == 0) { - BOOST_CHECK_MESSAGE(virt == LCC_API_VIRTUALIZATION_SUMMARY::VM, "VM detected"); + } else if (required_virtualization == "VM") { + BOOST_CHECK_MESSAGE(detected_virt == LCC_API_VIRTUALIZATION_SUMMARY::VM, "VM detected"); BOOST_CHECK_MESSAGE(!exec_env.is_container(), "VM is not a container"); BOOST_CHECK_MESSAGE(!exec_env.is_docker(), "VM is not a docker"); - } else if (strcmp(env, "NONE") == 0) { - BOOST_CHECK_EQUAL(virt, LCC_API_VIRTUALIZATION_SUMMARY::NONE); + BOOST_CHECK_MESSAGE(exec_env.virtualization_detail() != LCC_API_VIRTUALIZATION_DETAIL::BARE_TO_METAL, + "It is not run bare to metal."); + } else if (required_virtualization == "NONE") { + BOOST_CHECK_EQUAL(detected_virt, LCC_API_VIRTUALIZATION_SUMMARY::NONE); BOOST_CHECK_MESSAGE(!exec_env.is_container(), "not a container"); BOOST_CHECK_MESSAGE(!exec_env.is_docker(), "not a docker"); + BOOST_CHECK_MESSAGE(exec_env.virtualization_detail() == LCC_API_VIRTUALIZATION_DETAIL::BARE_TO_METAL, + "running bare to metal."); } else { BOOST_FAIL(string("value ") + env + " not supported: VM,DOCKER,CONTAINER,NONE"); } -- Gitblit v1.9.1