1 /*
2 * Copyright 2014 Haiku, Inc.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7 #include "BufferTest.h"
8
9 #include <Application.h>
10 #include <BufferGroup.h>
11 #include <Buffer.h>
12
13 #include <cppunit/TestCaller.h>
14 #include <cppunit/TestSuite.h>
15
16
BufferTest()17 BufferTest::BufferTest()
18 {
19 }
20
21
~BufferTest()22 BufferTest::~BufferTest()
23 {
24 }
25
26
27 void
TestDefault()28 BufferTest::TestDefault()
29 {
30 // app_server connection (no need to run it)
31 BApplication app("application/x-vnd-test");
32
33 BBufferGroup * group;
34 status_t s;
35 int32 count;
36
37 group = new BBufferGroup();
38
39 s = group->InitCheck();
40 CPPUNIT_ASSERT_EQUAL(B_OK, s);
41
42 s = group->CountBuffers(&count);
43 CPPUNIT_ASSERT_EQUAL(B_OK, s);
44 CPPUNIT_ASSERT_EQUAL(0, count);
45 }
46
47
48 void
TestRef()49 BufferTest::TestRef()
50 {
51 BBufferGroup * group;
52 status_t s;
53 int32 count;
54 BBuffer *buffer;
55
56 group = new BBufferGroup(1234);
57
58 s = group->InitCheck();
59 CPPUNIT_ASSERT_EQUAL(B_OK, s);
60
61 s = group->CountBuffers(&count);
62 CPPUNIT_ASSERT_EQUAL(B_OK, s);
63 CPPUNIT_ASSERT_EQUAL(3, count);
64
65 s = group->GetBufferList(1,&buffer);
66 CPPUNIT_ASSERT_EQUAL(B_OK, s);
67
68 CPPUNIT_ASSERT_EQUAL(1234, buffer->Size());
69 CPPUNIT_ASSERT_EQUAL(1234, buffer->SizeAvailable());
70 CPPUNIT_ASSERT_EQUAL(0, buffer->SizeUsed());
71
72 media_buffer_id id = buffer->ID();
73 BBufferGroup * group2 = new BBufferGroup(1,&id);
74
75 s = group2->InitCheck();
76 CPPUNIT_ASSERT_EQUAL(B_OK, s);
77
78 s = group2->CountBuffers(&count);
79 CPPUNIT_ASSERT_EQUAL(B_OK, s);
80 CPPUNIT_ASSERT_EQUAL(1, count);
81
82 buffer = 0;
83 s = group2->GetBufferList(1,&buffer);
84
85 CPPUNIT_ASSERT_EQUAL(1234, buffer->Size());
86 CPPUNIT_ASSERT_EQUAL(1234, buffer->SizeAvailable());
87 CPPUNIT_ASSERT_EQUAL(0, buffer->SizeUsed());
88
89 delete group;
90 delete group2;
91 }
92
93
94 void
TestSmall()95 BufferTest::TestSmall()
96 {
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());
104
105 delete sb;
106 #endif
107 }
108
109
110 /*static*/ void
AddTests(BTestSuite & parent)111 BufferTest::AddTests(BTestSuite& parent)
112 {
113 CppUnit::TestSuite& suite = *new CppUnit::TestSuite("BufferTest");
114
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));
121
122 parent.addTest("BufferTest", &suite);
123 }
124