aboutsummaryrefslogtreecommitdiffstats
path: root/tests/tests.py
blob: 0567a8c3714864c72162273a293f085f030a31d2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import unittest
import os
from eoparser.xmlparser import XMLparser
from eoparser.cparser import Cparser
from eoparser.helper import dir_files_get, abs_path_get, isC, isH, isXML, normalize_names

class testP(unittest.TestCase):
    
    def setUp(self):
        self.c_parser = Cparser(False)

    def test_fetch_data(self):
        f = open('test_data.in', 'r')
        s = f.read()
        f.close()

        class_def_answer = {"class_get" : ["parent", 
                                           ["brother"], 
                                           "test_class_name", 
                                           "EO_CLASS_TYPE_REGULAR", 
                                               ["ELM_OBJ_PAN_BASE_ID", 
                                               [("ELM_OBJ_PAN_SUB_ID_POS_SET", "pos_set"), ("ELM_OBJ_PAN_SUB_ID_POS_GET", "pos_get")],
                                                "ELM_OBJ_PAN_SUB_ID_LAST"], 
                                           ["EO_EV_CALLBACK_ADD", "EO_EV_CALLBACK_DEL", "EO_EV_DEL"]
                                           ]}
        answer = class_def_answer

        ret = self.c_parser.fetch_data(s)
        self.assertEqual(ret, answer)

    def test_isC(self):
        self.assertTrue(isC("abc.c"))
        self.assertTrue(isC("abc.cc"))
        self.assertTrue(isC("abc.cpp"))
        self.assertFalse(isC("abc.cp"))
        self.assertFalse(isC("abc.def.c"))

    def test_isH(self):
        self.assertTrue(isH("abc.h"))
        self.assertFalse(isH("abc.c"))
        self.assertFalse(isH("abc.def.h"))

    def test_isXML(self):
        self.assertTrue(isXML("abc.xml"))
        self.assertFalse(isXML("abc.h"))
        self.assertFalse(isXML("abc.qwe.xml"))

    def test_abs_path_get(self):
       _in = "test_data.in"
       _in_list = [_in]
       _out = _in
       _out = os.path.expanduser(_out)
       _out = os.path.abspath(_out)

       self.assertEqual(abs_path_get(_in_list), [_out])

    def test_normalize_names(self):
       _in = ["hello world", "elm_Box", "evas Object-SmaRt", "EvAs-common InTeRface"]
       _out = ["HelloWorld", "ElmBox", "EvasObjectSmart", "EvasCommonInterface"]

       self.assertEqual(normalize_names(_in), _out)


    def test_get_param_dir_from_comment(self):
       s = """
             @param[in,out] a
             @param[in] a
             @param[out] a
             parem[in]
             @param [in] a
             @param    [out] a
             @param[in, out] a
             @param in
             @param [  in  ]
             @param [  out, in  ]
             @param sdf [ out  ]
           """
       _out = ["in,out", "in", "out", "in", "out", "in,out", "in,out", "in", "in,out", "in,out"]
       ret = self.c_parser.get_param_dir_from_comment(s)
       self.assertEqual(ret, _out)



def suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(testP))
    return suite

if __name__ == '__main__':

    unittest.main()