test/tconfig.cc
/// Do some tests on test file. All of these should return normally,
/// none should throw.
///
Do some tests on test file. All of these should return normally,
none should throw.
Do some tests on test file . All of these should return normally none should throw .
BOOST_AUTO_TEST_CASE( Valid_params_test )
{
    namespace fs = boost::filesystem;
    LogFixture lf;
    LOG_INFO(Lgr) << "Unit test: Valid_params_test";
    const char *confname = "../test/tconfig.json";
    Config cfg(confname);
    cfg.read_config();
    bool sdr_player_enabled {false};
    BOOST_TEST(cfg.get_bool("Sdr_player","enabled", sdr_player_enabled));
    BOOST_TEST(sdr_player_enabled);
    bool mp3_player_enabled {true};
    BOOST_TEST(cfg.get_bool("Mp3_player","enabled",mp3_player_enabled));
    BOOST_TEST(mp3_player_enabled == false);
    int mpd_port=6600;
    BOOST_TEST(cfg.get_int("Mpd_player","mpd_port",mpd_port));
    BOOST_TEST(mpd_port == 6666);
    unsigned umpd_port=6600;
    BOOST_TEST(cfg.get_unsigned("Mpd_player","mpd_port",umpd_port));
    BOOST_CHECK_EQUAL(umpd_port,6666);
    unsigned unexpected_port = 1313;
    BOOST_TEST(not cfg.get_unsigned("Sdr_player","gqrx_port",unexpected_port));
    BOOST_CHECK_EQUAL(unexpected_port,1313);
    double low_s=13.0;
    BOOST_TEST(cfg.get_double("Sdr_player","gqrx_low_s",low_s));
    BOOST_CHECK_EQUAL(low_s, -20.0);
    fs::path path1_expected  { "/usr/bin/whoami" };
    BOOST_TEST( fs::exists(path1_expected) );
    fs::path path1 {"/foo/bar"};
    BOOST_TEST(cfg.get_pathname("Ogg_player","ogg_bin_path",
                                FileCond::MustExist, path1));
    BOOST_CHECK_EQUAL(path1,path1_expected);
    fs::path path2_default("/bin/bash"); 
    BOOST_TEST( fs::exists(path2_default) );
    fs::path path2 {path2_default};
    BOOST_TEST(not cfg.get_pathname("NA_player","well_trodden_path",
                                    FileCond::MustExist, path2));
    BOOST_CHECK_EQUAL(path2,path2_default);
    fs::path validpath("tconfig");
    BOOST_CHECK_THROW(cfg.get_pathname("NA_player","well_trodden_path",
                                       FileCond::MustNotExist, validpath),
                      Config_path_error);
    fs::path invalidpath {"/tmp"};
    BOOST_CHECK_THROW(cfg.get_pathname("NA_player","secret_path",
                                       FileCond::MustExist, invalidpath),
                      Config_path_error );
}
BOOST_AUTO_TEST_CASE ( Valid_params_test ) { namespace fs = boost :: filesystem ; LogFixture lf ; LOG_INFO ( Lgr ) << " " ; const char * confname = " " ; Config cfg ( confname ) ; cfg . read_config ( ) ; bool sdr_player_enabled { false } ; BOOST_TEST ( cfg . get_bool ( " " , " " , sdr_player_enabled ) ) ; BOOST_TEST ( sdr_player_enabled ) ; bool mp3_player_enabled { true } ; BOOST_TEST ( cfg . get_bool ( " " , " " , mp3_player_enabled ) ) ; BOOST_TEST ( mp3_player_enabled == false ) ; int mpd_port = 6600 ; BOOST_TEST ( cfg . get_int ( " " , " " , mpd_port ) ) ; BOOST_TEST ( mpd_port == 6666 ) ; unsigned umpd_port = 6600 ; BOOST_TEST ( cfg . get_unsigned ( " " , " " , umpd_port ) ) ; BOOST_CHECK_EQUAL ( umpd_port , 6666 ) ; unsigned unexpected_port = 1313 ; BOOST_TEST ( not cfg . get_unsigned ( " " , " " , unexpected_port ) ) ; BOOST_CHECK_EQUAL ( unexpected_port , 1313 ) ; double low_s = 13.0 ; BOOST_TEST ( cfg . get_double ( " " , " " , low_s ) ) ; BOOST_CHECK_EQUAL ( low_s , -20.0 ) ; fs :: path path1_expected { " " } ; BOOST_TEST ( fs :: exists ( path1_expected ) ) ; fs :: path path1 { " " } ; BOOST_TEST ( cfg . get_pathname ( " " , " " , FileCond :: MustExist , path1 ) ) ; BOOST_CHECK_EQUAL ( path1 , path1_expected ) ; fs :: path path2_default ( " " ) ; BOOST_TEST ( fs :: exists ( path2_default ) ) ; fs :: path path2 { path2_default } ; BOOST_TEST ( not cfg . get_pathname ( " " , " " , FileCond :: MustExist , path2 ) ) ; BOOST_CHECK_EQUAL ( path2 , path2_default ) ; fs :: path validpath ( " " ) ; BOOST_CHECK_THROW ( cfg . get_pathname ( " " , " " , FileCond :: MustNotExist , validpath ) , Config_path_error ) ; fs :: path invalidpath { " " } ; BOOST_CHECK_THROW ( cfg . get_pathname ( " " , " " , FileCond :: MustExist , invalidpath ) , Config_path_error ) ; }
Do some tests on test file.
Do some tests on test file .
// Bool // Int // Unsigned // Double // Pathnames // this file should exist  // this path exists but must not; the key is not present in the JSON. //  the path specified in the JSON does not exist, should throw