<commit_before>/*
 * Copyright (c) 2014 by <NAME>, Zuse Institute Berlin
 *
 * Licensed under the BSD License, see LICENSE file for details.
 *
 */

#include <gtest/gtest.h>

#include "libxtreemfs/options.h"
#include "libxtreemfs/xtreemfs_exception.h"
#include "util/logging.h"

using namespace xtreemfs::util;

namespace xtreemfs {
    
 class OptionsTest : public ::testing::Test {
 protected:
  virtual void SetUp() {
    initialize_logger(LEVEL_WARN);
  }

  virtual void TearDown() {
    shutdown_logger();
  }
};

TEST_F(OptionsTest, TestParseCommandLineAndConfigFile) {
  xtreemfs::Options options;
  
  {
    // Fail on multiple log level specifications.
    const char* n_argv[] = { "executable", "--log-level=DEBUG", "-dINFO" };
    ASSERT_THROW(
        options.ParseCommandLine(3, const_cast<char**>(n_argv)),
        std::exception
    );
  }
  
  {
    // Explicit specification overrides alternative specification.
    // Short alternative specification.
    const char* n_argv[] = {
        "executable",
        "--log-level=DEBUG",
        "-o", "-d=INFO"
    };
    options.ParseCommandLine(4, const_cast<char**>(n_argv));
    ASSERT_EQ("DEBUG", options.log_level_string);
  }
  
  {
    // Alternative specification complements explicit specifications.
    const char* n_argv[] = {
        "executable",
        "--log-file-path=/tmp/test.log",
        "-o", "-d=INFO"
    };
    options.ParseCommandLine(4, const_cast<char**>(n_argv));
    ASSERT_EQ("/tmp/test.log", options.log_file_path);
    ASSERT_EQ("INFO", options.log_level_string);
  }
  
  {
    // Multiple long alternative specifications.
    const char* n_argv[] = {
        "executable",
        "-o", "log-file-path=/tmp/test.log",
        "-o", "log-level=INFO"
    };
    options.ParseCommandLine(5, const_cast<char**>(n_argv));
    ASSERT_EQ("/tmp/test.log", options.log_file_path);
    ASSERT_EQ("INFO", options.log_level_string);
  }
  
  {
    // Comma separated alternative specification.
    const char* n_argv[] = {
        "executable",
        "-o", "log-file-path=/tmp/test.log,-d=INFO"
    };
    options.ParseCommandLine(3, const_cast<char**>(n_argv));
    ASSERT_EQ("/tmp/test.log", options.log_file_path);
    ASSERT_EQ("INFO", options.log_level_string);
  }
  
  {
    // Example from what can be passed in from /etc/fstab.
    const char* n_argv[] = {
        "executable",
        "-o", "_netdev,pkcs12-file-path=/tmp/pkcs12.p12,log-level=DEBUG"
    };
    options.ParseCommandLine(3, const_cast<char**>(n_argv));
    ASSERT_EQ("/tmp/pkcs12.p12", options.ssl_pkcs12_path);
    ASSERT_EQ("DEBUG", options.log_level_string);
  }
  
}

}  // namespace xtreemfs<commit_msg>cpp: libxtreemfs: expecting more specific exception during options test<commit_after>/*
 * Copyright (c) 2014 by <NAME>, Zuse Institute Berlin
 *
 * Licensed under the BSD License, see LICENSE file for details.
 *
 */

#include <gtest/gtest.h>

#include "libxtreemfs/options.h"
#include "libxtreemfs/xtreemfs_exception.h"
#include "util/logging.h"

using namespace xtreemfs::util;

namespace xtreemfs {
    
 class OptionsTest : public ::testing::Test {
 protected:
  virtual void SetUp() {
    initialize_logger(LEVEL_WARN);
  }

  virtual void TearDown() {
    shutdown_logger();
  }
};

TEST_F(OptionsTest, TestParseCommandLineAndConfigFile) {
  xtreemfs::Options options;
  
  {
    // Fail on multiple log level specifications.
    const char* n_argv[] = { "executable", "--log-level=DEBUG", "-dINFO" };
    ASSERT_THROW(
        options.ParseCommandLine(3, const_cast<char**>(n_argv)),
        InvalidCommandLineParametersException
    );
  }
  
  {
    // Explicit specification overrides alternative specification.
    // Short alternative specification.
    const char* n_argv[] = {
        "executable",
        "--log-level=DEBUG",
        "-o", "-d=INFO"
    };
    options.ParseCommandLine(4, const_cast<char**>(n_argv));
    ASSERT_EQ("DEBUG", options.log_level_string);
  }
  
  {
    // Alternative specification complements explicit specifications.
    const char* n_argv[] = {
        "executable",
        "--log-file-path=/tmp/test.log",
        "-o", "-d=INFO"
    };
    options.ParseCommandLine(4, const_cast<char**>(n_argv));
    ASSERT_EQ("/tmp/test.log", options.log_file_path);
    ASSERT_EQ("INFO", options.log_level_string);
  }
  
  {
    // Multiple long alternative specifications.
    const char* n_argv[] = {
        "executable",
        "-o", "log-file-path=/tmp/test.log",
        "-o", "log-level=INFO"
    };
    options.ParseCommandLine(5, const_cast<char**>(n_argv));
    ASSERT_EQ("/tmp/test.log", options.log_file_path);
    ASSERT_EQ("INFO", options.log_level_string);
  }
  
  {
    // Comma separated alternative specification.
    const char* n_argv[] = {
        "executable",
        "-o", "log-file-path=/tmp/test.log,-d=INFO"
    };
    options.ParseCommandLine(3, const_cast<char**>(n_argv));
    ASSERT_EQ("/tmp/test.log", options.log_file_path);
    ASSERT_EQ("INFO", options.log_level_string);
  }
  
  {
    // Example from what can be passed in from /etc/fstab.
    const char* n_argv[] = {
        "executable",
        "-o", "_netdev,pkcs12-file-path=/tmp/pkcs12.p12,log-level=DEBUG"
    };
    options.ParseCommandLine(3, const_cast<char**>(n_argv));
    ASSERT_EQ("/tmp/pkcs12.p12", options.ssl_pkcs12_path);
    ASSERT_EQ("DEBUG", options.log_level_string);
  }
  
}

}  // namespace xtreemfs
{'fraction_non_alphanumeric': 0.15220195319697807, 'fraction_numerical': 0.008107610097659848, 'mean_word_length': 3.1152388172858227, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1868910', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1826, 'n_words': 325}