1use strict;
2use warnings;
3use Test::More tests => 7;
4# This is the union runtime testcase. It ensures that values within a
5# union embedded within a struct can be set and read correctly.
6
7BEGIN { use_ok('unions') }
8require_ok('unions');
9
10# Create new instances of SmallStruct and BigStruct for later use
11my $small = new unions::SmallStruct();
12$small->{jill} = 200;
13
14my $big = new unions::BigStruct();
15$big->{smallstruct} = $small;
16$big->{jack} = 300;
17
18# Use SmallStruct then BigStruct to setup EmbeddedUnionTest.
19# Ensure values in EmbeddedUnionTest are set correctly for each.
20my $eut = new unions::EmbeddedUnionTest();
21
22# First check the SmallStruct in EmbeddedUnionTest
23$eut->{number} = 1;
24$eut->{uni}->{small} = $small;
25my $Jill1 = $eut->{uni}->{small}->{jill};
26is($Jill1, 200, "eut.uni.small.jill");
27
28my $Num1 = $eut->{number};
29is($Num1, 1, "test2 eut.number");
30
31# Secondly check the BigStruct in EmbeddedUnionTest
32$eut->{number} = 2;
33$eut->{uni}->{big} = $big;
34my $Jack1 = $eut->{uni}->{big}->{jack};
35is($Jack1, 300, "test3 eut.uni.big.jack");
36
37my $Jill2 = $eut->{uni}->{big}->{smallstruct}->{jill};
38is($Jill2, 200, "test4 eut.uni.big.smallstruct.jill");
39
40my $Num2 = $eut->{number};
41is($Num2,  2, "test5 eut.number");
42
43