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 <Application.h>
#include <BufferGroup.h> #include <BufferGroup.h>
#include <Buffer.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) // app_server connection (no need to run it)
BApplication app("application/x-vnd-test"); BApplication app("application/x-vnd-test");
@@ -11,91 +33,91 @@ int main()
BBufferGroup * group; BBufferGroup * group;
status_t s; status_t s;
int32 count; int32 count;
BBuffer *buffer;
/*
printf("using default constructor:\n");
group = new BBufferGroup(); group = new BBufferGroup();
s = group->InitCheck(); s = group->InitCheck();
printf("InitCheck: status = %ld\n",s); CPPUNIT_ASSERT_EQUAL(B_OK, s);
s = group->CountBuffers(&count); s = group->CountBuffers(&count);
printf("CountBuffers: count = %ld, status = %ld\n",count,s); CPPUNIT_ASSERT_EQUAL(B_OK, s);
CPPUNIT_ASSERT_EQUAL(0, count);
delete group; }
*/
printf("\n");
printf("using size = 1234 constructor:\n"); void
BufferTest::TestRef()
{
BBufferGroup * group;
status_t s;
int32 count;
BBuffer *buffer;
group = new BBufferGroup(1234); group = new BBufferGroup(1234);
s = group->InitCheck(); s = group->InitCheck();
printf("InitCheck: status = %ld\n",s); CPPUNIT_ASSERT_EQUAL(B_OK, s);
s = group->CountBuffers(&count); 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); 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()); CPPUNIT_ASSERT_EQUAL(1234, buffer->Size());
CPPUNIT_ASSERT_EQUAL(1234, buffer->SizeAvailable());
printf("Buffer->ID: = %d\n",(int)buffer->ID()); CPPUNIT_ASSERT_EQUAL(0, buffer->SizeUsed());
printf("Buffer->Size: = %ld\n",buffer->Size());
printf("Buffer->SizeAvailable: = %ld\n",buffer->SizeAvailable());
printf("Buffer->SizeUsed: = %ld\n",buffer->SizeUsed());
printf("\n");
media_buffer_id id = buffer->ID(); media_buffer_id id = buffer->ID();
BBufferGroup * group2 = new BBufferGroup(1,&id); BBufferGroup * group2 = new BBufferGroup(1,&id);
printf("creating second group with a buffer from first group:\n");
s = group2->InitCheck(); s = group2->InitCheck();
printf("InitCheck: status = %ld\n",s); CPPUNIT_ASSERT_EQUAL(B_OK, s);
s = group2->CountBuffers(&count); 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; buffer = 0;
s = group2->GetBufferList(1,&buffer); s = group2->GetBufferList(1,&buffer);
printf("GetBufferList: status = %ld\n",s);
printf("Buffer->Data: = %08x\n",(int)buffer->Data()); CPPUNIT_ASSERT_EQUAL(1234, buffer->Size());
CPPUNIT_ASSERT_EQUAL(1234, buffer->SizeAvailable());
printf("Buffer->ID: = %d\n",(int)buffer->ID()); CPPUNIT_ASSERT_EQUAL(0, buffer->SizeUsed());
printf("Buffer->Size: = %ld\n",buffer->Size());
printf("Buffer->SizeAvailable: = %ld\n",buffer->SizeAvailable());
printf("Buffer->SizeUsed: = %ld\n",buffer->SizeUsed());
delete group; delete group;
delete group2; delete group2;
}
printf("\n");
/* void
printf("creating a BSmallBuffer:\n"); BufferTest::TestSmall()
{
// FIXME currently not implemented, BSmallBuffer constructor will debugger().
#if 0
BSmallBuffer * sb = new BSmallBuffer; BSmallBuffer * sb = new BSmallBuffer;
CPPUNIT_ASSERT_EQUAL(0, sb->Size());
printf("sb->Data: = %08x\n",(int)sb->Data()); CPPUNIT_ASSERT_EQUAL(0, sb->SizeAvailable());
CPPUNIT_ASSERT_EQUAL(0, sb->SizeUsed());
printf("sb->ID: = %d\n",(int)sb->ID()); CPPUNIT_ASSERT_EQUAL(0, sb->SmallBufferSizeLimit());
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());
delete sb; delete sb;
*/ #endif
return 0; }
/*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 ; SubDir HAIKU_TOP src tests kits media ;
SimpleTest BufferTest : BufferTest.cpp : libmedia.so be [ TargetLibsupc++ ] ;
SimpleTest SizeofTest : SizeofTest.cpp : be ; SimpleTest SizeofTest : SizeofTest.cpp : be ;
SimpleTest TimedEventQueueTest : TimedEventQueueTest.cpp SimpleTest TimedEventQueueTest : TimedEventQueueTest.cpp
@@ -19,8 +17,9 @@ UnitTestLib libmediatest.so :
MediaKitTestAddon.cpp MediaKitTestAddon.cpp
AreaTest.cpp AreaTest.cpp
BufferTest.cpp
: be [ TargetLibstdc++ ] [ TargetLibsupc++ ] : be media [ TargetLibstdc++ ] [ TargetLibsupc++ ]
; ;
SubInclude HAIKU_TOP src tests kits media media_decoder ; SubInclude HAIKU_TOP src tests kits media media_decoder ;
@@ -8,6 +8,7 @@
#include <TestSuiteAddon.h> #include <TestSuiteAddon.h>
#include "AreaTest.h" #include "AreaTest.h"
#include "BufferTest.h"
BTestSuite* BTestSuite*
@@ -16,6 +17,7 @@ getTestSuite()
BTestSuite* suite = new BTestSuite("MediaKit"); BTestSuite* suite = new BTestSuite("MediaKit");
AreaTest::AddTests(*suite); AreaTest::AddTests(*suite);
BufferTest::AddTests(*suite);
return suite; return suite;
} }