OmniSciDB  04ee39c94c
OmniSQLUtilitiesTest.cpp File Reference
#include "../SQLFrontend/CommandHistoryFile.h"
#include "gtest/gtest.h"
#include <boost/program_options.hpp>
#include <cstring>
#include <fstream>
#include <type_traits>
+ Include dependency graph for OmniSQLUtilitiesTest.cpp:

Go to the source code of this file.

Classes

class  DefaultUnitTestResolver
 
class  NoHomeNoPWEntResolver
 
class  NoHomePWEntResolver
 
class  HomeResolver
 

Typedefs

using GetEnvRetType = decltype(DefaultEnvResolver().getenv(""))
 
using GetPWUIDRetType = decltype(DefaultEnvResolver().getpwuid(0))
 
using CommandHistoryFile_NoHomeNoPWEnt = CommandHistoryFileImpl< NoHomeNoPWEntResolver >
 
using CommandHistoryFile_NoHomePWEnt = CommandHistoryFileImpl< NoHomePWEntResolver >
 
using CommandHistoryFile_Home = CommandHistoryFileImpl< HomeResolver >
 

Functions

 TEST (CommandHistoryFile, NoHomeEnv)
 
 TEST (CommandHistoryFile, HomeEnv)
 
 TEST (CommandHistoryFile, Basic)
 
 TEST (CommandHistoryFile, Custom)
 
 TEST (CommandHistoryFile, BoostProgramOptionsCompatibility_DefaultOption)
 
 TEST (CommandHistoryFile, BoostProgramOptionsCompatibility_SetOption)
 
int main (int argc, char *argv[])
 

Typedef Documentation

◆ CommandHistoryFile_Home

◆ CommandHistoryFile_NoHomeNoPWEnt

◆ CommandHistoryFile_NoHomePWEnt

◆ GetEnvRetType

using GetEnvRetType = decltype(DefaultEnvResolver().getenv(""))

Definition at line 27 of file OmniSQLUtilitiesTest.cpp.

◆ GetPWUIDRetType

using GetPWUIDRetType = decltype(DefaultEnvResolver().getpwuid(0))

Definition at line 28 of file OmniSQLUtilitiesTest.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 136 of file OmniSQLUtilitiesTest.cpp.

136  {
137  ::testing::InitGoogleTest(&argc, argv);
138  return RUN_ALL_TESTS();
139 }

◆ TEST() [1/6]

TEST ( CommandHistoryFile  ,
NoHomeEnv   
)

Definition at line 71 of file OmniSQLUtilitiesTest.cpp.

References getDefaultHistoryFilename(), DefaultUnitTestResolver::getpwuid(), and DefaultUnitTestResolver::getuid().

71  {
73  ASSERT_EQ(std::string(getDefaultHistoryFilename()), std::string(cmd_file));
74 
76  ASSERT_EQ(std::string(getpwuid(getuid())->pw_dir) + '/' +
77  std::string(getDefaultHistoryFilename()),
78  std::string(cmd_file2));
79 }
constexpr char const *const getDefaultHistoryFilename()
+ Here is the call graph for this function:

◆ TEST() [2/6]

TEST ( CommandHistoryFile  ,
HomeEnv   
)

Definition at line 81 of file OmniSQLUtilitiesTest.cpp.

References getDefaultHistoryFilename(), DefaultUnitTestResolver::getpwuid(), and DefaultUnitTestResolver::getuid().

81  {
82  CommandHistoryFile_Home cmd_file;
83  ASSERT_EQ(std::string(getpwuid(getuid())->pw_dir) + '/' +
84  std::string(getDefaultHistoryFilename()),
85  std::string(cmd_file));
86 }
constexpr char const *const getDefaultHistoryFilename()
+ Here is the call graph for this function:

◆ TEST() [3/6]

TEST ( CommandHistoryFile  ,
Basic   
)

Definition at line 88 of file OmniSQLUtilitiesTest.cpp.

References getDefaultHistoryFilename(), DefaultUnitTestResolver::getpwuid(), and DefaultUnitTestResolver::getuid().

88  {
89  CommandHistoryFile cmd_file;
90  ASSERT_EQ(std::string(getpwuid(getuid())->pw_dir) + '/' +
91  std::string(getDefaultHistoryFilename()),
92  std::string(cmd_file));
93 }
constexpr char const *const getDefaultHistoryFilename()
+ Here is the call graph for this function:

◆ TEST() [4/6]

TEST ( CommandHistoryFile  ,
Custom   
)

Definition at line 95 of file OmniSQLUtilitiesTest.cpp.

95  {
96  CommandHistoryFile cmd_file("mutley.txt");
97  ASSERT_EQ(std::string("mutley.txt"), std::string(cmd_file));
98 }

◆ TEST() [5/6]

TEST ( CommandHistoryFile  ,
BoostProgramOptionsCompatibility_DefaultOption   
)

Definition at line 100 of file OmniSQLUtilitiesTest.cpp.

References getDefaultHistoryFilename(), DefaultUnitTestResolver::getpwuid(), DefaultUnitTestResolver::getuid(), and run.

100  {
101  namespace po = boost::program_options;
102  po::options_description desc("Options");
103  CommandHistoryFile cmd_file;
104 
105  int fake_argc = 1;
106  char const* fake_argv[] = {"lulz"};
107 
108  desc.add_options()(
109  "history", po::value<CommandHistoryFile>(&cmd_file), "History filename");
110  po::variables_map vm;
111  po::store(po::command_line_parser(fake_argc, fake_argv).options(desc).run(), vm);
112  po::notify(vm);
113 
114  ASSERT_EQ(std::string(getpwuid(getuid())->pw_dir) + '/' +
115  std::string(getDefaultHistoryFilename()),
116  std::string(cmd_file));
117 }
constexpr char const *const getDefaultHistoryFilename()
static bool run
+ Here is the call graph for this function:

◆ TEST() [6/6]

TEST ( CommandHistoryFile  ,
BoostProgramOptionsCompatibility_SetOption   
)

Definition at line 119 of file OmniSQLUtilitiesTest.cpp.

References run.

119  {
120  namespace po = boost::program_options;
121  po::options_description desc("Options");
122  CommandHistoryFile cmd_file;
123 
124  int fake_argc = 2;
125  char const* fake_argv[] = {"lulz", "--history=dudley_dawson.txt"};
126 
127  desc.add_options()(
128  "history", po::value<CommandHistoryFile>(&cmd_file), "History filename");
129  po::variables_map vm;
130  po::store(po::command_line_parser(fake_argc, fake_argv).options(desc).run(), vm);
131  po::notify(vm);
132 
133  ASSERT_EQ(std::string("dudley_dawson.txt"), std::string(cmd_file));
134 }
static bool run