repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / tests / kits / media / AreaTest.cpp
blobd960ed0331728f4ccc65b4892119b14d684f7758
1 /*
2 * Copyright 2014 Haiku, Inc.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "AreaTest.h"
9 #include <OS.h>
11 #include <cppunit/TestCaller.h>
12 #include <cppunit/TestSuite.h>
15 AreaTest::AreaTest()
20 AreaTest::~AreaTest()
25 void
26 AreaTest::TestAreas()
28 int * ptr = new int[1];
29 char *adr;
30 area_id id;
31 ptrdiff_t offset;
33 area_info info;
34 id = area_for(ptr);
35 get_area_info(id, &info);
36 adr = (char *)info.address;
37 offset = (ptrdiff_t)ptr - (ptrdiff_t)adr;
40 char * adrclone1;
41 char * adrclone2;
42 int * ptrclone1;
43 int * ptrclone2;
44 area_id idclone1;
45 area_id idclone2;
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.
69 ptr[0] = 0x12345678;
70 CPPUNIT_ASSERT(ptr[0] == ptrclone1[0]);
71 CPPUNIT_ASSERT(ptrclone2[0] == ptrclone1[0]);
72 CPPUNIT_ASSERT_EQUAL(0x12345678, ptrclone2[0]);
76 /*static*/ void
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);