<commit_before>#include <string>

#include <boost/bind.hpp>

#include <libport/export.hh>
#include <libport/unit-test.hh>

#include <serialize/serializable.hh>
#include <serialize/serializer.hh>
#include <serialize/xml-o-serializer.hh>
#include <serialize/xml-i-serializer.hh>

using namespace libport::serialize;
using libport::test_suite;

struct Data: public Serializable
{
  Data(const std::string& d1 = "",
       const std::string& d2 = "",
       const std::string& d3 = "")
    : data1(d1)
    , data2(d2)
    , data3(d3)
  {}

  virtual void serialize(libport::serialize::Serializer& ser)
  {
    ser.serialize("data1", data1);
    ser.serialize("data2", data2);
    ser.serialize("data3", data3);
  }

  std::string data1;
  std::string data2;
  std::string data3;
};

void test()
{
  {
    Data o("foo", "bar", "<baz");
    XmlOSerializer os("test.xml");
    os.serialize("test", o);
  }

  {
    Data i;
    XmlISerializer is("test.xml");
    is.serialize("test", i);
    BOOST_CHECK_EQUAL(i.data1, "foo");
    BOOST_CHECK_EQUAL(i.data2, "bar");
    BOOST_CHECK_EQUAL(i.data3, "<baz");
  }
}

LIBPORT_API test_suite*
init_test_suite()
{
  test_suite* suite = BOOST_TEST_SUITE("serialization test suite");

  suite->add(BOOST_TEST_CASE(test));

  return suite;
}<commit_msg>Test serialization harder.<commit_after>#include <string>

#include <boost/bind.hpp>

#include <libport/export.hh>
#include <libport/unit-test.hh>

#include <serialize/binary-i-serializer.hh>
#include <serialize/binary-o-serializer.hh>
#include <serialize/serializable.hh>
#include <serialize/serializer.hh>
#include <serialize/xml-i-serializer.hh>
#include <serialize/xml-o-serializer.hh>

using namespace libport::serialize;
using libport::test_suite;

struct Data: public Serializable
{
  Data(const std::string& d1 = "",
       const std::string& d2 = "")
    : data1(d1)
    , data2(d2)
  {}

  virtual void serialize(libport::serialize::Serializer& ser)
  {
    ser.serialize("data1", data1);
    ser.serialize("data2", data2);
  }

  bool operator == (const Data& other) const
  {
    return data1 == other.data1 && data2 == other.data2;
  }

  std::string data1;
  std::string data2;
};

struct Datas: public Serializable
{
  Datas(const std::string& n)
    : name(n)
    , datas()
  {}

  Datas& operator << (Data d)
  {
    datas.push_back(d);
    return *this;
  }

  bool operator == (const Datas& other) const
  {
    bool res = true;
    res = res && name == other.name;
    res = res && datas.size() == other.datas.size();
    for (unsigned i = 0; res && i < datas.size(); ++i)
      res = res && datas[i] == other.datas[i];
    return res;
  }

  virtual void serialize(libport::serialize::Serializer& ser)
  {
    ser.serialize("name", name);
    ser.serialize("datas", datas);
  }

  std::string name;
  std::vector<Data> datas;
};

void test()
{
  // Test datas
  Datas o("name");
  o << Data("foo&", "<bar>");
  o << Data("baz", "quux");

  // Export them as XML
  {
    XmlOSerializer os("test.xml");
    os.serialize("test", o);
  }
  // Import them as XML
  {
    Datas i("");
    {
      XmlISerializer is("test.xml");
      is.serialize("test", i);
    }
    BOOST_CHECK(i == o);
  }

  // Export them as binary
  {
    BinaryOSerializer os("test.bin");
    os.serialize("test", o);
  }
  // Import them as binary
  {
    Datas i("");
    {
      BinaryISerializer is("test.bin");
      is.serialize("test", i);
    }
    std::cerr << i.name << std::endl;
    BOOST_CHECK(i == o);
  }
}

LIBPORT_API test_suite*
init_test_suite()
{
  test_suite* suite = BOOST_TEST_SUITE("serialization test suite");

  suite->add(BOOST_TEST_CASE(test));

  return suite;
}
{'fraction_non_alphanumeric': 0.17103109656301146, 'fraction_numerical': 0.010365521003818877, 'mean_word_length': 3.4234016887816647, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '943024', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1315, 'n_words': 273}