Esempio n. 1
0
    def _test_search_2(self):
        """search()"""
        """
            Test with more regular expression where are not blow up REs.
        """
        
        parser = pcre_parser()
        
        hyfa = JHybridFA()
        hyfa.load_file(aux_func.getPatternMatchDir() + "/algorithms/j_hybrid_fa/tests_data/test_search_2.re")
        hyfa.set_parser(parser)

        hyfa.compute()
        
        self.assertTrue(hyfa.get_compute())
        
        ret = hyfa.search("0123")
        self.assertEqual(ret, [1,0,0,0])
        
        ret = hyfa.search("uvwx")
        self.assertEqual(ret, [0,0,1,0])

        ret = hyfa.search("abcd uvwx")
        self.assertEqual(ret, [0,1,1,0])
        
        ret = hyfa.search("cdefgh")
        self.assertEqual(ret, [0,0,0,0])
Esempio n. 2
0
    def _test_search_3(self):
        """search()"""
        """
            Test with more REs where some have blow up patterns on his starts.
        """
        
        parser = pcre_parser()
        
        hyfa = JHybridFA()
        hyfa.load_file(aux_func.getPatternMatchDir() + "/algorithms/j_hybrid_fa/tests_data/test_search_3.re")
        hyfa.set_parser(parser)

        hyfa.compute()
        
        self.assertTrue(hyfa.get_compute())
        
        ret = hyfa.search("0123")
        self.assertEqual(ret, [1,0,0,0])
        
        ret = hyfa.search("uvwx")
        self.assertEqual(ret, [0,0,1,0])

        ret = hyfa.search("abcd uvwx")
        self.assertEqual(ret, [0,1,1,1])
        
        ret = hyfa.search("abcd agcd")
        self.assertEqual(ret, [0,1,0,1])
        
        ret = hyfa.search("cdefgh")
        self.assertEqual(ret, [0,0,0,0])
Esempio n. 3
0
 def _test_search_1(self):
     """search()"""
     """
         Test with more regular expression where computed automaton
         has some NFA parts.
     """
     
     parser = pcre_parser()
     
     hyfa = JHybridFA()
     hyfa.load_file(aux_func.getPatternMatchDir() + "/algorithms/j_hybrid_fa/tests_data/test_search_1.re")
     hyfa.set_parser(parser)
   
     hyfa.compute()
     
     self.assertTrue(hyfa.get_compute())
     
     ret = hyfa.search("0123 uvwx")
     self.assertEqual(ret, [1,0,1,0])
     
     ret = hyfa.search("abcd abgggcd")
     self.assertEqual(ret, [0,1,0,1])
     
     ret = hyfa.search("aaaaa")
     self.assertEqual(ret, [0,0,0,0])
Esempio n. 4
0
    def _test_search_3(self):
        """search()"""
        """
            Test with more REs where some have blow up patterns on his starts.
        """

        parser = pcre_parser()

        hyfa = JHybridFA()
        hyfa.load_file(aux_func.getPatternMatchDir() +
                       "/algorithms/j_hybrid_fa/tests_data/test_search_3.re")
        hyfa.set_parser(parser)

        hyfa.compute()

        self.assertTrue(hyfa.get_compute())

        ret = hyfa.search("0123")
        self.assertEqual(ret, [1, 0, 0, 0])

        ret = hyfa.search("uvwx")
        self.assertEqual(ret, [0, 0, 1, 0])

        ret = hyfa.search("abcd uvwx")
        self.assertEqual(ret, [0, 1, 1, 1])

        ret = hyfa.search("abcd agcd")
        self.assertEqual(ret, [0, 1, 0, 1])

        ret = hyfa.search("cdefgh")
        self.assertEqual(ret, [0, 0, 0, 0])
Esempio n. 5
0
    def _test_search_2(self):
        """search()"""
        """
            Test with more regular expression where are not blow up REs.
        """

        parser = pcre_parser()

        hyfa = JHybridFA()
        hyfa.load_file(aux_func.getPatternMatchDir() +
                       "/algorithms/j_hybrid_fa/tests_data/test_search_2.re")
        hyfa.set_parser(parser)

        hyfa.compute()

        self.assertTrue(hyfa.get_compute())

        ret = hyfa.search("0123")
        self.assertEqual(ret, [1, 0, 0, 0])

        ret = hyfa.search("uvwx")
        self.assertEqual(ret, [0, 0, 1, 0])

        ret = hyfa.search("abcd uvwx")
        self.assertEqual(ret, [0, 1, 1, 0])

        ret = hyfa.search("cdefgh")
        self.assertEqual(ret, [0, 0, 0, 0])
Esempio n. 6
0
    def _test_search_1(self):
        """search()"""
        """
            Test with more regular expression where computed automaton
            has some NFA parts.
        """

        parser = pcre_parser()

        hyfa = JHybridFA()
        hyfa.load_file(aux_func.getPatternMatchDir() +
                       "/algorithms/j_hybrid_fa/tests_data/test_search_1.re")
        hyfa.set_parser(parser)

        hyfa.compute()

        self.assertTrue(hyfa.get_compute())

        ret = hyfa.search("0123 uvwx")
        self.assertEqual(ret, [1, 0, 1, 0])

        ret = hyfa.search("abcd abgggcd")
        self.assertEqual(ret, [0, 1, 0, 1])

        ret = hyfa.search("aaaaa")
        self.assertEqual(ret, [0, 0, 0, 0])
Esempio n. 7
0
    def _test_search_4(self):
        """search()"""
        """
            Test with many regular expression where computed automaton
            has many NFA parts.
            Compares results of searching in computed Hybrid FA with
            regular NFA automaton searching.
        """
        parser = pcre_parser()
        parser.load_file(aux_func.getPatternMatchDir() + "/rules/Moduly/web-cgi.rules.pcre")

        nfa_aut = b_nfa()
        nfa_aut.create_by_parser(parser)
        nfa_aut.compute()
        
        parser = pcre_parser()
        
        hyfa = JHybridFA()
        hyfa.set_parser(parser)
        hyfa.load_file(aux_func.getPatternMatchDir() + "/rules/Moduly/web-cgi.rules.pcre")
        
        hyfa.compute()

        input_data = "/awstats.pl?---configdir=| /calendar-admin.pl /db4web_c.exe/aaaa:  /itemid=123f  /ShellExample.cgi?*"
        self.assertEqual(nfa_aut.search(input_data), hyfa.search(input_data))
Esempio n. 8
0
    def _test_search_4(self):
        """search()"""
        """
            Test with many regular expression where computed automaton
            has many NFA parts.
            Compares results of searching in computed Hybrid FA with
            regular NFA automaton searching.
        """
        parser = pcre_parser()
        parser.load_file(aux_func.getPatternMatchDir() +
                         "/rules/Moduly/web-cgi.rules.pcre")

        nfa_aut = b_nfa()
        nfa_aut.create_by_parser(parser)
        nfa_aut.compute()

        parser = pcre_parser()

        hyfa = JHybridFA()
        hyfa.set_parser(parser)
        hyfa.load_file(aux_func.getPatternMatchDir() +
                       "/rules/Moduly/web-cgi.rules.pcre")

        hyfa.compute()

        input_data = "/awstats.pl?---configdir=| /calendar-admin.pl /db4web_c.exe/aaaa:  /itemid=123f  /ShellExample.cgi?*"
        self.assertEqual(nfa_aut.search(input_data), hyfa.search(input_data))