Skip to content

Commit f47628a

Browse files
committed
add test for folly::fbstring
1 parent daa3cb0 commit f47628a

File tree

4 files changed

+117
-2
lines changed

4 files changed

+117
-2
lines changed

.circleci/config.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ jobs:
141141
clang-12 \
142142
libboost-all-dev \
143143
libgflags-dev \
144-
llvm-12-dev
144+
llvm-12-dev \
145+
libfmt-dev \
146+
libjemalloc-dev
145147
- run:
146148
name: Test
147149
environment:

test/integration/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set(INTEGRATION_TEST_CONFIGS
55
container_enums.toml
66
cycles.toml
77
enums.toml
8+
fbstring.toml
89
ignored.toml
910
inheritance_access.toml
1011
inheritance_multiple.toml

test/integration/fbstring.toml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
includes = ["folly/FBString.h"]
2+
[cases]
3+
[cases.empty]
4+
param_types = ["folly::fbstring&"]
5+
setup = "return {};"
6+
expect_json = '''
7+
[
8+
{
9+
"typeName": "fbstring",
10+
"isTypedef": true,
11+
"staticSize": 24,
12+
"dynamicSize": 0,
13+
"exclusiveSize": 0,
14+
"members": [
15+
{
16+
"staticSize": 24,
17+
"dynamicSize": 0,
18+
"exclusiveSize": 24,
19+
"length": 0,
20+
"capacity": 23,
21+
"elementStaticSize": 1
22+
}
23+
]
24+
}
25+
]
26+
'''
27+
28+
[cases.inline]
29+
param_types = ["folly::fbstring&"]
30+
setup = 'return {"012345"};'
31+
expect_json = '''
32+
[
33+
{
34+
"typeName": "fbstring",
35+
"isTypedef": true,
36+
"staticSize": 24,
37+
"dynamicSize": 0,
38+
"exclusiveSize": 0,
39+
"members": [
40+
{
41+
"staticSize": 24,
42+
"dynamicSize": 0,
43+
"exclusiveSize": 24,
44+
"length": 6,
45+
"capacity": 23,
46+
"elementStaticSize": 1
47+
}
48+
]
49+
}
50+
]
51+
'''
52+
53+
[cases.heap_allocated]
54+
param_types = ["folly::fbstring&"]
55+
setup = 'return {"abcdefghijklmnopqrstuvwxzy"};'
56+
expect_json = '''
57+
[
58+
{
59+
"typeName": "fbstring",
60+
"isTypedef": true,
61+
"staticSize": 24,
62+
"dynamicSize": 26,
63+
"exclusiveSize": 0,
64+
"members": [
65+
{
66+
"staticSize": 24,
67+
"dynamicSize": 26,
68+
"exclusiveSize": 50,
69+
"length": 26,
70+
"capacity": 26,
71+
"elementStaticSize": 1
72+
}
73+
]
74+
}
75+
]
76+
'''
77+
78+
[cases.string_pooled]
79+
skip = "Potentially incorrect dynamic size"
80+
param_types = ["folly::fbstring&"]
81+
setup = "return folly::fbstring(1024, 'c');"
82+
expect_json = '''
83+
[
84+
{
85+
"typeName": "fbstring",
86+
"isTypedef": true,
87+
"staticSize": 24,
88+
"dynamicSize": 1024,
89+
"exclusiveSize": 0,
90+
"members": [
91+
{
92+
"staticSize": 24,
93+
"dynamicSize": 1024,
94+
"exclusiveSize": 1048,
95+
"length": 1024,
96+
"capacity": 1024,
97+
"elementStaticSize": 1
98+
}
99+
]
100+
}
101+
]
102+
'''

types/fb_string_type.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ typeName = "folly::basic_fbstring<"
33
numTemplateParams = 1
44
ctype = "FB_STRING_TYPE"
55
header = "folly/FBString.h"
6-
ns = ["folly::basic_fbstring"]
6+
ns = ["folly::basic_fbstring", "folly::fbstring_core"]
77
replaceTemplateParamIndex = []
88
# allocatorIndex = 0
99
# underlyingContainerIndex = 0
@@ -18,8 +18,18 @@ func = """
1818
template <typename E,class T,class A,class Storage>
1919
void getSizeType(const %1%<E, T, A, Storage> &t, size_t& returnArg)
2020
{
21+
SAVE_SIZE(sizeof(%1%<E, T, A, Storage>));
22+
2123
SAVE_DATA((uintptr_t)(t.data()));
2224
SAVE_DATA((uintptr_t)t.capacity());
2325
SAVE_DATA((uintptr_t)t.size());
26+
27+
// Check if the string is contained within the type (inlined) so as not to double count.
28+
SAVE_SIZE(
29+
((uintptr_t)t.data() < (uintptr_t)(&t + sizeof(%1%<E, T, A, Storage>)))
30+
&&
31+
((uintptr_t)t.data() >= (uintptr_t)&t)
32+
? 0 : (t.capacity() * sizeof(T))
33+
);
2434
}
2535
"""

0 commit comments

Comments
 (0)