Skip to content

Commit

Permalink
Convert AreaTest to cppunit.
Browse files Browse the repository at this point in the history
  • Loading branch information
pulkomandy committed Oct 22, 2014
1 parent d21b5a0 commit 55935df
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 18 deletions.
65 changes: 49 additions & 16 deletions src/tests/kits/media/AreaTest.cpp
@@ -1,8 +1,29 @@
/*
* Copyright 2014 Haiku, Inc.
* Distributed under the terms of the MIT License.
*/


#include "AreaTest.h"

#include <OS.h>
#include <stdio.h>

#include <cppunit/TestCaller.h>
#include <cppunit/TestSuite.h>


AreaTest::AreaTest()
{
}


AreaTest::~AreaTest()
{
}


int main()
void
AreaTest::TestAreas()
{
int * ptr = new int[1];
char *adr;
Expand Down Expand Up @@ -31,22 +52,34 @@ int main()
ptrclone1 = (int *)(adrclone1 + offset);
ptrclone2 = (int *)(adrclone2 + offset);

printf("offset = 0x%08x\n", (int)offset);
printf("id = 0x%08x\n", (int)id);
printf("id clone 1 = 0x%08x\n", (int)idclone1);
printf("id clone 2 = 0x%08x\n", (int)idclone2);
printf("adr = 0x%08x\n", (int)adr);
printf("adr clone 1 = 0x%08x\n", (int)adrclone1);
printf("adr clone 2 = 0x%08x\n", (int)adrclone2);
printf("ptr = 0x%08x\n", (int)ptr);
printf("ptr clone 1 = 0x%08x\n", (int)ptrclone1);
printf("ptr clone 2 = 0x%08x\n", (int)ptrclone2);
// Check that he pointer is inside the area returned by area_for...
CPPUNIT_ASSERT(offset >= 0);

// Chech that the clones have different IDs
CPPUNIT_ASSERT(id != idclone1);
CPPUNIT_ASSERT(id != idclone2);
CPPUNIT_ASSERT(idclone1 != idclone2);

// Check that the clones have different addresses
CPPUNIT_ASSERT(adr != adrclone1);
CPPUNIT_ASSERT(adr != adrclone2);
CPPUNIT_ASSERT(adrclone1 != adrclone2);

// Check that changes on one view of the area are visible in others.
ptr[0] = 0x12345678;
CPPUNIT_ASSERT(ptr[0] == ptrclone1[0]);
CPPUNIT_ASSERT(ptrclone2[0] == ptrclone1[0]);
CPPUNIT_ASSERT_EQUAL(0x12345678, ptrclone2[0]);
}


/*static*/ void
AreaTest::AddTests(BTestSuite& parent)
{
CppUnit::TestSuite& suite = *new CppUnit::TestSuite("AreaTest");

printf("ptr[0] = 0x%08x\n", (int)ptr[0]);
printf("ptr clone 1[0] = 0x%08x\n", (int)ptrclone1[0]);
printf("ptr clone 2[0] = 0x%08x\n", (int)ptrclone2[0]);
suite.addTest(new CppUnit::TestCaller<AreaTest>(
"AreaTest::TestAreas", &AreaTest::TestAreas));

return 0;
parent.addTest("AreaTest", &suite);
}
25 changes: 25 additions & 0 deletions src/tests/kits/media/AreaTest.h
@@ -0,0 +1,25 @@
/*
* Copyright 2014 Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef AREA_TEST_H
#define AREA_TEST_H


#include <TestCase.h>
#include <TestSuite.h>


class AreaTest: public BTestCase {
public:
AreaTest();
virtual ~AreaTest();

void TestAreas();

static void AddTests(BTestSuite& suite);
};


#endif

10 changes: 8 additions & 2 deletions src/tests/kits/media/Jamfile
@@ -1,7 +1,5 @@
SubDir HAIKU_TOP src tests kits media ;

SimpleTest AreaTest : AreaTest.cpp : be [ TargetLibsupc++ ] ;

SimpleTest BufferTest : BufferTest.cpp : libmedia.so be [ TargetLibsupc++ ] ;

SimpleTest SizeofTest : SizeofTest.cpp : be ;
Expand All @@ -17,6 +15,14 @@ SimpleTest mediaDescriptions :
mediaDescriptions.cpp
: media ;

UnitTestLib libmediatest.so :
MediaKitTestAddon.cpp

AreaTest.cpp

: be [ TargetLibstdc++ ] [ TargetLibsupc++ ]
;

SubInclude HAIKU_TOP src tests kits media media_decoder ;
SubInclude HAIKU_TOP src tests kits media mpeg2_decoder_test ;
SubInclude HAIKU_TOP src tests kits media mp3_decoder_test ;
Expand Down
22 changes: 22 additions & 0 deletions src/tests/kits/media/MediaKitTestAddon.cpp
@@ -0,0 +1,22 @@
/*
* Copyright 2014 Haiku, Inc.
* Distributed under the terms of the MIT License.
*/


#include <TestSuite.h>
#include <TestSuiteAddon.h>

#include "AreaTest.h"


BTestSuite*
getTestSuite()
{
BTestSuite* suite = new BTestSuite("MediaKit");

AreaTest::AddTests(*suite);

return suite;
}

0 comments on commit 55935df

Please sign in to comment.