<commit_before>// ------------------------------------------------------------------------
// Pion is a development platform for building Reactors that process Events
// ------------------------------------------------------------------------
// Copyright (C) 2007-2008 Atomic Labs, Inc.  (http://www.atomiclabs.com)
//
// Pion is free software: you can redistribute it and/or modify it under the
// terms of the GNU Affero General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// Pion is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for
// more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Pion.  If not, see <http://www.gnu.org/licenses/>.
//

#include <pion/PionConfig.hpp>
#include <pion/platform/Event.hpp>
#include <pion/platform/Vocabulary.hpp>
#include <boost/test/unit_test.hpp>

using namespace pion;
using namespace pion::platform;


class EventTests_F {
public:
	EventTests_F()
		: m_null_term("urn:vocab:test#null-term"), m_plain_int_term("urn:vocab:test#plain-old-int"),
		m_big_int_term("urn:vocab:test#big-int"), m_fixed_term("urn:vocab:test#fixed-text"),
		m_date_term("urn:vocab:test#date"), m_object_term("urn:vocab:test#simple-object")
	{
		// initialize our initial term set
		m_null_term.term_ref = static_cast<Vocabulary::TermRef>(1);
		m_plain_int_term.term_ref = static_cast<Vocabulary::TermRef>(2);
		m_big_int_term.term_ref = static_cast<Vocabulary::TermRef>(3);
		m_fixed_term.term_ref = static_cast<Vocabulary::TermRef>(4);
		m_date_term.term_ref = static_cast<Vocabulary::TermRef>(5);
		m_object_term.term_ref = static_cast<Vocabulary::TermRef>(6);
		m_null_term.term_type = Vocabulary::TYPE_NULL;
		m_plain_int_term.term_type = Vocabulary::TYPE_INT16;
		m_big_int_term.term_type = Vocabulary::TYPE_UINT64;
		m_fixed_term.term_type = Vocabulary::TYPE_CHAR;
		m_date_term.term_type = Vocabulary::TYPE_DATE;
		m_object_term.term_type = Vocabulary::TYPE_OBJECT;
		m_null_term.term_comment = "A plain, old integer number";
		m_plain_int_term.term_comment = "A plain, old integer number";
		m_big_int_term.term_comment = "A really big positive integer";
		m_fixed_term.term_comment = "Ten bytes of text";
		m_date_term.term_comment = "A date";
		m_object_term.term_comment = "An object containing other Terms";
		m_fixed_term.term_size = 10;
		m_date_term.term_format = "%Y-%m-%d";
	}
	~EventTests_F() {
	}
	void addAllTerms() {
		m_vocabulary.addTerm(m_null_term);
		m_vocabulary.addTerm(m_plain_int_term);
		m_vocabulary.addTerm(m_big_int_term);
		m_vocabulary.addTerm(m_fixed_term);
		m_vocabulary.addTerm(m_date_term);
		m_vocabulary.addTerm(m_object_term);
	}

	EventFactory		m_event_factory;
	Vocabulary			m_vocabulary;
	Vocabulary::Term	m_null_term;
	Vocabulary::Term	m_plain_int_term;
	Vocabulary::Term	m_big_int_term;
	Vocabulary::Term	m_fixed_term;
	Vocabulary::Term	m_date_term;
	Vocabulary::Term	m_object_term;
};

BOOST_FIXTURE_TEST_SUITE(EventTests_S, EventTests_F)

BOOST_AUTO_TEST_CASE(checkEventAllocatorIsOk) {
	void *mem_ptr = m_event_factory.getAllocator().malloc(sizeof(Event));
	Event *event_ptr = new (mem_ptr) Event(m_object_term.term_ref, &m_event_factory.getAllocator());
	event_ptr->setInt(m_plain_int_term.term_ref, 24);
	event_ptr->setUBigInt(m_big_int_term.term_ref, 2025221224);
	event_ptr->setDateTime(m_date_term.term_ref, PionDateTime(boost::gregorian::date(2007, 4, 5)));

	event_ptr->~Event();
	m_event_factory.getAllocator().free(event_ptr, sizeof(Event));
}

BOOST_AUTO_TEST_CASE(checkEmptyEventValues) {
	EventPtr event_ptr(m_event_factory.create(m_object_term.term_ref));
	BOOST_CHECK(event_ptr->empty());
	BOOST_CHECK(event_ptr->begin() == event_ptr->end());
	BOOST_CHECK(event_ptr->find(m_null_term.term_ref) == event_ptr->end());
	BOOST_CHECK(event_ptr->getPointer(m_null_term.term_ref) == NULL);
	BOOST_CHECK(! event_ptr->isDefined(m_null_term.term_ref));

	Event::ValuesRange range = event_ptr->equal_range(m_null_term.term_ref);
	BOOST_CHECK(range.first == range.second);
	BOOST_CHECK(range.first == event_ptr->end());
	BOOST_CHECK(range.second == event_ptr->end());
}

BOOST_AUTO_TEST_CASE(checkEventAssignmentValues) {
	addAllTerms();
	std::string short_msg_str("short msg");
	EventPtr event_ptr(m_event_factory.create(m_object_term.term_ref));
	event_ptr->setInt(m_plain_int_term.term_ref, 24);
	event_ptr->setUBigInt(m_big_int_term.term_ref, 0x1FFFFFFFFFFFFFFFULL);
	event_ptr->setString(m_fixed_term.term_ref, short_msg_str);
	event_ptr->setDateTime(m_date_term.term_ref, PionDateTime(boost::gregorian::date(2007, 4, 5)));

	const Event::ParameterValue *value_ptr = event_ptr->getPointer(m_plain_int_term.term_ref);
	BOOST_REQUIRE(value_ptr != NULL);
	BOOST_CHECK_EQUAL(boost::get<boost::int32_t>(*value_ptr), 24);
	BOOST_CHECK_EQUAL(event_ptr->getUBigInt(m_big_int_term.term_ref), 0x1FFFFFFFFFFFFFFF);
	BOOST_CHECK_EQUAL(event_ptr->getString(m_fixed_term.term_ref), short_msg_str);
	BOOST_CHECK_EQUAL(event_ptr->getBlob(m_fixed_term.term_ref).get(), short_msg_str);
	PionDateTime pdt = event_ptr->getDateTime(m_date_term.term_ref);
	BOOST_CHECK_EQUAL(pdt.date().year(), 2007);
	BOOST_CHECK_EQUAL(pdt.date().month(), 4);
	BOOST_CHECK_EQUAL(pdt.date().day(), 5);

	boost::uint32_t n;
	BOOST_CHECK(event_ptr->getInt(m_plain_int_term.term_ref, n));
	BOOST_CHECK_EQUAL(n, 24UL);

	boost::uint64_t n64;
	BOOST_CHECK(event_ptr->getUBigInt(m_big_int_term.term_ref, n64));
	BOOST_CHECK_EQUAL(n64, 0x1FFFFFFFFFFFFFFF);

	std::string str;
	BOOST_CHECK(event_ptr->getString(m_fixed_term.term_ref, str));
	BOOST_CHECK_EQUAL(str, short_msg_str);

	Event::BlobType b;
	BOOST_CHECK(event_ptr->getBlob(m_fixed_term.term_ref, b));
	BOOST_CHECK(! b.empty());
	BOOST_CHECK(! b.unique());
	BOOST_CHECK_EQUAL(b.use_count(), 2);
	BOOST_CHECK_EQUAL(short_msg_str, b.get());
}

BOOST_AUTO_TEST_CASE(checkEventAssignmentToBlobValues) {
	addAllTerms();
	std::string short_msg_str("short msg");
	EventPtr event_a(m_event_factory.create(m_object_term.term_ref));
	event_a->setString(m_fixed_term.term_ref, short_msg_str);
	BOOST_CHECK(event_a->getBlob(m_fixed_term.term_ref) == short_msg_str);
	BOOST_CHECK(event_a->getBlob(m_fixed_term.term_ref).unique());
	BOOST_CHECK_EQUAL(event_a->getBlob(m_fixed_term.term_ref).use_count(), 1);
	BOOST_CHECK_EQUAL(strcmp(event_a->getString(m_fixed_term.term_ref), short_msg_str.c_str()), 0);
<commit_msg>Adding ULL to 64-bit hex number to make gcc happy<commit_after>// ------------------------------------------------------------------------
// Pion is a development platform for building Reactors that process Events
// ------------------------------------------------------------------------
// Copyright (C) 2007-2008 Atomic Labs, Inc.  (http://www.atomiclabs.com)
//
// Pion is free software: you can redistribute it and/or modify it under the
// terms of the GNU Affero General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// Pion is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for
// more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Pion.  If not, see <http://www.gnu.org/licenses/>.
//

#include <pion/PionConfig.hpp>
#include <pion/platform/Event.hpp>
#include <pion/platform/Vocabulary.hpp>
#include <boost/test/unit_test.hpp>

using namespace pion;
using namespace pion::platform;


class EventTests_F {
public:
	EventTests_F()
		: m_null_term("urn:vocab:test#null-term"), m_plain_int_term("urn:vocab:test#plain-old-int"),
		m_big_int_term("urn:vocab:test#big-int"), m_fixed_term("urn:vocab:test#fixed-text"),
		m_date_term("urn:vocab:test#date"), m_object_term("urn:vocab:test#simple-object")
	{
		// initialize our initial term set
		m_null_term.term_ref = static_cast<Vocabulary::TermRef>(1);
		m_plain_int_term.term_ref = static_cast<Vocabulary::TermRef>(2);
		m_big_int_term.term_ref = static_cast<Vocabulary::TermRef>(3);
		m_fixed_term.term_ref = static_cast<Vocabulary::TermRef>(4);
		m_date_term.term_ref = static_cast<Vocabulary::TermRef>(5);
		m_object_term.term_ref = static_cast<Vocabulary::TermRef>(6);
		m_null_term.term_type = Vocabulary::TYPE_NULL;
		m_plain_int_term.term_type = Vocabulary::TYPE_INT16;
		m_big_int_term.term_type = Vocabulary::TYPE_UINT64;
		m_fixed_term.term_type = Vocabulary::TYPE_CHAR;
		m_date_term.term_type = Vocabulary::TYPE_DATE;
		m_object_term.term_type = Vocabulary::TYPE_OBJECT;
		m_null_term.term_comment = "A plain, old integer number";
		m_plain_int_term.term_comment = "A plain, old integer number";
		m_big_int_term.term_comment = "A really big positive integer";
		m_fixed_term.term_comment = "Ten bytes of text";
		m_date_term.term_comment = "A date";
		m_object_term.term_comment = "An object containing other Terms";
		m_fixed_term.term_size = 10;
		m_date_term.term_format = "%Y-%m-%d";
	}
	~EventTests_F() {
	}
	void addAllTerms() {
		m_vocabulary.addTerm(m_null_term);
		m_vocabulary.addTerm(m_plain_int_term);
		m_vocabulary.addTerm(m_big_int_term);
		m_vocabulary.addTerm(m_fixed_term);
		m_vocabulary.addTerm(m_date_term);
		m_vocabulary.addTerm(m_object_term);
	}

	EventFactory		m_event_factory;
	Vocabulary			m_vocabulary;
	Vocabulary::Term	m_null_term;
	Vocabulary::Term	m_plain_int_term;
	Vocabulary::Term	m_big_int_term;
	Vocabulary::Term	m_fixed_term;
	Vocabulary::Term	m_date_term;
	Vocabulary::Term	m_object_term;
};

BOOST_FIXTURE_TEST_SUITE(EventTests_S, EventTests_F)

BOOST_AUTO_TEST_CASE(checkEventAllocatorIsOk) {
	void *mem_ptr = m_event_factory.getAllocator().malloc(sizeof(Event));
	Event *event_ptr = new (mem_ptr) Event(m_object_term.term_ref, &m_event_factory.getAllocator());
	event_ptr->setInt(m_plain_int_term.term_ref, 24);
	event_ptr->setUBigInt(m_big_int_term.term_ref, 2025221224);
	event_ptr->setDateTime(m_date_term.term_ref, PionDateTime(boost::gregorian::date(2007, 4, 5)));

	event_ptr->~Event();
	m_event_factory.getAllocator().free(event_ptr, sizeof(Event));
}

BOOST_AUTO_TEST_CASE(checkEmptyEventValues) {
	EventPtr event_ptr(m_event_factory.create(m_object_term.term_ref));
	BOOST_CHECK(event_ptr->empty());
	BOOST_CHECK(event_ptr->begin() == event_ptr->end());
	BOOST_CHECK(event_ptr->find(m_null_term.term_ref) == event_ptr->end());
	BOOST_CHECK(event_ptr->getPointer(m_null_term.term_ref) == NULL);
	BOOST_CHECK(! event_ptr->isDefined(m_null_term.term_ref));

	Event::ValuesRange range = event_ptr->equal_range(m_null_term.term_ref);
	BOOST_CHECK(range.first == range.second);
	BOOST_CHECK(range.first == event_ptr->end());
	BOOST_CHECK(range.second == event_ptr->end());
}

BOOST_AUTO_TEST_CASE(checkEventAssignmentValues) {
	addAllTerms();
	std::string short_msg_str("short msg");
	EventPtr event_ptr(m_event_factory.create(m_object_term.term_ref));
	event_ptr->setInt(m_plain_int_term.term_ref, 24);
	event_ptr->setUBigInt(m_big_int_term.term_ref, 0x1FFFFFFFFFFFFFFFULL);
	event_ptr->setString(m_fixed_term.term_ref, short_msg_str);
	event_ptr->setDateTime(m_date_term.term_ref, PionDateTime(boost::gregorian::date(2007, 4, 5)));

	const Event::ParameterValue *value_ptr = event_ptr->getPointer(m_plain_int_term.term_ref);
	BOOST_REQUIRE(value_ptr != NULL);
	BOOST_CHECK_EQUAL(boost::get<boost::int32_t>(*value_ptr), 24);
	BOOST_CHECK_EQUAL(event_ptr->getUBigInt(m_big_int_term.term_ref), 0x1FFFFFFFFFFFFFFFULL);
	BOOST_CHECK_EQUAL(event_ptr->getString(m_fixed_term.term_ref), short_msg_str);
	BOOST_CHECK_EQUAL(event_ptr->getBlob(m_fixed_term.term_ref).get(), short_msg_str);
	PionDateTime pdt = event_ptr->getDateTime(m_date_term.term_ref);
	BOOST_CHECK_EQUAL(pdt.date().year(), 2007);
	BOOST_CHECK_EQUAL(pdt.date().month(), 4);
	BOOST_CHECK_EQUAL(pdt.date().day(), 5);

	boost::uint32_t n;
	BOOST_CHECK(event_ptr->getInt(m_plain_int_term.term_ref, n));
	BOOST_CHECK_EQUAL(n, 24UL);

	boost::uint64_t n64;
	BOOST_CHECK(event_ptr->getUBigInt(m_big_int_term.term_ref, n64));
	BOOST_CHECK_EQUAL(n64, 0x1FFFFFFFFFFFFFFFULL);

	std::string str;
	BOOST_CHECK(event_ptr->getString(m_fixed_term.term_ref, str));
	BOOST_CHECK_EQUAL(str, short_msg_str);

	Event::BlobType b;
	BOOST_CHECK(event_ptr->getBlob(m_fixed_term.term_ref, b));
	BOOST_CHECK(! b.empty());
	BOOST_CHECK(! b.unique());
	BOOST_CHECK_EQUAL(b.use_count(), 2);
	BOOST_CHECK_EQUAL(short_msg_str, b.get());
}

BOOST_AUTO_TEST_CASE(checkEventAssignmentToBlobValues) {
	addAllTerms();
	std::string short_msg_str("short msg");
	EventPtr event_a(m_event_factory.create(m_object_term.term_ref));
	event_a->setString(m_fixed_term.term_ref, short_msg_str);
	BOOST_CHECK(event_a->getBlob(m_fixed_term.term_ref) == short_msg_str);
	BOOST_CHECK(event_a->getBlob(m_fixed_term.term_ref).unique());
	BOOST_CHECK_EQUAL(event_a->getBlob(m_fixed_term.term_ref).use_count(), 1);
	BOOST_CHECK_EQUAL(strcmp(event_a->getString(m_fixed_term.term_ref), short_msg_str.c_str()), 0);

{'fraction_non_alphanumeric': 0.1487260666365144, 'fraction_numerical': 0.011910146238504447, 'mean_word_length': 6.175229853975122, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, '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': '1183104', 'n_tokens_mistral': 5177, 'n_tokens_neox': 4908, 'n_words': 735}