예제 #1
0
    def test_scope_in_const_definition(self):
        code = """
#include "cryptopp/cryptopp/pch.h"
#include "cryptopp/cryptopp/cast.h"

namespace CryptoPP{

// CAST S-boxes
int CAST::x = 1;
int CAST::y;
int z;

const word32 CAST::S[8][256] = {
{
    0x30FB40D4UL, 0x9FA0FF0BUL, 0x6BECCD2FUL, 0x3F258C7AUL,
    0x1E213F2FUL, 0x9C004DD3UL, 0x6003E540UL, 0xCF9FC949UL,
    0xBFD4AF27UL, 0x88BBBDB5UL, 0xE2034090UL, 0x98D09675UL,
    0x6E63A0E0UL, 0x15C361D2UL, 0xC2E7661DUL, 0x22D4FF8EUL
}}
"""
        parser = DRLCPPParser()
        parser.parse(code)
        expected = set([
            CPPItem(type_=CPPItem.VAR, name='S', scope='CryptoPP::CAST'),
            CPPItem(type_=CPPItem.VAR, name='x', scope='CryptoPP::CAST'),
            CPPItem(type_=CPPItem.VAR, name='y', scope='CryptoPP::CAST'),
            CPPItem(type_=CPPItem.VAR, name='z', scope='CryptoPP')
        ])
        self.assertItemsEqual(expected, parser.definitions)
예제 #2
0
    def test_explicit_dependencies(self):
        text = r'''
/*
 * Prueba de comentario en clase
 */
class Sphere
{
protected:
    float radius;
        protectedMethod();
        protectedMethod2(MYSTRUCT m);
public:
        ///Contructor
    Sphere(float r);
    ///bii://user/module/file
    float volume();

    ///bii://user2/module2/file2
    double hhh(){
                return 2*2;
    }
};'''
        parser = DRLCPPParser()
        parser.parse(text)
        explicitDependencies = parser.explicit_declarations
        expected = set(['user/module/file', 'user2/module2/file2'])
        self.assertSetEqual(expected,
                            set([str(expDep) for expDep in explicitDependencies]))
예제 #3
0
    def test_scope_in_const_definition(self):
        code = """
#include "cryptopp/cryptopp/pch.h"
#include "cryptopp/cryptopp/cast.h"

namespace CryptoPP{

// CAST S-boxes
int CAST::x = 1;
int CAST::y;
int z;

const word32 CAST::S[8][256] = {
{
    0x30FB40D4UL, 0x9FA0FF0BUL, 0x6BECCD2FUL, 0x3F258C7AUL,
    0x1E213F2FUL, 0x9C004DD3UL, 0x6003E540UL, 0xCF9FC949UL,
    0xBFD4AF27UL, 0x88BBBDB5UL, 0xE2034090UL, 0x98D09675UL,
    0x6E63A0E0UL, 0x15C361D2UL, 0xC2E7661DUL, 0x22D4FF8EUL
}}
"""
        parser = DRLCPPParser()
        parser.parse(code)
        expected = set([CPPItem(type_=CPPItem.VAR, name='S', scope='CryptoPP::CAST'),
                        CPPItem(type_=CPPItem.VAR, name='x', scope='CryptoPP::CAST'),
                        CPPItem(type_=CPPItem.VAR, name='y', scope='CryptoPP::CAST'),
                        CPPItem(type_=CPPItem.VAR, name='z', scope='CryptoPP')])
        self.assertItemsEqual(expected, parser.definitions)
예제 #4
0
    def test_explicit_dependencies(self):
        text = r'''
/*
 * Prueba de comentario en clase
 */
class Sphere
{
protected:
    float radius;
        protectedMethod();
        protectedMethod2(MYSTRUCT m);
public:
        ///Contructor
    Sphere(float r);
    ///bii://user/module/file
    float volume();

    ///bii://user2/module2/file2
    double hhh(){
                return 2*2;
    }
};'''
        parser = DRLCPPParser()
        parser.parse(text)
        explicitDependencies = parser.explicit_declarations
        expected = set(['user/module/file', 'user2/module2/file2'])
        self.assertSetEqual(
            expected, set([str(expDep) for expDep in explicitDependencies]))
예제 #5
0
 def test_find_mains(self):
     '''basic check that header is implemented by source'''
     resources = {
         'blink.h':
         Resource(
             SimpleCell('usr/block/blink.h', CPP),
             Content(id_=None, load=Blob(header), parser=DRLCPPParser())),
         'blink.cpp':
         Resource(
             SimpleCell('usr/block/blink.cpp', CPP),
             Content(id_=None,
                     load=Blob(implementation),
                     parser=DRLCPPParser())),
         'mainblink.cpp':
         Resource(SimpleCell('usr/block/mainblink.cpp', CPP),
                  Content(id_=None, load=Blob(main), parser=DRLCPPParser()))
     }
     block_holder = BlockHolder(BlockName('user/block'), resources)
     for r in resources.itervalues():
         r.content.parse()
         r.content.updated = False
     processor = ArduinoEntryPointProcesor()
     processor.do_process(block_holder, Mock())
     mainblink = block_holder['mainblink.cpp'].cell
     content = block_holder['mainblink.cpp'].content
     self.assertTrue(mainblink.hasMain)
     self.assertFalse(content.updated)
     self.assertFalse(content.blob_updated)
    def test_parsers(self):
        p = DRLCPPParser()
        s = p.serialize()
        p2 = Parser.deserialize(s)
        self.assert_bii_equal(p, p2)

        p = DRLCPPParser()
        s = p.serialize()
        p2 = Parser.deserialize(s)
        self.assert_bii_equal(p, p2)
예제 #7
0
    def test_destructor(self):
        text = r"""
namespace Poco {
LexicalHandler::~LexicalHandler()
{
}
}"""
        parser = DRLCPPParser()
        parser.parse(text)
        self.assertEqual(CPPItem(CPPItem.METHOD, '~LexicalHandler', 'Poco::LexicalHandler'),
                         parser.definitions.pop())
예제 #8
0
    def test_destructor(self):
        text = r"""
namespace Poco {
LexicalHandler::~LexicalHandler()
{
}
}"""
        parser = DRLCPPParser()
        parser.parse(text)
        self.assertEqual(
            CPPItem(CPPItem.METHOD, '~LexicalHandler', 'Poco::LexicalHandler'),
            parser.definitions.pop())
예제 #9
0
    def test_replace_includes(self):
        text = r'''# include   "file.h" //My comment
 # include   "file2.h"
# include   "path/to/file.h" //My comment
# include   "file3.h"
//bii://biicode.txt
'''
        parser = DRLCPPParser()
        parser.parse(text)
        d1 = CPPDeclaration('file.h')
        d2 = CPPDeclaration('user/block/file.h')
        text = parser.updateDeclaration(text, d1, d2)

        d1 = CPPDeclaration('file3.h')
        d2 = CPPDeclaration('user/block2/file3.h')
        text = parser.updateDeclaration(text, d1, d2)

        d1 = CPPDeclaration('file2.h')
        d2 = CPPDeclaration('user/block2/file2.h')
        text = parser.updateDeclaration(text, d1, d2)

        d1 = DataDeclaration('biicode.txt')
        d2 = DataDeclaration('user/block/biicode.txt')
        text = parser.updateDeclaration(text, d1, d2)
        expected = '''# include   "user/block/file.h" //My comment
 # include   "user/block2/file2.h"
# include   "path/to/file.h" //My comment
# include   "user/block2/file3.h"
//bii://user/block/biicode.txt
'''
        self.assertEqual(expected, text)
예제 #10
0
    def test_arduino_imports(self):
        arduino_imports = """#import "hola.h"
#include "fran/duino/fancy.h"

void setup(){
    foo();
}

void loop(){
    bar();
}
"""
        parser = DRLCPPParser()
        parser.parse(arduino_imports)
        obtained_includes = [ref.name for ref in parser.includes]
        expected = ['hola.h', 'fran/duino/fancy.h']
        self.assertItemsEqual(expected, obtained_includes)
예제 #11
0
    def test_arduino_imports(self):
        arduino_imports = """#import "hola.h"
#include "fran/duino/fancy.h"

void setup(){
    foo();
}

void loop(){
    bar();
}
"""
        parser = DRLCPPParser()
        parser.parse(arduino_imports)
        obtained_includes = [ref.name for ref in parser.includes]
        expected = ['hola.h', 'fran/duino/fancy.h']
        self.assertItemsEqual(expected, obtained_includes)
예제 #12
0
    def test_declaration_defintions(self):
        text = r'''
int a;
float b = 0.0f;

extern double c;
float suma(float a, float b) //comment
{
    //suma
    return a+b;
}
class PreDecl //My predc
    ;
float multiply(float a, float b);
class
    Sphere : public Polygon//MyClass comment
{
protected:
    float radius;
public:
    Sphere(float r):radius(r){ /*Inline coment*/};
    float volume(){
        return radius*radius*radius;
    }
    float methodDecl();
};
'''
        parser = DRLCPPParser()
        parser.parse(text)

        expected = set([
            CPPItem(CPPItem.CLASS, 'Sphere'),
            CPPItem(CPPItem.VAR, 'c'),
            CPPItem(CPPItem.METHOD, 'multiply'),
        ])

        #print parser.declarations
        self.assertEqual(expected, parser.declarations)

        expected = set([
            CPPItem(CPPItem.VAR, 'a'),
            CPPItem(CPPItem.VAR, 'b'),
            CPPItem(CPPItem.METHOD, 'suma'),
        ])

        self.assertEqual(expected, parser.definitions)
예제 #13
0
    def test_replace_includes(self):
        text = r'''# include   "file.h" //My comment
 # include   "file2.h"
# include   "path/to/file.h" //My comment
# include   "file3.h"
//bii://biicode.txt
'''
        parser = DRLCPPParser()
        parser.parse(text)
        d1 = CPPDeclaration('file.h')
        d2 = CPPDeclaration('user/block/file.h')
        text = parser.updateDeclaration(text, d1, d2)

        d1 = CPPDeclaration('file3.h')
        d2 = CPPDeclaration('user/block2/file3.h')
        text = parser.updateDeclaration(text, d1, d2)

        d1 = CPPDeclaration('file2.h')
        d2 = CPPDeclaration('user/block2/file2.h')
        text = parser.updateDeclaration(text, d1, d2)

        d1 = DataDeclaration('biicode.txt')
        d2 = DataDeclaration('user/block/biicode.txt')
        text = parser.updateDeclaration(text, d1, d2)
        expected = '''# include   "user/block/file.h" //My comment
 # include   "user/block2/file2.h"
# include   "path/to/file.h" //My comment
# include   "user/block2/file3.h"
//bii://user/block/biicode.txt
'''
        self.assertEqual(expected, text)
예제 #14
0
    def test_declaration_defintions(self):
        text = r'''
int a;
float b = 0.0f;

extern double c;
float suma(float a, float b) //comment
{
    //suma
    return a+b;
}
class PreDecl //My predc
    ;
float multiply(float a, float b);
class
    Sphere : public Polygon//MyClass comment
{
protected:
    float radius;
public:
    Sphere(float r):radius(r){ /*Inline coment*/};
    float volume(){
        return radius*radius*radius;
    }
    float methodDecl();
};
'''
        parser = DRLCPPParser()
        parser.parse(text)

        expected = set([CPPItem(CPPItem.CLASS, 'Sphere'),
                        CPPItem(CPPItem.VAR, 'c'),
                        CPPItem(CPPItem.METHOD, 'multiply'),
                        ])

        #print parser.declarations
        self.assertEqual(expected, parser.declarations)

        expected = set([CPPItem(CPPItem.VAR, 'a'),
                        CPPItem(CPPItem.VAR, 'b'),
                        CPPItem(CPPItem.METHOD, 'suma'),
                        ])

        self.assertEqual(expected, parser.definitions)
예제 #15
0
    def test_namespace(self):
        text = r'''
namespace Geom
{
    float intersect();
    float other(){
        return 0.0f;
    }
    class Line{

    };
    namespace NS{
        float foo();
        class Bar{
        };
    }
}
float Geom::intersect(){
    return 0;
}
float Geom::NS::intersect2(){
    return 0;
}
'''
        parser = DRLCPPParser()
        parser.parse(text)

        expected = set([
            CPPItem(CPPItem.CLASS, 'Line', 'Geom'),
            CPPItem(CPPItem.METHOD, 'intersect', 'Geom'),
            CPPItem(CPPItem.CLASS, 'Bar', 'Geom::NS'),
            CPPItem(CPPItem.METHOD, 'foo', 'Geom::NS'),
        ])

        self.assertEqual(expected, parser.declarations)

        expected = set([
            CPPItem(CPPItem.METHOD, 'other', 'Geom'),
            CPPItem(CPPItem.METHOD, 'intersect', 'Geom'),
            CPPItem(CPPItem.METHOD, 'intersect2', 'Geom::NS'),
        ])

        self.assertEqual(expected, parser.definitions)
예제 #16
0
    def test_scope(self):
        text = """
#include "cryptopp/cryptopp/pch.h"
#include "cryptopp/cryptopp/cast.h"

namespace CryptoPP{

// CAST S-boxes

const word32 CAST::S[8][256] = {
{
    0x30FB40D4UL, 0x9FA0FF0BUL, 0x6BECCD2FUL, 0x3F258C7AUL,
    0x1E213F2FUL, 0x9C004DD3UL, 0x6003E540UL, 0xCF9FC949UL,
    0xBFD4AF27UL, 0x88BBBDB5UL, 0xE2034090UL, 0x98D09675UL,
    0x6E63A0E0UL, 0x15C361D2UL, 0xC2E7661DUL, 0x22D4FF8EUL
}}
"""
        parser = DRLCPPParser()
        parser.parse(text)
예제 #17
0
    def test_includes(self):
        testIncludes = r'''
//comment
#include <iostream>
#include "file.h"
//#include "path/to/file2.h"
/*#include "file3.h" /**/*/
# include    "path/to/file4.h "
#include " file5.h " //Comment on include
#include <file6.h > /*Other comment*/
#define MYVAR 3
'''
        parser = DRLCPPParser()
        parser.parse(testIncludes)

        obtained = [ref.name for ref in parser.includes]
        expected = ['iostream', 'file.h', 'path/to/file4.h',
                      'file5.h', 'file6.h']
        self.assertEqual(expected, obtained)
예제 #18
0
    def test_scope(self):
        text = """
#include "cryptopp/cryptopp/pch.h"
#include "cryptopp/cryptopp/cast.h"

namespace CryptoPP{

// CAST S-boxes

const word32 CAST::S[8][256] = {
{
    0x30FB40D4UL, 0x9FA0FF0BUL, 0x6BECCD2FUL, 0x3F258C7AUL,
    0x1E213F2FUL, 0x9C004DD3UL, 0x6003E540UL, 0xCF9FC949UL,
    0xBFD4AF27UL, 0x88BBBDB5UL, 0xE2034090UL, 0x98D09675UL,
    0x6E63A0E0UL, 0x15C361D2UL, 0xC2E7661DUL, 0x22D4FF8EUL
}}
"""
        parser = DRLCPPParser()
        parser.parse(text)
예제 #19
0
    def test_includes(self):
        testIncludes = r'''
//comment
#include <iostream>
#include "file.h"
//#include "path/to/file2.h"
/*#include "file3.h" /**/*/
# include    "path/to/file4.h "
#include " file5.h " //Comment on include
#include <file6.h > /*Other comment*/
#define MYVAR 3
'''
        parser = DRLCPPParser()
        parser.parse(testIncludes)

        obtained = [ref.name for ref in parser.includes]
        expected = [
            'iostream', 'file.h', 'path/to/file4.h', 'file5.h', 'file6.h'
        ]
        self.assertEqual(expected, obtained)
예제 #20
0
    def test_namespace(self):
        text = r'''
namespace Geom
{
    float intersect();
    float other(){
        return 0.0f;
    }
    class Line{

    };
    namespace NS{
        float foo();
        class Bar{
        };
    }
}
float Geom::intersect(){
    return 0;
}
float Geom::NS::intersect2(){
    return 0;
}
'''
        parser = DRLCPPParser()
        parser.parse(text)

        expected = set([CPPItem(CPPItem.CLASS, 'Line', 'Geom'),
                        CPPItem(CPPItem.METHOD, 'intersect', 'Geom'),
                        CPPItem(CPPItem.CLASS, 'Bar', 'Geom::NS'),
                        CPPItem(CPPItem.METHOD, 'foo', 'Geom::NS'),
                        ])

        self.assertEqual(expected, parser.declarations)

        expected = set([CPPItem(CPPItem.METHOD, 'other',  'Geom'),
                        CPPItem(CPPItem.METHOD, 'intersect', 'Geom'),
                        CPPItem(CPPItem.METHOD, 'intersect2', 'Geom::NS'),
                        ])

        self.assertEqual(expected, parser.definitions)
예제 #21
0
    def _process_from_contents(self, contents):
        '''param contents: dict{name:code snippets}.
        Will create a HiveHolder, fill with the data and process it'''
        resources = []
        for name, content in contents.iteritems():
            cell = SimpleCell(name, CPP)
            block_name = cell.name.block_name
            resources.append(
                Resource(
                    cell,
                    Content(name, load=Blob(content), parser=DRLCPPParser())))

        block_holder = BlockHolder(block_name, resources)
        self._process(block_holder)
        return block_holder
예제 #22
0
    def test_parsers(self):
        p = DRLCPPParser()
        s = p.serialize()
        p2 = Parser.deserialize(s)
        self.assert_bii_equal(p, p2)

        p = DRLCPPParser()
        s = p.serialize()
        p2 = Parser.deserialize(s)
        self.assert_bii_equal(p, p2)
예제 #23
0
 def test_parse(self, header_file):
     BlobH = Blob(testfileutils.read(header_file))
     parserH = DRLCPPParser()
     parserH.parse(BlobH.bytes)
예제 #24
0
 def test_has_main(self, text):
     parser = DRLCPPParser()
     parser.parse(text)
     self.assertTrue(parser.has_main_function())
예제 #25
0
 def test_find_gtest_implementations(self):
     text = testfileutils.load('gtest/src/gtest-death-test.cc')
     parser = DRLCPPParser()
     parser.parse(text)
     self.assertIn(CPPDeclaration('../include/gtest/internal/gtest-port.h'),
                   parser.explicit_declarations)
예제 #26
0
 def test_using_no_definition(self):
     code = "using blobstore::onblocks::utils::ceilDivision;"
     parser = DRLCPPParser()
     parser.parse(code)
     expected = set()
     self.assertItemsEqual(expected, parser.definitions)
예제 #27
0
 def test_using_no_definition(self):
     code = "using blobstore::onblocks::utils::ceilDivision;"
     parser = DRLCPPParser()
     parser.parse(code)
     expected = set()
     self.assertItemsEqual(expected, parser.definitions)
예제 #28
0
 def test_find_gtest_implementations(self):
     text = testfileutils.load('gtest/src/gtest-death-test.cc')
     parser = DRLCPPParser()
     parser.parse(text)
     self.assertIn(CPPDeclaration('../include/gtest/internal/gtest-port.h'),
                   parser.explicit_declarations)
예제 #29
0
 def test_has_main(self, text):
     parser = DRLCPPParser()
     parser.parse(text)
     self.assertTrue(parser.has_main_function())