<s> """<STR_LIT>""" <EOL> import plistlib <EOL> import TestGyp <EOL> import os <EOL> import struct <EOL> import subprocess <EOL> import sys <EOL> import tempfile <EOL> if sys . platform == '<STR_LIT>' : <EOL> print "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> def CheckFileType ( file , expected ) : <EOL> proc = subprocess . Popen ( [ '<STR_LIT>' , '<STR_LIT>' , file ] , stdout = subprocess . PIPE ) <EOL> o = proc . communicate ( ) [ <NUM_LIT:0> ] . strip ( ) <EOL> assert not proc . returncode <EOL> if not expected in o : <EOL> print '<STR_LIT>' % ( expected , o ) <EOL> test . fail_test ( ) <EOL> def HasCerts ( ) : <EOL> proc = subprocess . Popen ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] , stdout = subprocess . PIPE ) <EOL> return "<STR_LIT>" not in proc . communicate ( ) [ <NUM_LIT:0> ] . strip ( ) <EOL> def CheckSignature ( file ) : <EOL> proc = subprocess . Popen ( [ '<STR_LIT>' , '<STR_LIT>' , file ] , stdout = subprocess . PIPE ) <EOL> o = proc . communicate ( ) [ <NUM_LIT:0> ] . strip ( ) <EOL> assert not proc . returncode <EOL> if "<STR_LIT>" in o : <EOL> print '<STR_LIT>' % ( file ) <EOL> test . fail_test ( ) <EOL> def CheckEntitlements ( file , expected_entitlements ) : <EOL> with tempfile . NamedTemporaryFile ( ) as temp : <EOL> proc = subprocess . Popen ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> temp . name , file ] , stdout = subprocess . PIPE ) <EOL> o = proc . communicate ( ) [ <NUM_LIT:0> ] . strip ( ) <EOL> assert not proc . returncode <EOL> data = temp . read ( ) <EOL> entitlements = ParseEntitlements ( data ) <EOL> if not entitlements : <EOL> print '<STR_LIT>' % ( file ) <EOL> test . fail_test ( ) <EOL> if entitlements != expected_entitlements : <EOL> print '<STR_LIT>' % ( file ) <EOL> test . fail_test ( ) <EOL> def ParseEntitlements ( data ) : <EOL> if len ( data ) < <NUM_LIT:8> : <EOL> return None <EOL> magic , length = struct . unpack ( '<STR_LIT>' , data [ : <NUM_LIT:8> ] ) <EOL> if magic != <NUM_LIT> or length != len ( data ) : <EOL> return None <EOL> return data [ <NUM_LIT:8> : ] <EOL> def GetProductVersion ( ) : <EOL> args = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> job = subprocess . Popen ( args , stdout = subprocess . PIPE ) <EOL> return job . communicate ( ) [ <NUM_LIT:0> ] . strip ( ) <EOL> def CheckPlistvalue ( plist , key , expected ) : <EOL> if key not in plist : <EOL> print '<STR_LIT>' % key <EOL> test . fail_test ( ) <EOL> return <EOL> actual = plist [ key ] <EOL> if actual != expected : <EOL> print '<STR_LIT>' % ( expected , actual , key ) <EOL> test . fail_test ( ) <EOL> def CheckPlistNotSet ( plist , key ) : <EOL> if key in plist : <EOL> print '<STR_LIT>' % key <EOL> test . fail_test ( ) <EOL> return <EOL> def ConvertBinaryPlistToXML ( path ) : <EOL> proc = subprocess . call ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , path ] , <EOL> stdout = subprocess . PIPE ) <EOL> if sys . platform == '<STR_LIT>' : <EOL> test = TestGyp . TestGyp ( formats = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> test . run_gyp ( '<STR_LIT>' , chdir = '<STR_LIT>' ) <EOL> test_configs = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if test . format == '<STR_LIT>' : <EOL> test_configs . remove ( '<STR_LIT>' ) <EOL> for configuration in test_configs : <EOL> test . set_configuration ( configuration ) <EOL> test . build ( '<STR_LIT>' , '<STR_LIT>' , chdir = '<STR_LIT>' ) <EOL> result_file = test . built_file_path ( '<STR_LIT>' , <EOL> chdir = '<STR_LIT>' ) <EOL> test . must_exist ( result_file ) <EOL> info_plist = test . built_file_path ( '<STR_LIT>' , <EOL> chdir = '<STR_LIT>' ) <EOL> if test . format == '<STR_LIT>' : <EOL> ConvertBinaryPlistToXML ( info_plist ) <EOL> plist = plistlib . readPlist ( info_plist ) <EOL> CheckPlistvalue ( plist , '<STR_LIT>' , [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> if configuration == '<STR_LIT>' : <EOL> CheckFileType ( result_file , '<STR_LIT>' ) <EOL> CheckPlistvalue ( plist , '<STR_LIT>' , GetProductVersion ( ) ) <EOL> CheckPlistvalue ( plist , '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> CheckPlistvalue ( plist , '<STR_LIT>' , '<STR_LIT>' ) <EOL> else : <EOL> CheckFileType ( result_file , '<STR_LIT>' ) <EOL> CheckPlistNotSet ( plist , '<STR_LIT>' ) <EOL> CheckPlistvalue ( plist , '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> CheckPlistvalue ( plist , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if HasCerts ( ) and configuration == '<STR_LIT>' : <EOL> test . build ( '<STR_LIT>' , '<STR_LIT>' , chdir = '<STR_LIT>' ) <EOL> result_file = test . built_file_path ( '<STR_LIT>' , <EOL> chdir = '<STR_LIT>' ) <EOL> CheckSignature ( result_file ) <EOL> info_plist = test . built_file_path ( '<STR_LIT>' , <EOL> chdir = '<STR_LIT>' ) <EOL> plist = plistlib . readPlist ( info_plist ) <EOL> CheckPlistvalue ( plist , '<STR_LIT>' , [ <NUM_LIT:1> ] ) <EOL> entitlements_file = test . built_file_path ( '<STR_LIT>' , <EOL> chdir = '<STR_LIT>' ) <EOL> if os . path . isfile ( entitlements_file ) : <EOL> expected_entitlements = open ( entitlements_file ) . read ( ) <EOL> CheckEntitlements ( result_file , expected_entitlements ) <EOL> test . pass_test ( ) </s>
