aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/test_struct_initialization.sh
blob: 0454c57f747926de7d5e5747f1da90876aeea822 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
cat <<'EOF' > expected
0
1
EOF
test_diff <<'EOF'
int printf();
void* calloc();

struct S {
    int a;
    int b;
};

int main() {
    struct S* s = calloc(1, sizeof(struct S));
    s->b = 1;
    printf("%ld\n", s->a);
    printf("%ld\n", s->b);
    return 0;
}
EOF

cat <<'EOF' > expected
123 456
0 0
123 456
EOF

test_diff <<'EOF'
struct S {
    int a;
    int b;
};
typedef struct S S;

void* calloc();
int printf();

int main() {
    S* s1 = calloc(1, sizeof(S));
    S* s2 = calloc(1, sizeof(S));
    s1->a = 123;
    s1->b = 456;
    printf("%d %d\n", s1->a, s1->b);
    printf("%d %d\n", s2->a, s2->b);
    *s2 = *s1;
    printf("%d %d\n", s2->a, s2->b);
}
EOF

cat <<'EOF' > expected
123 456
0 0
123 456
EOF

test_diff <<'EOF'
struct S {
    long a;
    long b;
};
typedef struct S S;

void* calloc();
int printf();

int main() {
    S* s1 = calloc(1, sizeof(S));
    S* s2 = calloc(1, sizeof(S));
    s1->a = 123;
    s1->b = 456;
    printf("%d %d\n", s1->a, s1->b);
    printf("%d %d\n", s2->a, s2->b);
    *s2 = *s1;
    printf("%d %d\n", s2->a, s2->b);
}
EOF

cat <<'EOF' > expected
123 456
0 0
123 456
EOF

test_diff <<'EOF'
struct S {
    long a;
    long b;
};
typedef struct S S;

void* calloc();
int printf();

int main() {
    S s1;
    S s2;
    s1.a = 123;
    s1.b = 456;
    s2.a = 0;
    s2.b = 0;
    printf("%d %d\n", s1.a, s1.b);
    printf("%d %d\n", s2.a, s2.b);
    s2 = s1;
    printf("%d %d\n", s2.a, s2.b);
}
EOF