Skip to content

Commit 45a5ea4

Browse files
committed
native type test
1 parent 7149384 commit 45a5ea4

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tests/test_native_types.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env python
2+
# *****************************************************************************
3+
#
4+
# Copyright (c) 2013-2019 Andrea Bonomi <andrea.bonomi@gmail.com>
5+
#
6+
# Published under the terms of the MIT license.
7+
#
8+
# Permission is hereby granted, free of charge, to any person obtaining a copy
9+
# of this software and associated documentation files (the "Software"), to
10+
# deal in the Software without restriction, including without limitation the
11+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12+
# sell copies of the Software, and to permit persons to whom the Software is
13+
# furnished to do so, subject to the following conditions:
14+
#
15+
# The above copyright notice and this permission notice shall be included in
16+
# all copies or substantial portions of the Software.
17+
#
18+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24+
# IN THE SOFTWARE.
25+
#
26+
# *****************************************************************************
27+
28+
from cstruct import MemCStruct, sizeof
29+
from cstruct.base import TYPEDEFS
30+
from cstruct.native_types import AbstractNativeType
31+
32+
33+
class SizeT(AbstractNativeType):
34+
type_name = "size_t"
35+
native_format = "Q"
36+
37+
38+
class StructWithSizeT(MemCStruct):
39+
__def__ = """
40+
typedef size_t size;
41+
typedef unsigned long long ull;
42+
43+
struct StructWithSizeT {
44+
ull a;
45+
size_t b;
46+
size c;
47+
}
48+
"""
49+
50+
51+
def test_typedef():
52+
assert TYPEDEFS["size"] == "size_t"
53+
assert TYPEDEFS["ull"] == "unsigned long long"
54+
55+
56+
def test_sizeof_custom_native_type():
57+
assert sizeof("size_t") == 8
58+
assert sizeof("ull") == 8
59+
assert sizeof("struct StructWithSizeT") == 8 * 3

0 commit comments

Comments
 (0)