Skip to content

Commit 29285ae

Browse files
committed
TEST: Port integration_tests/derived_types_01.f90 from LFortran
1 parent d0c73a8 commit 29285ae

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

integration_tests/struct_01.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#include <iostream>
2+
#include <complex>
3+
4+
using namespace std::complex_literals;
5+
6+
// module derived_types_01_m_01
7+
struct X {
8+
float r;
9+
int i;
10+
};
11+
12+
struct Y {
13+
std::complex<double> c;
14+
struct X d;
15+
};
16+
17+
void set(struct X& a) {
18+
a.i = 1;
19+
a.r = 1.5;
20+
}
21+
// module derived_types_01_m_01
22+
23+
// module derived_types_01_m_02
24+
struct Z {
25+
std::complex<double> k;
26+
struct Y l;
27+
};
28+
// module derived_types_01_m_02
29+
30+
int main() {
31+
32+
struct X b;
33+
struct Z c;
34+
35+
b.i = 5;
36+
b.r = 3.5;
37+
std::cout << b.i << " " << b.r << std::endl;
38+
if( b.i != 5 ) {
39+
exit(2);
40+
}
41+
if( b.r != 3.5 ) {
42+
exit(2);
43+
}
44+
45+
set(b);
46+
std::cout << b.i << " " << b.r << std::endl;
47+
if( b.i != 1 ) {
48+
exit(2);
49+
}
50+
if( b.r != 1.5 ) {
51+
exit(2);
52+
}
53+
54+
c.l.d.r = 2.0;
55+
c.l.d.i = 2;
56+
c.k = 2.0 + 2i;
57+
std::cout << c.l.d.r << " " << c.l.d.i << " " << c.k << std::endl;
58+
if( c.l.d.r != 2.0 ) {
59+
exit(2);
60+
}
61+
if( c.l.d.i != 2 ) {
62+
exit(2);
63+
}
64+
if( c.k != 2.0 + 2i ) {
65+
exit(2);
66+
}
67+
68+
set(c.l.d);
69+
std::cout << c.l.d.r << " " << c.l.d.i << " " << c.k << std::endl;
70+
if( c.l.d.r != 1.5 ) {
71+
exit(2);
72+
}
73+
if( c.l.d.i != 1.0 ) {
74+
exit(2);
75+
}
76+
if( c.k != 2.0 + 2i ) {
77+
exit(2);
78+
}
79+
80+
return 0;
81+
}

0 commit comments

Comments
 (0)