⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xpath_test.cpp

📁 Jabber code library, developed with c
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  // -------  name = "deepsearch && .. combined 2: //ggg/..";  result = aaa->findTagList( "//ggg/.." );  it = result.begin();  if( result.size() != 1 || (*it) != fff )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );//   // -------//   name = "select non-leaf elements: //..";//   result = aaa->findTagList( "//.." );//   it = result.begin();//   if( result.size() != 5 || (*it) != aaa || (*++it) != bbb ||//       (*++it) != hhh || (*++it) != ccc || (*++it) != fff )//   {//     ++fail;//     printResult( name, result );//     printf( "test '%s' failed\n", name.c_str() );//   }//   printf( "--------------------------------------------------------------\n" );  // -------  name = "deepsearch && .. combined 3: //ggg/../../bbb";  result = aaa->findTagList( "//ggg/../../bbb" );  it = result.begin();  if( result.size() != 1 || (*it) != bbb )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }  // -------  name = "deepsearch && .. combined 4: //ggg/../..//bbb";  result = aaa->findTagList( "//ggg/../..//bbb" );  it = result.begin();  if( result.size() != 3 || (*it) != bbb || (*++it) != jjj || (*++it) != iii )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }  // -------  name = "deepsearch && .. && * combined 1: //*/../..//bbb";  result = aaa->findTagList( "//*/../..//bbb" );  it = result.begin();  if( result.size() != 3 || (*it) != bbb || (*++it) != jjj || (*++it) != iii )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }  // -------  name = "deepsearch && .. && * combined 2: //*/*/..//*";  result = aaa->findTagList( "//*/*/..//*" );  it = result.begin();  if( result.size() != 9 || (*it) != bbb || (*++it) != hhh || (*++it) != jjj ||      (*++it) != iii || (*++it) != ccc || (*++it) != ddd || (*++it) != eee ||      (*++it) != fff || (*++it) != ggg )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }  // -------  name = "deepsearch: //bbb/hhh/bbb";  result = aaa->findTagList( "//bbb/hhh/bbb" );  it = result.begin();  if( result.size() != 1 || (*it) != jjj )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );  // -- ~simple paths --  // -- operators --  // ---- union ----  // -------  name = "union 1: //bbb|/aaa";  result = aaa->findTagList( "//bbb|/aaa" );  it = result.begin();  if( result.size() != 4 || (*it) != bbb || (*++it) != jjj || (*++it) != iii || (*++it) != aaa )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );  // -------  name = "union 1: //bbb|//bbb";  result = aaa->findTagList( "//bbb|//bbb" );  it = result.begin();  if( result.size() != 3 || (*it) != bbb || (*++it) != jjj || (*++it) != iii )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );  // -------  name = "union 2: /aaa|/aaa";  result = aaa->findTagList( "/aaa|/aaa" );  it = result.begin();  if( result.size() != 1 || (*it) != aaa )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );  // -------  name = "union 3: /aaa|/aaa|//bbb";  result = aaa->findTagList( "/aaa|/aaa|//bbb" );  it = result.begin();  if( result.size() != 4 || (*it) != aaa || (*++it) != bbb || (*++it) != jjj || (*++it) != iii )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );  // -------  name = "empty union 3: /cde|/def";  result = aaa->findTagList( "/cde|/def" );  it = result.begin();  if( result.size() != 0 )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );  // ---- ~union ----  // -- ~operators --  // -- predicates --  // -------  name = "filter 1: //bbb[1]";  result = aaa->findTagList( "//bbb[1]" );  it = result.begin();  if( result.size() != 1 || (*it) != bbb )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );  // -------  name = "filter 2: //bbb[2]";  result = aaa->findTagList( "//bbb[2]" );  it = result.begin();  if( result.size() != 1 || (*it) != jjj )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );  // -------  name = "filter 3: //bbb[3]";  result = aaa->findTagList( "//bbb[3]" );  it = result.begin();  if( result.size() != 1 || (*it) != iii )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );  // -------  name = "invalid filter 4: //bbb[4]";  result = aaa->findTagList( "//bbb[4]" );  it = result.begin();  if( result.size() != 0 )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );  // -------  name = "filter 5: /aaa/bbb[1]";  result = aaa->findTagList( "/aaa/bbb[1]" );  it = result.begin();  if( result.size() != 1 || (*it) != bbb )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );  // -------  name = "filter 5: /aaa[1]";  result = aaa->findTagList( "/aaa[1]" );  it = result.begin();  if( result.size() != 1 || (*it) != aaa )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );  // -------  name = "invalid filter 6: /aaa[2]";  result = aaa->findTagList( "/aaa[2]" );  it = result.begin();  if( result.size() != 0 )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );  // -------  name = "invalid filter 7: [2]";  result = aaa->findTagList( "[2]" );  it = result.begin();  if( result.size() != 0 )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );  // -------  name = "deepsearch + predicate 1: //bbb[@name]";  result = aaa->findTagList( "//bbb[@name]" );  it = result.begin();  if( result.size() != 3 || (*it) != bbb || (*++it) != jjj || (*++it) != iii )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );  // -------  name = "deepsearch + predicate 2: //bbb[@xyz]";  result = aaa->findTagList( "//bbb[@xyz]" );  it = result.begin();  if( result.size() != 0 )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );  // -------  name = "deepsearch + predicate + literal 1: //bbb[@name='b1']";  result = aaa->findTagList( "//bbb[@name='b1']" );  it = result.begin();  if( result.size() != 1 || (*it) != bbb )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }  name = "deepsearch + predicate + literal 2: //bbb[@name='test@test2']";  bbb->addAttribute( "blah", "test@test2" );  result = aaa->findTagList( "//bbb[@blah='test@test2']" );  it = result.begin();  if( result.size() != 1 || (*it) != bbb )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );  name = "deepsearch + predicate + literal + child: //bbb[@name='b1']/hhh";  bbb->addAttribute( "blah", "test@test2" );  result = aaa->findTagList( "//bbb[@blah='test@test2']/hhh" );  it = result.begin();  if( result.size() != 1 || (*it) != hhh )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );  name = "deepsearch + predicate + literal + child + predicate 1: //bbb[@name='b1']/hhh[@name]";  bbb->addAttribute( "blah", "test@test2" );  result = aaa->findTagList( "//bbb[@blah='test@test2']/hhh[@name]" );  it = result.begin();  if( result.size() != 1 || (*it) != hhh )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );  name = "deepsearch + predicate + literal + child + predicate 2: //bbb[@name='b1']/hhh[@name1]";  bbb->addAttribute( "blah", "test@test2" );  result = aaa->findTagList( "//bbb[@blah='test@test2']/hhh[@name1]" );  if( result.size() != 0 )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );  name = "deepsearch + predicate + literal + child + predicate + literal: //bbb[@name='b1']/hhh[@name='h1']";  bbb->addAttribute( "blah", "test@test2" );  result = aaa->findTagList( "//bbb[@blah='test@test2']/hhh[@name='h1']" );  it = result.begin();  if( result.size() != 1 || (*it) != hhh )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );  name = "deepsearch + predicate + literal + child + predicate + literal: //bbb[@name='b1']/hhh[@name='h2']";  bbb->addAttribute( "blah", "test@test2" );  result = aaa->findTagList( "//bbb[@blah='test@test2']/hhh[@name='h2']" );  if( result.size() != 0 )  {    ++fail;    printResult( name, result );    printf( "test '%s' failed\n", name.c_str() );  }//   printf( "--------------------------------------------------------------\n" );//   // -------//   name = "deepsearch + predicate + path 1: //bbb[hhh]";//   result = aaa->findTagList( "//bbb[hhh]" );//   it = result.begin();//   if( result.size() != 1 || (*it) != bbb )//   {//     ++fail;//     printResult( name, result );//     printf( "test '%s' failed\n", name.c_str() );//   }//   printf( "--------------------------------------------------------------\n" );//   // -------//   name = "filter 1: //bbb[1+2]";//   result = aaa->findTagList( "//bbb[1+2]" );//   it = result.begin();//   if( result.size() != 1 || (*it) != iii )//   {//     ++fail;//     printResult( name, result );//     printf( "test '%s' failed\n", name.c_str() );//   }//   printf( "--------------------------------------------------------------\n" );  // -- predicates --//   Tag *c2 = new Tag( ddd, "ccc" );//   Tag *c3 = new Tag( c2, "ccc" );//   Tag *c4 = new Tag( eee, "ccc" );//   Tag *c5 = new Tag( c4, "ccc" );// <aaa>//   <bbb name='b1'>//     <hhh>//       <bbb name='b3'/>//     </hhh>//     <bbb name='b2'/>//   </bbb>//   <ccc>//     <ddd>//       <ccc>//         <ccc/>//       </ccc>//     </ddd>//     <eee>//       <ccc>//         <ccc/>//       </ccc>//     </eee>//   </ccc>//   <fff>//     <ggg/>//   </fff>// </aaa>  delete aaa;  if( fail == 0 )  {    printf( "XPath: all tests passed\n" );    return 0;  }  else  {    printf( "XPath: %d test(s) failed\n", fail );    return 1;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -