@@ -46,7 +46,9 @@ source product.
4646using iText . Layout . Properties ;
4747using iText . StyledXmlParser ;
4848using iText . StyledXmlParser . Css ;
49+ using iText . StyledXmlParser . Css . Pseudo ;
4950using iText . StyledXmlParser . Exceptions ;
51+ using iText . StyledXmlParser . Node ;
5052using iText . StyledXmlParser . Node . Impl . Jsoup . Node ;
5153using iText . Test ;
5254using iText . Test . Attributes ;
@@ -460,5 +462,130 @@ public virtual void IsNegativeValueTest() {
460462 NUnit . Framework . Assert . IsTrue ( CssUtils . IsNegativeValue ( "-0.123" ) ) ;
461463 NUnit . Framework . Assert . IsTrue ( CssUtils . IsNegativeValue ( "-.34" ) ) ;
462464 }
465+
466+ [ NUnit . Framework . Test ]
467+ public virtual void TestWrongAttrTest01 ( ) {
468+ String strToParse = "attr((href))" ;
469+ String result = CssUtils . ExtractAttributeValue ( strToParse , null ) ;
470+ NUnit . Framework . Assert . IsNull ( result ) ;
471+ }
472+
473+ [ NUnit . Framework . Test ]
474+ public virtual void TestWrongAttrTest02 ( ) {
475+ String strToParse = "attr('href')" ;
476+ String result = CssUtils . ExtractAttributeValue ( strToParse , null ) ;
477+ NUnit . Framework . Assert . IsNull ( result ) ;
478+ }
479+
480+ [ NUnit . Framework . Test ]
481+ public virtual void TestWrongAttrTest03 ( ) {
482+ String strToParse = "attrrname)" ;
483+ String result = CssUtils . ExtractAttributeValue ( strToParse , null ) ;
484+ NUnit . Framework . Assert . IsNull ( result ) ;
485+ }
486+
487+ [ NUnit . Framework . Test ]
488+ public virtual void TestExtractingAttrTest01 ( ) {
489+ IElementNode iNode = new CssPseudoElementNode ( null , "url" ) ;
490+ String strToParse = "attr(url)" ;
491+ String result = CssUtils . ExtractAttributeValue ( strToParse , iNode ) ;
492+ NUnit . Framework . Assert . AreEqual ( "" , result ) ;
493+ }
494+
495+ [ NUnit . Framework . Test ]
496+ public virtual void TestExtractingAttrTest02 ( ) {
497+ IElementNode iNode = new CssPseudoElementNode ( null , "test" ) ;
498+ String strToParse = "attr(url url)" ;
499+ String result = CssUtils . ExtractAttributeValue ( strToParse , iNode ) ;
500+ NUnit . Framework . Assert . IsNull ( result ) ;
501+ }
502+
503+ [ NUnit . Framework . Test ]
504+ public virtual void TestExtractingAttrTest03 ( ) {
505+ IElementNode iNode = new CssPseudoElementNode ( null , "test" ) ;
506+ String strToParse = "attr(url url,#one)" ;
507+ String result = CssUtils . ExtractAttributeValue ( strToParse , iNode ) ;
508+ NUnit . Framework . Assert . AreEqual ( "#one" , result ) ;
509+ }
510+
511+ [ NUnit . Framework . Test ]
512+ public virtual void TestExtractingAttrTest04 ( ) {
513+ IElementNode iNode = new CssPseudoElementNode ( null , "test" ) ;
514+ String strToParse = "attr()" ;
515+ String result = CssUtils . ExtractAttributeValue ( strToParse , iNode ) ;
516+ NUnit . Framework . Assert . IsNull ( result ) ;
517+ }
518+
519+ [ NUnit . Framework . Test ]
520+ public virtual void TestExtractingAttrTest05 ( ) {
521+ IElementNode iNode = new CssPseudoElementNode ( null , "test" ) ;
522+ String strToParse = "attr('\' )" ;
523+ String result = CssUtils . ExtractAttributeValue ( strToParse , iNode ) ;
524+ NUnit . Framework . Assert . IsNull ( result ) ;
525+ }
526+
527+ [ NUnit . Framework . Test ]
528+ public virtual void TestExtractingAttrTest06 ( ) {
529+ IElementNode iNode = new CssPseudoElementNode ( null , "test" ) ;
530+ String strToParse = "attr(str,\" hey\" )" ;
531+ String result = CssUtils . ExtractAttributeValue ( strToParse , iNode ) ;
532+ NUnit . Framework . Assert . AreEqual ( "hey" , result ) ;
533+ }
534+
535+ [ NUnit . Framework . Test ]
536+ public virtual void TestExtractingAttrTest07 ( ) {
537+ IElementNode iNode = new CssPseudoElementNode ( null , "test" ) ;
538+ String strToParse = "attr(str string)" ;
539+ String result = CssUtils . ExtractAttributeValue ( strToParse , iNode ) ;
540+ NUnit . Framework . Assert . AreEqual ( "" , result ) ;
541+ }
542+
543+ [ NUnit . Framework . Test ]
544+ public virtual void TestExtractingAttrTest08 ( ) {
545+ IElementNode iNode = new CssPseudoElementNode ( null , "test" ) ;
546+ String strToParse = "attr(str string,\" value\" )" ;
547+ String result = CssUtils . ExtractAttributeValue ( strToParse , iNode ) ;
548+ NUnit . Framework . Assert . AreEqual ( "value" , result ) ;
549+ }
550+
551+ [ NUnit . Framework . Test ]
552+ public virtual void TestExtractingAttrTest09 ( ) {
553+ IElementNode iNode = new CssPseudoElementNode ( null , "test" ) ;
554+ String strToParse = "attr(str string,\" val,ue\" )" ;
555+ String result = CssUtils . ExtractAttributeValue ( strToParse , iNode ) ;
556+ NUnit . Framework . Assert . AreEqual ( "val,ue" , result ) ;
557+ }
558+
559+ [ NUnit . Framework . Test ]
560+ public virtual void TestExtractingAttrTest10 ( ) {
561+ IElementNode iNode = new CssPseudoElementNode ( null , "test" ) ;
562+ String strToParse = "attr(str string,'val,ue')" ;
563+ String result = CssUtils . ExtractAttributeValue ( strToParse , iNode ) ;
564+ NUnit . Framework . Assert . AreEqual ( "val,ue" , result ) ;
565+ }
566+
567+ [ NUnit . Framework . Test ]
568+ public virtual void TestExtractingAttrTest11 ( ) {
569+ IElementNode iNode = new CssPseudoElementNode ( null , "test" ) ;
570+ String strToParse = "attr(name, \" value\" , \" value\" , \" value\" )" ;
571+ String result = CssUtils . ExtractAttributeValue ( strToParse , iNode ) ;
572+ NUnit . Framework . Assert . IsNull ( result ) ;
573+ }
574+
575+ [ NUnit . Framework . Test ]
576+ public virtual void WrongAttributeTypeTest ( ) {
577+ IElementNode iNode = new CssPseudoElementNode ( null , "test" ) ;
578+ String strToParse = "attr(str mem)" ;
579+ String result = CssUtils . ExtractAttributeValue ( strToParse , iNode ) ;
580+ NUnit . Framework . Assert . IsNull ( result ) ;
581+ }
582+
583+ [ NUnit . Framework . Test ]
584+ public virtual void WrongParamsInAttrFunctionTest ( ) {
585+ IElementNode iNode = new CssPseudoElementNode ( null , "test" ) ;
586+ String strToParse = "attr(str mem lol)" ;
587+ String result = CssUtils . ExtractAttributeValue ( strToParse , iNode ) ;
588+ NUnit . Framework . Assert . IsNull ( result ) ;
589+ }
463590 }
464591}
0 commit comments