1use strict;
2use warnings;
3use Test::More;
4
5# this is needed to avoid false passes if was done first without 'info'
6use Inline CPP => config => force_build => 1, clean_after_build => 0;
7
8# Testing proper handling of inherited object methods.
9
10use Inline CPP => <<'END';
11
12class Foo {
13 public:
14   Foo() {
15    secret=0;
16   }
17
18   ~Foo() { }
19
20   int get_secret() { return secret; }
21   void set_secret(int s) { secret = s; }
22
23 protected:
24   int secret;
25};
26
27class Bar : public Foo {
28 public:
29   Bar(int s) { secret = s; }
30   ~Bar() {  }
31
32   void set_secret(int s) { secret = s * 2; }
33};
34
35END
36
37# If it works, it will print this. Otherwise it won't.
38ok(1);
39
40# Test Foo.
41my $o = new_ok( 'Foo' );
42is( $o->get_secret(), 0, "Foo: Object getter." );
43$o->set_secret(539);
44is( $o->get_secret(), 539, "Foo: Object setter." );
45
46
47# Test Bar.
48
49
50my $p = new_ok( 'Bar', [ 11 ] );
51is(
52    $p->get_secret(), 11,
53    "Bar: Overrides constructor, inherits accessor from Foo."
54);
55
56$p->set_secret( 21 );
57is( $p->get_secret(), 42, "Bar: Overrides setter." );
58
59done_testing();
60