mirror of https://github.com/vitalif/grive2
commit
113b1107d8
|
@ -34,12 +34,6 @@ const std::string default_filename = ".grive";
|
||||||
const char *env_name = "GR_CONFIG";
|
const char *env_name = "GR_CONFIG";
|
||||||
const std::string default_root_folder = ".";
|
const std::string default_root_folder = ".";
|
||||||
|
|
||||||
Config::Config( const fs::path& root_path ) :
|
|
||||||
m_path( GetPath( root_path ) )
|
|
||||||
{
|
|
||||||
m_file = Read() ;
|
|
||||||
}
|
|
||||||
|
|
||||||
Config::Config( const po::variables_map& vm )
|
Config::Config( const po::variables_map& vm )
|
||||||
{
|
{
|
||||||
m_cmd.Add( "log-xml", Json(vm.count("log-xml") > 0) ) ;
|
m_cmd.Add( "log-xml", Json(vm.count("log-xml") > 0) ) ;
|
||||||
|
|
|
@ -39,7 +39,6 @@ public :
|
||||||
struct Error : virtual Exception {} ;
|
struct Error : virtual Exception {} ;
|
||||||
typedef boost::error_info<struct FileTag, std::string> File ;
|
typedef boost::error_info<struct FileTag, std::string> File ;
|
||||||
|
|
||||||
Config( const fs::path& root_path ) ;
|
|
||||||
Config( const boost::program_options::variables_map& vm ) ;
|
Config( const boost::program_options::variables_map& vm ) ;
|
||||||
|
|
||||||
const fs::path Filename() const ;
|
const fs::path Filename() const ;
|
||||||
|
|
|
@ -25,33 +25,41 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
#include "protocol/Json.hh"
|
#include "protocol/Json.hh"
|
||||||
#include "util/log/Log.hh"
|
#include "util/log/Log.hh"
|
||||||
|
|
||||||
|
#include <boost/program_options.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace grut;
|
using namespace grut;
|
||||||
using namespace gr ;
|
using namespace gr ;
|
||||||
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
ConfigTest::ConfigTest( )
|
ConfigTest::ConfigTest( )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigTest::TestInitialiseWithEmptyString( )
|
void ConfigTest::TestInitialiseWithNoPath( )
|
||||||
{
|
{
|
||||||
Config config("");
|
po::variables_map vm;
|
||||||
GRUT_ASSERT_EQUAL( "/home/.grive", config.Filename().string()) ;
|
po::notify(vm);
|
||||||
|
|
||||||
|
Config config(vm);
|
||||||
|
GRUT_ASSERT_EQUAL( "./.grive", config.Filename().string()) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigTest::TestInitialiseWithString( )
|
void ConfigTest::TestInitialiseWithPath( )
|
||||||
{
|
{
|
||||||
Config config("/home/.grive");
|
char const *argv[] = { "Program", "-p", "/home/grive" };
|
||||||
GRUT_ASSERT_EQUAL( "/home/.grive", config.Filename().string()) ;
|
int argc = 3;
|
||||||
|
|
||||||
|
po::options_description desc( "Grive options" );
|
||||||
|
desc.add_options()
|
||||||
|
( "path,p", po::value<std::string>(), "Path to sync")
|
||||||
|
;
|
||||||
|
|
||||||
|
po::variables_map vm;
|
||||||
|
po::store(po::parse_command_line( argc, argv, desc), vm );
|
||||||
|
po::notify(vm);
|
||||||
|
|
||||||
|
Config config(vm);
|
||||||
|
GRUT_ASSERT_EQUAL( "/home/grive/.grive", config.Filename().string()) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigTest::TestInitialiseWithFileSystemPath( )
|
|
||||||
{
|
|
||||||
fs::path path("/home");
|
|
||||||
fs::path file(".grive");
|
|
||||||
Config config(path / file);
|
|
||||||
GRUT_ASSERT_EQUAL( "/home/.grive", config.Filename().string());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,11 @@ class ConfigTest : public CppUnit::TestFixture
|
||||||
public :
|
public :
|
||||||
ConfigTest( ) ;
|
ConfigTest( ) ;
|
||||||
|
|
||||||
// declare suit function
|
|
||||||
CPPUNIT_TEST_SUITE( ConfigTest ) ;
|
CPPUNIT_TEST_SUITE( ConfigTest ) ;
|
||||||
CPPUNIT_TEST_EXCEPTION( TestInitialiseWithEmptyString, gr::Config::Error ) ;
|
CPPUNIT_TEST( TestInitialiseWithEmptyString ) ;
|
||||||
CPPUNIT_TEST( TestInitialiseWithString ) ;
|
CPPUNIT_TEST( TestInitialiseWithString ) ;
|
||||||
CPPUNIT_TEST( TestInitialiseWithFileSystemPath ) ;
|
CPPUNIT_TEST( TestInitialiseWithFileSystemPath ) ;
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
|
||||||
private :
|
private :
|
||||||
void TestInitialiseWithEmptyString( );
|
void TestInitialiseWithEmptyString( );
|
||||||
|
|
Loading…
Reference in New Issue