#include <coral/core/Element.h>
#include <coral/core/ElementIterator.h>
#include <coral/coral.h>
#include <coral/core/garbage_collector.h>

#include <coral/core/io/xmi_writer_1.h>

#include <iostream>
#include <fstream>
#include <cmath>

#include <sys/time.h>
#include <unistd.h>

#include <coral/lib/debugstream.h>

int main() {
	coral::init_coral_framework();
	// so refcounting is correct
	coral::autounref<coral::Language> __dummy
		= coral::Language::__getLanguage__("UML", 1, 4);

	/*
	 * Loads a Model with 2 Classes and a Generalization
	 * in between them.
	 */
	int i = coral::all_modelelements_size();
	coral_assert(coral::all_modelelements_size() == i);

	coral::dlog << coral::DEBUGLEVEL_DEBUG << "Ready to load!" << std::endl;

	coral::Element* root = coral::io::loadModel("forward_refs_bad.xmi");
	/*
	 * Because we nowadays give a partial result...
	 */
	coral_assert(root != NULL);
	root->unref();
	std::cout << i << " " << coral::all_modelelements_size() << std::endl;
	coral_assert(coral::all_modelelements_size() == i + 4);

	coral::garbage_collect();
	
	std::cout << i << " " << coral::all_modelelements_size() << std::endl;

	//coral_assert(coral::all_modelelements_size() == i);

	return 0;
}


