forked from smooth80/defold
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_record.cpp
134 lines (120 loc) · 3.9 KB
/
test_record.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright 2020 The Defold Foundation
// Licensed under the Defold License version 1.0 (the "License"); you may not use
// this file except in compliance with the License.
//
// You may obtain a copy of the License, together with FAQs at
// https://www.defold.com/license
//
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
#include <stdint.h>
#include <stdlib.h>
#include <string>
#define JC_TEST_IMPLEMENTATION
#include <jc_test/jc_test.h>
#include "../record/record.h"
#if !defined(__NX__) // disabled platforms
TEST(dmRecord, InvalidWidth1)
{
dmRecord::NewParams params;
params.m_Width = 1281;
params.m_Height = 720;
params.m_Filename = "tmp/test.ivf";
dmRecord::HRecorder recorder = 0;
dmRecord::Result r = dmRecord::New(¶ms, &recorder);
ASSERT_EQ(dmRecord::RESULT_INVAL_ERROR, r);
ASSERT_EQ(0, recorder);
}
TEST(dmRecord, InvalidWidth2)
{
dmRecord::NewParams params;
params.m_Width = 0;
params.m_Height = 720;
params.m_Filename = "tmp/test.ivf";
dmRecord::HRecorder recorder = 0;
dmRecord::Result r = dmRecord::New(¶ms, &recorder);
ASSERT_EQ(dmRecord::RESULT_INVAL_ERROR, r);
ASSERT_EQ(0, recorder);
}
TEST(dmRecord, InvalidHeight1)
{
dmRecord::NewParams params;
params.m_Width = 1280;
params.m_Height = 721;
params.m_Filename = "tmp/test.ivf";
dmRecord::HRecorder recorder = 0;
dmRecord::Result r = dmRecord::New(¶ms, &recorder);
ASSERT_EQ(dmRecord::RESULT_INVAL_ERROR, r);
ASSERT_EQ(0, recorder);
}
TEST(dmRecord, InvalidHeight2)
{
dmRecord::NewParams params;
params.m_Width = 1280;
params.m_Height = 0;
params.m_Filename = "tmp/test.ivf";
dmRecord::HRecorder recorder = 0;
dmRecord::Result r = dmRecord::New(¶ms, &recorder);
ASSERT_EQ(dmRecord::RESULT_INVAL_ERROR, r);
ASSERT_EQ(0, recorder);
}
TEST(dmRecord, EmptyRecording)
{
dmRecord::NewParams params;
params.m_Width = 1280;
params.m_Height = 720;
params.m_Filename = "tmp/test.ivf";
dmRecord::HRecorder recorder = 0;
dmRecord::Result r = dmRecord::New(¶ms, &recorder);
ASSERT_EQ(dmRecord::RESULT_OK, r);
r = dmRecord::Delete(recorder);
ASSERT_EQ(dmRecord::RESULT_OK, r);
}
TEST(dmRecord, Simple)
{
dmRecord::NewParams params;
params.m_Width = 1280;
params.m_Height = 720;
params.m_Filename = "tmp/simple.ivf";
dmRecord::HRecorder recorder = 0;
dmRecord::Result r = dmRecord::New(¶ms, &recorder);
ASSERT_EQ(dmRecord::RESULT_OK, r);
uint32_t buffer_size_ints = params.m_Width * params.m_Height;
uint32_t buffer_size_bytes = params.m_Width * params.m_Height * sizeof(uint32_t);
uint32_t *buffer = new uint32_t[buffer_size_ints];
for (uint32_t i = 0; i < 64; ++i)
{
// Rectangle two pixel per frame to the right
for (uint32_t y = 0; y < params.m_Height; ++y)
{
for (uint32_t x = 0; x < params.m_Width; ++x)
{
if (x >= i*2 && x < (i*2 + 128) && y < 128)
{
buffer[y * params.m_Width + x] = 0x0000ff00;
}
else
{
buffer[y * params.m_Width + x] = 0;
}
}
}
r = dmRecord::RecordFrame(recorder, buffer, buffer_size_bytes,
dmRecord::BUFFER_FORMAT_BGRA);
ASSERT_EQ(dmRecord::RESULT_OK, r);
}
delete[] buffer;
r = dmRecord::Delete(recorder);
ASSERT_EQ(dmRecord::RESULT_OK, r);
}
#endif
int main(int argc, char **argv)
{
#if !defined(DM_NO_SYSTEM_FUNCTION)
system("python src/test/test_record.py");
#endif
jc_test_init(&argc, argv);
return jc_test_run_all();
}