Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional tests to cover untested functionality #210

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions tests/cpp/gen/ft/buffers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---

classes:
Buffers:
methods:
set_buffer:
buffers:
- { type: in, src: data, len: len }
get_buffer2:
buffers:
- { type: out, src: data, len: len }
get_buffer1:
buffers:
- { type: out, src: data, len: len }

v_set_buffer:
buffers:
- { type: in, src: data, len: len }
v_get_buffer2:
buffers:
- { type: out, src: data, len: len }
v_get_buffer1:
buffers:
- { type: out, src: data, len: len }
21 changes: 20 additions & 1 deletion tests/cpp/gen/ft/ignore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ functions:
classes:
IgnoredClass:
ignore: true
IgnoredTemplatedClass:
ignore: true
IgnoredClassWithEnum:
ignore: true
ClassWithIgnored:
Expand All @@ -36,6 +38,15 @@ classes:
Param1:
ignore: true
methods:
ClassWithIgnored:
cpp_code: |
[](py::args) {
return std::make_shared<ClassWithIgnored>(1);
}
keepalive: []
param_override:
y:
ignore: true
fnIgnore:
ignore: true
fnIgnoredParam:
Expand All @@ -46,4 +57,12 @@ classes:
cpp_code: |
[](ClassWithIgnored * self, int y) {
return self->fnIgnoredParam(42, y);
}
}
ClassWithIgnoredBase:
ignored_bases:
- IgnoredClass
force_no_trampoline: true
ClassWithIgnoredTemplateBase:
ignored_bases:
- IgnoredTemplatedClass<std::vector<int>>
force_no_trampoline: true
7 changes: 7 additions & 0 deletions tests/cpp/gen/ft/inline_code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

classes:
InlineCode:
constants:
- NS::inner::KONSTANT
enums:
MyE:
inline_code: |
.value("Value2", (InlineCode::MyE)2)
methods:
get2:
cpp_code_with_constant:
cpp_code: |
[](InlineCode *self) {
return KONSTANT;
}
inline_code: |
// you can even start with a comment
.def("get4", [](InlineCode *self) {
Expand Down
5 changes: 5 additions & 0 deletions tests/cpp/gen/ft/virtual_xform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ functions:
classes:
VBase:
methods:
different_cpp_and_py:
cpp_code: |
[](VBase * self, int x) {
return x + 2;
}
pure_io:
param_override:
ss:
Expand Down
2 changes: 2 additions & 0 deletions tests/cpp/pyproject.toml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ generate = [
{ abstract = "abstract.h" },
{ base_qualname = "base_qualname.h" },
{ base_qualname_hidden = "base_qualname_hidden.h" },
{ buffers = "buffers.h" },
{ custom_type_caster = "custom_type_caster.h" },
{ defaults = "defaults.h" },
{ docstrings = "docstrings.h" },
Expand All @@ -56,6 +57,7 @@ generate = [
{ inline_code = "inline_code.h" },
{ lifetime = "lifetime.h" },
{ nested = "nested.h" },
{ operators = "operators.h" },
{ overloads = "overloads.h" },
{ parameters = "parameters.h" },
{ refqual = "refqual.h" },
Expand Down
6 changes: 6 additions & 0 deletions tests/cpp/rpytest/ft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# autogenerated by 'robotpy-build create-imports rpytest.ft rpytest.ft._rpytest_ft'
from ._rpytest_ft import (
Abstract,
Buffers,
ClassWithFields,
ClassWithIgnored,
ClassWithTrampoline,
Expand All @@ -19,6 +20,7 @@
GEnum,
GEnumMath,
HasFactory,
HasOperator,
IBase,
IChild,
IFinal,
Expand Down Expand Up @@ -80,6 +82,7 @@
VChild,
VirtualComma,
checkConvertRpyintToInt,
check_different_cpp_and_py,
check_impure_io,
check_pure_io,
convertRpyintToInt,
Expand Down Expand Up @@ -107,6 +110,7 @@

__all__ = [
"Abstract",
"Buffers",
"ClassWithFields",
"ClassWithIgnored",
"ClassWithTrampoline",
Expand All @@ -123,6 +127,7 @@
"GEnum",
"GEnumMath",
"HasFactory",
"HasOperator",
"IBase",
"IChild",
"IFinal",
Expand Down Expand Up @@ -184,6 +189,7 @@
"VChild",
"VirtualComma",
"checkConvertRpyintToInt",
"check_different_cpp_and_py",
"check_impure_io",
"check_pure_io",
"convertRpyintToInt",
Expand Down
54 changes: 54 additions & 0 deletions tests/cpp/rpytest/ft/include/buffers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#pragma once

#include <cstring>
#include <vector>

class Buffers {
public:

// in
void set_buffer(const uint8_t *data, size_t len) {
m_buf.resize(len);
memcpy(m_buf.data(), data, len);
}

// out
// - data is bytes
// - len is input_size and output size
void get_buffer2(uint8_t *data, size_t *len) {
*len = get_buffer1(data, *len);
}

// out
// - data is bytes
// - len is input size
// - return value is output size
size_t get_buffer1(uint8_t *data, size_t len) {
size_t rlen = len < m_buf.size() ? len : m_buf.size();
if (rlen) {
memcpy(data, m_buf.data(), rlen);
}
return rlen;
}

//
// virtual functions -- trampolines are disabled but normal function
// calls work
//

virtual void v_set_buffer(const uint8_t *data, size_t len) {
set_buffer(data, len);
}

virtual void v_get_buffer2(uint8_t *data, size_t *len) {
get_buffer2(data, len);
}

virtual size_t v_get_buffer1(uint8_t *data, size_t len) {
return get_buffer1(data, len);
}

private:

std::vector<uint8_t> m_buf;
};
14 changes: 14 additions & 0 deletions tests/cpp/rpytest/ft/include/ignore.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <vector>

//
// Test anything that can be ignored
//
Expand All @@ -13,12 +15,18 @@ int fnIgnoredParam(int x) { return x; }
// class
struct IgnoredClass {};

template <typename T>
struct IgnoredTemplatedClass {};

struct IgnoredClassWithEnum {
enum AlsoIgnored { Value = 1 };
};

struct ClassWithIgnored {

// constructor with ignored param
ClassWithIgnored(int y) {}

// class function
int fnIgnore() { return 0x2; }

Expand All @@ -39,6 +47,12 @@ struct ClassWithIgnored {
};
};

struct ClassWithIgnoredBase : IgnoredClass {
};

struct ClassWithIgnoredTemplateBase : IgnoredTemplatedClass<std::vector<int>> {
};

// enums
enum IgnoredEnum {
Original1 = 1
Expand Down
5 changes: 5 additions & 0 deletions tests/cpp/rpytest/ft/include/inheritance/ibase.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,31 @@ struct IBase
IBase() {}
virtual ~IBase() {}

/** doc: base::baseOnly */
virtual std::string baseOnly()
{
return "base::baseOnly";
}

/** doc: base::baseAndGrandchild */
virtual std::string baseAndGrandchild()
{
return "base::baseAndGrandchild";
}

/** doc: base::baseAndChild */
virtual std::string baseAndChild()
{
return "base::baseAndChild";
}

/** doc: base::baseAndPyChild */
virtual std::string baseAndPyChild()
{
return "base::baseAndPyChild";
}

/** doc: base::baseAndChildFinal */
virtual std::string baseAndChildFinal()
{
return "base::baseAndChildFinal";
Expand Down
2 changes: 2 additions & 0 deletions tests/cpp/rpytest/ft/include/inheritance/ichild.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ struct IChild : IBase
{
IChild() : IBase(), i(42) {}

/** doc: child::baseAndChild */
std::string baseAndChild() override
{
return "child::baseAndChild";
}

/** doc: child::baseAndChildFinal */
std::string baseAndChildFinal() final
{
return "child::baseAndChildFinal";
Expand Down
1 change: 1 addition & 0 deletions tests/cpp/rpytest/ft/include/inheritance/igchild.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace inheritance

struct IGrandChild final : IChild
{
/** doc: grandchild::baseAndGrandchild */
std::string baseAndGrandchild() override
{
return "grandchild::baseAndGrandchild";
Expand Down
2 changes: 2 additions & 0 deletions tests/cpp/rpytest/ft/include/inheritance/imchild.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ struct IMOther {
// a child that does multiple inheritance
struct IMChild : IBase, IMOther {

/** doc: mchild::baseAndChild */
std::string baseAndChild() override { return "mchild::baseAndChild"; }

/** doc: mchild::baseAndChildFinal */
std::string baseAndChildFinal() final { return "mchild::baseAndChildFinal"; }
};

Expand Down
6 changes: 6 additions & 0 deletions tests/cpp/rpytest/ft/include/inline_code.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@

#pragma once

namespace NS::inner {
static constexpr auto KONSTANT = 4;
}

class InlineCode {
public:
enum MyE {
Value1 = 1
};

int get2() const { return 2; }

int cpp_code_with_constant() { return 3; }
};
14 changes: 14 additions & 0 deletions tests/cpp/rpytest/ft/include/operators.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

class HasOperator {
public:
HasOperator() : m_i(0) {}
HasOperator(int i) : m_i(i) {}

bool operator==(const HasOperator &o) const {
return m_i == o.m_i;
}

private:
int m_i;
};
5 changes: 5 additions & 0 deletions tests/cpp/rpytest/ft/include/overloads.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ struct OverloadedObject
return o;
}

// This shows rtnType is inconsistent in CppHeaderParser
const OverloadedObject& overloaded() {
return *this;
}

constexpr int overloaded_constexpr(int a, int b) {
return a + b;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/cpp/rpytest/ft/include/virtual_comma.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@

struct VirtualComma
{
struct RVal {};

virtual ~VirtualComma() {}

virtual std::pair<int, int> getTwoTwo()
{
return std::pair<int, int>{1, 2};
}

// ensures that RVal is recognized as VirtualComma::RVal
virtual RVal getRval() {
return RVal{};
}

int getRval(int) { return 1; }
};
Loading