File: EnvTest.cpp

package info (click to toggle)
cryfs 1.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 28,404 kB
  • sloc: cpp: 150,188; asm: 10,493; python: 1,455; javascript: 65; sh: 50; makefile: 17; xml: 7
file content (28 lines) | stat: -rw-r--r-- 730 bytes parent folder | download
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
#include <gtest/gtest.h>
#include <cpp-utils/system/env.h>
#include <string>

using std::string;

namespace {
	string read_env(const char* key) {
		const char* value = std::getenv(key);
		return value != nullptr ? string(value) : string();
	}
}

TEST(EnvTest, SetAndGetEnv_ValueIsCorrect) {
	cpputils::setenv("my_key", "my_value");
	EXPECT_EQ(string("my_value"), read_env("my_key"));
}

TEST(EnvTest, SetAndGetEnvWithSpacedValue_ValueIsCorrect) {
	cpputils::setenv("my_key", "my value with spaces");
	EXPECT_EQ(string("my value with spaces"), read_env("my_key"));
}

TEST(EnvTest, UnsetAndGetEnv_ValueIsEmpty) {
	cpputils::setenv("my_key", "my_value");
	cpputils::unsetenv("my_key");
	EXPECT_EQ(nullptr, std::getenv("my_key"));
}