AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Config.cpp File Reference
#include "Config.h"
#include "gtest/gtest.h"
#include <boost/filesystem.hpp>
#include <cstdlib>
#include <fstream>
#include <string>

Go to the source code of this file.

Classes

class  ConfigEnvTest
 

Functions

std::string CreateConfigWithMap (std::map< std::string, std::string > const &map)
 
 TEST_F (ConfigEnvTest, NestedInt)
 
 TEST_F (ConfigEnvTest, SimpleLowerString)
 
 TEST_F (ConfigEnvTest, SimpleUpperString)
 
 TEST_F (ConfigEnvTest, LongNestedNameWithNumber)
 
 TEST_F (ConfigEnvTest, ValueWithSeveralUpperlLaters)
 
 TEST_F (ConfigEnvTest, StringThatNotExistInConfig)
 
 TEST_F (ConfigEnvTest, IntThatNotExistInConfig)
 
 TEST_F (ConfigEnvTest, NotExistingString)
 
 TEST_F (ConfigEnvTest, NotExistingInt)
 

Function Documentation

◆ CreateConfigWithMap()

std::string CreateConfigWithMap ( std::map< std::string, std::string > const &  map)
27{
28 auto mTempFileRel = boost::filesystem::unique_path("deleteme.ini");
29 auto mTempFileAbs = boost::filesystem::temp_directory_path() / mTempFileRel;
30 std::ofstream iniStream;
31 iniStream.open(mTempFileAbs.c_str());
32
33 iniStream << "[test]\n";
34 for (auto const& itr : map)
35 iniStream << itr.first << " = " << itr.second << "\n";
36
37 iniStream.close();
38
39 return mTempFileAbs.native();
40}

Referenced by ConfigEnvTest::SetUp().

◆ TEST_F() [1/9]

TEST_F ( ConfigEnvTest  ,
IntThatNotExistInConfig   
)
112{
113 setenv("AC_UNIQUE_INT", "100", 1);
114 EXPECT_EQ(sConfigMgr->GetOption<int>("Unique.Int", 1), 100);
115}
#define sConfigMgr
Definition: Config.h:95

References sConfigMgr.

◆ TEST_F() [2/9]

TEST_F ( ConfigEnvTest  ,
LongNestedNameWithNumber   
)
90{
91 EXPECT_EQ(sConfigMgr->GetOption<float>("SomeLong.NestedNameWithNumber.Like1", 0), 1);
92 setenv("AC_SOME_LONG_NESTED_NAME_WITH_NUMBER_LIKE_1", "42", 1);
93 EXPECT_EQ(sConfigMgr->OverrideWithEnvVariablesIfAny().empty(), false);
94 EXPECT_EQ(sConfigMgr->GetOption<float>("SomeLong.NestedNameWithNumber.Like1", 0), 42);
95}

References sConfigMgr.

◆ TEST_F() [3/9]

TEST_F ( ConfigEnvTest  ,
NestedInt   
)
66{
67 EXPECT_EQ(sConfigMgr->GetOption<int32>("Int.Nested", 10), 4242);
68 setenv("AC_INT_NESTED", "8080", 1);
69 EXPECT_EQ(sConfigMgr->OverrideWithEnvVariablesIfAny().empty(), false);
70 EXPECT_EQ(sConfigMgr->GetOption<int32>("Int.Nested", 10), 8080);
71}
std::int32_t int32
Definition: Define.h:104

References sConfigMgr.

◆ TEST_F() [4/9]

TEST_F ( ConfigEnvTest  ,
NotExistingInt   
)
123{
124 EXPECT_EQ(sConfigMgr->GetOption<int>("NotFound.Int", 1), 1);
125}

References sConfigMgr.

◆ TEST_F() [5/9]

TEST_F ( ConfigEnvTest  ,
NotExistingString   
)
118{
119 EXPECT_EQ(sConfigMgr->GetOption<std::string>("NotFound.String", "none"), "none");
120}

References sConfigMgr.

◆ TEST_F() [6/9]

TEST_F ( ConfigEnvTest  ,
SimpleLowerString   
)
74{
75 EXPECT_EQ(sConfigMgr->GetOption<std::string>("lower", ""), "simpleString");
76 setenv("AC_LOWER", "envstring", 1);
77 EXPECT_EQ(sConfigMgr->OverrideWithEnvVariablesIfAny().empty(), false);
78 EXPECT_EQ(sConfigMgr->GetOption<std::string>("lower", ""), "envstring");
79}

References sConfigMgr.

◆ TEST_F() [7/9]

TEST_F ( ConfigEnvTest  ,
SimpleUpperString   
)
82{
83 EXPECT_EQ(sConfigMgr->GetOption<std::string>("UPPER", ""), "simpleString");
84 setenv("AC_UPPER", "envupperstring", 1);
85 EXPECT_EQ(sConfigMgr->OverrideWithEnvVariablesIfAny().empty(), false);
86 EXPECT_EQ(sConfigMgr->GetOption<std::string>("UPPER", ""), "envupperstring");
87}

References sConfigMgr.

◆ TEST_F() [8/9]

TEST_F ( ConfigEnvTest  ,
StringThatNotExistInConfig   
)
106{
107 setenv("AC_UNIQUE_STRING", "somevalue", 1);
108 EXPECT_EQ(sConfigMgr->GetOption<std::string>("Unique.String", ""), "somevalue");
109}

References sConfigMgr.

◆ TEST_F() [9/9]

TEST_F ( ConfigEnvTest  ,
ValueWithSeveralUpperlLaters   
)
98{
99 EXPECT_EQ(sConfigMgr->GetOption<int>("GM.InGMList.Level", 1), 50);
100 setenv("AC_GM_IN_GMLIST_LEVEL", "42", 1);
101 EXPECT_EQ(sConfigMgr->OverrideWithEnvVariablesIfAny().empty(), false);
102 EXPECT_EQ(sConfigMgr->GetOption<int>("GM.InGMList.Level", 0), 42);
103}

References sConfigMgr.