1#!/usr/bin/python 2# 3# Copyright 2016 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 18 19import cstruct 20 21 22# These aren't constants, they're classes. So, pylint: disable=invalid-name 23TestStructA = cstruct.Struct("TestStructA", "=BI", "byte1 int2") 24TestStructB = cstruct.Struct("TestStructB", "=BI", "byte1 int2") 25 26 27class CstructTest(unittest.TestCase): 28 29 def CheckEquals(self, a, b): 30 self.assertEquals(a, b) 31 self.assertEquals(b, a) 32 assert a == b 33 assert b == a 34 assert not (a != b) # pylint: disable=g-comparison-negation,superfluous-parens 35 assert not (b != a) # pylint: disable=g-comparison-negation,superfluous-parens 36 37 def CheckNotEquals(self, a, b): 38 self.assertNotEquals(a, b) 39 self.assertNotEquals(b, a) 40 assert a != b 41 assert b != a 42 assert not (a == b) # pylint: disable=g-comparison-negation,superfluous-parens 43 assert not (b == a) # pylint: disable=g-comparison-negation,superfluous-parens 44 45 def testEqAndNe(self): 46 a1 = TestStructA((1, 2)) 47 a2 = TestStructA((2, 3)) 48 a3 = TestStructA((1, 2)) 49 b = TestStructB((1, 2)) 50 self.CheckNotEquals(a1, b) 51 self.CheckNotEquals(a2, b) 52 self.CheckNotEquals(a1, a2) 53 self.CheckNotEquals(a2, a3) 54 for i in [a1, a2, a3, b]: 55 self.CheckEquals(i, i) 56 self.CheckEquals(a1, a3) 57 58 59if __name__ == "__main__": 60 unittest.main() 61