void TestListe::TestAjouter()
        {
  	      // 
          ListeAssociation< ElementTestListe > temp ;
  
          Composition< ElementTestListe > element1(new ElementTestListe(1)) ;
          Composition< ElementTestListe > element2(new ElementTestListe(2)) ;
  
          temp.AjouterEnTete(element1) ;
          temp.AjouterEnTete(element2) ;
  
          CPPUNIT_ASSERT(temp.NombreDElements() == 2) ;
  
          CPPUNIT_ASSERT(temp.Contient(element1)) ;
          CPPUNIT_ASSERT(temp.Contient(element2)) ;
  
          Entier resultat(0) ;
  
          for(
            IterateurListeAssociation< ElementTestListe > i(temp) ;
            i.Valide() ;
            ++i)
          {
            resultat += i->valeur ;
          }
          
          CPPUNIT_ASSERT(resultat == 3) ;

          // liste de valeurs
   
          listeChaine.AjouterEnTete("toto") ;
          listeChaine.AjouterEnTete("titi") ;
  
          CPPUNIT_ASSERT(listeChaine.Contient("toto")) ;
          CPPUNIT_ASSERT(listeChaine.Contient("titi")) ;
          
          // test de l'itérateur
          
          IterateurListeValeur<Chaine> chaine(listeChaine) ;

          CPPUNIT_ASSERT(chaine == Chaine("titi")) ;
          ++chaine ;

          CPPUNIT_ASSERT(chaine == "toto") ;
          
        }
Example #2
0
int main()
{
	elem element1(1);
	elem element2(2);
	elem element3(3);


	List list;
	list.push(element1);
	list.push(element2);
	list.push(element3);
	const char* a = "You can't pop from empty one connected list.";
	list.pop();
	list.pop();
	list.pop();
	list.pop();

}
       void TestListe::TestDestruction()
       {
 
         // on ouvre un nouveau bloc, ses variables temporaires sont détruites 
         // à la sortie
         {
           // 
           ListeComposition< ElementTestListe > liste2 ;
 
           Composition< ElementTestListe > element1(new ElementTestListe(1)) ;
           Composition< ElementTestListe > element2(new ElementTestListe(2)) ;
 
           liste2.AjouterEnTete(element1.Liberer()) ;
           liste2.AjouterEnTete(element2.Liberer()) ;
 
         } 
         // ici liste2 est détruite et ses doivent l'être aussi 
         CPPUNIT_ASSERT(ElementTestListe::nombreDObjetsDetruits == 2 ) ;
       }
Example #4
0
File: main.cpp Project: logic17/ex5
void main() {
	CElement element1(123);
	CElement element2(element1);

	cout << "The value of the element is " << element2.getValue() << endl;

	CFile<CElement> cfile("C:\\Development\\file.txt");
	cout << "file size is " << cfile.size() << endl; // expected 0  

	cfile.write(element1);
	cout << "After writing single element, file size is " << cfile.size() << endl; // expected 1 

	CElement element3 = cfile.read();
	cout << "Reading the single element from file: " << element3.getValue() << endl;

	CElement element4(456);
	CElement element5(78);
	CElement writeBuf[] = { element4, element5 };


	cout << "writing one more element..." << endl;
	CElement element6(1000091);
	cfile.write(element6);

	cout << "Trying to write two elements from buffer... " << endl;
	cfile.write(writeBuf, 2);

	cout << "After writing 4 elements, size is: " << cfile.size() << endl;

	cout << "Trying to read 4 elems with buffer: " << endl;
	CElement* readBuf;
	int index = cfile.read(&readBuf, 4);
	cout << "elements are: " << endl;

	for (int i = 0; i < index; i++) {
		cout << readBuf[i];
	}
}
Example #5
0
/**
* Test application to test creating a document from scratch
*/
int main()
{
   // Create the basic context and document to work on
   // - All nodes need to have an associated context
   //   we will just define one here at the beginning and use it
   //   the entire way through
   cppdom::ContextPtr ctx( new cppdom::Context );
   cppdom::Document doc("Document", ctx );

   // What it should look like
   // - Root
   //   - Element1: attrib1:1, attrib2:two
   //        cdata: This is element1
   //   - Element2:
   //      - Element3: attrib1:attrib1
   //        cdata: We are element 3
   //        cdata: We are still element 3
   cppdom::NodePtr root(new cppdom::Node("root", ctx));
   cppdom::NodePtr element1(new cppdom::Node("Element1", ctx));
   cppdom::NodePtr element2(new cppdom::Node("Element2", ctx));
   cppdom::NodePtr element3(new cppdom::Node("Element3", ctx));
   cppdom::NodePtr element1_cdata(new cppdom::Node("Element1-cdata", ctx));
   cppdom::NodePtr element3_cdata2(new cppdom::Node("Element3-cdata2", ctx));

   // Document can only have one element as child (to be valid xml)
   // Set this to the root element
   doc.addChild(root);

   // Now add element 1
   // - Also set it's attributes
   root->addChild(element1);
   element1->setAttribute("attrib1", 1);
   element1->setAttribute("attrib2", "two");
   std::string escaped_attrib_text = "<this>&<that>\"\'<done>";
   element1->setAttribute("attrib3", escaped_attrib_text);
   element1->addChild(element1_cdata);

   // Cdata must have it's type set
   // then set the actual contents of the cdata
   element1_cdata->setType(Node::xml_nt_cdata);
   std::string escaped_elt1_cdata("\n<test>\n<more>This is 'element1'<here>&\"there\"");
   element1_cdata->setCdata(escaped_elt1_cdata);

   // Add a couple of nested nodes and set the attributes
   root->addChild(element2);
   element2->addChild(element3);
   element3->setAttribute("attrib1", "attrib1");

   // Set Cdata a couple of different ways (this is a test isn't it :)
   element3->setCdata("We are element 3 <<clear me>>");
   element3_cdata2->setType(Node::xml_nt_cdata);
   element3_cdata2->setCdata("We are still element 3");
   element3->addChild(element3_cdata2);
   element3->setCdata("We are element 3");

   // Get the cdata contents and make sure they match up
   std::string cdata_text;
   cdata_text = element1->getCdata();
   std::cout << escaped_elt1_cdata << cdata_text << std::endl;
   cdata_text = element1->getFullCdata();
   std::cout << escaped_elt1_cdata << cdata_text << std::endl;
   cdata_text = element1_cdata->getCdata();
   std::cout << escaped_elt1_cdata << cdata_text << std::endl;

   cdata_text = element3->getCdata();
   std::cout << "We are element 3: " << cdata_text << std::endl;
   cdata_text = element3->getFullCdata();
   std::cout << "We are element 3,We are still element 3: " << cdata_text << std::endl;

   // Dump the tree to the screen
   testHelpers::dump_node(doc);

   // Write the document out to a file
   std::cout << "------- Indented document ------\n";
   doc.save(std::cout);
   std::cout << "------- No indent, no newline document ------\n";
   doc.save(std::cout, false, false);
   std::cout << std::endl;

   std::string filename("maketree.xml");
   doc.saveFile(filename);

   // Now load it to test some things
   cppdom::Document loaded_doc(ctx);
   loaded_doc.loadFile(filename);

   cppdom::NodePtr r_element1 = loaded_doc.getChild("root")->getChild("Element1");

   std::string r_elt1_cdata = r_element1->getCdata();
   std::string tr_elt1_cdata = trimWhitespace(r_elt1_cdata);
   std::string t_escaped_elt1_cdata = trimWhitespace(escaped_elt1_cdata);

//   assert(tr_elt1_cdata == t_escaped_elt1_cdata);

   std::string r_attrib = r_element1->getAttribute("attrib3");
   assert(r_attrib == escaped_attrib_text);

   std::cout << "---------------------------------------\n"
             << "Tests passed." << std::endl;

   return 0;
}
void DistribImmediate::EcrireLog(bool PasErreur, int ration)
{
	log = new TiXmlDocument("Log.xml");
	log->LoadFile();

	time_t t;
	time(&t); // t contient la date et l'heure courante
	struct tm *newTime1;
	newTime1 = localtime(&t);
	int heure = newTime1->tm_hour;		// Les heures sont dans "heures"
	int minute = newTime1->tm_min;		// Les minutes sont dans "minutes"
	int joursemaine = newTime1->tm_wday; //a transformer en chaine de charactere
	int jourmois = newTime1->tm_mday;
	int mois = newTime1->tm_mon;

	stringstream ss1, ss2,ss3,ss4, rat;

	ss1 << heure;
	ss2 << minute;
	ss3 << jourmois;
	ss4 << mois;
	//itoa(heure, h, 10); 
	//	itoa(minute, m, 10); //on transforme les entiers heure et minute en char h et m
	
	string he = ss1.str(); //on transfmorme les char h et m en string he et mi 
	string mi = ss2.str();
	string daymonth = ss3.str();
	string month = ss4.str();
	
	//h = to_string(heure); //pas supporté sur raspberry
	//m = to_string(minute);
	string hor = daymonth + '/' + month +' ' + he + ':' + mi;

	const char * horaire = hor.c_str(); // on transforme la string hor en char* horaire


	rat << ration;
	string rati = rat.str();
	const char * nbRation = rati.c_str();

	if (PasErreur == false)//il y a eu une erreur lors de la distribution
	{
		TiXmlElement* f = log->FirstChildElement();

		TiXmlElement element("HoraireIm");
		TiXmlText * text = new TiXmlText(horaire);
		element.LinkEndChild(text);
		f->InsertEndChild(element);

		TiXmlElement element2("RationIm");
		TiXmlText * text2 = new TiXmlText("Echec");
		element2.LinkEndChild(text2);
		f->InsertEndChild(element2);

	}
	else
	{
		TiXmlElement* f = log->FirstChildElement();

		TiXmlElement element("HoraireIm");
		TiXmlText * text = new TiXmlText(horaire);
		element.LinkEndChild(text);
		f->InsertEndChild(element);

		TiXmlElement element2("RationIm");
		TiXmlText * text2 = new TiXmlText(nbRation);
		element2.LinkEndChild(text2);
		f->InsertEndChild(element2);
	}

	log->SaveFile("Log.xml");
	delete log;
}