2 * Copyright 2014 Haiku, Inc.
3 * Distributed under the terms of the MIT License.
11 #include <cppunit/TestCaller.h>
12 #include <cppunit/TestSuite.h>
28 int * ptr
= new int[1];
35 get_area_info(id
, &info
);
36 adr
= (char *)info
.address
;
37 offset
= (ptrdiff_t)ptr
- (ptrdiff_t)adr
;
47 idclone1
= clone_area("clone 1", (void **)&adrclone1
, B_ANY_ADDRESS
,
48 B_READ_AREA
| B_WRITE_AREA
, id
);
49 idclone2
= clone_area("clone 2", (void **)&adrclone2
, B_ANY_ADDRESS
,
50 B_READ_AREA
| B_WRITE_AREA
, id
);
52 ptrclone1
= (int *)(adrclone1
+ offset
);
53 ptrclone2
= (int *)(adrclone2
+ offset
);
55 // Check that he pointer is inside the area returned by area_for...
56 CPPUNIT_ASSERT(offset
>= 0);
58 // Chech that the clones have different IDs
59 CPPUNIT_ASSERT(id
!= idclone1
);
60 CPPUNIT_ASSERT(id
!= idclone2
);
61 CPPUNIT_ASSERT(idclone1
!= idclone2
);
63 // Check that the clones have different addresses
64 CPPUNIT_ASSERT(adr
!= adrclone1
);
65 CPPUNIT_ASSERT(adr
!= adrclone2
);
66 CPPUNIT_ASSERT(adrclone1
!= adrclone2
);
68 // Check that changes on one view of the area are visible in others.
70 CPPUNIT_ASSERT(ptr
[0] == ptrclone1
[0]);
71 CPPUNIT_ASSERT(ptrclone2
[0] == ptrclone1
[0]);
72 CPPUNIT_ASSERT_EQUAL(0x12345678, ptrclone2
[0]);
77 AreaTest::AddTests(BTestSuite
& parent
)
79 CppUnit::TestSuite
& suite
= *new CppUnit::TestSuite("AreaTest");
81 suite
.addTest(new CppUnit::TestCaller
<AreaTest
>(
82 "AreaTest::TestAreas", &AreaTest::TestAreas
));
84 parent
.addTest("AreaTest", &suite
);