Skip to content

Commit 675d32c

Browse files
committed
Add additional tests to cover untested functionality
1 parent b202dc0 commit 675d32c

19 files changed

+258
-0
lines changed

tests/cpp/gen/ft/buffers.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
3+
classes:
4+
Buffers:
5+
methods:
6+
set_buffer:
7+
buffers:
8+
- { type: in, src: data, len: len }
9+
get_buffer2:
10+
buffers:
11+
- { type: out, src: data, len: len }
12+
get_buffer1:
13+
buffers:
14+
- { type: out, src: data, len: len }
15+
16+
v_set_buffer:
17+
buffers:
18+
- { type: in, src: data, len: len }
19+
v_get_buffer2:
20+
buffers:
21+
- { type: out, src: data, len: len }
22+
v_get_buffer1:
23+
buffers:
24+
- { type: out, src: data, len: len }

tests/cpp/gen/ft/ignore.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ classes:
3636
Param1:
3737
ignore: true
3838
methods:
39+
ClassWithIgnored:
40+
cpp_code: |
41+
[](py::args) {
42+
return std::make_shared<ClassWithIgnored>(1);
43+
}
44+
keepalive: []
45+
param_override:
46+
y:
47+
ignore: true
3948
fnIgnore:
4049
ignore: true
4150
fnIgnoredParam:

tests/cpp/gen/ft/inline_code.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22

33
classes:
44
InlineCode:
5+
constants:
6+
- NS::inner::KONSTANT
57
enums:
68
MyE:
79
inline_code: |
810
.value("Value2", (InlineCode::MyE)2)
911
methods:
1012
get2:
13+
cpp_code_with_constant:
14+
cpp_code: |
15+
[](InlineCode *self) {
16+
return KONSTANT;
17+
}
1118
inline_code: |
1219
// you can even start with a comment
1320
.def("get4", [](InlineCode *self) {

tests/cpp/gen/ft/virtual_xform.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ functions:
55
classes:
66
VBase:
77
methods:
8+
different_cpp_and_py:
9+
cpp_code: |
10+
[](VBase * self, int x) {
11+
return x + 2;
12+
}
813
pure_io:
914
param_override:
1015
ss:

tests/cpp/pyproject.toml.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ generate = [
4444
{ abstract = "abstract.h" },
4545
{ base_qualname = "base_qualname.h" },
4646
{ base_qualname_hidden = "base_qualname_hidden.h" },
47+
{ buffers = "buffers.h" },
4748
{ custom_type_caster = "custom_type_caster.h" },
4849
{ defaults = "defaults.h" },
4950
{ docstrings = "docstrings.h" },
@@ -56,6 +57,7 @@ generate = [
5657
{ inline_code = "inline_code.h" },
5758
{ lifetime = "lifetime.h" },
5859
{ nested = "nested.h" },
60+
{ operators = "operators.h" },
5961
{ overloads = "overloads.h" },
6062
{ parameters = "parameters.h" },
6163
{ refqual = "refqual.h" },

tests/cpp/rpytest/ft/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# autogenerated by 'robotpy-build create-imports rpytest.ft rpytest.ft._rpytest_ft'
44
from ._rpytest_ft import (
55
Abstract,
6+
Buffers,
67
ClassWithFields,
78
ClassWithIgnored,
89
ClassWithTrampoline,
@@ -19,6 +20,7 @@
1920
GEnum,
2021
GEnumMath,
2122
HasFactory,
23+
HasOperator,
2224
IBase,
2325
IChild,
2426
IFinal,
@@ -80,6 +82,7 @@
8082
VChild,
8183
VirtualComma,
8284
checkConvertRpyintToInt,
85+
check_different_cpp_and_py,
8386
check_impure_io,
8487
check_pure_io,
8588
convertRpyintToInt,
@@ -107,6 +110,7 @@
107110

108111
__all__ = [
109112
"Abstract",
113+
"Buffers",
110114
"ClassWithFields",
111115
"ClassWithIgnored",
112116
"ClassWithTrampoline",
@@ -123,6 +127,7 @@
123127
"GEnum",
124128
"GEnumMath",
125129
"HasFactory",
130+
"HasOperator",
126131
"IBase",
127132
"IChild",
128133
"IFinal",
@@ -184,6 +189,7 @@
184189
"VChild",
185190
"VirtualComma",
186191
"checkConvertRpyintToInt",
192+
"check_different_cpp_and_py",
187193
"check_impure_io",
188194
"check_pure_io",
189195
"convertRpyintToInt",
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#pragma once
2+
3+
#include <cstring>
4+
#include <vector>
5+
6+
class Buffers {
7+
public:
8+
9+
// in
10+
void set_buffer(const uint8_t *data, size_t len) {
11+
m_buf.resize(len);
12+
memcpy(m_buf.data(), data, len);
13+
}
14+
15+
// out
16+
// - data is bytes
17+
// - len is input_size and output size
18+
void get_buffer2(uint8_t *data, size_t *len) {
19+
*len = get_buffer1(data, *len);
20+
}
21+
22+
// out
23+
// - data is bytes
24+
// - len is input size
25+
// - return value is output size
26+
size_t get_buffer1(uint8_t *data, size_t len) {
27+
size_t rlen = len < m_buf.size() ? len : m_buf.size();
28+
if (rlen) {
29+
memcpy(data, m_buf.data(), rlen);
30+
}
31+
return rlen;
32+
}
33+
34+
//
35+
// virtual functions -- trampolines are disabled but normal function
36+
// calls work
37+
//
38+
39+
virtual void v_set_buffer(const uint8_t *data, size_t len) {
40+
set_buffer(data, len);
41+
}
42+
43+
virtual void v_get_buffer2(uint8_t *data, size_t *len) {
44+
get_buffer2(data, len);
45+
}
46+
47+
virtual size_t v_get_buffer1(uint8_t *data, size_t len) {
48+
return get_buffer1(data, len);
49+
}
50+
51+
private:
52+
53+
std::vector<uint8_t> m_buf;
54+
};

tests/cpp/rpytest/ft/include/ignore.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ struct IgnoredClassWithEnum {
1919

2020
struct ClassWithIgnored {
2121

22+
// constructor with ignored param
23+
ClassWithIgnored(int y) {}
24+
2225
// class function
2326
int fnIgnore() { return 0x2; }
2427

tests/cpp/rpytest/ft/include/inheritance/ibase.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,31 @@ struct IBase
1111
IBase() {}
1212
virtual ~IBase() {}
1313

14+
/** doc: base::baseOnly */
1415
virtual std::string baseOnly()
1516
{
1617
return "base::baseOnly";
1718
}
1819

20+
/** doc: base::baseAndGrandchild */
1921
virtual std::string baseAndGrandchild()
2022
{
2123
return "base::baseAndGrandchild";
2224
}
2325

26+
/** doc: base::baseAndChild */
2427
virtual std::string baseAndChild()
2528
{
2629
return "base::baseAndChild";
2730
}
2831

32+
/** doc: base::baseAndPyChild */
2933
virtual std::string baseAndPyChild()
3034
{
3135
return "base::baseAndPyChild";
3236
}
3337

38+
/** doc: base::baseAndChildFinal */
3439
virtual std::string baseAndChildFinal()
3540
{
3641
return "base::baseAndChildFinal";

tests/cpp/rpytest/ft/include/inheritance/ichild.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ struct IChild : IBase
1010
{
1111
IChild() : IBase(), i(42) {}
1212

13+
/** doc: child::baseAndChild */
1314
std::string baseAndChild() override
1415
{
1516
return "child::baseAndChild";
1617
}
1718

19+
/** doc: child::baseAndChildFinal */
1820
std::string baseAndChildFinal() final
1921
{
2022
return "child::baseAndChildFinal";

0 commit comments

Comments
 (0)