示例#1
0
 def test_WriteLinesAndReadLines(self):
     fileName = "test.txt"
     line1 = "line1"
     line2 = "line2"
     lineList = [line1, line2]
     myTextFileManager = TextFileManager(fileName)
     self.assertEqual(fileName, myTextFileManager.fileName)
     myTextFileManager.writeLines(lineList)
     #myTextFileManager.readLines()
     self.assertEqual(lineList, myTextFileManager.readLines())
     os.remove(fileName)
	def test_WriteLinesAndReadLines(self):
		fileName="test.txt"
		line1="line1"
		line2="line2"
		lineList=[line1, line2]
		myTextFileManager = TextFileManager(fileName);
		self.assertEqual(fileName, myTextFileManager.fileName);
		myTextFileManager.writeLines(lineList)
		#myTextFileManager.readLines()
		self.assertEqual(lineList, myTextFileManager.readLines())
		os.remove(fileName)
示例#3
0
 def test_InsertLineAfter(self):
     fileName = "test.txt"
     line1 = "line1"
     line2 = "line2"
     line3 = "line3"
     lineList1 = [line1, line3]
     lineList2 = [line1, line2, line3]
     myTextFileManager = TextFileManager(fileName)
     myTextFileManager.writeLines(lineList1)
     myTextFileManager2 = TextFileManager(fileName)
     myTextFileManager2.insertLineBefore(line2, line3)
     self.assertEqual(lineList2, myTextFileManager2.readLines())
     os.remove(fileName)
	def test_ReadAndWriteString(self):
		fileName1="test.txt"
		fileName2="test2.txt"
		line1="line1"
		line2="line2"
		line3="line3"
		lineList2=[line1, line2,line3]
		myTextFileManager = TextFileManager(fileName1);
		myTextFileManager2 = TextFileManager(fileName2);
		myTextFileManager.writeLines(lineList2)
		#print myTextFileManager.readString()
		myTextFileManager2.writeString(myTextFileManager.readString())
		self.assertEqual(myTextFileManager.readString(), myTextFileManager2.readString())
		os.remove(fileName1)
		os.remove(fileName2)		
	def test_InsertLineAfter(self):
		fileName="test.txt"
		line1="line1"
		line2="line2"
		line3="line3"
		lineList1=[line1, line3]
		lineList2=[line1, line2,line3]
		myTextFileManager = TextFileManager(fileName);
		myTextFileManager.writeLines(lineList1)
		myTextFileManager2 = TextFileManager(fileName);
		myTextFileManager2.insertLineBefore(line2,line3)
		self.assertEqual(lineList2,myTextFileManager2.readLines())
		os.remove(fileName)
示例#6
0
    def addClass(self, className):
        #add the src file: className.cpp in ./src/ direcotry
        srcFile = self.workingPath + "/src/" + className + ".cpp"
        if os.path.isfile(srcFile):
            print srcFile, " already exists, we need not add this class:", className
            return
        srcFileManager = TextFileManager(srcFile)
        srcFileManager.writeString(self.genSRCString(className))

        ##add the header file: className.hpp in ./inc/ direcotry
        incFile = self.workingPath + "/inc/" + className + ".hpp"
        if os.path.isfile(incFile):
            print incFile, "already exists, we need not add this class:", className
            return
        incFileManager = TextFileManager(incFile)
        incFileManager.writeString(self.genINCString(className))

        #Added GoogleTest test case source code file:testClassName.cpp in ./tests/ directory
        testFile = self.workingPath + "/tests/test" + className + ".cpp"
        if os.path.isfile(testFile):
            print testFile, " already exists, we need not add this class:", className
            return
        testFileManager = TextFileManager(testFile)
        testFileManager.writeString(self.genTestCodeString(className))

        #Add line in inc.cfg
        incCfgFile = self.workingPath + "/inc.cfg"
        incCfgFileManager = TextFileManager(incCfgFile)
        #add "export                  CLASS_LIST+=ClassName"
        insertString = "export              CLASS_LIST+= "
        insertString += className
        incCfgFileManager.insertLineBefore(
            insertString, "#The above CLASS_LIST definition done")
        #add "export BASH_CLASS_LIST+=ClassName"
        insertString = "export BASH_CLASS_LIST+=\" "
        insertString += className
        insertString += "\""
        incCfgFileManager.insertLineBefore(
            insertString, "#The above BASH_CLASS_LIST definition done")

        #add "export DEBUG_ClassName=${ENABLE_DEBUG_VALUE}"
        insertString = "export DEBUG_" + className + "=${ENABLE_DEBUG_VALUE}"
        incCfgFileManager.insertLineBefore(
            insertString, "#The above debug flag switch done")
        #add "#export DEBUG_ClassName=1"
        insertString = "#export DEBUG_" + className + "=1"
        incCfgFileManager.insertLineBefore(
            insertString, "#The above debug flag switch done")
        #add "export DEBUG_testClassName=${DEBUG_ClassName}"
        insertString = "export DEBUG_test" + className + "=${DEBUG_" + className + "}\n"
        incCfgFileManager.insertLineBefore(
            insertString, "#The above debug flag switch done")

        makefileFile = self.workingPath + "/makefile"
        makefileFileManager = TextFileManager(makefileFile)
        #add "$(TESTS_PATH)/testClassName.o : $(TESTS_PATH)/testClassName.d" into ./makefile
        insertString = "$(TESTS_PATH)/test" + className + ".o : $(TESTS_PATH)/test" + className + ".d"
        makefileFileManager.insertLineBefore(
            insertString, "####The above class test cases finished here")
        #add "$(TESTS_PATH)/testClassName : $(TESTS_PATH)/testClassName.o libMyClass.a" into ./makefile
        insertString = "$(TESTS_PATH)/test" + className + " : $(TESTS_PATH)/test" + className + ".o libMyClass.a"
        makefileFileManager.insertLineBefore(
            insertString, "####The above class test cases finished here")
        #add "	$(CXX)  $^ -o $@ $(CPPFLAGS)" into ./makefile
        insertString = "	$(CXX)  $^ -o $@ $(CPPFLAGS)\n"
        makefileFileManager.insertLineBefore(
            insertString, "####The above class test cases finished here")
示例#7
0
 def test_ReadAndWriteString(self):
     fileName1 = "test.txt"
     fileName2 = "test2.txt"
     line1 = "line1"
     line2 = "line2"
     line3 = "line3"
     lineList2 = [line1, line2, line3]
     myTextFileManager = TextFileManager(fileName1)
     myTextFileManager2 = TextFileManager(fileName2)
     myTextFileManager.writeLines(lineList2)
     #print myTextFileManager.readString()
     myTextFileManager2.writeString(myTextFileManager.readString())
     self.assertEqual(myTextFileManager.readString(),
                      myTextFileManager2.readString())
     os.remove(fileName1)
     os.remove(fileName2)
示例#8
0
	def addClass(self, className):
		#add the src file: className.cpp in ./src/ direcotry
		srcFile=self.workingPath+"/src/"+className+".cpp"
		if os.path.isfile(srcFile):
			print srcFile, " already exists, we need not add this class:", className
			return
		srcFileManager=TextFileManager(srcFile)
		srcFileManager.writeString(self.genSRCString(className))

		##add the header file: className.hpp in ./inc/ direcotry
		incFile=self.workingPath+"/inc/"+className+".hpp"
		if os.path.isfile(incFile):
			print incFile, "already exists, we need not add this class:", className
			return
		incFileManager=TextFileManager(incFile)
		incFileManager.writeString(self.genINCString(className))

		#Added GoogleTest test case source code file:testClassName.cpp in ./tests/ directory
		testFile=self.workingPath+"/tests/test"+className+".cpp"
		if os.path.isfile(testFile):
			print testFile, " already exists, we need not add this class:", className
			return
		testFileManager=TextFileManager(testFile)
		testFileManager.writeString(self.genTestCodeString(className))

		#Add line in inc.cfg
		incCfgFile=self.workingPath+"/inc.cfg"
		incCfgFileManager=TextFileManager(incCfgFile)
		#add "export                  CLASS_LIST+=ClassName"
		insertString="export              CLASS_LIST+= "
		insertString+=className
		incCfgFileManager.insertLineBefore(insertString, "#The above CLASS_LIST definition done")
		#add "export BASH_CLASS_LIST+=ClassName"
		insertString="export BASH_CLASS_LIST+=\" "
		insertString+=className
		insertString+="\""
		incCfgFileManager.insertLineBefore(insertString, "#The above BASH_CLASS_LIST definition done")

		#add "export DEBUG_ClassName=${ENABLE_DEBUG_VALUE}"
		insertString="export DEBUG_"+className+"=${ENABLE_DEBUG_VALUE}"
		incCfgFileManager.insertLineBefore(insertString, "#The above debug flag switch done")
		#add "#export DEBUG_ClassName=1"
		insertString="#export DEBUG_"+className+"=1"
		incCfgFileManager.insertLineBefore(insertString, "#The above debug flag switch done")
		#add "export DEBUG_testClassName=${DEBUG_ClassName}"
		insertString="export DEBUG_test"+className+"=${DEBUG_"+className+"}\n"
		incCfgFileManager.insertLineBefore(insertString, "#The above debug flag switch done")


		makefileFile=self.workingPath+"/makefile"
		makefileFileManager=TextFileManager(makefileFile)
		#add "$(TESTS_PATH)/testClassName.o : $(TESTS_PATH)/testClassName.d" into ./makefile
		insertString="$(TESTS_PATH)/test"+className+".o : $(TESTS_PATH)/test"+className+".d"
		makefileFileManager.insertLineBefore(insertString, "####The above class test cases finished here")
		#add "$(TESTS_PATH)/testClassName : $(TESTS_PATH)/testClassName.o libMyClass.a" into ./makefile
		insertString="$(TESTS_PATH)/test"+className+" : $(TESTS_PATH)/test"+className+".o libMyClass.a"
		makefileFileManager.insertLineBefore(insertString, "####The above class test cases finished here")
		#add "	$(CXX)  $^ -o $@ $(CPPFLAGS)" into ./makefile
		insertString="	$(CXX)  $^ -o $@ $(CPPFLAGS)\n"
		makefileFileManager.insertLineBefore(insertString, "####The above class test cases finished here")