12c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil#!/usr/bin/env python2 22c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# 32c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# Copyright (C) 2014 The Android Open Source Project 42c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# 52c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# Licensed under the Apache License, Version 2.0 (the "License"); 62c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# you may not use this file except in compliance with the License. 72c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# You may obtain a copy of the License at 82c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# 92c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# http://www.apache.org/licenses/LICENSE-2.0 102c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# 112c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# Unless required by applicable law or agreed to in writing, software 122c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# distributed under the License is distributed on an "AS IS" BASIS, 132c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 142c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# See the License for the specific language governing permissions and 152c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# limitations under the License. 162c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil 172c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdilfrom common.testing import ToUnicode 182c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdilfrom file_format.c1visualizer.parser import ParseC1visualizerStream 192c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdilfrom file_format.c1visualizer.struct import C1visualizerFile, C1visualizerPass 202c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil 212c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdilimport io 222c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdilimport unittest 232c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil 242c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdilclass C1visualizerParser_Test(unittest.TestCase): 252c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil 262c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil def createFile(self, passList): 272c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil """ Creates an instance of CheckerFile from provided info. 282c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil 292c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil Data format: [ ( <case-name>, [ ( <text>, <assert-variant> ), ... ] ), ... ] 302c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil """ 312c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil c1File = C1visualizerFile("<c1_file>") 322c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil for passEntry in passList: 332c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil passName = passEntry[0] 342c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil passBody = passEntry[1] 352c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil c1Pass = C1visualizerPass(c1File, passName, passBody, 0) 362c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil return c1File 372c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil 382c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil def assertParsesTo(self, c1Text, expectedData): 392c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil expectedFile = self.createFile(expectedData) 402c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil actualFile = ParseC1visualizerStream("<c1_file>", io.StringIO(ToUnicode(c1Text))) 412c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil return self.assertEqual(expectedFile, actualFile) 422c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil 432c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil def test_EmptyFile(self): 442c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil self.assertParsesTo("", []) 452c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil 462c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil def test_SingleGroup(self): 472c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil self.assertParsesTo( 482c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil """ 492c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil begin_compilation 502c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil method "MyMethod" 512c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil end_compilation 522c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil begin_cfg 532c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil name "pass1" 542c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil foo 552c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil bar 562c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil end_cfg 572c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil """, 582c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil [ ( "MyMethod pass1", [ "foo", "bar" ] ) ]) 592c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil 602c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil def test_MultipleGroups(self): 612c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil self.assertParsesTo( 622c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil """ 632c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil begin_compilation 642c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil name "xyz1" 652c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil method "MyMethod1" 662c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil date 1234 672c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil end_compilation 682c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil begin_cfg 692c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil name "pass1" 702c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil foo 712c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil bar 722c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil end_cfg 732c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil begin_cfg 742c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil name "pass2" 752c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil abc 762c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil def 772c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil end_cfg 782c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil """, 792c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil [ ( "MyMethod1 pass1", [ "foo", "bar" ] ), 802c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil ( "MyMethod1 pass2", [ "abc", "def" ] ) ]) 812c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil self.assertParsesTo( 822c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil """ 832c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil begin_compilation 842c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil name "xyz1" 852c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil method "MyMethod1" 862c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil date 1234 872c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil end_compilation 882c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil begin_cfg 892c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil name "pass1" 902c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil foo 912c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil bar 922c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil end_cfg 932c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil begin_compilation 942c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil name "xyz2" 952c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil method "MyMethod2" 962c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil date 5678 972c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil end_compilation 982c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil begin_cfg 992c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil name "pass2" 1002c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil abc 1012c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil def 1022c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil end_cfg 1032c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil """, 1042c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil [ ( "MyMethod1 pass1", [ "foo", "bar" ] ), 1052c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil ( "MyMethod2 pass2", [ "abc", "def" ] ) ]) 106