-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnitTests.cpp
110 lines (90 loc) · 4.41 KB
/
UnitTests.cpp
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* Copyright (c) 2020-2021 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "CrossPlatformUtils.h"
#include "RteFsUtils.h"
#include "gtest/gtest.h"
using namespace std;
TEST(CrossPlatformUnitTests, GetEnv_Empty) {
string value = CrossPlatformUtils::GetEnv("");
EXPECT_TRUE(value.empty());
}
TEST(CrossPlatformUnitTests, GetEnv_Existing) {
string value = CrossPlatformUtils::GetEnv("PATH"); // present always in our test environment
EXPECT_FALSE(value.empty());
}
TEST(CrossPlatformUnitTests, GetEnv_NoExising) {
string value = CrossPlatformUtils::GetEnv("DUMMY_ENV_VAR_NON_EXISTING");
EXPECT_TRUE(value.empty());
}
TEST(CrossPlatformUnitTests, SetEnv_EmptyVar) {
EXPECT_FALSE(CrossPlatformUtils::SetEnv("", "DUMMY_ENV_VAR_VALUE"));
}
TEST(CrossPlatformUnitTests, SetGetEnv_NonEmpty) {
string value = "non_empty";
EXPECT_TRUE(CrossPlatformUtils::SetEnv("DUMMY_ENV_VAR", value));
EXPECT_EQ(CrossPlatformUtils::GetEnv("DUMMY_ENV_VAR"), value);
}
TEST(CrossPlatformUnitTests, SetGetEnv_Empty) {
string value;
EXPECT_TRUE(CrossPlatformUtils::SetEnv("DUMMY_ENV_VAR", value));
EXPECT_TRUE(CrossPlatformUtils::GetEnv("DUMMY_ENV_VAR").empty());
}
TEST(CrossPlatformUnitTests, GetPackRootDir_ValidEnvSet) {
string value = "packrootpath";
EXPECT_TRUE(CrossPlatformUtils::SetEnv("CMSIS_PACK_ROOT", value));
EXPECT_EQ(CrossPlatformUtils::GetEnv("CMSIS_PACK_ROOT"), value);
EXPECT_EQ(CrossPlatformUtils::GetCMSISPackRootDir(), value);
}
TEST(CrossPlatformUnitTests, GetPackRootDir_NoEnvSet) {
EXPECT_TRUE(CrossPlatformUtils::SetEnv("CMSIS_PACK_ROOT", ""));
EXPECT_EQ(CrossPlatformUtils::GetCMSISPackRootDir(), CrossPlatformUtils::GetDefaultCMSISPackRootDir());
}
TEST(CrossPlatformUnitTests, GetPackRootDir_Default) {
EXPECT_TRUE(CrossPlatformUtils::SetEnv("CMSIS_PACK_ROOT", ""));
#ifdef DEFAULT_PACKROOTDEF
EXPECT_EQ(CrossPlatformUtils::GetCMSISPackRootDir().find((CrossPlatformUtils::GetEnv(DEFAULT_PACKROOTDEF))), 0);
EXPECT_EQ(CrossPlatformUtils::GetDefaultCMSISPackRootDir().find((CrossPlatformUtils::GetEnv(DEFAULT_PACKROOTDEF))), 0);
#endif
EXPECT_EQ(CrossPlatformUtils::GetCMSISPackRootDir(), CrossPlatformUtils::GetDefaultCMSISPackRootDir());
}
TEST(CrossPlatformUnitTests, GetExecutablePath) {
std::error_code ec;
std::string exePath = fs::canonical(CrossPlatformUtils::GetExecutablePath(ec)).generic_string();
EXPECT_STREQ(TEST_BIN_PATH, exePath.c_str());
EXPECT_EQ(ec.value(), 0);
}
TEST(CrossPlatformUnitTests, CanExecute) {
EXPECT_TRUE(CrossPlatformUtils::CanExecute(TEST_BIN_PATH));
std::string genFolder = std::string(GLOBAL_TEST_DIR) + std::string("/packs/ARM/RteTestGenerator/0.1.0/Generator/");
std::string genExe = genFolder + ((CrossPlatformUtils::GetHostType() == "win") ? string("script.bat") : string("script.sh"));
EXPECT_TRUE(CrossPlatformUtils::CanExecute(genExe));
std::string noExe = genFolder + string("noexe.sh");
EXPECT_FALSE(CrossPlatformUtils::CanExecute(noExe));
}
TEST(CrossPlatformUnitTests, GetRegistryString) {
if (CrossPlatformUtils::GetHostType() == "win") {
EXPECT_TRUE(CrossPlatformUtils::GetRegistryString("HKEY_CURRENT_USER\\DUMMY_KEY_\\DUMMY_VAL").empty());
EXPECT_TRUE(CrossPlatformUtils::GetRegistryString("DUMMY_KEY_\\DUMMY_VAL").empty());
EXPECT_TRUE(!CrossPlatformUtils::GetRegistryString("HKEY_CURRENT_USER\\Environment\\Temp").empty());
EXPECT_TRUE(!CrossPlatformUtils::GetRegistryString("Environment\\Temp").empty());
EXPECT_EQ(CrossPlatformUtils::GetRegistryString("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\CommonFilesDir"), "C:\\Program Files\\Common Files");
EXPECT_EQ(CrossPlatformUtils::GetRegistryString("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\CommonFilesDir"), "C:\\Program Files\\Common Files");
// fall-back to environment variable
EXPECT_EQ(CrossPlatformUtils::GetRegistryString("PATH"), CrossPlatformUtils::GetEnv("PATH"));
} else {
EXPECT_EQ(CrossPlatformUtils::GetRegistryString("PATH"), CrossPlatformUtils::GetEnv("PATH"));
}
}
TEST(CrossPlatformUnitTests, GetLongPathRegStatus) {
CrossPlatformUtils::REG_STATUS status = CrossPlatformUtils::GetLongPathRegStatus();
if (CrossPlatformUtils::GetHostType() == "win") {
EXPECT_TRUE(CrossPlatformUtils::REG_STATUS::ENABLED == status || CrossPlatformUtils::REG_STATUS::DISABLED == status);
}
else {
EXPECT_EQ(CrossPlatformUtils::REG_STATUS::NOT_SUPPORTED, status);
}
}
// end of UnitTests.cpp