<commit_before>/******************************************************************************
 *                    _   _____   __________                                  *
 *                   | | / / _ | / __/_  __/     Visibility                   *
 *                   | |/ / __ |_\ \  / /          Across                     *
 *                   |___/_/ |_/___/ /_/       Space and Time                 *
 *                                                                            *
 * This file is part of VAST. It is subject to the license terms in the       *
 * LICENSE file found in the top-level directory of this distribution and at  *
 * http://vast.io/license. No part of VAST, including this file, may be       *
 * copied, modified, propagated, or distributed except according to the terms *
 * contained in the LICENSE file.                                             *
 ******************************************************************************/

#define SUITE format

#include "vast/format/mrt.hpp"

#include "vast/test/test.hpp"
#include "vast/test/data.hpp"

#include "vast/concept/parseable/to.hpp"
#include "vast/detail/make_io_stream.hpp"
#include "vast/filesystem.hpp"

using namespace vast;

TEST(MRT) {
  auto in = detail::make_input_stream(mrt::updates20150505, false);
  format::mrt::reader reader{std::move(*in)};
  auto result = expected<event>{no_error};
  std::vector<event> events;
  while (result || !result.error()) {
    result = reader.read();
  if (result)
    events.push_back(std::move(*result));
  }
  REQUIRE(!result);
  CHECK_EQUAL(result.error(), ec::end_of_input);
  REQUIRE(!events.empty());
  CHECK_EQUAL(events.size(), 26479u);
  REQUIRE(events.size() == 26479u);
  // Event 2
  CHECK_EQUAL(events[2].type().name(), "mrt::bgp4mp::update::announcement");
  auto record = caf::get_if<vector>(&events[2].data());
  REQUIRE(record);
  auto addr = caf::get_if<address>(&record->at(0));
  CHECK_EQUAL(*addr, unbox(to<address>("192.168.127.12")));
  CHECK_EQUAL(record->at(1), count{7018});
  auto subn = caf::get_if<subnet>(&record->at(2));
  CHECK_EQUAL(*subn, unbox(to<subnet>("172.16.58.3/24")));
  // Event 17
  CHECK_EQUAL(events[17].type().name(), "mrt::bgp4mp::update::withdrawn");
  record = caf::get_if<vector>(&events[17].data());
  REQUIRE(record);
  addr = caf::get_if<address>(&record->at(0));
  CHECK_EQUAL(*addr, unbox(to<address>("192.168.127.12")));
  CHECK_EQUAL(record->at(1), count{7018});
  subn = caf::get_if<subnet>(&record->at(2));
  CHECK_EQUAL(*subn, unbox(to<subnet>("172.16.58.3/24")));
  // Event 73
  CHECK_EQUAL(events[73].type().name(), "mrt::bgp4mp::state_change");
  record = caf::get_if<vector>(&events[73].data());
  REQUIRE(record);
  addr = caf::get_if<address>(&record->at(0));
  CHECK_EQUAL(*addr, unbox(to<address>("192.168.127.12")));
  CHECK_EQUAL(record->at(1), count{45896});
  CHECK_EQUAL(record->at(2), count{3});
  CHECK_EQUAL(record->at(3), count{2});
  // Event 26478
  CHECK_EQUAL(events[26478].type().name(), "mrt::bgp4mp::update::announcement");
  record = caf::get_if<vector>(&events[26478].data());
  REQUIRE(record);
  addr = caf::get_if<address>(&record->at(0));
  CHECK_EQUAL(*addr, unbox(to<address>("fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b")));
  subn = caf::get_if<subnet>(&record->at(2));
  CHECK_EQUAL(*subn, unbox(to<subnet>("2a00:bdc0:e003::/48")));
  auto as_path = caf::get_if<vector>(&record->at(3));
  CHECK_EQUAL(as_path->size(), 4u);
  CHECK_EQUAL(as_path->at(0), count{1836});<commit_msg>Make judicious use of unbox<commit_after>/******************************************************************************
 *                    _   _____   __________                                  *
 *                   | | / / _ | / __/_  __/     Visibility                   *
 *                   | |/ / __ |_\ \  / /          Across                     *
 *                   |___/_/ |_/___/ /_/       Space and Time                 *
 *                                                                            *
 * This file is part of VAST. It is subject to the license terms in the       *
 * LICENSE file found in the top-level directory of this distribution and at  *
 * http://vast.io/license. No part of VAST, including this file, may be       *
 * copied, modified, propagated, or distributed except according to the terms *
 * contained in the LICENSE file.                                             *
 ******************************************************************************/

#define SUITE format

#include "vast/format/mrt.hpp"

#include "vast/test/test.hpp"
#include "vast/test/data.hpp"

#include "vast/concept/parseable/to.hpp"
#include "vast/detail/make_io_stream.hpp"
#include "vast/filesystem.hpp"

using namespace vast;

TEST(MRT) {
  auto in = detail::make_input_stream(mrt::updates20150505, false);
  format::mrt::reader reader{std::move(*in)};
  auto result = expected<event>{no_error};
  std::vector<event> events;
  while (result || !result.error()) {
    result = reader.read();
  if (result)
    events.push_back(std::move(*result));
  }
  REQUIRE(!result);
  CHECK_EQUAL(result.error(), ec::end_of_input);
  REQUIRE(!events.empty());
  REQUIRE_EQUAL(events.size(), 26479u);
  // Event 2
  CHECK_EQUAL(events[2].type().name(), "mrt::bgp4mp::update::announcement");
  auto xs = unbox(caf::get_if<vector>(&events[2].data()));
  auto addr = unbox(caf::get_if<address>(&xs.at(0)));
  CHECK_EQUAL(addr, unbox(to<address>("192.168.127.12")));
  CHECK_EQUAL(xs.at(1), count{7018});
  auto sn = unbox(caf::get_if<subnet>(&xs.at(2)));
  CHECK_EQUAL(sn, unbox(to<subnet>("172.16.58.3/24")));
  // Event 17
  CHECK_EQUAL(events[17].type().name(), "mrt::bgp4mp::update::withdrawn");
  xs = unbox(caf::get_if<vector>(&events[17].data()));
  addr = unbox(caf::get_if<address>(&xs.at(0)));
  CHECK_EQUAL(addr, unbox(to<address>("192.168.127.12")));
  CHECK_EQUAL(xs.at(1), count{7018});
  sn = unbox(caf::get_if<subnet>(&xs.at(2)));
  CHECK_EQUAL(sn, unbox(to<subnet>("172.16.58.3/24")));
  // Event 73
  CHECK_EQUAL(events[73].type().name(), "mrt::bgp4mp::state_change");
  xs = unbox(caf::get_if<vector>(&events[73].data()));
  addr = unbox(caf::get_if<address>(&xs.at(0)));
  CHECK_EQUAL(addr, unbox(to<address>("192.168.127.12")));
  CHECK_EQUAL(xs.at(1), count{45896});
  CHECK_EQUAL(xs.at(2), count{3});
  CHECK_EQUAL(xs.at(3), count{2});
  // Event 26478
  CHECK_EQUAL(events[26478].type().name(), "mrt::bgp4mp::update::announcement");
  xs = unbox(caf::get_if<vector>(&events[26478].data()));
  addr = unbox(caf::get_if<address>(&xs.at(0)));
  CHECK_EQUAL(addr, unbox(to<address>("fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b")));
  sn = unbox(caf::get_if<subnet>(&xs.at(2)));
  CHECK_EQUAL(sn, unbox(to<subnet>("2a00:bdc0:e003::/48")));
  auto as_path = caf::get_if<vector>(&xs.at(3));
  CHECK_EQUAL(as_path->size(), 4u);
  CHECK_EQUAL(as_path->at(0), count{1836});
{'fraction_non_alphanumeric': 0.22891043264361163, 'fraction_numerical': 0.04760526696570684, 'mean_word_length': 3.388571428571429, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 10, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2945272', 'n_tokens_mistral': 2580, 'n_tokens_neox': 2381, 'n_words': 357}