repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / tests / kits / media / BufferTest.cpp
blobb9b72d028e741cabd77d749e7c9e3344634a8335
1 /*
2 * Copyright 2014 Haiku, Inc.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "BufferTest.h"
9 #include <Application.h>
10 #include <BufferGroup.h>
11 #include <Buffer.h>
13 #include <cppunit/TestCaller.h>
14 #include <cppunit/TestSuite.h>
17 BufferTest::BufferTest()
22 BufferTest::~BufferTest()
27 void
28 BufferTest::TestDefault()
30 // app_server connection (no need to run it)
31 BApplication app("application/x-vnd-test");
33 BBufferGroup * group;
34 status_t s;
35 int32 count;
37 group = new BBufferGroup();
39 s = group->InitCheck();
40 CPPUNIT_ASSERT_EQUAL(B_OK, s);
42 s = group->CountBuffers(&count);
43 CPPUNIT_ASSERT_EQUAL(B_OK, s);
44 CPPUNIT_ASSERT_EQUAL(0, count);
48 void
49 BufferTest::TestRef()
51 BBufferGroup * group;
52 status_t s;
53 int32 count;
54 BBuffer *buffer;
56 group = new BBufferGroup(1234);
58 s = group->InitCheck();
59 CPPUNIT_ASSERT_EQUAL(B_OK, s);
61 s = group->CountBuffers(&count);
62 CPPUNIT_ASSERT_EQUAL(B_OK, s);
63 CPPUNIT_ASSERT_EQUAL(3, count);
65 s = group->GetBufferList(1,&buffer);
66 CPPUNIT_ASSERT_EQUAL(B_OK, s);
68 CPPUNIT_ASSERT_EQUAL(1234, buffer->Size());
69 CPPUNIT_ASSERT_EQUAL(1234, buffer->SizeAvailable());
70 CPPUNIT_ASSERT_EQUAL(0, buffer->SizeUsed());
72 media_buffer_id id = buffer->ID();
73 BBufferGroup * group2 = new BBufferGroup(1,&id);
75 s = group2->InitCheck();
76 CPPUNIT_ASSERT_EQUAL(B_OK, s);
78 s = group2->CountBuffers(&count);
79 CPPUNIT_ASSERT_EQUAL(B_OK, s);
80 CPPUNIT_ASSERT_EQUAL(1, count);
82 buffer = 0;
83 s = group2->GetBufferList(1,&buffer);
85 CPPUNIT_ASSERT_EQUAL(1234, buffer->Size());
86 CPPUNIT_ASSERT_EQUAL(1234, buffer->SizeAvailable());
87 CPPUNIT_ASSERT_EQUAL(0, buffer->SizeUsed());
89 delete group;
90 delete group2;
94 void
95 BufferTest::TestSmall()
97 // FIXME currently not implemented, BSmallBuffer constructor will debugger().
98 #if 0
99 BSmallBuffer * sb = new BSmallBuffer;
100 CPPUNIT_ASSERT_EQUAL(0, sb->Size());
101 CPPUNIT_ASSERT_EQUAL(0, sb->SizeAvailable());
102 CPPUNIT_ASSERT_EQUAL(0, sb->SizeUsed());
103 CPPUNIT_ASSERT_EQUAL(0, sb->SmallBufferSizeLimit());
105 delete sb;
106 #endif
110 /*static*/ void
111 BufferTest::AddTests(BTestSuite& parent)
113 CppUnit::TestSuite& suite = *new CppUnit::TestSuite("BufferTest");
115 suite.addTest(new CppUnit::TestCaller<BufferTest>(
116 "BufferTest::TestDefault", &BufferTest::TestDefault));
117 suite.addTest(new CppUnit::TestCaller<BufferTest>(
118 "BufferTest::TestRef", &BufferTest::TestRef));
119 suite.addTest(new CppUnit::TestCaller<BufferTest>(
120 "BufferTest::TestSmall", &BufferTest::TestSmall));
122 parent.addTest("BufferTest", &suite);