def testUserExtentionHeader(self): dec = Dec('test.dec', False) # OK: [userextensions.intel."myid"] dec._RawData.CurrentLine = CleanString(dec._RawData.GetNextLine())[0] dec._UserExtentionSectionParser() self.assertEqual(len(dec._RawData.CurrentScope), 1) self.assertEqual(dec._RawData.CurrentScope[0][0], 'userextensions'.upper()) self.assertEqual(dec._RawData.CurrentScope[0][1], 'intel') self.assertEqual(dec._RawData.CurrentScope[0][2], '"myid"') self.assertEqual(dec._RawData.CurrentScope[0][3], 'COMMON') # OK: [userextensions.intel."myid".IA32] dec._RawData.CurrentLine = CleanString(dec._RawData.GetNextLine())[0] dec._UserExtentionSectionParser() self.assertEqual(len(dec._RawData.CurrentScope), 1) self.assertEqual(dec._RawData.CurrentScope[0][0], 'userextensions'.upper()) self.assertEqual(dec._RawData.CurrentScope[0][1], 'intel') self.assertEqual(dec._RawData.CurrentScope[0][2], '"myid"') self.assertEqual(dec._RawData.CurrentScope[0][3], 'IA32') # Fail: [userextensions.intel."myid".IA32,] dec._RawData.CurrentLine = CleanString(dec._RawData.GetNextLine())[0] self.assertRaises(FatalError, dec._UserExtentionSectionParser) # Fail: [userextensions.intel."myid] dec._RawData.CurrentLine = CleanString(dec._RawData.GetNextLine())[0] self.assertRaises(FatalError, dec._UserExtentionSectionParser)
def testCleanString(self): Line, Comment = CleanString('') self.assertEqual(Line, '') self.assertEqual(Comment, '') Line, Comment = CleanString('line without comment') self.assertEqual(Line, 'line without comment') self.assertEqual(Comment, '') Line, Comment = CleanString('# pure comment') self.assertEqual(Line, '') self.assertEqual(Comment, '# pure comment') Line, Comment = CleanString('line # and comment') self.assertEqual(Line, 'line') self.assertEqual(Comment, '# and comment')
def testSectionHeader(self): dec = Dec('test.dec', False) # [no section start or end dec._RawData.CurrentLine = CleanString(dec._RawData.GetNextLine())[0] self.assertRaises(FatalError, dec._SectionHeaderParser) #[,] # empty sub-section dec._RawData.CurrentLine = CleanString(dec._RawData.GetNextLine())[0] self.assertRaises(FatalError, dec._SectionHeaderParser) # [unknow_section_name] dec._RawData.CurrentLine = CleanString(dec._RawData.GetNextLine())[0] self.assertRaises(FatalError, dec._SectionHeaderParser) # [Includes.IA32.other] # no third one dec._RawData.CurrentLine = CleanString(dec._RawData.GetNextLine())[0] self.assertRaises(FatalError, dec._SectionHeaderParser) # [PcdsFeatureFlag, PcdsFixedAtBuild] dec._RawData.CurrentLine = CleanString(dec._RawData.GetNextLine())[0] self.assertRaises(FatalError, dec._SectionHeaderParser) # [Includes.IA32, Includes.IA32] dec._RawData.CurrentLine = CleanString(dec._RawData.GetNextLine())[0] dec._SectionHeaderParser() self.assertEqual(len(dec._RawData.CurrentScope), 1) self.assertEqual(dec._RawData.CurrentScope[0][0], 'Includes'.upper()) self.assertEqual(dec._RawData.CurrentScope[0][1], 'IA32') # [Includes, Includes.IA32] # common cannot be with other arch dec._RawData.CurrentLine = CleanString(dec._RawData.GetNextLine())[0] self.assertRaises(FatalError, dec._SectionHeaderParser) # [Includes.IA32, PcdsFeatureFlag] # different section name not allowed dec._RawData.CurrentLine = CleanString(dec._RawData.GetNextLine())[0] self.assertRaises(FatalError, dec._SectionHeaderParser)
def testCleanStringCpp(self): Line, Comment = CleanString('line // and comment', AllowCppStyleComment=True) self.assertEqual(Line, 'line') self.assertEqual(Comment, '# and comment')