void AppWarmux::DisplayLoadingPicture() { Config *config = Config::GetInstance(); std::string txt_version = _("Version") + std::string(" ") + Constants::WARMUX_VERSION; std::string filename = config->GetDataDir() + "menu" PATH_SEPARATOR "background_loading.jpg"; Surface surfaceLoading(filename.c_str()); Sprite loading_image(surfaceLoading); loading_image.ScaleSize(video->window.GetSize()); loading_image.Blit(video->window, 0, 0); GameTime::GetInstance()->Reset(); Text text1(_("Warmux launching..."), white_color, Font::FONT_HUGE, Font::FONT_BOLD, true); Text text2(txt_version, white_color, Font::FONT_HUGE, Font::FONT_BOLD, true); Point2i windowCenter = video->window.GetSize() / 2; text1.DrawCenter(windowCenter); text2.DrawCenter(windowCenter + Point2i(0, Font::GetInstance(Font::FONT_HUGE, Font::FONT_BOLD)->GetHeight() + 20)); video->window.Flip(); }
void CFinalQuery::ConstructL() { CALLSTACKITEM_N(_CL("CFinalQuery"), _CL("ConstructL")); iSelections = new (ELeave) CDesCArrayFlat(10); #ifdef ADD_SHORTCUT_QUERY auto_ptr<HBufC> text1( StringLoader::LoadL( R_TEXT_WELCOME_ADD_SHORTCUT_TO_IDLE) ); auto_ptr<HBufC> text2( StringLoader::LoadL( R_TEXT_WELCOME_LAUNCH_JAIKU ) ); iSelections->AppendL( *text1 ); iSelections->AppendL( *text2 ); #else auto_ptr<HBufC> text1( StringLoader::LoadL( R_TEXT_WELCOME_LAUNCH_JAIKU__NOSHORTCUT ) ); iSelections->AppendL( *text1 ); #endif }
void video_manager::record_frame() { // ignore if nothing to do if (m_mngfile == NULL && m_avifile == NULL) return; // start the profiler and get the current time g_profiler.start(PROFILER_MOVIE_REC); attotime curtime = machine().time(); // create the bitmap create_snapshot_bitmap(NULL); // loop until we hit the right time while (m_movie_next_frame_time <= curtime) { // handle an AVI recording if (m_avifile != NULL) { // write the next frame avi_error avierr = avi_append_video_frame(m_avifile, m_snap_bitmap); if (avierr != AVIERR_NONE) { g_profiler.stop(); return end_recording(); } } // handle a MNG recording if (m_mngfile != NULL) { // set up the text fields in the movie info png_info pnginfo = { 0 }; if (m_movie_frame == 0) { astring text1(emulator_info::get_appname(), " ", build_version); astring text2(machine().system().manufacturer, " ", machine().system().description); png_add_text(&pnginfo, "Software", text1); png_add_text(&pnginfo, "System", text2); } // write the next frame const rgb_t *palette = (machine().palette != NULL) ? palette_entry_list_adjusted(machine().palette) : NULL; png_error error = mng_capture_frame(*m_mngfile, &pnginfo, m_snap_bitmap, machine().total_colors(), palette); png_free(&pnginfo); if (error != PNGERR_NONE) { g_profiler.stop(); return end_recording(); } } // advance time m_movie_next_frame_time += m_movie_frame_period; m_movie_frame++; } g_profiler.stop(); }
TEST(Encryption, Simple) { std::string text1("abcdef"); std::string text2; for (int i = 0; i < 200; i++) { text2.push_back(i); } testEncryption(ENC_AES128_CTR, text1); testEncryption(ENC_AES128_CTR, text2); testEncryption(ENC_AES128_OFB, text1); testEncryption(ENC_AES128_OFB, text2); }
void mykeyboard(unsigned char key,int x,int y) { if(key=='y' || key=='Y') { glClear(GL_COLOR_BUFFER_BIT); draw(); text(); } else if(key=='N' || key=='n') exit(0); else if(key=='P' || key=='p') { glClear(GL_COLOR_BUFFER_BIT); text1(); } }
void CCalendarSettingsQuery::ConstructL() { CALLSTACKITEM_N(_CL("CCalendarSettingsQuery"), _CL("ConstructL")); iSelections = new (ELeave) CDesCArrayFlat(10); auto_ptr<HBufC> text1( StringLoader::LoadL( R_TEXT_WELCOME_SHOW_TITLE_OF_EVENT ) ); auto_ptr<HBufC> text2( StringLoader::LoadL( R_TEXT_WELCOME_SHOW_BUSY_INSTEAD ) ); auto_ptr<HBufC> text3( StringLoader::LoadL( R_TEXT_WELCOME_DONT_SHARE_EVENTS ) ); iSelections->AppendL( *text1 ); iSelections->AppendL( *text2 ); iSelections->AppendL( *text3 ); }
// TODO: uh... this is really a super basic/not great test (better than // nothing but barely) TEST(Encryption, SuperBasic) { std::string text1("abcdef"); text1.push_back('\0'); // let's have some binary in there text1.append("89"); // even number and small (9) std::string text2; for (int i = 0; i < 274; i++) { text2.push_back(i); // will wrap and bigger than 256 } std::string text3 = text2; for (int i = ENC_NONE + 1; i < NUM_ENC_TYPES; ++i) { EncryptionType t = static_cast<EncryptionType>(i); testEncryption(t, text1); testEncryption(t, text2); EXPECT_EQ(text2, text3); // paranoia } }
void SearchDialog::setSearchColour(QLineEdit *lineEdit,int result) { QPalette palette = lineEdit->palette(); QColor text0(255,255,255); QColor text1(0,0,0); QColor background0(255,102,102); QColor background1(255,255,255); switch(result){ case 0: palette.setColor(QPalette::Text,text0); lineEdit->setPalette(palette); palette.setColor(QPalette::Base,background0); lineEdit->setPalette(palette); break; case 1: palette.setColor(QPalette::Text,text1); lineEdit->setPalette(palette); palette.setColor(QPalette::Base,background1); lineEdit->setPalette(palette); break; } }
void Ut::read_write() { qDebug() << "begin read_write"; QFile inp(filename); if (!inp.open(QFile::ReadOnly)) { qDebug() << "ERROR1"; return; } QTextStream text1(&inp); QString filename2 = filename.left(filename.size() - 6) + "ut.txt"; qDebug() << filename << "-->" << filename2; QFile out(filename2); if (!out.open(QFile::WriteOnly)) { qDebug() << "ERROR2"; return; } QTextStream text2(&out); while (!text1.atEnd()) { QString line(text1.readLine()); if (line.mid(42,1) != " ") text2 << line << endl; else if (ui.JD2UT->isChecked()) text2 << convJD(line) << endl; else text2 << conv(line) << endl; } inp.close(); out.close(); ui.convert->setText("DONE!"); ui.convert->setDisabled(true); write_cfg(); qDebug() << "end read_write"; }
void video_manager::save_snapshot(screen_device *screen, emu_file &file) { // validate assert(!m_snap_native || screen != NULL); // create the bitmap to pass in create_snapshot_bitmap(screen); // add two text entries describing the image astring text1(emulator_info::get_appname(), " ", build_version); astring text2(machine().system().manufacturer, " ", machine().system().description); png_info pnginfo = { 0 }; png_add_text(&pnginfo, "Software", text1); png_add_text(&pnginfo, "System", text2); // now do the actual work const rgb_t *palette = (machine().palette != NULL) ? palette_entry_list_adjusted(machine().palette) : NULL; png_error error = png_write_bitmap(file, &pnginfo, m_snap_bitmap, machine().total_colors(), palette); if (error != PNGERR_NONE) mame_printf_error("Error generating PNG for snapshot: png_error = %d\n", error); // free any data allocated png_free(&pnginfo); }
void Engine::view(sf::RenderWindow &SCREEN) { sf::Sprite spr; spr.setTexture( Engine::CARDS ); spr.setTextureRect( Engine::TILE[ Engine::cCARD-1 ]); spr.setPosition(10, 22); std::stringstream ss1; ss1 << "Winning Streak : " << Engine::win; sf::Text text1( ss1.str(), Engine::MONA, 20); text1.setPosition(170, 22); std::stringstream ss2; ss2 << "Total Score : " << Engine::score; sf::Text text2( ss2.str(), Engine::MONA, 20); text2.setPosition(170, 52); SCREEN.clear(); SCREEN.draw(text1); SCREEN.draw(text2); SCREEN.draw(spr); SCREEN.display(); }
int compare( const void *arg1, const void *arg2 ) { try { const I_MapItem *i1 = *reinterpret_cast<I_MapItem**>(const_cast<void*>(arg1)); const I_MapItem *i2 = *reinterpret_cast<I_MapItem**>(const_cast<void*>(arg2)); C_TextPtr text1(const_cast<I_MapItem*>(i1)); C_TextPtr text2(const_cast<I_MapItem*>(i2)); if (text1 && !text2) { return 1; } else if (text2 && !text1) { return -1; } C_PicturePtr pic1(const_cast<I_MapItem*>(i1)); C_PicturePtr pic2(const_cast<I_MapItem*>(i2)); if (pic1 && !pic2) { return 1; } else if (pic2 && !pic1) { return -1; } C_PositionPtr p1(const_cast<I_MapItem*>(i1)); C_PositionPtr p2(const_cast<I_MapItem*>(i2)); if (p1 && p2) { C_Area area1(p1.GetPoints()); C_Area area2(p2.GetPoints()); int n = 0; int cnt1 = area1.GetLength(); int cnt2 = area2.GetLength(); if (0 == cnt1) { return -1; } if (0 == cnt2) { return 1; } POINT3D *ptr1 = area1[cnt1 - 1]; POINT3D *ptr2 = area2[cnt2 - 1]; if (ptr1->x < 0 && ptr2->x > 0) { n = -1; } else if (ptr1->x > 0 && ptr2->x < 0) { n = 1; } else if (ptr1->y < ptr2->y) { n = -1; } else if (ptr1->y > ptr2->y) { n = 1; } if (0 == n) { if (cnt1 < cnt2) { n = -1; } else if (cnt1 > cnt2) { n = 1; } } if (0 != n) { return n; } } C_UniquePtr u1(const_cast<I_MapItem*>(i1)); C_UniquePtr u2(const_cast<I_MapItem*>(i2)); if (!u1 && !u2) { return 0; } else if (!u1) { return -1; } else if (!u2) { return 1; } else { BSTR bs1 = NULL; BSTR bs2 = NULL; u1->get_UID(&bs1); u2->get_UID(&bs2); int n = ::wcscmp(bs1, bs2); String::FreeBSTR(&bs1); String::FreeBSTR(&bs2); return n; } } catch (C_STLNonStackException const &exception) { exception.Log(_T("Exception in Items.cpp (compare)")); } return 0; }
void opening(XInfo &xinfo) { char *filename[31]; filename[0] = (char *)"bitmap/open/open0.xbm"; filename[1] = (char *)"bitmap/open/open1.xbm"; filename[2] = (char *)"bitmap/open/open2.xbm"; filename[3] = (char *)"bitmap/open/open3.xbm"; filename[4] = (char *)"bitmap/open/open4.xbm"; filename[5] = (char *)"bitmap/open/open5.xbm"; filename[6] = (char *)"bitmap/open/open6.xbm"; filename[7] = (char *)"bitmap/open/open7.xbm"; filename[8] = (char *)"bitmap/open/open8.xbm"; filename[9] = (char *)"bitmap/open/open9.xbm"; filename[10] = (char *)"bitmap/open/open10.xbm"; filename[11] = (char *)"bitmap/open/open11.xbm"; filename[12] = (char *)"bitmap/open/open12.xbm"; filename[13] = (char *)"bitmap/open/open13.xbm"; filename[14] = (char *)"bitmap/open/open14.xbm"; filename[15] = (char *)"bitmap/open/open15.xbm"; filename[16] = (char *)"bitmap/open/open16.xbm"; filename[17] = (char *)"bitmap/open/open17.xbm"; filename[18] = (char *)"bitmap/open/open18.xbm"; filename[19] = (char *)"bitmap/open/open19.xbm"; filename[20] = (char *)"bitmap/open/open20.xbm"; filename[21] = (char *)"bitmap/open/open21.xbm"; filename[22] = (char *)"bitmap/open/open22.xbm"; filename[23] = (char *)"bitmap/open/open23.xbm"; filename[24] = (char *)"bitmap/open/open24.xbm"; filename[25] = (char *)"bitmap/open/open25.xbm"; filename[26] = (char *)"bitmap/open/open26.xbm"; filename[27] = (char *)"bitmap/open/open27.xbm"; filename[28] = (char *)"bitmap/open/open28.xbm"; filename[29] = (char *)"bitmap/open/open29.xbm"; filename[30] = (char *)"bitmap/open/open30.xbm"; filename[31] = (char *)"bitmap/open/open31.xbm"; Pixmap opening[31]; int FPS = 30; XEvent event; unsigned long lastRepaint = 0; int frame = 0; int start_huh = 0; int time = 60000000; XFillRectangle(xinfo.display, xinfo.window, xinfo.gc[0], 0, 0, 800, 600); while( start_huh == 0) { if (XPending(xinfo.display) > 0) { XNextEvent( xinfo.display, &event ); switch( event.type ) { case KeyPress: handleKeyPress_skip(xinfo, event, start_huh); break; case ConfigureNotify: handleResize(xinfo, event); break; } } // animation timing unsigned long end = now(); if (frame == 31) { //printf("set start to 1\n"); start_huh = 1; } if (end - lastRepaint > time/FPS) { if (frame >= 16) time = 90000000; //printf("frame is %d\n", frame); opening[frame] = loadbitmap(xinfo, filename[frame]); XCopyPlane(xinfo.display, opening[frame], xinfo.window, xinfo.gc[0], 0, 0, 800,600, (xinfo.current_w-800)/2, (xinfo.current_h-600)/2,1); std::string text1("PRESS 's' TO SKIP"); XDrawImageString( xinfo.display, xinfo.window, xinfo.gc[1], (xinfo.current_w-800)/2+350, (xinfo.current_h-600)/2+550, text1.c_str(), text1.length() ); frame++; lastRepaint = now(); } // give the system time to do other things if (XPending(xinfo.display) == 0) { usleep(time/FPS - (end - lastRepaint)); } } //end while }
void GraphicTestWindow::onPaint(int width, int height) { glClearColor(1.0f, 1.0f, 1.0f, 1.0f); _image.setTextureCoordinate(1, 3); _image.setSize(_image.originalSize()); _image.draw(); _rect.setColor(QColor(0, 255, 0)); _rect.setRect(50, 100, 500, 75); _rect.draw(); _rect.setColor(QColor(0, 255, 255)); _rect.setRect(50, 175, 500, 25); _rect.draw(); int textCount = 1; int quadCount = 1; QString textContent("Change the text from the settings"); if(_settings) { quadCount = _settings->quadCount(); textCount = _settings->textCount(); textContent = _settings->textContent(); } for(int i = 0; i < textCount; i++) { PhGraphicText text1(&_font1, textContent); text1.setRect(i % 200, i / 200, 500, 100); text1.setColor(QColor(128, 255, 0)); text1.setZ(5); text1.draw(); } _font1.setFontFile(_settings->font1File()); _font1.select(); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glColor3f(0, 0, 1); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_QUADS); //Begining the cube's drawing { for(int i = 0; i < quadCount; i++) { glTexCoord3f(0, 0, 1); glVertex3i(0, 0, 0); glTexCoord3f(1, 0, 1); glVertex3i(width, 0, 0); glTexCoord3f(1, 1, 1); glVertex3i(width, height, 0); glTexCoord3f(0, 1, 1); glVertex3i(0, height, 0); } } glEnd(); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); // _text.setX(_text.getX() + 4); // if(_text.getX() > this.width()) // _text.setX(0); // if((_text.getX()+_text.getWidth()) < 0) // _text.setX(this.width()); PhGraphicSolidRect rect3(0, 800, 400, 300); rect3.setColor(Qt::blue); rect3.draw(); PhGraphicLoop vLoop; vLoop.setPosition(100, 500, 3); vLoop.setSize(220, 200); vLoop.setThickness(30); vLoop.setCrossSize(100); vLoop.setColor(QColor(255, 0, 255)); vLoop.draw(); PhGraphicLoop hLoop; hLoop.setHorizontalLoop(true); hLoop.setPosition(0, 800, 3); hLoop.setSize(300, 50); hLoop.setThickness(20); hLoop.setCrossSize(60); hLoop.setColor(QColor(255, 0, 255)); hLoop.draw(); //_yuvRect.draw(); PhGraphicDisc disc(300, 300, 100); disc.setColor(Qt::yellow); disc.draw(); for (int i = 0; i < 5; ++i) { PhGraphicDashedLine line(i, 0, 50*i, 300, 30); line.setColor(Qt::green); line.setZ(4); line.draw(); } PhGraphicArrow arrow1(PhGraphicArrow::DownLeftToUpRight, 150, 250, 200, 100); arrow1.setColor(Qt::red); arrow1.setZ(5); arrow1.draw(); PhGraphicArrow arrow2(PhGraphicArrow::UpLefToDownRight, 150, 400, 200, 100); arrow2.setColor(Qt::red); arrow2.setZ(5); arrow2.draw(); _yuvRect.draw(); _rgbRect.draw(); _font2.setFontFile(_settings->font2File()); _font2.select(); PhGraphicText text2(&_font2, "eéaàiîoô"); int textWidth = 500; text2.setRect(_x, 300, textWidth, 100); text2.setColor(QColor(255, 0, 0)); text2.setZ(1); text2.draw(); _x += 4; if(_x > width) _x = -textWidth; }
int main() { // // We start with the 'demoStart' todo list. Process it. And // should hopefully end up with the todo list as illustrated. // const char* demoStart = "<?xml version=\"1.0\" standalone='no' >\n" "<!-- Our to do list data -->" "<ToDo>\n" "<!-- Do I need a secure PDA? -->\n" "<Item priority=\"1\" distance='close'> Go to the <bold>Toy store!</bold></Item>" "<Item priority=\"2\" distance='none'> Do bills </Item>" "<Item priority=\"2\" distance='far & back'> Look for Evil Dinosaurs! </Item>" "</ToDo>"; { #ifdef TIXML_USE_STL // What the todo list should look like after processing. // In stream (no formatting) representation. const char* demoEnd = "<?xml version=\"1.0\" standalone=\"no\" ?>" "<!-- Our to do list data -->" "<ToDo>" "<!-- Do I need a secure PDA? -->" "<Item priority=\"2\" distance=\"close\">Go to the" "<bold>Toy store!" "</bold>" "</Item>" "<Item priority=\"1\" distance=\"far\">Talk to:" "<Meeting where=\"School\">" "<Attendee name=\"Marple\" position=\"teacher\" />" "<Attendee name=\"Voel\" position=\"counselor\" />" "</Meeting>" "<Meeting where=\"Lunch\" />" "</Item>" "<Item priority=\"2\" distance=\"here\">Do bills" "</Item>" "</ToDo>"; #endif // The example parses from the character string (above): #if defined( WIN32 ) && defined( TUNE ) _CrtMemCheckpoint( &startMemState ); #endif { // Write to a file and read it back, to check file I/O. TiXmlDocument doc( "demotest.xml" ); doc.Parse( demoStart ); if ( doc.Error() ) { printf( "Error in %s: %s\n", doc.Value(), doc.ErrorDesc() ); exit( 1 ); } doc.SaveFile(); } TiXmlDocument doc( "demotest.xml" ); bool loadOkay = doc.LoadFile(); if ( !loadOkay ) { printf( "Could not load test file 'demotest.xml'. Error='%s'. Exiting.\n", doc.ErrorDesc() ); exit( 1 ); } printf( "** Demo doc read from disk: ** \n\n" ); printf( "** Printing via doc.Print **\n" ); doc.Print( stdout ); { printf( "** Printing via TiXmlPrinter **\n" ); TiXmlPrinter printer; doc.Accept( &printer ); fprintf( stdout, "%s", printer.CStr() ); } #ifdef TIXML_USE_STL { printf( "** Printing via operator<< **\n" ); std::cout << doc; } #endif TiXmlNode* node = 0; TiXmlElement* todoElement = 0; TiXmlElement* itemElement = 0; // -------------------------------------------------------- // An example of changing existing attributes, and removing // an element from the document. // -------------------------------------------------------- // Get the "ToDo" element. // It is a child of the document, and can be selected by name. node = doc.FirstChild( "ToDo" ); assert( node ); todoElement = node->ToElement(); assert( todoElement ); // Going to the toy store is now our second priority... // So set the "priority" attribute of the first item in the list. node = todoElement->FirstChildElement(); // This skips the "PDA" comment. assert( node ); itemElement = node->ToElement(); assert( itemElement ); itemElement->SetAttribute( "priority", 2 ); // Change the distance to "doing bills" from // "none" to "here". It's the next sibling element. itemElement = itemElement->NextSiblingElement(); assert( itemElement ); itemElement->SetAttribute( "distance", "here" ); // Remove the "Look for Evil Dinosaurs!" item. // It is 1 more sibling away. We ask the parent to remove // a particular child. itemElement = itemElement->NextSiblingElement(); todoElement->RemoveChild( itemElement ); itemElement = 0; // -------------------------------------------------------- // What follows is an example of created elements and text // nodes and adding them to the document. // -------------------------------------------------------- // Add some meetings. TiXmlElement item( "Item" ); item.SetAttribute( "priority", "1" ); item.SetAttribute( "distance", "far" ); TiXmlText text( "Talk to:" ); TiXmlElement meeting1( "Meeting" ); meeting1.SetAttribute( "where", "School" ); TiXmlElement meeting2( "Meeting" ); meeting2.SetAttribute( "where", "Lunch" ); TiXmlElement attendee1( "Attendee" ); attendee1.SetAttribute( "name", "Marple" ); attendee1.SetAttribute( "position", "teacher" ); TiXmlElement attendee2( "Attendee" ); attendee2.SetAttribute( "name", "Voel" ); attendee2.SetAttribute( "position", "counselor" ); // Assemble the nodes we've created: meeting1.InsertEndChild( attendee1 ); meeting1.InsertEndChild( attendee2 ); item.InsertEndChild( text ); item.InsertEndChild( meeting1 ); item.InsertEndChild( meeting2 ); // And add the node to the existing list after the first child. node = todoElement->FirstChild( "Item" ); assert( node ); itemElement = node->ToElement(); assert( itemElement ); todoElement->InsertAfterChild( itemElement, item ); printf( "\n** Demo doc processed: ** \n\n" ); doc.Print( stdout ); #ifdef TIXML_USE_STL printf( "** Demo doc processed to stream: ** \n\n" ); cout << doc << endl << endl; #endif // -------------------------------------------------------- // Different tests...do we have what we expect? // -------------------------------------------------------- int count = 0; TiXmlElement* element; ////////////////////////////////////////////////////// #ifdef TIXML_USE_STL cout << "** Basic structure. **\n"; ostringstream outputStream( ostringstream::out ); outputStream << doc; XmlTest( "Output stream correct.", string( demoEnd ).c_str(), outputStream.str().c_str(), true ); #endif node = doc.RootElement(); assert( node ); XmlTest( "Root element exists.", true, ( node != 0 && node->ToElement() ) ); XmlTest ( "Root element value is 'ToDo'.", "ToDo", node->Value()); node = node->FirstChild(); XmlTest( "First child exists & is a comment.", true, ( node != 0 && node->ToComment() ) ); node = node->NextSibling(); XmlTest( "Sibling element exists & is an element.", true, ( node != 0 && node->ToElement() ) ); XmlTest ( "Value is 'Item'.", "Item", node->Value() ); node = node->FirstChild(); XmlTest ( "First child exists.", true, ( node != 0 && node->ToText() ) ); XmlTest ( "Value is 'Go to the'.", "Go to the", node->Value() ); ////////////////////////////////////////////////////// printf ("\n** Iterators. **\n"); // Walk all the top level nodes of the document. count = 0; for( node = doc.FirstChild(); node; node = node->NextSibling() ) { count++; } XmlTest( "Top level nodes, using First / Next.", 3, count ); count = 0; for( node = doc.LastChild(); node; node = node->PreviousSibling() ) { count++; } XmlTest( "Top level nodes, using Last / Previous.", 3, count ); // Walk all the top level nodes of the document, // using a different syntax. count = 0; for( node = doc.IterateChildren( 0 ); node; node = doc.IterateChildren( node ) ) { count++; } XmlTest( "Top level nodes, using IterateChildren.", 3, count ); // Walk all the elements in a node. count = 0; for( element = todoElement->FirstChildElement(); element; element = element->NextSiblingElement() ) { count++; } XmlTest( "Children of the 'ToDo' element, using First / Next.", 3, count ); // Walk all the elements in a node by value. count = 0; for( node = todoElement->FirstChild( "Item" ); node; node = node->NextSibling( "Item" ) ) { count++; } XmlTest( "'Item' children of the 'ToDo' element, using First/Next.", 3, count ); count = 0; for( node = todoElement->LastChild( "Item" ); node; node = node->PreviousSibling( "Item" ) ) { count++; } XmlTest( "'Item' children of the 'ToDo' element, using Last/Previous.", 3, count ); #ifdef TIXML_USE_STL { cout << "\n** Parsing. **\n"; istringstream parse0( "<Element0 attribute0='foo0' attribute1= noquotes attribute2 = '>' />" ); TiXmlElement element0( "default" ); parse0 >> element0; XmlTest ( "Element parsed, value is 'Element0'.", "Element0", element0.Value() ); XmlTest ( "Reads attribute 'attribute0=\"foo0\"'.", "foo0", element0.Attribute( "attribute0" )); XmlTest ( "Reads incorrectly formatted 'attribute1=noquotes'.", "noquotes", element0.Attribute( "attribute1" ) ); XmlTest ( "Read attribute with entity value '>'.", ">", element0.Attribute( "attribute2" ) ); } #endif { const char* error = "<?xml version=\"1.0\" standalone=\"no\" ?>\n" "<passages count=\"006\" formatversion=\"20020620\">\n" " <wrong error>\n" "</passages>"; TiXmlDocument docTest; docTest.Parse( error ); XmlTest( "Error row", docTest.ErrorRow(), 3 ); XmlTest( "Error column", docTest.ErrorCol(), 17 ); //printf( "error=%d id='%s' row %d col%d\n", (int) doc.Error(), doc.ErrorDesc(), doc.ErrorRow()+1, doc.ErrorCol() + 1 ); } #ifdef TIXML_USE_STL { ////////////////////////////////////////////////////// cout << "\n** Streaming. **\n"; // Round trip check: stream in, then stream back out to verify. The stream // out has already been checked, above. We use the output istringstream inputStringStream( outputStream.str() ); TiXmlDocument document0; inputStringStream >> document0; ostringstream outputStream0( ostringstream::out ); outputStream0 << document0; XmlTest( "Stream round trip correct.", string( demoEnd ).c_str(), outputStream0.str().c_str(), true ); std::string str; str << document0; XmlTest( "String printing correct.", string( demoEnd ).c_str(), str.c_str(), true ); } #endif } { const char* str = "<doc attr0='1' attr1='2.0' attr2='foo' />"; TiXmlDocument doc; doc.Parse( str ); TiXmlElement* ele = doc.FirstChildElement(); int iVal, result; double dVal; result = ele->QueryDoubleAttribute( "attr0", &dVal ); XmlTest( "Query attribute: int as double", result, TIXML_SUCCESS ); XmlTest( "Query attribute: int as double", (int)dVal, 1 ); result = ele->QueryDoubleAttribute( "attr1", &dVal ); XmlTest( "Query attribute: double as double", (int)dVal, 2 ); result = ele->QueryIntAttribute( "attr1", &iVal ); XmlTest( "Query attribute: double as int", result, TIXML_SUCCESS ); XmlTest( "Query attribute: double as int", iVal, 2 ); result = ele->QueryIntAttribute( "attr2", &iVal ); XmlTest( "Query attribute: not a number", result, TIXML_WRONG_TYPE ); result = ele->QueryIntAttribute( "bar", &iVal ); XmlTest( "Query attribute: does not exist", result, TIXML_NO_ATTRIBUTE ); } { const char* str = "<doc/>"; TiXmlDocument doc; doc.Parse( str ); TiXmlElement* ele = doc.FirstChildElement(); int iVal; double dVal; ele->SetAttribute( "str", "strValue" ); ele->SetAttribute( "int", 1 ); ele->SetDoubleAttribute( "double", -1.0 ); const char* cStr = ele->Attribute( "str" ); ele->QueryIntAttribute( "int", &iVal ); ele->QueryDoubleAttribute( "double", &dVal ); XmlTest( "Attribute round trip. c-string.", "strValue", cStr ); XmlTest( "Attribute round trip. int.", 1, iVal ); XmlTest( "Attribute round trip. double.", -1, (int)dVal ); } { const char* str = "\t<?xml version=\"1.0\" standalone=\"no\" ?>\t<room doors='2'>\n" "</room>"; TiXmlDocument doc; doc.SetTabSize( 8 ); doc.Parse( str ); TiXmlHandle docHandle( &doc ); TiXmlHandle roomHandle = docHandle.FirstChildElement( "room" ); assert( docHandle.Node() ); assert( roomHandle.Element() ); TiXmlElement* room = roomHandle.Element(); assert( room ); TiXmlAttribute* doors = room->FirstAttribute(); assert( doors ); XmlTest( "Location tracking: Tab 8: room row", room->Row(), 1 ); XmlTest( "Location tracking: Tab 8: room col", room->Column(), 49 ); XmlTest( "Location tracking: Tab 8: doors row", doors->Row(), 1 ); XmlTest( "Location tracking: Tab 8: doors col", doors->Column(), 55 ); } { const char* str = "\t<?xml version=\"1.0\" standalone=\"no\" ?>\t<room doors='2'>\n" " <!-- Silly example -->\n" " <door wall='north'>A great door!</door>\n" "\t<door wall='east'/>" "</room>"; TiXmlDocument doc; doc.Parse( str ); TiXmlHandle docHandle( &doc ); TiXmlHandle roomHandle = docHandle.FirstChildElement( "room" ); TiXmlHandle commentHandle = docHandle.FirstChildElement( "room" ).FirstChild(); TiXmlHandle textHandle = docHandle.FirstChildElement( "room" ).ChildElement( "door", 0 ).FirstChild(); TiXmlHandle door0Handle = docHandle.FirstChildElement( "room" ).ChildElement( 0 ); TiXmlHandle door1Handle = docHandle.FirstChildElement( "room" ).ChildElement( 1 ); assert( docHandle.Node() ); assert( roomHandle.Element() ); assert( commentHandle.Node() ); assert( textHandle.Text() ); assert( door0Handle.Element() ); assert( door1Handle.Element() ); TiXmlDeclaration* declaration = doc.FirstChild()->ToDeclaration(); assert( declaration ); TiXmlElement* room = roomHandle.Element(); assert( room ); TiXmlAttribute* doors = room->FirstAttribute(); assert( doors ); TiXmlText* text = textHandle.Text(); TiXmlComment* comment = commentHandle.Node()->ToComment(); assert( comment ); TiXmlElement* door0 = door0Handle.Element(); TiXmlElement* door1 = door1Handle.Element(); XmlTest( "Location tracking: Declaration row", declaration->Row(), 1 ); XmlTest( "Location tracking: Declaration col", declaration->Column(), 5 ); XmlTest( "Location tracking: room row", room->Row(), 1 ); XmlTest( "Location tracking: room col", room->Column(), 45 ); XmlTest( "Location tracking: doors row", doors->Row(), 1 ); XmlTest( "Location tracking: doors col", doors->Column(), 51 ); XmlTest( "Location tracking: Comment row", comment->Row(), 2 ); XmlTest( "Location tracking: Comment col", comment->Column(), 3 ); XmlTest( "Location tracking: text row", text->Row(), 3 ); XmlTest( "Location tracking: text col", text->Column(), 24 ); XmlTest( "Location tracking: door0 row", door0->Row(), 3 ); XmlTest( "Location tracking: door0 col", door0->Column(), 5 ); XmlTest( "Location tracking: door1 row", door1->Row(), 4 ); XmlTest( "Location tracking: door1 col", door1->Column(), 5 ); } // -------------------------------------------------------- // UTF-8 testing. It is important to test: // 1. Making sure name, value, and text read correctly // 2. Row, Col functionality // 3. Correct output // -------------------------------------------------------- printf ("\n** UTF-8 **\n"); { TiXmlDocument doc( "utf8test.xml" ); doc.LoadFile(); if ( doc.Error() && doc.ErrorId() == TiXmlBase::TIXML_ERROR_OPENING_FILE ) { printf( "WARNING: File 'utf8test.xml' not found.\n" "(Are you running the test from the wrong directory?)\n" "Could not test UTF-8 functionality.\n" ); } else { TiXmlHandle docH( &doc ); // Get the attribute "value" from the "Russian" element and check it. TiXmlElement* element = docH.FirstChildElement( "document" ).FirstChildElement( "Russian" ).Element(); const unsigned char correctValue[] = { 0xd1U, 0x86U, 0xd0U, 0xb5U, 0xd0U, 0xbdU, 0xd0U, 0xbdU, 0xd0U, 0xbeU, 0xd1U, 0x81U, 0xd1U, 0x82U, 0xd1U, 0x8cU, 0 }; XmlTest( "UTF-8: Russian value.", (const char*)correctValue, element->Attribute( "value" ), true ); XmlTest( "UTF-8: Russian value row.", 4, element->Row() ); XmlTest( "UTF-8: Russian value column.", 5, element->Column() ); const unsigned char russianElementName[] = { 0xd0U, 0xa0U, 0xd1U, 0x83U, 0xd1U, 0x81U, 0xd1U, 0x81U, 0xd0U, 0xbaU, 0xd0U, 0xb8U, 0xd0U, 0xb9U, 0 }; const char russianText[] = "<\xD0\xB8\xD0\xBC\xD0\xB5\xD0\xB5\xD1\x82>"; TiXmlText* text = docH.FirstChildElement( "document" ).FirstChildElement( (const char*) russianElementName ).Child( 0 ).Text(); XmlTest( "UTF-8: Browsing russian element name.", russianText, text->Value(), true ); XmlTest( "UTF-8: Russian element name row.", 7, text->Row() ); XmlTest( "UTF-8: Russian element name column.", 47, text->Column() ); TiXmlDeclaration* dec = docH.Child( 0 ).Node()->ToDeclaration(); XmlTest( "UTF-8: Declaration column.", 1, dec->Column() ); XmlTest( "UTF-8: Document column.", 1, doc.Column() ); // Now try for a round trip. doc.SaveFile( "utf8testout.xml" ); // Check the round trip. char savedBuf[256]; char verifyBuf[256]; int okay = 1; FILE* saved = fopen( "data/utf8testout.xml", "r" ); FILE* verify = fopen( "data/utf8testverify.xml", "r" ); //bool firstLineBOM=true; if ( saved && verify ) { while ( fgets( verifyBuf, 256, verify ) ) { fgets( savedBuf, 256, saved ); NullLineEndings( verifyBuf ); NullLineEndings( savedBuf ); if ( /*!firstLineBOM && */ strcmp( verifyBuf, savedBuf ) ) { printf( "verify:%s<\n", verifyBuf ); printf( "saved :%s<\n", savedBuf ); okay = 0; break; } //firstLineBOM = false; } } if ( saved ) fclose( saved ); if ( verify ) fclose( verify ); XmlTest( "UTF-8: Verified multi-language round trip.", 1, okay ); // On most Western machines, this is an element that contains // the word "resume" with the correct accents, in a latin encoding. // It will be something else completely on non-wester machines, // which is why TinyXml is switching to UTF-8. const char latin[] = "<element>r\x82sum\x82</element>"; TiXmlDocument latinDoc; latinDoc.Parse( latin, 0, TIXML_ENCODING_LEGACY ); text = latinDoc.FirstChildElement()->FirstChild()->ToText(); XmlTest( "Legacy encoding: Verify text element.", "r\x82sum\x82", text->Value() ); } } ////////////////////// // Copy and assignment ////////////////////// printf ("\n** Copy and Assignment **\n"); { TiXmlElement element( "foo" ); element.Parse( "<element name='value' />", 0, TIXML_ENCODING_UNKNOWN ); TiXmlElement elementCopy( element ); TiXmlElement elementAssign( "foo" ); elementAssign.Parse( "<incorrect foo='bar'/>", 0, TIXML_ENCODING_UNKNOWN ); elementAssign = element; XmlTest( "Copy/Assign: element copy #1.", "element", elementCopy.Value() ); XmlTest( "Copy/Assign: element copy #2.", "value", elementCopy.Attribute( "name" ) ); XmlTest( "Copy/Assign: element assign #1.", "element", elementAssign.Value() ); XmlTest( "Copy/Assign: element assign #2.", "value", elementAssign.Attribute( "name" ) ); XmlTest( "Copy/Assign: element assign #3.", true, ( 0 == elementAssign.Attribute( "foo" )) ); TiXmlComment comment; comment.Parse( "<!--comment-->", 0, TIXML_ENCODING_UNKNOWN ); TiXmlComment commentCopy( comment ); TiXmlComment commentAssign; commentAssign = commentCopy; XmlTest( "Copy/Assign: comment copy.", "comment", commentCopy.Value() ); XmlTest( "Copy/Assign: comment assign.", "comment", commentAssign.Value() ); TiXmlUnknown unknown; unknown.Parse( "<[unknown]>", 0, TIXML_ENCODING_UNKNOWN ); TiXmlUnknown unknownCopy( unknown ); TiXmlUnknown unknownAssign; unknownAssign.Parse( "incorrect", 0, TIXML_ENCODING_UNKNOWN ); unknownAssign = unknownCopy; XmlTest( "Copy/Assign: unknown copy.", "[unknown]", unknownCopy.Value() ); XmlTest( "Copy/Assign: unknown assign.", "[unknown]", unknownAssign.Value() ); TiXmlText text( "TextNode" ); TiXmlText textCopy( text ); TiXmlText textAssign( "incorrect" ); textAssign = text; XmlTest( "Copy/Assign: text copy.", "TextNode", textCopy.Value() ); XmlTest( "Copy/Assign: text assign.", "TextNode", textAssign.Value() ); TiXmlDeclaration dec; dec.Parse( "<?xml version='1.0' encoding='UTF-8'?>", 0, TIXML_ENCODING_UNKNOWN ); TiXmlDeclaration decCopy( dec ); TiXmlDeclaration decAssign; decAssign = dec; XmlTest( "Copy/Assign: declaration copy.", "UTF-8", decCopy.Encoding() ); XmlTest( "Copy/Assign: text assign.", "UTF-8", decAssign.Encoding() ); TiXmlDocument doc; elementCopy.InsertEndChild( textCopy ); doc.InsertEndChild( decAssign ); doc.InsertEndChild( elementCopy ); doc.InsertEndChild( unknownAssign ); TiXmlDocument docCopy( doc ); TiXmlDocument docAssign; docAssign = docCopy; #ifdef TIXML_USE_STL std::string original, copy, assign; original << doc; copy << docCopy; assign << docAssign; XmlTest( "Copy/Assign: document copy.", original.c_str(), copy.c_str(), true ); XmlTest( "Copy/Assign: document assign.", original.c_str(), assign.c_str(), true ); #endif } ////////////////////////////////////////////////////// #ifdef TIXML_USE_STL printf ("\n** Parsing, no Condense Whitespace **\n"); TiXmlBase::SetCondenseWhiteSpace( false ); { istringstream parse1( "<start>This is \ntext</start>" ); TiXmlElement text1( "text" ); parse1 >> text1; XmlTest ( "Condense white space OFF.", "This is \ntext", text1.FirstChild()->Value(), true ); } TiXmlBase::SetCondenseWhiteSpace( true ); #endif ////////////////////////////////////////////////////// // GetText(); { const char* str = "<foo>This is text</foo>"; TiXmlDocument doc; doc.Parse( str ); const TiXmlElement* element = doc.RootElement(); XmlTest( "GetText() normal use.", "This is text", element->GetText() ); str = "<foo><b>This is text</b></foo>"; doc.Clear(); doc.Parse( str ); element = doc.RootElement(); XmlTest( "GetText() contained element.", element->GetText() == 0, true ); str = "<foo>This is <b>text</b></foo>"; doc.Clear(); TiXmlBase::SetCondenseWhiteSpace( false ); doc.Parse( str ); TiXmlBase::SetCondenseWhiteSpace( true ); element = doc.RootElement(); XmlTest( "GetText() partial.", "This is ", element->GetText() ); } ////////////////////////////////////////////////////// // CDATA { const char* str = "<xmlElement>" "<![CDATA[" "I am > the rules!\n" "...since I make symbolic puns" "]]>" "</xmlElement>"; TiXmlDocument doc; doc.Parse( str ); doc.Print(); XmlTest( "CDATA parse.", doc.FirstChildElement()->FirstChild()->Value(), "I am > the rules!\n...since I make symbolic puns", true ); #ifdef TIXML_USE_STL //cout << doc << '\n'; doc.Clear(); istringstream parse0( str ); parse0 >> doc; //cout << doc << '\n'; XmlTest( "CDATA stream.", doc.FirstChildElement()->FirstChild()->Value(), "I am > the rules!\n...since I make symbolic puns", true ); #endif TiXmlDocument doc1 = doc; //doc.Print(); XmlTest( "CDATA copy.", doc1.FirstChildElement()->FirstChild()->Value(), "I am > the rules!\n...since I make symbolic puns", true ); } { // [ 1482728 ] Wrong wide char parsing char buf[256]; buf[255] = 0; for( int i=0; i<255; ++i ) { buf[i] = (char)((i>=32) ? i : 32); } TIXML_STRING str( "<xmlElement><![CDATA[" ); str += buf; str += "]]></xmlElement>"; TiXmlDocument doc; doc.Parse( str.c_str() ); TiXmlPrinter printer; printer.SetStreamPrinting(); doc.Accept( &printer ); XmlTest( "CDATA with all bytes #1.", str.c_str(), printer.CStr(), true ); #ifdef TIXML_USE_STL doc.Clear(); istringstream iss( printer.Str() ); iss >> doc; std::string out; out << doc; XmlTest( "CDATA with all bytes #2.", out.c_str(), printer.CStr(), true ); #endif } { // [ 1480107 ] Bug-fix for STL-streaming of CDATA that contains tags // CDATA streaming had a couple of bugs, that this tests for. const char* str = "<xmlElement>" "<![CDATA[" "<b>I am > the rules!</b>\n" "...since I make symbolic puns" "]]>" "</xmlElement>"; TiXmlDocument doc; doc.Parse( str ); doc.Print(); XmlTest( "CDATA parse. [ 1480107 ]", doc.FirstChildElement()->FirstChild()->Value(), "<b>I am > the rules!</b>\n...since I make symbolic puns", true ); #ifdef TIXML_USE_STL doc.Clear(); istringstream parse0( str ); parse0 >> doc; XmlTest( "CDATA stream. [ 1480107 ]", doc.FirstChildElement()->FirstChild()->Value(), "<b>I am > the rules!</b>\n...since I make symbolic puns", true ); #endif TiXmlDocument doc1 = doc; //doc.Print(); XmlTest( "CDATA copy. [ 1480107 ]", doc1.FirstChildElement()->FirstChild()->Value(), "<b>I am > the rules!</b>\n...since I make symbolic puns", true ); } ////////////////////////////////////////////////////// // Visit() ////////////////////////////////////////////////////// printf( "\n** Fuzzing... **\n" ); const int FUZZ_ITERATION = 300; // The only goal is not to crash on bad input. int len = (int) strlen( demoStart ); for( int i=0; i<FUZZ_ITERATION; ++i ) { char* demoCopy = new char[ len+1 ]; strcpy( demoCopy, demoStart ); demoCopy[ i%len ] = (char)((i+1)*3); demoCopy[ (i*7)%len ] = '>'; demoCopy[ (i*11)%len ] = '<'; TiXmlDocument xml; xml.Parse( demoCopy ); delete [] demoCopy; } printf( "** Fuzzing Complete. **\n" ); ////////////////////////////////////////////////////// printf ("\n** Bug regression tests **\n"); // InsertBeforeChild and InsertAfterChild causes crash. { TiXmlElement parent( "Parent" ); TiXmlElement childText0( "childText0" ); TiXmlElement childText1( "childText1" ); TiXmlNode* childNode0 = parent.InsertEndChild( childText0 ); TiXmlNode* childNode1 = parent.InsertBeforeChild( childNode0, childText1 ); XmlTest( "Test InsertBeforeChild on empty node.", ( childNode1 == parent.FirstChild() ), true ); } { // InsertBeforeChild and InsertAfterChild causes crash. TiXmlElement parent( "Parent" ); TiXmlElement childText0( "childText0" ); TiXmlElement childText1( "childText1" ); TiXmlNode* childNode0 = parent.InsertEndChild( childText0 ); TiXmlNode* childNode1 = parent.InsertAfterChild( childNode0, childText1 ); XmlTest( "Test InsertAfterChild on empty node. ", ( childNode1 == parent.LastChild() ), true ); } // Reports of missing constructors, irregular string problems. { // Missing constructor implementation. No test -- just compiles. TiXmlText text( "Missing" ); #ifdef TIXML_USE_STL // Missing implementation: TiXmlDocument doc; string name = "missing"; doc.LoadFile( name ); TiXmlText textSTL( name ); #else // verifying some basic string functions: TiXmlString a; TiXmlString b( "Hello" ); TiXmlString c( "ooga" ); c = " World!"; a = b; a += c; a = a; XmlTest( "Basic TiXmlString test. ", "Hello World!", a.c_str() ); #endif } // Long filenames crashing STL version { TiXmlDocument doc( "midsummerNightsDreamWithAVeryLongFilenameToConfuseTheStringHandlingRoutines.xml" ); bool loadOkay = doc.LoadFile(); loadOkay = true; // get rid of compiler warning. // Won't pass on non-dev systems. Just a "no crash" check. //XmlTest( "Long filename. ", true, loadOkay ); } { // Entities not being written correctly. // From Lynn Allen const char* passages = "<?xml version=\"1.0\" standalone=\"no\" ?>" "<passages count=\"006\" formatversion=\"20020620\">" "<psg context=\"Line 5 has "quotation marks" and 'apostrophe marks'." " It also has <, >, and &, as well as a fake copyright ©.\"> </psg>" "</passages>"; TiXmlDocument doc( "passages.xml" ); doc.Parse( passages ); TiXmlElement* psg = doc.RootElement()->FirstChildElement(); const char* context = psg->Attribute( "context" ); const char* expected = "Line 5 has \"quotation marks\" and 'apostrophe marks'. It also has <, >, and &, as well as a fake copyright \xC2\xA9."; XmlTest( "Entity transformation: read. ", expected, context, true ); FILE* textfile = fopen( "textfile.txt", "w" ); if ( textfile ) { psg->Print( textfile, 0 ); fclose( textfile ); } textfile = fopen( "textfile.txt", "r" ); assert( textfile ); if ( textfile ) { char buf[ 1024 ]; fgets( buf, 1024, textfile ); XmlTest( "Entity transformation: write. ", "<psg context=\'Line 5 has "quotation marks" and 'apostrophe marks'." " It also has <, >, and &, as well as a fake copyright \xC2\xA9.' />", buf, true ); } fclose( textfile ); } { FILE* textfile = fopen( "test5.xml", "w" ); if ( textfile ) { fputs("<?xml version='1.0'?><a.elem xmi.version='2.0'/>", textfile); fclose(textfile); TiXmlDocument doc; doc.LoadFile( "test5.xml" ); XmlTest( "dot in element attributes and names", doc.Error(), 0); } } { FILE* textfile = fopen( "test6.xml", "w" ); if ( textfile ) { fputs("<element><Name>1.1 Start easy ignore fin thickness
</Name></element>", textfile ); fclose(textfile); TiXmlDocument doc; bool result = doc.LoadFile( "test6.xml" ); XmlTest( "Entity with one digit.", result, true ); TiXmlText* text = doc.FirstChildElement()->FirstChildElement()->FirstChild()->ToText(); XmlTest( "Entity with one digit.", text->Value(), "1.1 Start easy ignore fin thickness\n" ); } } { // DOCTYPE not preserved (950171) // const char* doctype = "<?xml version=\"1.0\" ?>" "<!DOCTYPE PLAY SYSTEM 'play.dtd'>" "<!ELEMENT title (#PCDATA)>" "<!ELEMENT books (title,authors)>" "<element />"; TiXmlDocument doc; doc.Parse( doctype ); doc.SaveFile( "test7.xml" ); doc.Clear(); doc.LoadFile( "test7.xml" ); TiXmlHandle docH( &doc ); TiXmlUnknown* unknown = docH.Child( 1 ).Unknown(); XmlTest( "Correct value of unknown.", "!DOCTYPE PLAY SYSTEM 'play.dtd'", unknown->Value() ); #ifdef TIXML_USE_STL TiXmlNode* node = docH.Child( 2 ).Node(); std::string str; str << (*node); XmlTest( "Correct streaming of unknown.", "<!ELEMENT title (#PCDATA)>", str.c_str() ); #endif } { // [ 791411 ] Formatting bug // Comments do not stream out correctly. const char* doctype = "<!-- Somewhat<evil> -->"; TiXmlDocument doc; doc.Parse( doctype ); TiXmlHandle docH( &doc ); TiXmlComment* comment = docH.Child( 0 ).Node()->ToComment(); XmlTest( "Comment formatting.", " Somewhat<evil> ", comment->Value() ); #ifdef TIXML_USE_STL std::string str; str << (*comment); XmlTest( "Comment streaming.", "<!-- Somewhat<evil> -->", str.c_str() ); #endif } { // [ 870502 ] White space issues TiXmlDocument doc; TiXmlText* text; TiXmlHandle docH( &doc ); const char* doctype0 = "<element> This has leading and trailing space </element>"; const char* doctype1 = "<element>This has internal space</element>"; const char* doctype2 = "<element> This has leading, trailing, and internal space </element>"; TiXmlBase::SetCondenseWhiteSpace( false ); doc.Clear(); doc.Parse( doctype0 ); text = docH.FirstChildElement( "element" ).Child( 0 ).Text(); XmlTest( "White space kept.", " This has leading and trailing space ", text->Value() ); doc.Clear(); doc.Parse( doctype1 ); text = docH.FirstChildElement( "element" ).Child( 0 ).Text(); XmlTest( "White space kept.", "This has internal space", text->Value() ); doc.Clear(); doc.Parse( doctype2 ); text = docH.FirstChildElement( "element" ).Child( 0 ).Text(); XmlTest( "White space kept.", " This has leading, trailing, and internal space ", text->Value() ); TiXmlBase::SetCondenseWhiteSpace( true ); doc.Clear(); doc.Parse( doctype0 ); text = docH.FirstChildElement( "element" ).Child( 0 ).Text(); XmlTest( "White space condensed.", "This has leading and trailing space", text->Value() ); doc.Clear(); doc.Parse( doctype1 ); text = docH.FirstChildElement( "element" ).Child( 0 ).Text(); XmlTest( "White space condensed.", "This has internal space", text->Value() ); doc.Clear(); doc.Parse( doctype2 ); text = docH.FirstChildElement( "element" ).Child( 0 ).Text(); XmlTest( "White space condensed.", "This has leading, trailing, and internal space", text->Value() ); } { // Double attributes const char* doctype = "<element attr='red' attr='blue' />"; TiXmlDocument doc; doc.Parse( doctype ); XmlTest( "Parsing repeated attributes.", true, doc.Error() ); // is an error to tinyxml (didn't use to be, but caused issues) //XmlTest( "Parsing repeated attributes.", "blue", doc.FirstChildElement( "element" )->Attribute( "attr" ) ); } { // Embedded null in stream. const char* doctype = "<element att\0r='red' attr='blue' />"; TiXmlDocument doc; doc.Parse( doctype ); XmlTest( "Embedded null throws error.", true, doc.Error() ); #ifdef TIXML_USE_STL istringstream strm( doctype ); doc.Clear(); doc.ClearError(); strm >> doc; XmlTest( "Embedded null throws error.", true, doc.Error() ); #endif } { /** // Legacy mode test. (This test may only pass on a western system) const char* str = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" "<?" "C鰊t鋘t咪鳇闹?" "</?"; TiXmlDocument doc; doc.Parse( str ); TiXmlHandle docHandle( &doc ); TiXmlHandle aHandle = docHandle.FirstChildElement( "?" ); TiXmlHandle tHandle = aHandle.Child( 0 ); assert( aHandle.Element() ); assert( tHandle.Text() ); XmlTest( "ISO-8859-1 Parsing.", "C鰊t鋘t咪鳇闹?, tHandle.Text()->Value() "); } { // Empty documents should return TIXML_ERROR_PARSING_EMPTY, bug 1070717 const char* str = " "; TiXmlDocument doc; doc.Parse( str ); XmlTest( "Empty document error TIXML_ERROR_DOCUMENT_EMPTY", TiXmlBase::TIXML_ERROR_DOCUMENT_EMPTY, doc.ErrorId() ); } #ifndef TIXML_USE_STL { // String equality. [ 1006409 ] string operator==/!= no worky in all cases TiXmlString temp; XmlTest( "Empty tinyxml string compare equal", ( temp == "" ), true ); TiXmlString foo; TiXmlString bar( "" ); XmlTest( "Empty tinyxml string compare equal", ( foo == bar ), true ); } #endif { // Bug [ 1195696 ] from marlonism TiXmlBase::SetCondenseWhiteSpace(false); TiXmlDocument xml; xml.Parse("<text><break/>This hangs</text>"); XmlTest( "Test safe error return.", xml.Error(), false ); } { // Bug [ 1243992 ] - another infinite loop TiXmlDocument doc; doc.SetCondenseWhiteSpace(false); doc.Parse("<p><pb></pb>test</p>"); } { // Low entities TiXmlDocument xml; xml.Parse( "<test></test>" ); const char result[] = { 0x0e, 0 }; XmlTest( "Low entities.", xml.FirstChildElement()->GetText(), result ); xml.Print(); } { // Bug [ 1451649 ] Attribute values with trailing quotes not handled correctly TiXmlDocument xml; xml.Parse( "<foo attribute=bar\" />" ); XmlTest( "Throw error with bad end quotes.", xml.Error(), true ); } #ifdef TIXML_USE_STL { // Bug [ 1449463 ] Consider generic query TiXmlDocument xml; xml.Parse( "<foo bar='3' barStr='a string'/>" ); TiXmlElement* ele = xml.FirstChildElement(); double d; int i; float f; bool b; std::string str; XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &d ), TIXML_SUCCESS ); XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &i ), TIXML_SUCCESS ); XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &f ), TIXML_SUCCESS ); XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &b ), TIXML_WRONG_TYPE ); XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "nobar", &b ), TIXML_NO_ATTRIBUTE ); XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "barStr", &str ), TIXML_SUCCESS ); XmlTest( "QueryValueAttribute", (d==3.0), true ); XmlTest( "QueryValueAttribute", (i==3), true ); XmlTest( "QueryValueAttribute", (f==3.0f), true ); XmlTest( "QueryValueAttribute", (str==std::string( "a string" )), true ); } #endif #ifdef TIXML_USE_STL { // [ 1505267 ] redundant malloc in TiXmlElement::Attribute TiXmlDocument xml; xml.Parse( "<foo bar='3' />" ); TiXmlElement* ele = xml.FirstChildElement(); double d; int i; std::string bar = "bar"; const std::string* atrrib = ele->Attribute( bar ); ele->Attribute( bar, &d ); ele->Attribute( bar, &i ); XmlTest( "Attribute", atrrib->empty(), false ); XmlTest( "Attribute", (d==3.0), true ); XmlTest( "Attribute", (i==3), true ); } #endif { // [ 1356059 ] Allow TiXMLDocument to only be at the top level TiXmlDocument xml, xml2; xml.InsertEndChild( xml2 ); XmlTest( "Document only at top level.", xml.Error(), true ); XmlTest( "Document only at top level.", xml.ErrorId(), TiXmlBase::TIXML_ERROR_DOCUMENT_TOP_ONLY ); } { // [ 1663758 ] Failure to report error on bad XML TiXmlDocument xml; xml.Parse("<x>"); XmlTest("Missing end tag at end of input", xml.Error(), true); xml.Parse("<x> "); XmlTest("Missing end tag with trailing whitespace", xml.Error(), true); } { // [ 1635701 ] fail to parse files with a tag separated into two lines // I'm not sure this is a bug. Marked 'pending' for feedback. TiXmlDocument xml; xml.Parse( "<title><p>text</p\n><title>" ); //xml.Print(); //XmlTest( "Tag split by newline", xml.Error(), false ); } #ifdef TIXML_USE_STL { // [ 1475201 ] TinyXML parses entities in comments TiXmlDocument xml; istringstream parse1( "<!-- declarations for <head> & <body> -->" "<!-- far & away -->" ); parse1 >> xml; TiXmlNode* e0 = xml.FirstChild(); TiXmlNode* e1 = e0->NextSibling(); TiXmlComment* c0 = e0->ToComment(); TiXmlComment* c1 = e1->ToComment(); XmlTest( "Comments ignore entities.", " declarations for <head> & <body> ", c0->Value(), true ); XmlTest( "Comments ignore entities.", " far & away ", c1->Value(), true ); } #endif { // [ 1475201 ] TinyXML parses entities in comments TiXmlDocument xml; xml.Parse("<!-- declarations for <head> & <body> -->" "<!-- far & away -->" ); TiXmlNode* e0 = xml.FirstChild(); TiXmlNode* e1 = e0->NextSibling(); TiXmlComment* c0 = e0->ToComment(); TiXmlComment* c1 = e1->ToComment(); XmlTest( "Comments ignore entities.", " declarations for <head> & <body> ", c0->Value(), true ); XmlTest( "Comments ignore entities.", " far & away ", c1->Value(), true ); } { TiXmlDocument xml; xml.Parse( "<Parent>" "<child1 att=''/>" "<!-- With this comment, child2 will not be parsed! -->" "<child2 att=''/>" "</Parent>" ); int count = 0; TiXmlNode* ele = 0; while ( (ele = xml.FirstChildElement( "Parent" )->IterateChildren( ele ) ) != 0 ) { ++count; } XmlTest( "Comments iterate correctly.", 3, count ); } { // trying to repro ]1874301]. If it doesn't go into an infinite loop, all is well. unsigned char buf[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?><feed><![CDATA[Test XMLblablablalblbl"; buf[60] = 239; buf[61] = 0; TiXmlDocument doc; doc.Parse( (const char*)buf); } { // bug 1827248 Error while parsing a little bit malformed file // Actually not malformed - should work. TiXmlDocument xml; xml.Parse( "<attributelist> </attributelist >" ); XmlTest( "Handle end tag whitespace", false, xml.Error() ); } { // This one must not result in an infinite loop TiXmlDocument xml; xml.Parse( "<infinite>loop" ); XmlTest( "Infinite loop test.", true, true ); } { // 1709904 - can not repro the crash { TiXmlDocument xml; xml.Parse( "<tag>/</tag>" ); XmlTest( "Odd XML parsing.", xml.FirstChild()->Value(), "tag" ); } /* Could not repro. { TiXmlDocument xml; xml.LoadFile( "EQUI_Inventory.xml" ); //XmlTest( "Odd XML parsing.", xml.FirstChildElement()->Value(), "XML" ); TiXmlPrinter printer; xml.Accept( &printer ); fprintf( stdout, "%s", printer.CStr() ); }*/ } /* 1417717 experiment { TiXmlDocument xml; xml.Parse("<text>Dan & Tracie</text>"); xml.Print(stdout); } { TiXmlDocument xml; xml.Parse("<text>Dan &foo; Tracie</text>"); xml.Print(stdout); } */ #if defined( WIN32 ) && defined( TUNE ) _CrtMemCheckpoint( &endMemState ); //_CrtMemDumpStatistics( &endMemState ); _CrtMemState diffMemState; _CrtMemDifference( &diffMemState, &startMemState, &endMemState ); _CrtMemDumpStatistics( &diffMemState ); #endif printf ("\nPass %d, Fail %d\n", gPass, gFail); return gFail; }
// Return true iff S1 is a prefix of S2 static bool is_prefix(const MString& m1, const MString& m2) { XmString s1 = m1.xmstring(); XmString s2 = m2.xmstring(); XmStringContext c1; XmStringContext c2; XmStringInitContext(&c1, s1); XmStringInitContext(&c2, s2); XmStringComponentType t1 = XmSTRING_COMPONENT_UNKNOWN; XmStringComponentType t2 = XmSTRING_COMPONENT_UNKNOWN; while (t1 != XmSTRING_COMPONENT_END && t2 != XmSTRING_COMPONENT_END) { char *s_text1 = 0; XmStringCharSet s_cs1 = 0; XmStringDirection d1 = XmSTRING_DIRECTION_DEFAULT; XmStringComponentType u1 = XmSTRING_COMPONENT_UNKNOWN; unsigned short ul1 = 0; unsigned char *s_uv1 = 0; t1 = XmStringGetNextComponent(c1, &s_text1, &s_cs1, &d1, &u1, &ul1, &s_uv1); char *s_text2 = 0; XmStringCharSet s_cs2 = 0; XmStringDirection d2 = XmSTRING_DIRECTION_DEFAULT; XmStringComponentType u2 = XmSTRING_COMPONENT_UNKNOWN; unsigned short ul2 = 0; unsigned char *s_uv2 = 0; t2 = XmStringGetNextComponent(c2, &s_text2, &s_cs2, &d2, &u2, &ul2, &s_uv2); // Upon EOF in LessTif 0.82, XmStringGetNextComponent() // returns XmSTRING_COMPONENT_UNKNOWN instead of // XmSTRING_COMPONENT_END. Work around this. if (t1 == XmSTRING_COMPONENT_UNKNOWN && s_uv1 == 0) t1 = XmSTRING_COMPONENT_END; if (t2 == XmSTRING_COMPONENT_UNKNOWN && s_uv2 == 0) t2 = XmSTRING_COMPONENT_END; // Place string values in strings string text1(s_text1 == 0 ? "" : s_text1); string text2(s_text2 == 0 ? "" : s_text2); string cs1(s_cs1 == 0 ? "" : s_cs1); string cs2(s_cs2 == 0 ? "" : s_cs2); string uv1; string uv2; if (s_uv1 != 0) uv1 = string((char *)s_uv1, ul1); if (s_uv2 != 0) uv2 = string((char *)s_uv2, ul2); // Free unused memory XtFree(s_text1); XtFree(s_text2); XtFree(s_cs1); XtFree(s_cs2); XtFree((char *)s_uv1); XtFree((char *)s_uv2); if (t1 != t2) { goto done; // Differing tags } switch (t1) { case XmSTRING_COMPONENT_CHARSET: { if (cs1.empty()) // In LessTif 0.82, XmStringGetNextComponent() cs1 = text1; // swaps CS and TEXT. Work around this. if (cs2.empty()) cs2 = text2; if (cs1 != cs2) goto done; // Differing character sets break; } case XmSTRING_COMPONENT_TEXT: #if XmVersion >= 1002 case XmSTRING_COMPONENT_LOCALE_TEXT: #endif #if XmVersion >= 2000 case XmSTRING_COMPONENT_WIDECHAR_TEXT: #endif { if (text1.empty()) // In LessTif 0.82, XmStringGetNextComponent() text1 = cs1; // swaps CS and TEXT. Work around this. if (text2.empty()) text2 = cs2; if (!text2.contains(text1, 0)) goto done; XmStringComponentType next2 = XmStringPeekNextComponent(c2); // In LessTif 0.82, XmStringPeekNextComponent() returns // XmSTRING_COMPONENT_UNKNOWN instead of // XmSTRING_COMPONENT_END. Work around this. if (next2 != XmSTRING_COMPONENT_END && next2 != XmSTRING_COMPONENT_UNKNOWN) goto done; break; } case XmSTRING_COMPONENT_DIRECTION: { if (d1 != d2) goto done; break; } case XmSTRING_COMPONENT_SEPARATOR: case XmSTRING_COMPONENT_END: { // These are the same by definition break; } case XmSTRING_COMPONENT_UNKNOWN: { if (uv1 != uv2) goto done; // Differing unknown tags break; } default: { break; // Skip everything else } } } done: XmStringFreeContext(c2); XmStringFreeContext(c1); return t1 == XmSTRING_COMPONENT_END; }
virtual void on_draw() { double ewidth = initial_width() / 2 - 10; double ecenter = initial_width() / 2; typedef agg::renderer_base<pixfmt> ren_base; pixfmt pixf(rbuf_window()); ren_base rb(pixf); agg::rgba8 color; rb.clear(agg::rgba(1, 1, 1)); g_ctrl.text_size(10.0, 12.0); agg::rasterizer_scanline_aa<> ras; agg::scanline_p8 sl; agg::render_ctrl(ras, sl, rb, g_ctrl); ras.gamma(g_ctrl); agg::ellipse ellipse; agg::conv_stroke<agg::ellipse> poly(ellipse); agg::conv_transform<agg::conv_stroke<agg::ellipse> > tpoly(poly, trans_affine_resizing()); color = agg::rgba8(0, 0, 0); ellipse.init(ecenter, 220, ewidth, 15, 100); poly.width(2.0); ras.add_path(tpoly, 0); agg::render_scanlines_aa_solid(ras, sl, rb, color); ellipse.init(ecenter, 220, 11, 11, 100); poly.width(2.0); ras.add_path(tpoly, 0); agg::render_scanlines_aa_solid(ras, sl, rb, color); color = agg::rgba8(127, 127, 127); ellipse.init(ecenter, 260, ewidth, 15, 100); poly.width(2.0); ras.add_path(tpoly, 0); agg::render_scanlines_aa_solid(ras, sl, rb, color); ellipse.init(ecenter, 260, 11, 11, 100); poly.width(2.0); ras.add_path(tpoly, 0); agg::render_scanlines_aa_solid(ras, sl, rb, color); color = agg::rgba8(192, 192, 192); ellipse.init(ecenter, 300, ewidth, 15, 100); poly.width(2.0); ras.add_path(tpoly, 0); agg::render_scanlines_aa_solid(ras, sl, rb, color); ellipse.init(ecenter, 300, 11, 11, 100); poly.width(2.0); ras.add_path(tpoly, 0); agg::render_scanlines_aa_solid(ras, sl, rb, color); color = agg::rgba(0.0, 0.0, 0.4); ellipse.init(ecenter, 340, ewidth, 15.5, 100); poly.width(1.0); ras.add_path(tpoly, 0); agg::render_scanlines_aa_solid(ras, sl, rb, color); ellipse.init(ecenter, 340, 10.5, 10.5, 100); poly.width(1.0); ras.add_path(tpoly, 0); agg::render_scanlines_aa_solid(ras, sl, rb, color); ellipse.init(ecenter, 380, ewidth, 15.5, 100); poly.width(0.4); ras.add_path(tpoly, 0); agg::render_scanlines_aa_solid(ras, sl, rb, color); ellipse.init(ecenter, 380, 10.5, 10.5, 100); poly.width(0.4); ras.add_path(tpoly, 0); agg::render_scanlines_aa_solid(ras, sl, rb, color); ellipse.init(ecenter, 420, ewidth, 15.5, 100); poly.width(0.1); ras.add_path(tpoly, 0); agg::render_scanlines_aa_solid(ras, sl, rb, color); ellipse.init(ecenter, 420, 10.5, 10.5, 100); poly.width(0.1); ras.add_path(tpoly, 0); agg::render_scanlines_aa_solid(ras, sl, rb, color); agg::trans_affine mtx; mtx *= agg::trans_affine_skewing(0.15, 0.0); mtx *= trans_affine_resizing(); agg::gsv_text text; agg::gsv_text_outline<agg::trans_affine> text1(text, mtx); text.text("Text 2345"); text.size(50, 20); text1.width(2.0); text.start_point(320, 10); color = agg::rgba(0.0, 0.5, 0.0); ras.add_path(text1, 0); agg::render_scanlines_aa_solid(ras, sl, rb, color); color = agg::rgba(0.5, 0.0, 0.0); agg::path_storage path; path.move_to(30, -1.0); path.line_to(60, 0.0); path.line_to(30, 1.0); path.move_to(27, -1.0); path.line_to(10, 0.0); path.line_to(27, 1.0); agg::conv_transform<agg::path_storage> trans(path, mtx); for(int i = 0; i < 35; i++) { mtx.reset(); mtx *= agg::trans_affine_rotation(double(i) / 35.0 * agg::pi * 2.0); mtx *= agg::trans_affine_translation(400, 130); mtx *= trans_affine_resizing(); ras.add_path(trans, 0); agg::render_scanlines_aa_solid(ras, sl, rb, color); } }
void PlotDummy( const TString &sim, UInt_t time, Int_t zoom=2, const TString &opt="") { PlasmaGlob::Initialize(); // Palettes! gROOT->Macro("PlasmaPalettes.C"); // More makeup gStyle->SetPadRightMargin(0.12); // Margin for palettes in 2D histos // Load PData PData *pData = PData::Get(sim.Data()); pData->LoadFileNames(time); if(!pData->IsInit()) return; // Get charge density histos Int_t index = 1; if(opt.Contains("beam")) index = 1; char hName[24]; sprintf(hName,"hDen_%i",index); TH2F *hDen2D = (TH2F*) gROOT->FindObject(hName); if(hDen2D) delete hDen2D; hDen2D = pData->GetCharge(index); hDen2D->SetName(hName); hDen2D->GetXaxis()->CenterTitle(); hDen2D->GetYaxis()->CenterTitle(); hDen2D->GetXaxis()->SetTitle("z [c/#omega_{p}]"); hDen2D->GetYaxis()->SetTitle("y [c/#omega_{p}]"); hDen2D->SetBit(kCanDelete); // Tunning the Histograms // --------------------- Float_t Time = hDen2D->GetXaxis()->GetXmin(); // Set the range of the histogram for maximum constrast Float_t density = 1; if(opt.Contains("units") && pData->GetPlasmaDensity()) density = 1e-15 * 1e-6 * pData->GetPlasmaDensity(); if(index==0) { Float_t Max = 1.1 * hDen2D->GetMaximum(); Float_t Base = density; Float_t Min = 2.* Base - Max; if(Max >= 2. * Base) { Min = 0; } else if(Max<1.0 * Base) { Max = 1.1 * Base; Min = 0.; } hDen2D->GetZaxis()->SetRangeUser(Min,Max); } // Zoom Float_t range = (hDen2D->GetYaxis()->GetXmax() - hDen2D->GetYaxis()->GetXmin())/zoom; Float_t midPoint = (hDen2D->GetYaxis()->GetXmax() + hDen2D->GetYaxis()->GetXmin())/2.; hDen2D->GetYaxis()->SetRangeUser(midPoint-range/2,midPoint+range/2); // Plotting // ----------------------------------------------- // Canvas setup TCanvas *C = new TCanvas("C","Charge density and Electric field",850,500); // Text objects TPaveText text1(0.6,0.94,0.88,1.0,"NDC"); PlasmaGlob::SetPaveStyle(&text1); text1.AddText("Charge density [a.u.]"); TPaveText textTime(0.7,0.82,0.85,0.88,"NDC"); PlasmaGlob::SetPaveStyle(&textTime); char ctext[128]; sprintf(ctext,"T = %5.1f [1/#omega_{p}]",Time); textTime.AddText(ctext); // Palettes!! // const Int_t electronNRGBs = 5; // const Int_t electronNCont = 64; // Double_t electronStops[electronNRGBs] = { 0.00, 0.10, 0.50, 0.95, 1.00}; // Double_t electronRed[electronNRGBs] = { 0.90, 0.52, 0.22, 0.39, 0.50}; // Double_t electronGreen[electronNRGBs] = { 0.90, 0.74, 0.34, 0.05, 0.00}; // Double_t electronBlue[electronNRGBs] = { 0.90, 0.80, 0.58, 0.33, 0.09}; // PPalette *electronPalette = new PPalette("electron"); // electronPalette->CreateGradientColorTable(electronNRGBs, electronStops, electronRed, electronGreen, electronBlue, electronNCont); // Actual Plotting! // ------------------------------------------------------------ // Output file TString fOutName = Form("./%s/Plots/Dummy/Dummy",sim.Data()); fOutName += Form("-%s_%i",sim.Data(),time); C->cd(0); C->cd(1); // <--- Top Plot gPad->SetFrameLineWidth(3); // if(index == 0) // plasmaPalette->cd(); // else PPalette * electronPalette = (PPalette*) gROOT->FindObject("electron"); electronPalette->cd(); hDen2D->Draw("colz"); // text1.Draw(); // textTime.Draw(); C->cd(); // Print to a file PlasmaGlob::imgconv(C,fOutName,opt); // --------------------------------------------------------- }