blob: 540f4ef931c97c283531083112ecca268cfbcb43 [file] [log] [blame]
Li, Hao0e1bef32019-11-07 12:13:27 +00001// Copyright 2019 The Dawn Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include <gtest/gtest.h>
16
17#include "common/SystemUtils.h"
18
19// Tests for GetEnvironmentVar
20TEST(SystemUtilsTests, GetEnvironmentVar) {
21 // Test nonexistent environment variable
22 ASSERT_EQ(GetEnvironmentVar("NonexistentEnvironmentVar"), "");
23}
24
25// Tests for SetEnvironmentVar
26TEST(SystemUtilsTests, SetEnvironmentVar) {
27 // Test new environment variable
28 ASSERT_TRUE(SetEnvironmentVar("EnvironmentVarForTest", "NewEnvironmentVarValue"));
29 ASSERT_EQ(GetEnvironmentVar("EnvironmentVarForTest"), "NewEnvironmentVarValue");
30 // Test override environment variable
31 ASSERT_TRUE(SetEnvironmentVar("EnvironmentVarForTest", "OverrideEnvironmentVarValue"));
32 ASSERT_EQ(GetEnvironmentVar("EnvironmentVarForTest"), "OverrideEnvironmentVarValue");
33}
34
35// Tests for GetExecutableDirectory
36TEST(SystemUtilsTests, GetExecutableDirectory) {
37 // Test returned value is non-empty string
38 ASSERT_NE(GetExecutableDirectory(), "");
39 // Test last charecter in path
40 ASSERT_EQ(GetExecutableDirectory().back(), *GetPathSeparator());
41}