Skip to content

Commit a78e700

Browse files
committed
Add integration tests.
1 parent d9db740 commit a78e700

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

bindgen-integration/cpp/Test.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "Test.h"
22

3+
#include <stdio.h>
4+
35
const int Test::COUNTDOWN[] = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
46
const int* Test::COUNTDOWN_PTR = Test::COUNTDOWN;
57

@@ -130,4 +132,17 @@ Seventh::assert(bool first,
130132
this->seventh_thirty_bits == seventh;
131133
};
132134

135+
bool
136+
Eight::assert(char a, unsigned b) const
137+
{
138+
printf("{ a: %u, b: %u }\n", this->a, this->b);
139+
return this->a == a && this->b == b;
140+
}
141+
142+
bool
143+
Ninth::assert(char a, unsigned short b) const
144+
{
145+
return this->a == a && this->b == b;
146+
}
147+
133148
} // namespace bitfields

bindgen-integration/cpp/Test.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,22 @@ struct Seventh {
163163
int seventh);
164164
};
165165

166+
struct Eight {
167+
unsigned char a;
168+
unsigned b : 15;
169+
170+
/// Returns true if the bitfields match the arguments, false otherwise.
171+
bool assert(char a, unsigned b) const;
172+
};
173+
174+
struct Ninth {
175+
unsigned char a;
176+
unsigned short b : 15;
177+
178+
/// Returns true if the bitfields match the arguments, false otherwise.
179+
bool assert(char a, unsigned short b) const;
180+
};
181+
166182
} // namespace bitfields
167183

168184
struct AutoRestoreBool {

bindgen-integration/src/lib.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,34 @@ fn test_bitfields_seventh() {
213213
assert_eq!(large.seventh_thirty_bits(), 1061657575);
214214
}
215215

216+
#[test]
217+
fn test_bitfields_eight() {
218+
let mut s: bindings::bitfields::Eight = unsafe { mem::zeroed() };
219+
assert!(unsafe { s.assert(0, 0) });
220+
221+
s.a = 10;
222+
s.set_b(1);
223+
224+
assert!(unsafe { s.assert(10, 1) });
225+
226+
assert_eq!(s.a, 10);
227+
assert_eq!(s.b(), 1);
228+
}
229+
230+
#[test]
231+
fn test_bitfields_ninth() {
232+
let mut s: bindings::bitfields::Ninth = unsafe { mem::zeroed() };
233+
assert!(unsafe { s.assert(0, 0) });
234+
235+
s.a = 10;
236+
s.set_b(656);
237+
238+
assert!(unsafe { s.assert(10, 656) });
239+
240+
assert_eq!(s.a, 10);
241+
assert_eq!(s.b(), 656);
242+
}
243+
216244
#[test]
217245
fn test_bitfield_constructors() {
218246
use std::mem;

0 commit comments

Comments
 (0)