1#!/usr/bin/env python
2#
3# Copyright (C) 2018 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import unittest
18import make_header
19
20test_input = r'''
21// Check that the various other assembly lines are ignored.
22.globl  _Z49AsmDefineHelperFor_MIRROR_OBJECT_LOCK_WORD_OFFSETv
23.type   _Z49AsmDefineHelperFor_MIRROR_OBJECT_LOCK_WORD_OFFSETv,%function
24.ascii  ">>MIRROR_OBJECT_LOCK_WORD_OFFSET #4 #0<<"
25bx      lr
26
27// Check large positive 32-bit constant.
28.ascii  ">>OBJECT_ALIGNMENT_MASK_TOGGLED #4294967288 #0<<"
29
30// Check large positive 64-bit constant (it overflows into negative value).
31.ascii  ">>OBJECT_ALIGNMENT_MASK_TOGGLED64 #-8 #0<<"
32
33// Check negative constant.
34.ascii  ">>JIT_CHECK_OSR #-1 #1<<"
35'''
36
37test_output = r'''
38#define JIT_CHECK_OSR -0x1
39#define MIRROR_OBJECT_LOCK_WORD_OFFSET 0x4
40#define OBJECT_ALIGNMENT_MASK_TOGGLED 0xfffffff8
41#define OBJECT_ALIGNMENT_MASK_TOGGLED64 0xfffffffffffffff8
42'''
43
44class CppDefineGeneratorTest(unittest.TestCase):
45  def test_convert(self):
46    self.assertEqual(test_output.strip(), make_header.convert(test_input))
47
48if __name__ == '__main__':
49  unittest.main()
50