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") ;
          
        }
예제 #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 ) ;
       }
예제 #4
0
void
updateP0EltMarkerFromFaceRange( IteratorRange const& range, boost::shared_ptr<SpaceP0Type> const& XhP0,
                                boost::shared_ptr<VectorType> & markEltVec )
{
    for ( auto itr = range.template get<1>(), enr = range.template get<2>() ; itr!=enr ; ++itr )
    {
        if ( itr->isConnectedTo0() )
        {
            auto const& elt = itr->element0();
            const size_type thedof = XhP0->dof()->localToGlobal(elt,0,0).index();
            markEltVec->add(thedof, 1.);
        }
        if ( itr->isConnectedTo1() )
        {
            auto const& elt = itr->element1();
            const size_type thedof = XhP0->dof()->localToGlobal(elt,0,0).index();
            markEltVec->add(thedof, 1.);
        }
    }
}
예제 #5
0
파일: main.cpp 프로젝트: 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];
	}
}
예제 #6
0
파일: maketree.cpp 프로젝트: godbyk/cppdom
/**
* 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;
}