Convert BufferTest to cppunit.

This commit is contained in:
Adrien Destugues
2014-10-22 11:11:55 +02:00
parent 55935df47d
commit 2521f8ea39
4 changed files with 111 additions and 60 deletions
+79 -57
View File
@@ -1,9 +1,31 @@
/*
* Copyright 2014 Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#include "BufferTest.h"
#include <Application.h>
#include <BufferGroup.h>
#include <Buffer.h>
#include <stdio.h>
int main()
#include <cppunit/TestCaller.h>
#include <cppunit/TestSuite.h>
BufferTest::BufferTest()
{
}
BufferTest::~BufferTest()
{
}
void
BufferTest::TestDefault()
{
// app_server connection (no need to run it)
BApplication app("application/x-vnd-test");
@@ -11,91 +33,91 @@ int main()
BBufferGroup * group;
status_t s;
int32 count;
BBuffer *buffer;
/*
printf("using default constructor:\n");
group = new BBufferGroup();
s = group->InitCheck();
printf("InitCheck: status = %ld\n",s);
CPPUNIT_ASSERT_EQUAL(B_OK, s);
s = group->CountBuffers(&count);
printf("CountBuffers: count = %ld, status = %ld\n",count,s);
delete group;
*/
printf("\n");
printf("using size = 1234 constructor:\n");
CPPUNIT_ASSERT_EQUAL(B_OK, s);
CPPUNIT_ASSERT_EQUAL(0, count);
}
void
BufferTest::TestRef()
{
BBufferGroup * group;
status_t s;
int32 count;
BBuffer *buffer;
group = new BBufferGroup(1234);
s = group->InitCheck();
printf("InitCheck: status = %ld\n",s);
CPPUNIT_ASSERT_EQUAL(B_OK, s);
s = group->CountBuffers(&count);
printf("CountBuffers: count = %ld, status = %ld\n",count,s);
CPPUNIT_ASSERT_EQUAL(B_OK, s);
CPPUNIT_ASSERT_EQUAL(3, count);
s = group->GetBufferList(1,&buffer);
printf("GetBufferList: status = %ld\n",s);
CPPUNIT_ASSERT_EQUAL(B_OK, s);
printf("Buffer->Data: = %08x\n",(int)buffer->Data());
printf("Buffer->ID: = %d\n",(int)buffer->ID());
printf("Buffer->Size: = %ld\n",buffer->Size());
printf("Buffer->SizeAvailable: = %ld\n",buffer->SizeAvailable());
printf("Buffer->SizeUsed: = %ld\n",buffer->SizeUsed());
printf("\n");
CPPUNIT_ASSERT_EQUAL(1234, buffer->Size());
CPPUNIT_ASSERT_EQUAL(1234, buffer->SizeAvailable());
CPPUNIT_ASSERT_EQUAL(0, buffer->SizeUsed());
media_buffer_id id = buffer->ID();
BBufferGroup * group2 = new BBufferGroup(1,&id);
printf("creating second group with a buffer from first group:\n");
s = group2->InitCheck();
printf("InitCheck: status = %ld\n",s);
CPPUNIT_ASSERT_EQUAL(B_OK, s);
s = group2->CountBuffers(&count);
printf("CountBuffers: count = %ld, status = %ld\n",count,s);
CPPUNIT_ASSERT_EQUAL(B_OK, s);
CPPUNIT_ASSERT_EQUAL(1, count);
buffer = 0;
s = group2->GetBufferList(1,&buffer);
printf("GetBufferList: status = %ld\n",s);
printf("Buffer->Data: = %08x\n",(int)buffer->Data());
printf("Buffer->ID: = %d\n",(int)buffer->ID());
printf("Buffer->Size: = %ld\n",buffer->Size());
printf("Buffer->SizeAvailable: = %ld\n",buffer->SizeAvailable());
printf("Buffer->SizeUsed: = %ld\n",buffer->SizeUsed());
CPPUNIT_ASSERT_EQUAL(1234, buffer->Size());
CPPUNIT_ASSERT_EQUAL(1234, buffer->SizeAvailable());
CPPUNIT_ASSERT_EQUAL(0, buffer->SizeUsed());
delete group;
delete group2;
}
printf("\n");
/*
printf("creating a BSmallBuffer:\n");
void
BufferTest::TestSmall()
{
// FIXME currently not implemented, BSmallBuffer constructor will debugger().
#if 0
BSmallBuffer * sb = new BSmallBuffer;
printf("sb->Data: = %08x\n",(int)sb->Data());
printf("sb->ID: = %d\n",(int)sb->ID());
printf("sb->Size: = %ld\n",sb->Size());
printf("sb->SizeAvailable: = %ld\n",sb->SizeAvailable());
printf("sb->SizeUsed: = %ld\n",sb->SizeUsed());
printf("sb->SmallBufferSizeLimit: = %ld\n",sb->SmallBufferSizeLimit());
CPPUNIT_ASSERT_EQUAL(0, sb->Size());
CPPUNIT_ASSERT_EQUAL(0, sb->SizeAvailable());
CPPUNIT_ASSERT_EQUAL(0, sb->SizeUsed());
CPPUNIT_ASSERT_EQUAL(0, sb->SmallBufferSizeLimit());
delete sb;
*/
return 0;
#endif
}
/*static*/ void
BufferTest::AddTests(BTestSuite& parent)
{
CppUnit::TestSuite& suite = *new CppUnit::TestSuite("BufferTest");
suite.addTest(new CppUnit::TestCaller<BufferTest>(
"BufferTest::TestDefault", &BufferTest::TestDefault));
suite.addTest(new CppUnit::TestCaller<BufferTest>(
"BufferTest::TestRef", &BufferTest::TestRef));
suite.addTest(new CppUnit::TestCaller<BufferTest>(
"BufferTest::TestSmall", &BufferTest::TestSmall));
parent.addTest("BufferTest", &suite);
}
+28
View File
@@ -0,0 +1,28 @@
/*
* Copyright 2014 Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef BUFFER_TEST_H
#define BUFFER_TEST_H
#include <TestCase.h>
#include <TestSuite.h>
class BufferTest: public BTestCase {
public:
BufferTest();
virtual ~BufferTest();
void TestDefault();
void TestRef();
void TestSmall();
static void AddTests(BTestSuite& suite);
};
#endif
+2 -3
View File
@@ -1,7 +1,5 @@
SubDir HAIKU_TOP src tests kits media ;
SimpleTest BufferTest : BufferTest.cpp : libmedia.so be [ TargetLibsupc++ ] ;
SimpleTest SizeofTest : SizeofTest.cpp : be ;
SimpleTest TimedEventQueueTest : TimedEventQueueTest.cpp
@@ -19,8 +17,9 @@ UnitTestLib libmediatest.so :
MediaKitTestAddon.cpp
AreaTest.cpp
BufferTest.cpp
: be [ TargetLibstdc++ ] [ TargetLibsupc++ ]
: be media [ TargetLibstdc++ ] [ TargetLibsupc++ ]
;
SubInclude HAIKU_TOP src tests kits media media_decoder ;
@@ -8,6 +8,7 @@
#include <TestSuiteAddon.h>
#include "AreaTest.h"
#include "BufferTest.h"
BTestSuite*
@@ -16,6 +17,7 @@ getTestSuite()
BTestSuite* suite = new BTestSuite("MediaKit");
AreaTest::AddTests(*suite);
BufferTest::AddTests(*suite);
return suite;
}