Skip to content

Additional struct integration tests #943

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

Merged
merged 2 commits into from
Jun 3, 2022
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@


/* -------------------------- NEW OUTPUT -------------------------- */

namespace LIBRARY_NAMESPACE
{
public struct vec2
{
public float x;
public float y;
}
public struct vec3
{
public vec2 Base;
public float z;
}
public struct vec4
{
public vec3 Base;
public float w;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


/* -------------------------- NEW OUTPUT -------------------------- */

namespace LIBRARY_NAMESPACE
{
public struct x
{
public y* p;
}
public struct y
{
public x* q;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,96 @@ typedef struct {
} Test;");
return Verifier.Verify(result);
}

[Fact]
public Task Test2()
{
var result = TestHelper.GetCSharpOutputFromCpp(@"
struct vec2 { float x, y; };
struct vec3 : vec2 { float z; };
struct vec4 : vec3 { float w; };");
return Verifier.Verify(result);
}

[Fact(Skip = "Union Support")]
public Task Test3()
{
// from https://en.cppreference.com/w/c/language/struct
var result = TestHelper.GetCSharpOutputFromCpp(@"
struct v {
union { // anonymous union
struct { int i, j; }; // anonymous structure
struct { long k, l; } w;
};
int m;
} v1;");
return Verifier.Verify(result);
}

[Fact]
public Task Test4()
{
// from https://en.cppreference.com/w/c/language/struct
var result = TestHelper.GetCSharpOutputFromCpp(@"
struct y;
struct x { struct y *p; /* ... */ };
struct y { struct x *q; /* ... */ };");
return Verifier.Verify(result);
}

[Fact(Skip = "Union Support")]
public Task Test5()
{
// from https://en.cppreference.com/w/cpp/language/union
var result = TestHelper.GetCSharpOutputFromCpp(@"
#include <iostream>
#include <cstdint>
union S
{
std::int32_t n; // occupies 4 bytes
std::uint16_t s[2]; // occupies 4 bytes
std::uint8_t c; // occupies 1 byte
}; ");
return Verifier.Verify(result);
}

[Fact(Skip = "Union Support")]
public Task Test6()
{
// from https://en.cppreference.com/w/cpp/language/union
var result = TestHelper.GetCSharpOutputFromCpp(@"
#include <iostream>
#include <string>
#include <vector>

union S
{
std::string str;
std::vector<int> vec;
~S() {} // needs to know which member is active, only possible in union-like class
}; // the whole union occupies max(sizeof(string), sizeof(vector<int>))");
return Verifier.Verify(result);
}

[Fact(Skip = "Union Support, Enum Support")]
public Task Test7()
{
// from https://en.cppreference.com/w/cpp/language/union
var result = TestHelper.GetCSharpOutputFromCpp(@"
#include <iostream>

// S has one non-static data member (tag), three enumerator members (CHAR, INT, DOUBLE),
// and three variant members (c, i, d)
struct S
{
enum{CHAR, INT, DOUBLE} tag;
union
{
char c;
int i;
double d;
};
};");
return Verifier.Verify(result);
}
}