# Path: dependency/Builder.py
# class Builder(object):
#     """
#     base class for splicing the compile command
#     """
#     def __init__(self, obj, compiler, workspace):
#         """
#         init function
#         Args:
#             obj : the cvs path of object file
#             compiler : the path of compiler
#             workspace : the workspace path
#         """
#         self.obj = obj
#         self.obj_dir = os.path.dirname(obj)
#         self.compiler = compiler
#         self.workspace = workspace
#         self.build_cmd = None      # build cmd
#         self.error = "OK"
# 
#     def __str__(self):
#         """
#         """
#         return self.build_cmd
#     
#     def GetBuildCmd(self):
#         """
#         return the build cmd
#         """
#         return self.build_cmd
# 
#     def Error(self):
#         """
#         return the error message
#         """
#         return self.error
# 
# Path: util/Function.py
# DIGITS = [str(x) for x in xrange(0, 10)] 
# ALPHABETS = []
# def CheckName(v):
# def DelFiles(path):
# def MoveFiles(src, dst):
# def Mkdir(target_dir):
# def CalcHash(data, method='MD5'):
# def GetFileHash(path, method='MD5'):
# def RunCommand(cmd, ignore_stderr_when_ok=False):
# def RunCommand_tty(cmd):


import os
import sys
import unittest
from dependency import Builder
from util import Function
broc_path = os.path.realpath(os.path.join(os.path.realpath(__file__), '..', '..'))
sys.path.insert(0, broc_path)

class TestBuilder(unittest.TestCase):
    """
    unit test for Builder
    """
    def setUp(self):
        """
        """
        pass

    def tearDown(self):
        """
        """
        pass

    def test_BinBuilder(self):
        """
        test BinBuilder
        """
        obj = 'broc_out/a/b/c/test'
        dep_objs = ['a/b/c/fun.o', 'a/b/c/util.o']
        dep_libs = ['broc_out/a/b/d/output/lib/libfun.a', 'broc_out/a/b/d/output/lib/libutil.a']
        dep_links = ['-DBROC', '-Werror', '-Wpublick=private']
        compiler = '/usr/bin/g++'
        right_cmd = "mkdir -p broc_out/a/b/c && /usr/bin/g++ \\\n\t-DBROC \\\n\t-o \
\\\n\tbroc_out/a/b/c/test \\\n\ta/b/c/fun.o \\\n\ta/b/c/util.o \\\n\t-DBROC \\\n\t-Werror \
\\\n\t-Wpublick=private \\\n\t-Xlinker \\\n\t\"-(\" \\\n\t\tbroc_out/a/b/d/output/lib/libfun.a \
\\\n\t\tbroc_out/a/b/d/output/lib/libutil.a \\\n\t-Xlinker \\\n\t\"-)\""

# Path: dependency/Builder.py
# class Builder(object):
#     """
#     base class for splicing the compile command
#     """
#     def __init__(self, obj, compiler, workspace):
#         """
#         init function
#         Args:
#             obj : the cvs path of object file
#             compiler : the path of compiler
#             workspace : the workspace path
#         """
#         self.obj = obj
#         self.obj_dir = os.path.dirname(obj)
#         self.compiler = compiler
#         self.workspace = workspace
#         self.build_cmd = None      # build cmd
#         self.error = "OK"
# 
#     def __str__(self):
#         """
#         """
#         return self.build_cmd
#     
#     def GetBuildCmd(self):
#         """
#         return the build cmd
#         """
#         return self.build_cmd
# 
#     def Error(self):
#         """
#         return the error message
#         """
#         return self.error
# 
# Path: util/Function.py
# DIGITS = [str(x) for x in xrange(0, 10)] 
# ALPHABETS = []
# def CheckName(v):
# def DelFiles(path):
# def MoveFiles(src, dst):
# def Mkdir(target_dir):
# def CalcHash(data, method='MD5'):
# def GetFileHash(path, method='MD5'):
# def RunCommand(cmd, ignore_stderr_when_ok=False):
# def RunCommand_tty(cmd):


# Path: unittest/test_Builder.py
import os
import sys
import unittest
from dependency import Builder
from util import Function

broc_path = os.path.realpath(os.path.join(os.path.realpath(__file__), '..', '..'))
sys.path.insert(0, broc_path)

class TestBuilder(unittest.TestCase):
    """
    unit test for Builder
    """
    def setUp(self):
        """
        """
        pass

    def tearDown(self):
        """
        """
        pass

    def test_BinBuilder(self):
        """
        test BinBuilder
        """
        obj = 'broc_out/a/b/c/test'
        dep_objs = ['a/b/c/fun.o', 'a/b/c/util.o']
        dep_libs = ['broc_out/a/b/d/output/lib/libfun.a', 'broc_out/a/b/d/output/lib/libutil.a']
        dep_links = ['-DBROC', '-Werror', '-Wpublick=private']
        compiler = '/usr/bin/g++'
        right_cmd = "mkdir -p broc_out/a/b/c && /usr/bin/g++ \\\n\t-DBROC \\\n\t-o \
\\\n\tbroc_out/a/b/c/test \\\n\ta/b/c/fun.o \\\n\ta/b/c/util.o \\\n\t-DBROC \\\n\t-Werror \
\\\n\t-Wpublick=private \\\n\t-Xlinker \\\n\t\"-(\" \\\n\t\tbroc_out/a/b/d/output/lib/libfun.a \
\\\n\t\tbroc_out/a/b/d/output/lib/libutil.a \\\n\t-Xlinker \\\n\t\"-)\""

        builder = Builder.BinBuilder(obj, dep_objs, dep_libs, dep_links, compiler, '.')          