• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2019 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 
6 // system_utils_unittest.cpp: Unit tests for ANGLE's system utility functions
7 
8 #include "gmock/gmock.h"
9 #include "gtest/gtest.h"
10 
11 #include "common/system_utils.h"
12 
13 using namespace angle;
14 
15 namespace
16 {
17 // Test getting the executable path
TEST(SystemUtils,ExecutablePath)18 TEST(SystemUtils, ExecutablePath)
19 {
20     // TODO: fuchsia support. http://anglebug.com/3161
21 #if !defined(ANGLE_PLATFORM_FUCHSIA)
22     std::string executablePath = GetExecutablePath();
23     EXPECT_NE("", executablePath);
24 #endif
25 }
26 
27 // Test getting the executable directory
TEST(SystemUtils,ExecutableDir)28 TEST(SystemUtils, ExecutableDir)
29 {
30     // TODO: fuchsia support. http://anglebug.com/3161
31 #if !defined(ANGLE_PLATFORM_FUCHSIA)
32     std::string executableDir = GetExecutableDirectory();
33     EXPECT_NE("", executableDir);
34 
35     std::string executablePath = GetExecutablePath();
36     EXPECT_LT(executableDir.size(), executablePath.size());
37     EXPECT_EQ(0, strncmp(executableDir.c_str(), executablePath.c_str(), executableDir.size()));
38 #endif
39 }
40 
41 // Test setting environment variables
TEST(SystemUtils,Environment)42 TEST(SystemUtils, Environment)
43 {
44     constexpr char kEnvVarName[]  = "UNITTEST_ENV_VARIABLE";
45     constexpr char kEnvVarValue[] = "The quick brown fox jumps over the lazy dog";
46 
47     bool setEnvDone = SetEnvironmentVar(kEnvVarName, kEnvVarValue);
48     EXPECT_TRUE(setEnvDone);
49 
50     std::string readback = GetEnvironmentVar(kEnvVarName);
51     EXPECT_EQ(kEnvVarValue, readback);
52 
53     bool unsetEnvDone = UnsetEnvironmentVar(kEnvVarName);
54     EXPECT_TRUE(unsetEnvDone);
55 
56     readback = GetEnvironmentVar(kEnvVarName);
57     EXPECT_EQ("", readback);
58 }
59 }  // anonymous namespace
60